From 408b1c7a4ea5fc3efe2df48a723e128a0ced25f7 Mon Sep 17 00:00:00 2001 From: Edward Hope-Morley Date: Wed, 10 Feb 2016 15:21:47 +0000 Subject: [PATCH 1/3] [hopem,r=] Support multiple l3 segments. Closes-Bug: 1523871 --- config.yaml | 6 ++++++ hooks/ceph_hooks.py | 21 ++++++++++++++------- hooks/utils.py | 13 ++++++++----- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/config.yaml b/config.yaml index 2dc2a586..e748671a 100644 --- a/config.yaml +++ b/config.yaml @@ -107,12 +107,18 @@ options: description: | The IP address and netmask of the public (front-side) network (e.g., 192.168.0.0/24) + . + If multiple networks are to be used, a space-delimited list of a.b.c.d/x + can be provided. ceph-cluster-network: type: string default: description: | The IP address and netmask of the cluster (back-side) network (e.g., 192.168.0.0/24) + . + If multiple networks are to be used, a space-delimited list of a.b.c.d/x + can be provided. prefer-ipv6: type: boolean default: False diff --git a/hooks/ceph_hooks.py b/hooks/ceph_hooks.py index 18d7141d..cb5c6cc6 100755 --- a/hooks/ceph_hooks.py +++ b/hooks/ceph_hooks.py @@ -41,15 +41,16 @@ from charmhelpers.fetch import ( from charmhelpers.core.sysctl import create as create_sysctl from utils import ( - render_template, get_host_ip, - assert_charm_supports_ipv6 + get_networks, + assert_charm_supports_ipv6, + render_template, ) from charmhelpers.contrib.openstack.alternatives import install_alternative from charmhelpers.contrib.network.ip import ( get_ipv6_addr, - format_ipv6_addr + format_ipv6_addr, ) from charmhelpers.contrib.charmsupport import nrpe @@ -76,6 +77,12 @@ def emit_cephconf(): mon_hosts = get_mon_hosts() log('Monitor hosts are ' + repr(mon_hosts)) + networks = get_networks('ceph-public-network') + public_network = ', '.join(networks) + + networks = get_networks('ceph-cluster-network') + cluster_network = ', '.join(networks) + cephcontext = { 'auth_supported': get_auth(), 'mon_hosts': ' '.join(mon_hosts), @@ -83,16 +90,16 @@ def emit_cephconf(): 'old_auth': cmp_pkgrevno('ceph', "0.51") < 0, 'osd_journal_size': config('osd-journal-size'), 'use_syslog': str(config('use-syslog')).lower(), - 'ceph_public_network': config('ceph-public-network'), - 'ceph_cluster_network': config('ceph-cluster-network'), + 'ceph_public_network': public_network, + 'ceph_cluster_network': cluster_network, 'loglevel': config('loglevel'), } if config('prefer-ipv6'): dynamic_ipv6_address = get_ipv6_addr()[0] - if not config('ceph-public-network'): + if not public_network: cephcontext['public_addr'] = dynamic_ipv6_address - if not config('ceph-cluster-network'): + if not cluster_network: cephcontext['cluster_addr'] = dynamic_ipv6_address # Install ceph.conf as an alternative to support diff --git a/hooks/utils.py b/hooks/utils.py index ada3563b..1823790a 100644 --- a/hooks/utils.py +++ b/hooks/utils.py @@ -23,8 +23,8 @@ from charmhelpers.core.host import ( lsb_release ) -from charmhelpers.contrib.network import ip from charmhelpers.contrib.network.ip import ( + get_address_in_network, get_ipv6_addr ) @@ -87,10 +87,13 @@ def get_host_ip(hostname=None): return answers[0].address -@cached -def get_public_addr(): - return ip.get_address_in_network(config('ceph-public-network'), - fallback=get_host_ip()) +def get_networks(config_opt='ceph-public-network'): + networks = config(config_opt) + if networks: + networks = networks.split() + return [n for n in networks if get_address_in_network(n)] + + return [] def assert_charm_supports_ipv6(): From 3f59f4fc7f1a46dea755570922663d1506b68044 Mon Sep 17 00:00:00 2001 From: Edward Hope-Morley Date: Thu, 18 Feb 2016 11:39:47 +0000 Subject: [PATCH 2/3] post-review fixes --- hooks/utils.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/hooks/utils.py b/hooks/utils.py index 1823790a..f0c98df0 100644 --- a/hooks/utils.py +++ b/hooks/utils.py @@ -88,6 +88,11 @@ def get_host_ip(hostname=None): def get_networks(config_opt='ceph-public-network'): + """Get all configured networks from provided config option. + + If public network(s) are provided, go through them and return those for + which we have an address configured. + """ networks = config(config_opt) if networks: networks = networks.split() @@ -96,6 +101,16 @@ def get_networks(config_opt='ceph-public-network'): return [] +def get_public_addr(fallback=None): + """Get all configured public networks addresses. + + If public network(s) are provided, go through them and return the first + address we have configured on any of those networks. + """ + return get_address_in_network(config('ceph-public-network'), + fallback=fallback) + + def assert_charm_supports_ipv6(): """Check whether we are able to support charms ipv6.""" if lsb_release()['DISTRIB_CODENAME'].lower() < "trusty": From 384d3c80d5fef895451a9f2d8d4228d6c4810871 Mon Sep 17 00:00:00 2001 From: Edward Hope-Morley Date: Thu, 18 Feb 2016 17:10:53 +0000 Subject: [PATCH 3/3] remove unused function --- hooks/utils.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/hooks/utils.py b/hooks/utils.py index f0c98df0..0071ecbd 100644 --- a/hooks/utils.py +++ b/hooks/utils.py @@ -101,16 +101,6 @@ def get_networks(config_opt='ceph-public-network'): return [] -def get_public_addr(fallback=None): - """Get all configured public networks addresses. - - If public network(s) are provided, go through them and return the first - address we have configured on any of those networks. - """ - return get_address_in_network(config('ceph-public-network'), - fallback=fallback) - - def assert_charm_supports_ipv6(): """Check whether we are able to support charms ipv6.""" if lsb_release()['DISTRIB_CODENAME'].lower() < "trusty":