~james-page/charms/trusty/cinder/https-multi-network

« back to all changes in this revision

Viewing changes to hooks/cinder_hooks.py

  • Committer: james.page at ubuntu
  • Date: 2014-10-01 22:07:44 UTC
  • mfrom: (45.1.1 cinder)
  • Revision ID: james.page@ubuntu.com-20141001220744-v35hu9iblt15phc7
Rebase and resync

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
    CLUSTER_RES,
21
21
    CINDER_CONF,
22
22
    CINDER_API_CONF,
23
 
    ceph_config_file
 
23
    ceph_config_file,
 
24
    setup_ipv6
24
25
)
25
26
 
26
27
from charmhelpers.core.hookenv import (
38
39
    ERROR,
39
40
)
40
41
 
41
 
from charmhelpers.fetch import apt_install, apt_update
 
42
from charmhelpers.fetch import (
 
43
    apt_install,
 
44
    apt_update
 
45
)
 
46
 
42
47
from charmhelpers.core.host import lsb_release, restart_on_change
43
48
 
44
49
from charmhelpers.contrib.openstack.utils import (
45
 
    configure_installation_source, openstack_upgrade_available)
 
50
    configure_installation_source,
 
51
    openstack_upgrade_available,
 
52
    sync_db_with_multi_ipv6_addresses)
46
53
 
47
54
from charmhelpers.contrib.storage.linux.ceph import ensure_ceph_keyring
48
55
 
55
62
from charmhelpers.contrib.network.ip import (
56
63
    get_iface_for_address,
57
64
    get_netmask_for_address,
58
 
    get_address_in_network
 
65
    get_address_in_network,
 
66
    get_ipv6_addr,
 
67
    is_ipv6
59
68
)
60
69
from charmhelpers.contrib.openstack.ip import (
61
70
    canonical_url,
85
94
@restart_on_change(restart_map(), stopstart=True)
86
95
def config_changed():
87
96
    conf = config()
 
97
 
 
98
    if conf['prefer-ipv6']:
 
99
        setup_ipv6()
 
100
        sync_db_with_multi_ipv6_addresses(config('database'),
 
101
                                          config('database-user'))
 
102
 
88
103
    if (service_enabled('volume') and
89
104
            conf['block-device'] not in [None, 'None', 'none']):
90
105
        block_devices = conf['block-device'].split()
115
130
        log(e, level=ERROR)
116
131
        raise Exception(e)
117
132
 
118
 
    conf = config()
119
 
    relation_set(database=conf['database'], username=conf['database-user'],
120
 
                 hostname=unit_get('private-address'))
 
133
    if config('prefer-ipv6'):
 
134
        sync_db_with_multi_ipv6_addresses(config('database'),
 
135
                                          config('database-user'))
 
136
    else:
 
137
        host = unit_get('private-address')
 
138
        conf = config()
 
139
        relation_set(database=conf['database'],
 
140
                     username=conf['database-user'],
 
141
                     hostname=host)
121
142
 
122
143
 
123
144
@hooks.hook('pgsql-db-relation-joined')
262
283
                relation_id=relation_id,
263
284
                relation_settings={'{}-address'.format(addr_type): address}
264
285
            )
 
286
    if config('prefer-ipv6'):
 
287
        private_addr = get_ipv6_addr(exc_list=[config('vip')])[0]
 
288
        relation_set(relation_id=relation_id,
 
289
                     relation_settings={'private-address': address})
265
290
 
266
291
 
267
292
@hooks.hook('cluster-relation-changed',
273
298
 
274
299
@hooks.hook('ha-relation-joined')
275
300
def ha_joined():
276
 
    config = get_hacluster_config()
 
301
    cluster_config = get_hacluster_config()
277
302
 
278
303
    resources = {
279
304
        'res_cinder_haproxy': 'lsb:haproxy'
284
309
    }
285
310
 
286
311
    vip_group = []
287
 
    for vip in config['vip'].split():
 
312
    for vip in cluster_config['vip'].split():
 
313
        if is_ipv6(vip):
 
314
            res_cinder_vip = 'ocf:heartbeat:IPv6addr'
 
315
            vip_params = 'ipv6addr'
 
316
        else:
 
317
            res_cinder_vip = 'ocf:heartbeat:IPaddr2'
 
318
            vip_params = 'ip'
 
319
 
288
320
        iface = get_iface_for_address(vip)
289
321
        if iface is not None:
290
322
            vip_key = 'res_cinder_{}_vip'.format(iface)
291
 
            resources[vip_key] = 'ocf:heartbeat:IPaddr2'
 
323
            resources[vip_key] = res_cinder_vip
292
324
            resource_params[vip_key] = (
293
 
                'params ip="{vip}" cidr_netmask="{netmask}"'
294
 
                ' nic="{iface}"'.format(vip=vip,
 
325
                'params {ip}="{vip}" cidr_netmask="{netmask}"'
 
326
                ' nic="{iface}"'.format(ip=vip_params,
 
327
                                        vip=vip,
295
328
                                        iface=iface,
296
329
                                        netmask=get_netmask_for_address(vip))
297
330
            )
307
340
        'cl_cinder_haproxy': 'res_cinder_haproxy'
308
341
    }
309
342
    relation_set(init_services=init_services,
310
 
                 corosync_bindiface=config['ha-bindiface'],
311
 
                 corosync_mcastport=config['ha-mcastport'],
 
343
                 corosync_bindiface=cluster_config['ha-bindiface'],
 
344
                 corosync_mcastport=cluster_config['ha-mcastport'],
312
345
                 resources=resources,
313
346
                 resource_params=resource_params,
314
347
                 clones=clones)