diff options
author | Rick Harris <rick.harris@rackspace.com> | 2011-03-24 21:50:27 +0000 |
---|---|---|
committer | Rick Harris <rick.harris@rackspace.com> | 2011-03-24 21:50:27 +0000 |
commit | 77c62a6730b3e36a828d733236efcfa697103b6b (patch) | |
tree | 7a99a70342bf8356b560f470e57d95783b3011de /nova/utils.py | |
parent | 4793991cdfa171839ddbc40e513b9625a1c89bbe (diff) | |
parent | f8d1d6da8daac5169948d504560ee8c1b4c0df3c (diff) | |
download | nova-77c62a6730b3e36a828d733236efcfa697103b6b.tar.gz nova-77c62a6730b3e36a828d733236efcfa697103b6b.tar.xz nova-77c62a6730b3e36a828d733236efcfa697103b6b.zip |
Merging trunk
Diffstat (limited to 'nova/utils.py')
-rw-r--r-- | nova/utils.py | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/nova/utils.py b/nova/utils.py index 3d65a88ec..3f6f9fc8a 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -171,10 +171,6 @@ def execute(*cmd, **kwargs): stdout=stdout, stderr=stderr, cmd=' '.join(cmd)) - # NOTE(termie): this appears to be necessary to let the subprocess - # call clean something up in between calls, without - # it two execute calls in a row hangs the second one - greenthread.sleep(0) return result except ProcessExecutionError: if not attempts: @@ -183,6 +179,11 @@ def execute(*cmd, **kwargs): LOG.debug(_("%r failed. Retrying."), cmd) if delay_on_retry: greenthread.sleep(random.randint(20, 200) / 100.0) + finally: + # NOTE(termie): this appears to be necessary to let the subprocess + # call clean something up in between calls, without + # it two execute calls in a row hangs the second one + greenthread.sleep(0) def ssh_execute(ssh, cmd, process_input=None, @@ -310,11 +311,15 @@ def get_my_linklocal(interface): def to_global_ipv6(prefix, mac): - mac64 = netaddr.EUI(mac).eui64().words - int_addr = int(''.join(['%02x' % i for i in mac64]), 16) - mac64_addr = netaddr.IPAddress(int_addr) - maskIP = netaddr.IPNetwork(prefix).ip - return (mac64_addr ^ netaddr.IPAddress('::0200:0:0:0') | maskIP).format() + try: + mac64 = netaddr.EUI(mac).eui64().words + int_addr = int(''.join(['%02x' % i for i in mac64]), 16) + mac64_addr = netaddr.IPAddress(int_addr) + maskIP = netaddr.IPNetwork(prefix).ip + return (mac64_addr ^ netaddr.IPAddress('::0200:0:0:0') | maskIP).\ + format() + except TypeError: + raise TypeError(_("Bad mac for to_global_ipv6: %s") % mac) def to_mac(ipv6_address): @@ -336,11 +341,8 @@ utcnow.override_time = None def is_older_than(before, seconds): - """Return True if before is older than 'seconds'""" - if utcnow() - before > datetime.timedelta(seconds=seconds): - return True - else: - return False + """Return True if before is older than seconds""" + return utcnow() - before > datetime.timedelta(seconds=seconds) def utcnow_ts(): |