diff options
author | Brian Waldon <brian.waldon@rackspace.com> | 2011-03-17 14:22:02 -0400 |
---|---|---|
committer | Brian Waldon <brian.waldon@rackspace.com> | 2011-03-17 14:22:02 -0400 |
commit | 58f66ff1d20286b4e321f90f60b3abef2d9ba8c6 (patch) | |
tree | 3209577d1860c6a5a50979a85d1fda910af282ae /nova/utils.py | |
parent | f05e4d0cec29ed352c6afbe32ab5b12382769711 (diff) | |
parent | 866845870f71f08203d0b29e9f35ecd5eec44151 (diff) | |
download | nova-58f66ff1d20286b4e321f90f60b3abef2d9ba8c6.tar.gz nova-58f66ff1d20286b4e321f90f60b3abef2d9ba8c6.tar.xz nova-58f66ff1d20286b4e321f90f60b3abef2d9ba8c6.zip |
merging parent branch lp:~rackspace-titan/nova/openstack-api-version-split
Diffstat (limited to 'nova/utils.py')
-rw-r--r-- | nova/utils.py | 39 |
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, |