Refactor codes.
This commit is contained in:
parent
4a8f174ba5
commit
65bd882a32
|
@ -41,15 +41,14 @@ from charmhelpers.fetch import (
|
||||||
from charmhelpers.payload.execd import execd_preinstall
|
from charmhelpers.payload.execd import execd_preinstall
|
||||||
from charmhelpers.contrib.openstack.alternatives import install_alternative
|
from charmhelpers.contrib.openstack.alternatives import install_alternative
|
||||||
from charmhelpers.contrib.network.ip import (
|
from charmhelpers.contrib.network.ip import (
|
||||||
is_ipv6,
|
get_ipv6_addr,
|
||||||
get_ipv6_addr
|
format_ipv6_addr
|
||||||
)
|
)
|
||||||
|
|
||||||
from utils import (
|
from utils import (
|
||||||
render_template,
|
render_template,
|
||||||
get_public_addr,
|
get_public_addr,
|
||||||
assert_charm_supports_ipv6,
|
assert_charm_supports_ipv6
|
||||||
get_host_ip
|
|
||||||
)
|
)
|
||||||
|
|
||||||
hooks = Hooks()
|
hooks = Hooks()
|
||||||
|
@ -61,9 +60,6 @@ def install_upstart_scripts():
|
||||||
for x in glob.glob('files/upstart/*.conf'):
|
for x in glob.glob('files/upstart/*.conf'):
|
||||||
shutil.copy(x, '/etc/init/')
|
shutil.copy(x, '/etc/init/')
|
||||||
|
|
||||||
if config('prefer-ipv6'):
|
|
||||||
assert_charm_supports_ipv6()
|
|
||||||
|
|
||||||
|
|
||||||
@hooks.hook('install')
|
@hooks.hook('install')
|
||||||
def install():
|
def install():
|
||||||
|
@ -83,7 +79,7 @@ def emit_cephconf():
|
||||||
'osd_journal_size': config('osd-journal-size'),
|
'osd_journal_size': config('osd-journal-size'),
|
||||||
'use_syslog': str(config('use-syslog')).lower(),
|
'use_syslog': str(config('use-syslog')).lower(),
|
||||||
'ceph_public_network': config('ceph-public-network'),
|
'ceph_public_network': config('ceph-public-network'),
|
||||||
'ceph_cluster_network': config('ceph-cluster-network')
|
'ceph_cluster_network': config('ceph-cluster-network'),
|
||||||
}
|
}
|
||||||
|
|
||||||
if config('prefer-ipv6'):
|
if config('prefer-ipv6'):
|
||||||
|
@ -151,24 +147,14 @@ def config_changed():
|
||||||
def get_mon_hosts():
|
def get_mon_hosts():
|
||||||
hosts = []
|
hosts = []
|
||||||
addr = get_public_addr()
|
addr = get_public_addr()
|
||||||
if is_ipv6(addr):
|
hosts.append('{}:6789'.format(format_ipv6_addr(addr) or addr))
|
||||||
hosts.append('[{}]:6789'.format(addr))
|
|
||||||
else:
|
|
||||||
hosts.append('{}:6789'.format(addr))
|
|
||||||
|
|
||||||
for relid in relation_ids('mon'):
|
for relid in relation_ids('mon'):
|
||||||
for unit in related_units(relid):
|
for unit in related_units(relid):
|
||||||
if config('prefer-ipv6'):
|
addr = relation_get('ceph-public-address', unit, relid)
|
||||||
r_attr = 'ceph-public-address'
|
|
||||||
else:
|
|
||||||
r_attr = 'private-address'
|
|
||||||
|
|
||||||
addr = relation_get(r_attr, unit, relid)
|
|
||||||
if addr is not None:
|
if addr is not None:
|
||||||
if is_ipv6(addr):
|
hosts.append('{}:6789'.format(
|
||||||
hosts.append('[{}]:6789'.format(addr))
|
format_ipv6_addr(addr) or addr))
|
||||||
else:
|
|
||||||
hosts.append('{}:6789'.format(addr))
|
|
||||||
|
|
||||||
hosts.sort()
|
hosts.sort()
|
||||||
return hosts
|
return hosts
|
||||||
|
@ -191,16 +177,15 @@ def get_devices():
|
||||||
@hooks.hook('mon-relation-joined')
|
@hooks.hook('mon-relation-joined')
|
||||||
def mon_relation_joined():
|
def mon_relation_joined():
|
||||||
for relid in relation_ids('mon'):
|
for relid in relation_ids('mon'):
|
||||||
settings = {'ceph-public-address': get_public_addr()}
|
relation_set(relation_id=relid,
|
||||||
relation_set(relation_id=relid, relation_settings=settings)
|
relation_settings={'ceph-public-address':
|
||||||
|
get_public_addr()})
|
||||||
|
|
||||||
|
|
||||||
@hooks.hook('mon-relation-departed',
|
@hooks.hook('mon-relation-departed',
|
||||||
'mon-relation-changed')
|
'mon-relation-changed')
|
||||||
def mon_relation():
|
def mon_relation():
|
||||||
emit_cephconf()
|
emit_cephconf()
|
||||||
relation_data = {'private-address': get_host_ip()}
|
|
||||||
relation_set(**relation_data)
|
|
||||||
|
|
||||||
moncount = int(config('monitor-count'))
|
moncount = int(config('monitor-count'))
|
||||||
if len(get_mon_hosts()) >= moncount:
|
if len(get_mon_hosts()) >= moncount:
|
||||||
|
@ -279,11 +264,6 @@ def radosgw_relation(relid=None):
|
||||||
else:
|
else:
|
||||||
log('mon cluster not in quorum - deferring key provision')
|
log('mon cluster not in quorum - deferring key provision')
|
||||||
|
|
||||||
relation_data = {'private-address': get_host_ip()}
|
|
||||||
relation_set(**relation_data)
|
|
||||||
|
|
||||||
log('End radosgw-relation hook.')
|
|
||||||
|
|
||||||
|
|
||||||
@hooks.hook('client-relation-joined')
|
@hooks.hook('client-relation-joined')
|
||||||
def client_relation(relid=None):
|
def client_relation(relid=None):
|
||||||
|
@ -301,7 +281,6 @@ def client_relation(relid=None):
|
||||||
'key': ceph.get_named_key(service_name),
|
'key': ceph.get_named_key(service_name),
|
||||||
'auth': config('auth-supported'),
|
'auth': config('auth-supported'),
|
||||||
'ceph-public-address': get_public_addr(),
|
'ceph-public-address': get_public_addr(),
|
||||||
'private-address': get_host_ip()
|
|
||||||
}
|
}
|
||||||
relation_set(relation_id=relid,
|
relation_set(relation_id=relid,
|
||||||
relation_settings=data)
|
relation_settings=data)
|
||||||
|
|
|
@ -72,7 +72,7 @@ def get_unit_hostname():
|
||||||
@cached
|
@cached
|
||||||
def get_host_ip(hostname=None):
|
def get_host_ip(hostname=None):
|
||||||
if config('prefer-ipv6'):
|
if config('prefer-ipv6'):
|
||||||
return hostname or get_ipv6_addr()[0]
|
return get_ipv6_addr()[0]
|
||||||
|
|
||||||
hostname = hostname or unit_get('private-address')
|
hostname = hostname or unit_get('private-address')
|
||||||
try:
|
try:
|
||||||
|
@ -89,8 +89,8 @@ def get_host_ip(hostname=None):
|
||||||
|
|
||||||
@cached
|
@cached
|
||||||
def get_public_addr():
|
def get_public_addr():
|
||||||
network = config('ceph-public-network')
|
return ip.get_address_in_network(config('ceph-public-network'),
|
||||||
return ip.get_address_in_network(network, fallback=get_host_ip())
|
fallback=get_host_ip())
|
||||||
|
|
||||||
|
|
||||||
def assert_charm_supports_ipv6():
|
def assert_charm_supports_ipv6():
|
||||||
|
|
Loading…
Reference in New Issue