summaryrefslogtreecommitdiffstats
path: root/nova/utils.py
diff options
context:
space:
mode:
authorjaypipes@gmail.com <>2011-02-21 10:04:32 -0500
committerjaypipes@gmail.com <>2011-02-21 10:04:32 -0500
commit6facb35c26b2c90d4ba7a34f3eccd10de2fb7207 (patch)
tree29fff56413ee20c45b99ac6596796eadfc94841d /nova/utils.py
parentf02c41a7fe332b215421320d041a944e4b9ee9ee (diff)
parentbd0ca93866b48a7a65de8b97ab0ac0ac9c737f73 (diff)
downloadnova-6facb35c26b2c90d4ba7a34f3eccd10de2fb7207.tar.gz
nova-6facb35c26b2c90d4ba7a34f3eccd10de2fb7207.tar.xz
nova-6facb35c26b2c90d4ba7a34f3eccd10de2fb7207.zip
Merge trunk and re-run build_i18n
Diffstat (limited to 'nova/utils.py')
-rw-r--r--nova/utils.py25
1 files changed, 24 insertions, 1 deletions
diff --git a/nova/utils.py b/nova/utils.py
index 8d7ff1f64..42efa0008 100644
--- a/nova/utils.py
+++ b/nova/utils.py
@@ -20,13 +20,14 @@
System-level utilities and helper functions.
"""
+import base64
import datetime
import inspect
import json
import os
import random
-import subprocess
import socket
+import string
import struct
import sys
import time
@@ -36,6 +37,7 @@ import netaddr
from eventlet import event
from eventlet import greenthread
+from eventlet.green import subprocess
from nova import exception
from nova.exception import ProcessExecutionError
@@ -235,6 +237,15 @@ def generate_mac():
return ':'.join(map(lambda x: "%02x" % x, mac))
+def generate_password(length=20):
+ """Generate a random sequence of letters and digits
+ to be used as a password. Note that this is not intended
+ to represent the ultimate in security.
+ """
+ chrs = string.letters + string.digits
+ return "".join([random.choice(chrs) for i in xrange(length)])
+
+
def last_octet(address):
return int(address.split(".")[-1])
@@ -476,3 +487,15 @@ def dumps(value):
def loads(s):
return json.loads(s)
+
+
+def ensure_b64_encoding(val):
+ """Safety method to ensure that values expected to be base64-encoded
+ actually are. If they are, the value is returned unchanged. Otherwise,
+ the encoded value is returned.
+ """
+ try:
+ dummy = base64.decode(val)
+ return val
+ except TypeError:
+ return base64.b64encode(val)