Start move over to contexts for ceph.conf to pave way for workload status
This commit is contained in:
parent
e005c31c6c
commit
6e41a1433b
@ -3,7 +3,14 @@ from charmhelpers.contrib.hahelpers.cluster import (
|
||||
determine_api_port,
|
||||
determine_apache_port,
|
||||
)
|
||||
|
||||
from charmhelpers.core.host import cmp_pkgrevno
|
||||
from charmhelpers.core.hookenv import (
|
||||
config,
|
||||
relation_ids,
|
||||
related_units,
|
||||
relation_get,
|
||||
)
|
||||
import socket
|
||||
|
||||
class HAProxyContext(context.HAProxyContext):
|
||||
|
||||
@ -27,3 +34,74 @@ class HAProxyContext(context.HAProxyContext):
|
||||
# for haproxy.conf
|
||||
ctxt['service_ports'] = port_mapping
|
||||
return ctxt
|
||||
|
||||
|
||||
class IdentityServiceContext(context.IdentityServiceContext):
|
||||
interfaces = ['identity-service']
|
||||
|
||||
def __call__(self):
|
||||
ctxt = super(IdentityServiceContext, self).__call__()
|
||||
if not ctxt:
|
||||
return
|
||||
|
||||
for relid in relation_ids('identity-service'):
|
||||
for unit in related_units(relid):
|
||||
if not ctxt.get('admin_token'):
|
||||
ctxt['admin_token'] = \
|
||||
relation_get('admin_token', unit, relid)
|
||||
|
||||
ctxt['auth_type'] = 'keystone'
|
||||
ctxt['user_roles'] = config('operator-roles')
|
||||
ctxt['cache_size'] = config('cache-size')
|
||||
ctxt['revocation_check_interval'] = config('revocation-check-interval')
|
||||
if self.context_complete(ctxt):
|
||||
return ctxt
|
||||
|
||||
return {}
|
||||
|
||||
|
||||
class MonContext(context.OSContextGenerator):
|
||||
interfaces = ['mon']
|
||||
|
||||
def __call__(self):
|
||||
if not relation_ids('mon'):
|
||||
return {}
|
||||
hosts = []
|
||||
auth = 'none'
|
||||
for relid in relation_ids('mon'):
|
||||
for unit in related_units(relid):
|
||||
host_ip = self.get_host_ip(relation_get('ceph-public-address',
|
||||
unit, relid))
|
||||
hosts.append('{}:6789'.format(host_ip))
|
||||
_auth = relation_get('auth', unit, relid)
|
||||
if _auth:
|
||||
auth = _auth
|
||||
hosts.sort()
|
||||
ctxt = {
|
||||
'auth_supported': auth,
|
||||
'mon_hosts': ' '.join(hosts),
|
||||
'hostname': socket.gethostname(),
|
||||
'old_auth': cmp_pkgrevno('radosgw', "0.51") < 0,
|
||||
'use_syslog': str(config('use-syslog')).lower(),
|
||||
'embedded_webserver': config('use-embedded-webserver'),
|
||||
}
|
||||
|
||||
if self.context_complete(ctxt):
|
||||
print ctxt
|
||||
return ctxt
|
||||
|
||||
return {}
|
||||
|
||||
def get_host_ip(self, hostname=None):
|
||||
try:
|
||||
if not hostname:
|
||||
hostname = unit_get('private-address')
|
||||
# Test to see if already an IPv4 address
|
||||
socket.inet_aton(hostname)
|
||||
return hostname
|
||||
except socket.error:
|
||||
# This may throw an NXDOMAIN exception; in which case
|
||||
# things are badly broken so just let it kill the hook
|
||||
answers = dns.resolver.query(hostname, 'A')
|
||||
if answers:
|
||||
return answers[0].address
|
||||
|
@ -23,6 +23,7 @@ from charmhelpers.core.hookenv import (
|
||||
relation_set,
|
||||
log, ERROR,
|
||||
Hooks, UnregisteredHookError,
|
||||
status_set,
|
||||
)
|
||||
from charmhelpers.fetch import (
|
||||
apt_update,
|
||||
@ -32,7 +33,7 @@ from charmhelpers.fetch import (
|
||||
)
|
||||
from charmhelpers.core.host import (
|
||||
lsb_release,
|
||||
restart_on_change
|
||||
restart_on_change,
|
||||
)
|
||||
from utils import (
|
||||
render_template,
|
||||
@ -41,6 +42,8 @@ from utils import (
|
||||
is_apache_24,
|
||||
CEPHRG_HA_RES,
|
||||
register_configs,
|
||||
REQUIRED_INTERFACES,
|
||||
check_optional_relations,
|
||||
)
|
||||
|
||||
from charmhelpers.payload.execd import execd_preinstall
|
||||
@ -55,7 +58,9 @@ from charmhelpers.contrib.openstack.ip import (
|
||||
canonical_url,
|
||||
PUBLIC, INTERNAL, ADMIN,
|
||||
)
|
||||
|
||||
from charmhelpers.contrib.openstack.utils import (
|
||||
os_workload_status,
|
||||
)
|
||||
hooks = Hooks()
|
||||
CONFIGS = register_configs()
|
||||
|
||||
@ -96,6 +101,7 @@ APACHE_PACKAGES = [
|
||||
|
||||
|
||||
def install_packages():
|
||||
status_set('maintenance', 'Installing apt packages')
|
||||
add_source(config('source'), config('key'))
|
||||
if (config('use-ceph-optimised-packages') and
|
||||
not config('use-embedded-webserver')):
|
||||
@ -110,7 +116,10 @@ def install_packages():
|
||||
|
||||
|
||||
@hooks.hook('install.real')
|
||||
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
|
||||
charm_func=check_optional_relations)
|
||||
def install():
|
||||
status_set('maintenance', 'Executing pre-install')
|
||||
execd_preinstall()
|
||||
enable_pocket('multiverse')
|
||||
install_packages()
|
||||
@ -139,6 +148,7 @@ def emit_cephconf():
|
||||
if ks_conf:
|
||||
cephcontext.update(ks_conf)
|
||||
|
||||
print cephcontext
|
||||
with open('/etc/ceph/ceph.conf', 'w') as cephconf:
|
||||
cephconf.write(render_template('ceph.conf', cephcontext))
|
||||
|
||||
@ -177,6 +187,8 @@ def apache_ports():
|
||||
|
||||
@hooks.hook('upgrade-charm',
|
||||
'config-changed')
|
||||
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
|
||||
charm_func=check_optional_relations)
|
||||
@restart_on_change({'/etc/ceph/ceph.conf': ['radosgw'],
|
||||
'/etc/haproxy/haproxy.cfg': ['haproxy']})
|
||||
def config_changed():
|
||||
@ -184,6 +196,7 @@ def config_changed():
|
||||
emit_cephconf()
|
||||
CONFIGS.write_all()
|
||||
if not config('use-embedded-webserver'):
|
||||
status_set('maintenance', 'configuring apache')
|
||||
emit_apacheconf()
|
||||
install_www_scripts()
|
||||
apache_sites()
|
||||
@ -236,12 +249,15 @@ def get_keystone_conf():
|
||||
config('revocation-check-interval')
|
||||
}
|
||||
if None not in ks_auth.itervalues():
|
||||
print ks_auth
|
||||
return ks_auth
|
||||
return None
|
||||
|
||||
|
||||
@hooks.hook('mon-relation-departed',
|
||||
'mon-relation-changed')
|
||||
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
|
||||
charm_func=check_optional_relations)
|
||||
@restart_on_change({'/etc/ceph/ceph.conf': ['radosgw']})
|
||||
def mon_relation():
|
||||
emit_cephconf()
|
||||
@ -273,6 +289,8 @@ def restart():
|
||||
|
||||
|
||||
@hooks.hook('identity-service-relation-joined')
|
||||
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
|
||||
charm_func=check_optional_relations)
|
||||
def identity_joined(relid=None):
|
||||
if cmp_pkgrevno('radosgw', '0.55') < 0:
|
||||
log('Integration with keystone requires ceph >= 0.55')
|
||||
@ -293,6 +311,8 @@ def identity_joined(relid=None):
|
||||
|
||||
|
||||
@hooks.hook('identity-service-relation-changed')
|
||||
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
|
||||
charm_func=check_optional_relations)
|
||||
@restart_on_change({'/etc/ceph/ceph.conf': ['radosgw']})
|
||||
def identity_changed():
|
||||
emit_cephconf()
|
||||
@ -301,6 +321,8 @@ def identity_changed():
|
||||
|
||||
@hooks.hook('cluster-relation-changed',
|
||||
'cluster-relation-joined')
|
||||
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
|
||||
charm_func=check_optional_relations)
|
||||
@restart_on_change({'/etc/haproxy/haproxy.cfg': ['haproxy']})
|
||||
def cluster_changed():
|
||||
CONFIGS.write_all()
|
||||
@ -309,6 +331,8 @@ def cluster_changed():
|
||||
|
||||
|
||||
@hooks.hook('ha-relation-joined')
|
||||
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
|
||||
charm_func=check_optional_relations)
|
||||
def ha_relation_joined():
|
||||
# Obtain the config values necessary for the cluster config. These
|
||||
# include multicast port and interface to bind to.
|
||||
@ -361,6 +385,8 @@ def ha_relation_joined():
|
||||
|
||||
|
||||
@hooks.hook('ha-relation-changed')
|
||||
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
|
||||
charm_func=check_optional_relations)
|
||||
def ha_relation_changed():
|
||||
clustered = relation_get('clustered')
|
||||
if clustered:
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
#
|
||||
# Copyright 2012 Canonical Ltd.
|
||||
#
|
||||
@ -12,16 +11,26 @@ import re
|
||||
import os
|
||||
from copy import deepcopy
|
||||
from collections import OrderedDict
|
||||
from charmhelpers.core.hookenv import unit_get
|
||||
from charmhelpers.core.hookenv import unit_get, relation_ids, status_get
|
||||
from charmhelpers.fetch import apt_install
|
||||
from charmhelpers.contrib.openstack import context, templating
|
||||
from charmhelpers.contrib.openstack.utils import set_os_workload_status
|
||||
from charmhelpers.contrib.hahelpers.cluster import get_hacluster_config
|
||||
from charmhelpers.core.host import cmp_pkgrevno
|
||||
|
||||
import ceph_radosgw_context
|
||||
|
||||
# The interface is said to be satisfied if anyone of the interfaces in the
|
||||
# list has a complete context.
|
||||
REQUIRED_INTERFACES = {
|
||||
'identity': ['identity-service'],
|
||||
'mon': ['ceph-radosgw'],
|
||||
}
|
||||
CEPHRG_HA_RES = 'grp_cephrg_vips'
|
||||
TEMPLATES_DIR = 'templates'
|
||||
TEMPLATES = 'templates/'
|
||||
HAPROXY_CONF = '/etc/haproxy/haproxy.cfg'
|
||||
CEPH_CONF = '/etc/ceph/ceph.conf'
|
||||
|
||||
BASE_RESOURCE_MAP = OrderedDict([
|
||||
(HAPROXY_CONF, {
|
||||
@ -29,6 +38,10 @@ BASE_RESOURCE_MAP = OrderedDict([
|
||||
ceph_radosgw_context.HAProxyContext()],
|
||||
'services': ['haproxy'],
|
||||
}),
|
||||
(CEPH_CONF, {
|
||||
'contexts': [ceph_radosgw_context.MonContext()],
|
||||
'services': ['radosgw'],
|
||||
}),
|
||||
])
|
||||
|
||||
try:
|
||||
@ -58,7 +71,13 @@ def resource_map():
|
||||
def register_configs(release='icehouse'):
|
||||
configs = templating.OSConfigRenderer(templates_dir=TEMPLATES,
|
||||
openstack_release=release)
|
||||
for cfg, rscs in resource_map().iteritems():
|
||||
CONFIGS = resource_map()
|
||||
if cmp_pkgrevno('radosgw', '0.55') >= 0:
|
||||
# Add keystone configuration if found
|
||||
CONFIGS[CEPH_CONF]['contexts'].append(
|
||||
ceph_radosgw_context.IdentityServiceContext()
|
||||
)
|
||||
for cfg, rscs in CONFIGS.iteritems():
|
||||
configs.register(cfg, rscs['contexts'])
|
||||
return configs
|
||||
|
||||
@ -103,3 +122,20 @@ def is_apache_24():
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def check_optional_relations(configs):
|
||||
required_interfaces = {}
|
||||
if relation_ids('ha'):
|
||||
required_interfaces['ha'] = ['cluster']
|
||||
try:
|
||||
get_hacluster_config()
|
||||
except:
|
||||
return ('blocked',
|
||||
'hacluster missing configuration: '
|
||||
'vip, vip_iface, vip_cidr')
|
||||
if required_interfaces:
|
||||
set_os_workload_status(configs, required_interfaces)
|
||||
return status_get()
|
||||
else:
|
||||
return 'unknown', 'No optional relations'
|
||||
|
Loading…
x
Reference in New Issue
Block a user