diff options
| author | Soren Hansen <soren@linux2go.dk> | 2011-02-19 00:37:15 +0100 |
|---|---|---|
| committer | Soren Hansen <soren@linux2go.dk> | 2011-02-19 00:37:15 +0100 |
| commit | c10e3ddb19f20e5ac3a424a2296fe63fa4c4b7ee (patch) | |
| tree | d6553216bc3b3988a1c80b53d37e93e1b9a94992 /nova/utils.py | |
| parent | 23729c543350ce4ce563077522f18d0bedd1e61b (diff) | |
| parent | 8de8d1d045ca9fe12596e53d2244f4f8703cc209 (diff) | |
| download | nova-c10e3ddb19f20e5ac3a424a2296fe63fa4c4b7ee.tar.gz nova-c10e3ddb19f20e5ac3a424a2296fe63fa4c4b7ee.tar.xz nova-c10e3ddb19f20e5ac3a424a2296fe63fa4c4b7ee.zip | |
Merge trunk
Diffstat (limited to 'nova/utils.py')
| -rw-r--r-- | nova/utils.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/nova/utils.py b/nova/utils.py index bf3a4b098..644bf18fd 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -20,12 +20,14 @@ System-level utilities and helper functions. """ +import base64 import datetime import inspect import json import os import random import socket +import string import struct import sys import time @@ -244,6 +246,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]) @@ -485,3 +496,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) |
