diff options
author | Ed Leafe <ed@leafe.com> | 2011-02-17 22:50:17 +0000 |
---|---|---|
committer | Tarmac <> | 2011-02-17 22:50:17 +0000 |
commit | 76a82e57dfbca67e1e70a12db4f4b5c2111e4d93 (patch) | |
tree | ad470c12b3650141ec74051386af8e87e6515999 /nova/utils.py | |
parent | 5688fbd7a06ea47e18f38e4c900be4dbb50b921c (diff) | |
parent | c0972233901774598fe6c836fcc3a0dd1f28f180 (diff) | |
download | nova-76a82e57dfbca67e1e70a12db4f4b5c2111e4d93.tar.gz nova-76a82e57dfbca67e1e70a12db4f4b5c2111e4d93.tar.xz nova-76a82e57dfbca67e1e70a12db4f4b5c2111e4d93.zip |
Added support for feature parity with the current Rackspace Cloud Servers practice of "injecting" files into newly-created instances for configuration, etc. However, this is in no way restricted to only writing files to the guest when it is first created.
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 ba71ebf39..42efa0008 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 @@ -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) |