~corey.bryant/charms/trusty/percona-cluster/render

« back to all changes in this revision

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

  • Committer: Marco Ceppi
  • Date: 2014-08-21 13:01:51 UTC
  • mfrom: (35.2.4 percona-cluster)
  • Revision ID: marco@ceppi.net-20140821130151-dwwkq6b6jmxg6ioc
[gnuoy] Store shared-db information in the peer relation for clustered deploys and echo back to client service for each unit. The removes the current SPOF where only the leader has set the relation information.

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)