Ceph need to set public/cluster network for IPv6.

This commit is contained in:
Hui Xiang 2014-09-28 12:41:06 +08:00
parent 5d4bfefdcc
commit 719623f0b6
2 changed files with 40 additions and 1 deletions

View File

@ -48,7 +48,8 @@ from utils import (
render_template,
get_public_addr,
assert_charm_supports_ipv6,
get_host_ip
get_host_ip,
get_network
)
hooks = Hooks()
@ -84,6 +85,14 @@ def emit_cephconf():
'ceph_public_network': config('ceph-public-network'),
'ceph_cluster_network': config('ceph-cluster-network')
}
if config('prefer-ipv6'):
network = get_network()
if not config('ceph-public-network'):
cephcontext['ceph_public_network'] = network
if not config('ceph-cluster-network'):
cephcontext['ceph_cluster_network'] = network
# Install ceph.conf as an alternative to support
# co-existence with other charms that write this file
charm_ceph_conf = "/var/lib/charm/{}/ceph.conf".format(service_name())

View File

@ -98,3 +98,33 @@ 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)