diff options
| author | Andy Smith <code@term.ie> | 2011-01-14 17:48:48 -0800 |
|---|---|---|
| committer | Andy Smith <code@term.ie> | 2011-01-14 17:48:48 -0800 |
| commit | 073336d206e124f7bebbe8a239193a8727fef7ed (patch) | |
| tree | 45d2ef9bab084f5e0a63192a73936d321f7e7bc1 /nova/utils.py | |
| parent | 731126b299da757588656fa72b291ca4da96b5fe (diff) | |
| parent | 34ceed1ce114ab01eca06eced00a204ae71dc3db (diff) | |
| download | nova-073336d206e124f7bebbe8a239193a8727fef7ed.tar.gz nova-073336d206e124f7bebbe8a239193a8727fef7ed.tar.xz nova-073336d206e124f7bebbe8a239193a8727fef7ed.zip | |
merge from upstream
Diffstat (limited to 'nova/utils.py')
| -rw-r--r-- | nova/utils.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/nova/utils.py b/nova/utils.py index 3fefc80fc..fdbe81c0c 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -31,6 +31,8 @@ import struct import sys import time from xml.sax import saxutils +import re +import netaddr from eventlet import event from eventlet import greenthread @@ -201,6 +203,40 @@ def last_octet(address): return int(address.split(".")[-1]) +def get_my_linklocal(interface): + try: + if_str = execute("ip -f inet6 -o addr show %s" % interface) + condition = "\s+inet6\s+([0-9a-f:]+/\d+)\s+scope\s+link" + links = [re.search(condition, x) for x in if_str[0].split('\n')] + address = [w.group(1) for w in links if w is not None] + if address[0] is not None: + return address[0] + else: + return 'fe00::' + except IndexError as ex: + LOG.warn(_("Couldn't get Link Local IP of %s :%s"), interface, ex) + except ProcessExecutionError as ex: + LOG.warn(_("Couldn't get Link Local IP of %s :%s"), interface, ex) + except: + return 'fe00::' + + +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() + + +def to_mac(ipv6_address): + address = netaddr.IPAddress(ipv6_address) + mask1 = netaddr.IPAddress("::ffff:ffff:ffff:ffff") + mask2 = netaddr.IPAddress("::0200:0:0:0") + mac64 = netaddr.EUI(int(address & mask1 ^ mask2)).words + return ":".join(["%02x" % i for i in mac64[0:3] + mac64[5:8]]) + + def utcnow(): """Overridable version of datetime.datetime.utcnow.""" if utcnow.override_time: |
