From dba5727f460618a54a6ca930076c5e4c8f7552ac Mon Sep 17 00:00:00 2001 From: "james.page@ubuntu.com" <> Date: Wed, 16 Jul 2014 14:43:20 +0100 Subject: [PATCH] Resync helpers, drop surplus vip config --- config.yaml | 14 ++++------ .../charmhelpers/contrib/hahelpers/cluster.py | 4 +-- .../charmhelpers/contrib/openstack/context.py | 13 ++++++--- hooks/swift_hooks.py | 27 +++++++++++++++---- hooks/swift_utils.py | 2 +- 5 files changed, 39 insertions(+), 21 deletions(-) diff --git a/config.yaml b/config.yaml index f1abccf..03366ae 100644 --- a/config.yaml +++ b/config.yaml @@ -147,15 +147,11 @@ options: description: Hash to use across all swift-proxy servers - don't loose vip: type: string - description: "Virtual IP to use to front swift-proxy in ha configuration" - vip_iface: - type: string - default: eth0 - description: "Network Interface where to place the Virtual IP" - vip_cidr: - type: int - default: 24 - description: "Netmask that will be used for the Virtual IP" + description: | + Virtual IP(s) to use to front API services in HA configuration. + . + If multiple networks are being used, a VIP should be provided for each + network, separated by spaces. ha-bindiface: type: string default: eth0 diff --git a/hooks/charmhelpers/contrib/hahelpers/cluster.py b/hooks/charmhelpers/contrib/hahelpers/cluster.py index dd89f34..5e9ff01 100644 --- a/hooks/charmhelpers/contrib/hahelpers/cluster.py +++ b/hooks/charmhelpers/contrib/hahelpers/cluster.py @@ -146,12 +146,12 @@ def get_hacluster_config(): Obtains all relevant configuration from charm configuration required for initiating a relation to hacluster: - ha-bindiface, ha-mcastport, vip, vip_iface, vip_cidr + ha-bindiface, ha-mcastport, vip returns: dict: A dict containing settings keyed by setting name. raises: HAIncompleteConfig if settings are missing. ''' - settings = ['ha-bindiface', 'ha-mcastport', 'vip', 'vip_iface', 'vip_cidr'] + settings = ['ha-bindiface', 'ha-mcastport', 'vip'] conf = {} for setting in settings: conf[setting] = config_get(setting) diff --git a/hooks/charmhelpers/contrib/openstack/context.py b/hooks/charmhelpers/contrib/openstack/context.py index 1e8cfc7..92c41b2 100644 --- a/hooks/charmhelpers/contrib/openstack/context.py +++ b/hooks/charmhelpers/contrib/openstack/context.py @@ -25,6 +25,7 @@ from charmhelpers.core.hookenv import ( unit_get, unit_private_ip, ERROR, + INFO ) from charmhelpers.contrib.hahelpers.cluster import ( @@ -714,7 +715,7 @@ class SubordinateConfigContext(OSContextGenerator): self.interface = interface def __call__(self): - ctxt = {} + ctxt = {'sections': {}} for rid in relation_ids(self.interface): for unit in related_units(rid): sub_config = relation_get('subordinate_configuration', @@ -740,10 +741,14 @@ class SubordinateConfigContext(OSContextGenerator): sub_config = sub_config[self.config_file] for k, v in sub_config.iteritems(): - ctxt[k] = v + if k == 'sections': + for section, config_dict in v.iteritems(): + log("adding section '%s'" % (section)) + ctxt[k][section] = config_dict + else: + ctxt[k] = v - if not ctxt: - ctxt['sections'] = {} + log("%d section(s) found" % (len(ctxt['sections'])), level=INFO) return ctxt diff --git a/hooks/swift_hooks.py b/hooks/swift_hooks.py index c3ba37e..536afd3 100755 --- a/hooks/swift_hooks.py +++ b/hooks/swift_hooks.py @@ -52,6 +52,10 @@ from charmhelpers.contrib.openstack.ip import ( canonical_url, PUBLIC, INTERNAL, ADMIN ) +from charmhelpers.contrib.network.ip import ( + get_iface_for_address, + get_netmask_for_address +) extra_pkgs = [ "haproxy", @@ -232,8 +236,6 @@ def ha_relation_joined(): corosync_bindiface = config('ha-bindiface') corosync_mcastport = config('ha-mcastport') vip = config('vip') - vip_cidr = config('vip_cidr') - vip_iface = config('vip_iface') if not vip: log('Unable to configure hacluster as vip not provided', level=ERROR) @@ -241,14 +243,29 @@ def ha_relation_joined(): # Obtain resources resources = { - 'res_swift_vip': 'ocf:heartbeat:IPaddr2', 'res_swift_haproxy': 'lsb:haproxy' } resource_params = { - 'res_swift_vip': 'params ip="%s" cidr_netmask="%s" nic="%s"' % - (vip, vip_cidr, vip_iface), 'res_swift_haproxy': 'op monitor interval="5s"' } + + vip_group = [] + for vip in vip.split(): + iface = get_iface_for_address(vip) + if iface is not None: + vip_key = 'res_swift_{}_vip'.format(iface) + resources[vip_key] = 'ocf:heartbeat:IPaddr2' + resource_params[vip_key] = ( + 'params ip="{vip}" cidr_netmask="{netmask}"' + ' nic="{iface}"'.format(vip=vip, + iface=iface, + netmask=get_netmask_for_address(vip)) + ) + vip_group.append(vip_key) + + if len(vip_group) > 1: + relation_set(groups={'grp_swift_vips': ' '.join(vip_group)}) + init_services = { 'res_swift_haproxy': 'haproxy' } diff --git a/hooks/swift_utils.py b/hooks/swift_utils.py index e93a623..1a30a48 100644 --- a/hooks/swift_utils.py +++ b/hooks/swift_utils.py @@ -63,7 +63,7 @@ BASE_PACKAGES = [ # > Folsom specific packages FOLSOM_PACKAGES = BASE_PACKAGES + ['swift-plugin-s3'] -SWIFT_HA_RES = 'res_swift_vip' +SWIFT_HA_RES = 'grp_swift_vips' TEMPLATES = 'templates/'