From c9c6735a7e8eccb9ecd6f6ad4910180ea60470a1 Mon Sep 17 00:00:00 2001 From: Liam Young Date: Sun, 12 Oct 2014 07:08:43 +0000 Subject: [PATCH] Add in unicast support --- config.yaml | 5 +++++ hooks/hooks.py | 26 ++++++++++++++++++++++++-- templates/corosync.conf | 16 +++++++++++++++- 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/config.yaml b/config.yaml index 48a84b7..ada8469 100644 --- a/config.yaml +++ b/config.yaml @@ -85,3 +85,8 @@ options: order for this charm to function correctly, the privacy extension must be disabled and a non-temporary address must be configured/available on your network interface. + corosync_transport: + type: string + default: "udp" + description: | + Two supported modes are udp (multicast) or udpu (unicast) diff --git a/hooks/hooks.py b/hooks/hooks.py index 691efee..2ad1065 100755 --- a/hooks/hooks.py +++ b/hooks/hooks.py @@ -29,6 +29,7 @@ from charmhelpers.core.hookenv import ( config, Hooks, UnregisteredHookError, local_unit, + unit_private_ip, ) from charmhelpers.core.host import ( @@ -48,6 +49,7 @@ from charmhelpers.fetch import ( ) from charmhelpers.contrib.hahelpers.cluster import ( + peer_ips, peer_units, oldest_peer ) @@ -78,6 +80,18 @@ def install(): shutil.copy('ocf/ceph/rbd', '/usr/lib/ocf/resource.d/ceph/rbd') +def get_ha_nodes(): + ha_units = peer_ips(peer_relation='hanode') + ha_units[local_unit()] = unit_private_ip() + ha_nodes = {} + # Corosync nodeid 0 is reserved so increase all the nodeids to avoid it + off_set = 1000 + for unit in ha_units: + unit_no = off_set + int(unit.split('/')[1]) + ha_nodes[unit_no] = ha_units[unit] + return ha_nodes + + def get_corosync_conf(): if config('prefer-ipv6'): ip_version = 'ipv6' @@ -85,7 +99,6 @@ def get_corosync_conf(): else: ip_version = 'ipv4' bindnetaddr = hacluster.get_network_address - # NOTE(jamespage) use local charm configuration over any provided by # principle charm conf = { @@ -94,6 +107,8 @@ def get_corosync_conf(): 'corosync_mcastport': config('corosync_mcastport'), 'corosync_mcastaddr': config('corosync_mcastaddr'), 'ip_version': ip_version, + 'ha_nodes': get_ha_nodes(), + 'transport': config('corosync_transport'), } if None not in conf.itervalues(): return conf @@ -109,6 +124,8 @@ def get_corosync_conf(): unit, relid), 'corosync_mcastaddr': config('corosync_mcastaddr'), 'ip_version': ip_version, + 'ha_nodes': get_ha_nodes(), + 'transport': config('corosync_transport'), } if config('prefer-ipv6'): @@ -161,7 +178,12 @@ def config_changed(): log('CRITICAL', 'No Corosync key supplied, cannot proceed') sys.exit(1) - + supported_transports = ['udp', 'udpu'] + if config('corosync_transport') not in supported_transports: + raise ValueError('The corosync_transport type %s is not supported.' + 'Supported types are: %s' % + (config('corosync_transport'), + str(supported_transports))) hacluster.enable_lsb_services('pacemaker') if configure_corosync(): diff --git a/templates/corosync.conf b/templates/corosync.conf index e4c0de6..6d05301 100644 --- a/templates/corosync.conf +++ b/templates/corosync.conf @@ -1,5 +1,5 @@ # Config file generated by the ha charm. - +# udp.template totem { version: 2 @@ -47,9 +47,12 @@ totem { # The following values need to be set based on your environment ringnumber: 0 bindnetaddr: {{ corosync_bindnetaddr }} + {% if transport == "udp" %} mcastaddr: {{ corosync_mcastaddr }} + {% endif %} mcastport: {{ corosync_mcastport }} } + transport: {{ transport }} } quorum { @@ -59,6 +62,17 @@ quorum { expected_votes: 2 } +{% if transport == "udp" %} +nodelist { +{% for nodeid, ip in ha_nodes.iteritems() %} + node { + ring0_addr: {{ ip }} + nodeid: {{ nodeid }} + } +{% endfor %} +} +{% endif %} + logging { fileline: off to_stderr: yes