From 6f8364f410cd143d94758f964a30bca2e1c7f565 Mon Sep 17 00:00:00 2001 From: Hui Xiang Date: Sun, 28 Sep 2014 14:00:11 +0800 Subject: [PATCH] Use public/cluster addr for osd, osd mon can't parse ipv6 network. --- hooks/hooks.py | 12 ++++++------ hooks/utils.py | 30 ------------------------------ templates/ceph.conf | 6 ++++++ 3 files changed, 12 insertions(+), 36 deletions(-) diff --git a/hooks/hooks.py b/hooks/hooks.py index 98cdd34..9bdd776 100755 --- a/hooks/hooks.py +++ b/hooks/hooks.py @@ -41,15 +41,15 @@ from charmhelpers.fetch import ( from charmhelpers.payload.execd import execd_preinstall from charmhelpers.contrib.openstack.alternatives import install_alternative from charmhelpers.contrib.network.ip import ( - is_ipv6 + is_ipv6, + get_ipv6_addr ) from utils import ( render_template, get_public_addr, assert_charm_supports_ipv6, - get_host_ip, - get_network + get_host_ip ) hooks = Hooks() @@ -87,11 +87,11 @@ def emit_cephconf(): } if config('prefer-ipv6'): - network = get_network() + dynamic_ipv6_address = get_ipv6_addr()[0] if not config('ceph-public-network'): - cephcontext['ceph_public_network'] = network + cephcontext['public_addr'] = dynamic_ipv6_address if not config('ceph-cluster-network'): - cephcontext['ceph_cluster_network'] = network + cephcontext['cluster_addr'] = dynamic_ipv6_address # Install ceph.conf as an alternative to support # co-existence with other charms that write this file diff --git a/hooks/utils.py b/hooks/utils.py index 791dc54..825c079 100644 --- a/hooks/utils.py +++ b/hooks/utils.py @@ -98,33 +98,3 @@ def assert_charm_supports_ipv6(): if lsb_release()['DISTRIB_CODENAME'].lower() < "trusty": raise Exception("IPv6 is not supported in the charms for Ubuntu " "versions less than Trusty 14.04") - - -def get_network(iface="eth0"): - try: - try: - import netifaces - except ImportError: - apt_install('python-netifaces') - import netifaces - - try: - from netaddr import IPNetwork - except ImportError: - apt_install('python-netaddr', fatal=True) - from netaddr import IPNetwork - - ipv6_address = get_ipv6_addr(iface)[0] - ifa_addrs = netifaces.ifaddresses(iface) - - for ifaddr in ifa_addrs[netifaces.AF_INET6]: - if ipv6_address == ifaddr['addr']: - network = "{}/{}".format(ifaddr['addr'], - ifaddr['netmask']) - ip = IPNetwork(network) - return str(ip.network) - - except ValueError: - raise Exception("Invalid interface '%s'" % iface) - - raise Exception("No valid network found in interface '%s'" % iface) diff --git a/templates/ceph.conf b/templates/ceph.conf index 3b0d91f..5ea82d1 100644 --- a/templates/ceph.conf +++ b/templates/ceph.conf @@ -33,3 +33,9 @@ keyring = /var/lib/ceph/osd/$cluster-$id/keyring osd journal size = {{ osd_journal_size }} filestore xattr use omap = true +{% if public_addr %} +public addr = {{ public_addr }} +{% endif %} +{% if cluster_addr %} +cluster addr = {{ cluster_addr }} +{%- endif %}