summaryrefslogtreecommitdiffstats
path: root/nova/utils.py
diff options
context:
space:
mode:
authorTrey Morris <trey.morris@rackspace.com>2011-03-17 15:57:04 -0500
committerTrey Morris <trey.morris@rackspace.com>2011-03-17 15:57:04 -0500
commit400ca259f49a741cf2cefd86afcf2494ee0bd446 (patch)
tree881a11a7ba5a306f0d728c085a8021cb7e527bd5 /nova/utils.py
parent038d99d9fa4354bd617adfa332d69a87a9f7918e (diff)
parent88ae79505a84736ebdf57ba67c60ff16de5c9e87 (diff)
downloadnova-400ca259f49a741cf2cefd86afcf2494ee0bd446.tar.gz
nova-400ca259f49a741cf2cefd86afcf2494ee0bd446.tar.xz
nova-400ca259f49a741cf2cefd86afcf2494ee0bd446.zip
merged trunk, merged qos, slight refactor regarding merges
Diffstat (limited to 'nova/utils.py')
-rw-r--r--nova/utils.py39
1 files changed, 21 insertions, 18 deletions
diff --git a/nova/utils.py b/nova/utils.py
index 87e726394..24b8da9ea 100644
--- a/nova/utils.py
+++ b/nova/utils.py
@@ -262,13 +262,25 @@ 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.
+# Default symbols to use for passwords. Avoids visually confusing characters.
+# ~6 bits per symbol
+DEFAULT_PASSWORD_SYMBOLS = ("23456789" # Removed: 0,1
+ "ABCDEFGHJKLMNPQRSTUVWXYZ" # Removed: I, O
+ "abcdefghijkmnopqrstuvwxyz") # Removed: l
+
+
+# ~5 bits per symbol
+EASIER_PASSWORD_SYMBOLS = ("23456789" # Removed: 0, 1
+ "ABCDEFGHJKLMNPQRSTUVWXYZ") # Removed: I, O
+
+
+def generate_password(length=20, symbols=DEFAULT_PASSWORD_SYMBOLS):
+ """Generate a random password from the supplied symbols.
+
+ Believed to be reasonably secure (with a reasonable password length!)
"""
- chrs = string.letters + string.digits
- return "".join([random.choice(chrs) for i in xrange(length)])
+ r = random.SystemRandom()
+ return "".join([r.choice(symbols) for _i in xrange(length)])
def last_octet(address):
@@ -518,6 +530,9 @@ def synchronized(name):
def wrap(f):
@functools.wraps(f)
def inner(*args, **kwargs):
+ LOG.debug(_("Attempting to grab %(lock)s for method "
+ "%(method)s..." % {"lock": name,
+ "method": f.__name__}))
lock = lockfile.FileLock(os.path.join(FLAGS.lock_path,
'nova-%s.lock' % name))
with lock:
@@ -526,18 +541,6 @@ def synchronized(name):
return wrap
-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)
-
-
def get_from_path(items, path):
""" Returns a list of items matching the specified path. Takes an
XPath-like expression e.g. prop1/prop2/prop3, and for each item in items,