Add support for multiple l3 networks.

This commit is contained in:
James Page 2016-02-25 15:48:22 +00:00
commit 2585d6f872
3 changed files with 33 additions and 12 deletions

View File

@ -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

View File

@ -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,17 +90,17 @@ 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'),
'dio': str(config('use-direct-io')).lower(),
}
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

View File

@ -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,18 @@ 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'):
"""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()
return [n for n in networks if get_address_in_network(n)]
return []
def assert_charm_supports_ipv6():