~cbjchen/charms/trusty/heat/ha

« back to all changes in this revision

Viewing changes to hooks/heat_relations.py

  • Committer: lchen
  • Date: 2015-12-10 07:03:42 UTC
  • Revision ID: lchen@liang.chen-20151210070342-1ngfp5l34s9cyl88
update charmhelper

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
    apt_update
36
36
)
37
37
 
 
38
from charmhelpers.contrib.network.ip import (
 
39
    get_iface_for_address,
 
40
    get_netmask_for_address,
 
41
    get_address_in_network,
 
42
    get_ipv6_addr,
 
43
    is_ipv6
 
44
)
 
45
 
38
46
from charmhelpers.contrib.openstack.utils import (
39
47
    configure_installation_source,
40
48
    openstack_upgrade_available,
62
70
    API_PORTS,
63
71
)
64
72
 
 
73
from charmhelpers.contrib.openstack.context import ADDRESS_TYPES
65
74
from charmhelpers.payload.execd import execd_preinstall
66
75
 
67
76
hooks = Hooks()
200
209
def relation_broken():
201
210
    CONFIGS.write_all()
202
211
 
 
212
@hooks.hook('cluster-relation-joined')
 
213
def cluster_joined(relation_id=None):
 
214
    for addr_type in ADDRESS_TYPES:
 
215
        address = get_address_in_network(
 
216
            config('os-{}-network'.format(addr_type))
 
217
        )
 
218
        if address:
 
219
            relation_set(
 
220
                relation_id=relation_id,
 
221
                relation_settings={'{}-address'.format(addr_type): address}
 
222
            )
 
223
 
 
224
    # Only do if this is fired by cluster rel
 
225
    if not relation_id:
 
226
        check_db_initialised()
 
227
 
 
228
    if config('prefer-ipv6'):
 
229
        private_addr = get_ipv6_addr(exc_list=[config('vip')])[0]
 
230
        relation_set(relation_id=relation_id,
 
231
                     relation_settings={'private-address': private_addr})
 
232
 
 
233
 
 
234
@hooks.hook('cluster-relation-changed',
 
235
            'cluster-relation-departed')
 
236
@restart_on_change(restart_map(), stopstart=True)
 
237
def cluster_changed():
 
238
    check_db_initialised()
 
239
    CONFIGS.write_all()
 
240
 
 
241
 
 
242
@hooks.hook('ha-relation-joined')
 
243
def ha_joined(relation_id=None):
 
244
    cluster_config = get_hacluster_config()
 
245
 
 
246
    resources = {
 
247
        'res_cinder_haproxy': 'lsb:haproxy'
 
248
    }
 
249
 
 
250
    resource_params = {
 
251
        'res_cinder_haproxy': 'op monitor interval="5s"'
 
252
    }
 
253
 
 
254
    vip_group = []
 
255
    for vip in cluster_config['vip'].split():
 
256
        if is_ipv6(vip):
 
257
            res_cinder_vip = 'ocf:heartbeat:IPv6addr'
 
258
            vip_params = 'ipv6addr'
 
259
        else:
 
260
            res_cinder_vip = 'ocf:heartbeat:IPaddr2'
 
261
            vip_params = 'ip'
 
262
 
 
263
        iface = (get_iface_for_address(vip) or
 
264
                 config('vip_iface'))
 
265
        netmask = (get_netmask_for_address(vip) or
 
266
                   config('vip_cidr'))
 
267
 
 
268
        if iface is not None:
 
269
            vip_key = 'res_cinder_{}_vip'.format(iface)
 
270
            resources[vip_key] = res_cinder_vip
 
271
            resource_params[vip_key] = (
 
272
                'params {ip}="{vip}" cidr_netmask="{netmask}"'
 
273
                ' nic="{iface}"'.format(ip=vip_params,
 
274
                                        vip=vip,
 
275
                                        iface=iface,
 
276
                                        netmask=netmask)
 
277
            )
 
278
            vip_group.append(vip_key)
 
279
 
 
280
    if len(vip_group) >= 1:
 
281
        relation_set(relation_id=relation_id,
 
282
                     groups={'grp_cinder_vips': ' '.join(vip_group)})
 
283
 
 
284
    init_services = {
 
285
        'res_cinder_haproxy': 'haproxy'
 
286
    }
 
287
    clones = {
 
288
        'cl_cinder_haproxy': 'res_cinder_haproxy'
 
289
    }
 
290
    relation_set(relation_id=relation_id,
 
291
                 init_services=init_services,
 
292
                 corosync_bindiface=cluster_config['ha-bindiface'],
 
293
                 corosync_mcastport=cluster_config['ha-mcastport'],
 
294
                 resources=resources,
 
295
                 resource_params=resource_params,
 
296
                 clones=clones)
 
297
 
 
298
 
 
299
@hooks.hook('ha-relation-changed')
 
300
def ha_changed():
 
301
    clustered = relation_get('clustered')
 
302
    if not clustered or clustered in [None, 'None', '']:
 
303
        juju_log('ha_changed: hacluster subordinate not fully clustered.')
 
304
    else:
 
305
        juju_log('Cluster configured, notifying other services and updating '
 
306
                 'keystone endpoint configuration')
 
307
        for rid in relation_ids('identity-service'):
 
308
            identity_joined(rid=rid)
 
309
 
203
310
 
204
311
def main():
205
312
    try: