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
=== modified file 'charmhelpers/contrib/hahelpers/cluster.py'
--- charmhelpers/contrib/hahelpers/cluster.py 2014-06-12 17:55:56 +0000
+++ charmhelpers/contrib/hahelpers/cluster.py 2014-06-27 11:19:30 +0000
@@ -11,6 +11,8 @@
1111
12from socket import gethostname as get_unit_hostname12from socket import gethostname as get_unit_hostname
1313
14from charmhelpers.fetch import apt_install
15
14from charmhelpers.core.hookenv import (16from charmhelpers.core.hookenv import (
15 log,17 log,
16 relation_ids,18 relation_ids,
@@ -179,6 +181,35 @@
179 scheme = 'https'181 scheme = 'https'
180 if is_clustered():182 if is_clustered():
181 addr = config_get(vip_setting)183 addr = config_get(vip_setting)
184 elif config_get('use-ipv6'):
185 addr = '[%s]' % get_ipv6_addr()
182 else:186 else:
183 addr = unit_get('private-address')187 addr = unit_get('private-address')
184 return '%s://%s' % (scheme, addr)188 return '%s://%s' % (scheme, addr)
189
190
191def get_ipv6_addr(iface="eth0"):
192# TODO Is there a scenario that the ipv6 will be gone in the middle
193# phrase, which caused ipv6 address async.
194
195 try:
196 try:
197 import netifaces
198 except ImportError:
199 apt_install('python-netifaces')
200 import netifaces
201
202 iface_addrs = netifaces.ifaddresses(iface)
203 if netifaces.AF_INET6 not in iface_addrs:
204 raise Exception("Interface '%s' doesn't have an ipv6 address.")
205
206 addresses = netifaces.ifaddresses(iface)[netifaces.AF_INET6]
207 ipv6_addr = [addr['addr'] for addr in addresses \
208 if 'fe80' not in addr['addr']]
209 if not ipv6_addr:
210 raise Exception("Interface '%s' doesn't have global ipv6 address.")
211
212 return ipv6_addr[0]
213
214 except ValueError:
215 raise Exception("Invalid interface '%s'" % iface)

Subscribers

People subscribed via source and target branches