~corey.bryant/charms/trusty/cinder/remove-missing

« back to all changes in this revision

Viewing changes to hooks/charmhelpers/contrib/network/ip.py

  • Committer: Liam Young
  • Date: 2014-08-13 14:17:18 UTC
  • mfrom: (40.1.1 cinder)
  • Revision ID: liam.young@canonical.com-20140813141718-71vqzaf1jjfdiz9i
[gnuoy, rs=jamespage] Sync charm-helpers from lp:charm-helpers

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 
5
5
from charmhelpers.fetch import apt_install
6
6
from charmhelpers.core.hookenv import (
7
 
    ERROR, log,
 
7
    ERROR, log, config,
8
8
)
9
9
 
10
10
try:
154
154
get_iface_for_address = partial(_get_for_address, key='iface')
155
155
 
156
156
get_netmask_for_address = partial(_get_for_address, key='netmask')
 
157
 
 
158
 
 
159
def get_ipv6_addr(iface="eth0"):
 
160
    try:
 
161
        iface_addrs = netifaces.ifaddresses(iface)
 
162
        if netifaces.AF_INET6 not in iface_addrs:
 
163
            raise Exception("Interface '%s' doesn't have an ipv6 address." % iface)
 
164
 
 
165
        addresses = netifaces.ifaddresses(iface)[netifaces.AF_INET6]
 
166
        ipv6_addr = [a['addr'] for a in addresses if not a['addr'].startswith('fe80')
 
167
                     and config('vip') != a['addr']]
 
168
        if not ipv6_addr:
 
169
            raise Exception("Interface '%s' doesn't have global ipv6 address." % iface)
 
170
 
 
171
        return ipv6_addr[0]
 
172
 
 
173
    except ValueError:
 
174
        raise ValueError("Invalid interface '%s'" % iface)