Merge lp:~xianghui/charm-helpers/support-ipv6 into lp:charm-helpers

Proposed by Xiang Hui
Status: Rejected
Rejected by: James Page
Proposed branch: lp:~xianghui/charm-helpers/support-ipv6
Merge into: lp:charm-helpers
Diff against target: 48 lines (+31/-0)
1 file modified
charmhelpers/contrib/hahelpers/cluster.py (+31/-0)
To merge this branch: bzr merge lp:~xianghui/charm-helpers/support-ipv6
Reviewer Review Type Date Requested Status
Juan L. Negron (community) Approve
OpenStack Charmers Pending
Review via email: mp+224793@code.launchpad.net

Description of the change

Add a function get_ipv6_addr() to let service charm get an ipv6 address.
And could return a url containing ipv6 address if service charm have set the "use-ipv6" config.

To post a comment you must log in.
Revision history for this message
Juan L. Negron (negronjl) wrote :

LGTM.

+1

review: Approve
Revision history for this message
James Page (james-page) wrote :

I backed out this change from lp:charm-helpers - specifically because it breaks the unit tests already present and provides no new ones to exercise this functionality.

I'd also prefer to see this in the contrib.network.ip helper, rather than the clustering hahelper.

Revision history for this message
James Page (james-page) wrote :

I'd also like to see the IPv6 support changeset as a complete, tested changeset prior to merging into either charm-helpers or the charms themselves - sorry - but this is a potentially wide impacting topic and we need to ensure that its fully tested prior to landing.

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charmhelpers/contrib/hahelpers/cluster.py'
2--- charmhelpers/contrib/hahelpers/cluster.py 2014-06-12 17:55:56 +0000
3+++ charmhelpers/contrib/hahelpers/cluster.py 2014-06-27 11:19:30 +0000
4@@ -11,6 +11,8 @@
5
6 from socket import gethostname as get_unit_hostname
7
8+from charmhelpers.fetch import apt_install
9+
10 from charmhelpers.core.hookenv import (
11 log,
12 relation_ids,
13@@ -179,6 +181,35 @@
14 scheme = 'https'
15 if is_clustered():
16 addr = config_get(vip_setting)
17+ elif config_get('use-ipv6'):
18+ addr = '[%s]' % get_ipv6_addr()
19 else:
20 addr = unit_get('private-address')
21 return '%s://%s' % (scheme, addr)
22+
23+
24+def get_ipv6_addr(iface="eth0"):
25+# TODO Is there a scenario that the ipv6 will be gone in the middle
26+# phrase, which caused ipv6 address async.
27+
28+ try:
29+ try:
30+ import netifaces
31+ except ImportError:
32+ apt_install('python-netifaces')
33+ import netifaces
34+
35+ iface_addrs = netifaces.ifaddresses(iface)
36+ if netifaces.AF_INET6 not in iface_addrs:
37+ raise Exception("Interface '%s' doesn't have an ipv6 address.")
38+
39+ addresses = netifaces.ifaddresses(iface)[netifaces.AF_INET6]
40+ ipv6_addr = [addr['addr'] for addr in addresses \
41+ if 'fe80' not in addr['addr']]
42+ if not ipv6_addr:
43+ raise Exception("Interface '%s' doesn't have global ipv6 address.")
44+
45+ return ipv6_addr[0]
46+
47+ except ValueError:
48+ raise Exception("Invalid interface '%s'" % iface)

Subscribers

People subscribed via source and target branches