~le-charmers/charms/trusty/neutron-api/leadership-election

« back to all changes in this revision

Viewing changes to hooks/neutron_api_hooks.py

  • Committer: Edward Hope-Morley
  • Date: 2015-04-01 13:38:16 UTC
  • mfrom: (82.1.12 neutron-api)
  • Revision ID: edward.hope-morley@canonical.com-20150401133816-rgnwcquxc668oa97
synced /next

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 
3
3
import sys
4
4
import uuid
 
5
from subprocess import (
 
6
    check_call,
 
7
)
5
8
 
6
 
from subprocess import check_call
7
9
from charmhelpers.core.hookenv import (
8
10
    Hooks,
9
11
    UnregisteredHookError,
20
22
 
21
23
from charmhelpers.core.host import (
22
24
    restart_on_change,
 
25
    service_reload,
23
26
)
24
27
 
25
28
from charmhelpers.fetch import (
40
43
    determine_packages,
41
44
    determine_ports,
42
45
    do_openstack_upgrade,
 
46
    dvr_router_present,
 
47
    l3ha_router_present,
43
48
    register_configs,
44
49
    restart_map,
45
50
    services,
46
51
    setup_ipv6
47
52
)
48
53
from neutron_api_context import (
 
54
    get_dvr,
 
55
    get_l3ha,
49
56
    get_l2population,
50
57
    get_overlay_network_type,
 
58
    IdentityServiceContext,
51
59
)
52
60
 
53
61
from charmhelpers.contrib.hahelpers.cluster import (
92
100
        cmd = ['a2dissite', 'openstack_https_frontend']
93
101
        check_call(cmd)
94
102
 
 
103
    # TODO: improve this by checking if local CN certs are available
 
104
    # first then checking reload status (see LP #1433114).
 
105
    service_reload('apache2', restart_on_failure=True)
 
106
 
95
107
    for rid in relation_ids('identity-service'):
96
108
        identity_joined(rid=rid)
97
109
 
110
122
@hooks.hook('config-changed')
111
123
@restart_on_change(restart_map(), stopstart=True)
112
124
def config_changed():
 
125
    if l3ha_router_present() and not get_l3ha():
 
126
        e = ('Cannot disable Router HA while ha enabled routers exist. Please'
 
127
             ' remove any ha routers')
 
128
        log(e, level=ERROR)
 
129
        raise Exception(e)
 
130
    if dvr_router_present() and not get_dvr():
 
131
        e = ('Cannot disable dvr while dvr enabled routers exist. Please'
 
132
             ' remove any distributed routers')
 
133
        log(e, level=ERROR)
 
134
        raise Exception(e)
113
135
    apt_install(filter_installed_packages(
114
136
                determine_packages(config('openstack-origin'))),
115
137
                fatal=True)
235
257
    CONFIGS.write(NEUTRON_CONF)
236
258
    for r_id in relation_ids('neutron-api'):
237
259
        neutron_api_relation_joined(rid=r_id)
 
260
    for r_id in relation_ids('neutron-plugin-api'):
 
261
        neutron_plugin_api_relation_joined(rid=r_id)
238
262
    configure_https()
239
263
 
240
264
 
278
302
        relation_data = {
279
303
            'neutron-security-groups': config('neutron-security-groups'),
280
304
            'l2-population': get_l2population(),
 
305
            'enable-dvr': get_dvr(),
 
306
            'enable-l3ha': get_l3ha(),
281
307
            'overlay-network-type': get_overlay_network_type(),
282
308
        }
283
309
 
287
313
        if net_dev_mtu:
288
314
            relation_data['network-device-mtu'] = net_dev_mtu
289
315
 
 
316
    identity_ctxt = IdentityServiceContext()()
 
317
    if not identity_ctxt:
 
318
        identity_ctxt = {}
 
319
 
 
320
    relation_data.update({
 
321
        'auth_host': identity_ctxt.get('auth_host'),
 
322
        'auth_port': identity_ctxt.get('auth_port'),
 
323
        'auth_protocol': identity_ctxt.get('auth_protocol'),
 
324
        'service_protocol': identity_ctxt.get('service_protocol'),
 
325
        'service_host': identity_ctxt.get('service_host'),
 
326
        'service_port': identity_ctxt.get('service_port'),
 
327
        'service_tenant': identity_ctxt.get('admin_tenant_name'),
 
328
        'service_username': identity_ctxt.get('admin_user'),
 
329
        'service_password': identity_ctxt.get('admin_password'),
 
330
        'region': config('region'),
 
331
    })
 
332
 
290
333
    relation_set(relation_id=rid, **relation_data)
291
334
 
292
335