~tribaal/charms/trusty/quantum-gateway-mac-address-fix/trunk

« back to all changes in this revision

Viewing changes to hooks/quantum_utils.py

  • Committer: James Page
  • Date: 2014-04-16 08:28:29 UTC
  • mfrom: (41.3.49 quantum-gateway)
  • Revision ID: james.page@canonical.com-20140416082829-o7ojjk3oes6ksb69
[yolanda.robla,james-page,hazmat,r=james-page,t=*]

Support for Icehouse on 12.04 and 14.04
Support for Active/Active and SSL RabbitMQ
Support for SSL MySQL
Support for SSL endpoints
Support for PostgreSQL

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
from charmhelpers.core.host import (
2
2
    service_running,
3
 
    service_stop
 
3
    service_stop,
 
4
    service_restart
4
5
)
5
6
from charmhelpers.core.hookenv import (
6
7
    log,
9
10
    unit_private_ip
10
11
)
11
12
from charmhelpers.fetch import (
 
13
    apt_upgrade,
 
14
    apt_update,
12
15
    apt_install,
13
 
    apt_update
14
16
)
15
17
from charmhelpers.contrib.network.ovs import (
16
18
    add_bridge,
24
26
    get_hostname
25
27
)
26
28
 
 
29
from charmhelpers.contrib.openstack.neutron import (
 
30
    determine_dkms_package
 
31
)
 
32
 
27
33
import charmhelpers.contrib.openstack.context as context
28
34
from charmhelpers.contrib.openstack.context import (
29
35
    SyslogContext
37
43
    QuantumGatewayContext,
38
44
    NetworkServiceContext,
39
45
    L3AgentContext,
40
 
    QuantumSharedDBContext,
41
46
    ExternalPortContext,
42
47
)
43
48
 
 
49
from copy import deepcopy
 
50
 
44
51
 
45
52
def valid_plugin():
46
53
    return config('plugin') in CORE_PLUGIN[networking_name()]
47
54
 
 
55
QUANTUM_CONF_DIR = '/etc/quantum'
 
56
 
48
57
QUANTUM_OVS_PLUGIN_CONF = \
49
58
    "/etc/quantum/plugins/openvswitch/ovs_quantum_plugin.ini"
50
59
QUANTUM_NVP_PLUGIN_CONF = \
54
63
    NVP: QUANTUM_NVP_PLUGIN_CONF
55
64
}
56
65
 
 
66
NEUTRON_CONF_DIR = '/etc/neutron'
 
67
 
57
68
NEUTRON_OVS_PLUGIN_CONF = \
58
69
    "/etc/neutron/plugins/openvswitch/ovs_neutron_plugin.ini"
 
70
NEUTRON_ML2_PLUGIN_CONF = \
 
71
    "/etc/neutron/plugins/ml2/ml2_conf.ini"
59
72
NEUTRON_NVP_PLUGIN_CONF = \
60
73
    "/etc/neutron/plugins/nicira/nvp.ini"
61
74
NEUTRON_PLUGIN_CONF = {
69
82
        "quantum-l3-agent",
70
83
        "quantum-dhcp-agent",
71
84
        'python-mysqldb',
 
85
        'python-psycopg2',
72
86
        "nova-api-metadata"
73
87
    ],
74
88
    NVP: [
75
89
        "openvswitch-switch",
76
90
        "quantum-dhcp-agent",
77
91
        'python-mysqldb',
 
92
        'python-psycopg2',
78
93
        "nova-api-metadata"
79
94
    ]
80
95
}
86
101
        "neutron-l3-agent",
87
102
        "neutron-dhcp-agent",
88
103
        'python-mysqldb',
 
104
        'python-psycopg2',
89
105
        'python-oslo.config',  # Force upgrade
90
 
        "nova-api-metadata"
 
106
        "nova-api-metadata",
 
107
        "neutron-plugin-metering-agent",
 
108
        "neutron-lbaas-agent",
 
109
        "openswan"
91
110
    ],
92
111
    NVP: [
93
112
        "neutron-dhcp-agent",
94
113
        'python-mysqldb',
 
114
        'python-psycopg2',
95
115
        'python-oslo.config',  # Force upgrade
96
116
        "nova-api-metadata"
97
117
    ]
102
122
    NEUTRON: NEUTRON_GATEWAY_PKGS,
103
123
}
104
124
 
105
 
EARLY_PACKAGES = {
106
 
    OVS: ['openvswitch-datapath-dkms'],
107
 
    NVP: []
108
 
}
109
 
 
110
125
 
111
126
def get_early_packages():
112
127
    '''Return a list of package for pre-install based on configured plugin'''
113
 
    if config('plugin') in EARLY_PACKAGES:
114
 
        pkgs = EARLY_PACKAGES[config('plugin')]
 
128
    if config('plugin') in [OVS]:
 
129
        pkgs = determine_dkms_package()
115
130
    else:
116
131
        return []
117
132
 
123
138
 
124
139
def get_packages():
125
140
    '''Return a list of packages for install based on the configured plugin'''
126
 
    return GATEWAY_PKGS[networking_name()][config('plugin')]
 
141
    packages = deepcopy(GATEWAY_PKGS[networking_name()][config('plugin')])
 
142
    if (get_os_codename_install_source(config('openstack-origin'))
 
143
            >= 'icehouse' and config('plugin') == 'ovs'):
 
144
        # NOTE(jamespage) neutron-vpn-agent supercedes l3-agent for icehouse
 
145
        packages.remove('neutron-l3-agent')
 
146
        packages.append('neutron-vpn-agent')
 
147
    return packages
127
148
 
128
149
 
129
150
def get_common_package():
145
166
NEUTRON_DHCP_AGENT_CONF = "/etc/neutron/dhcp_agent.ini"
146
167
NEUTRON_DNSMASQ_CONF = "/etc/neutron/dnsmasq.conf"
147
168
NEUTRON_METADATA_AGENT_CONF = "/etc/neutron/metadata_agent.ini"
 
169
NEUTRON_METERING_AGENT_CONF = "/etc/neutron/metering_agent.ini"
 
170
NEUTRON_LBAAS_AGENT_CONF = "/etc/neutron/lbaas_agent.ini"
 
171
NEUTRON_VPNAAS_AGENT_CONF = "/etc/neutron/vpn_agent.ini"
 
172
NEUTRON_FWAAS_CONF = "/etc/neutron/fwaas_driver.ini"
148
173
 
 
174
NOVA_CONF_DIR = '/etc/nova'
149
175
NOVA_CONF = "/etc/nova/nova.conf"
150
176
 
151
177
NOVA_CONFIG_FILES = {
152
178
    NOVA_CONF: {
153
 
        'hook_contexts': [context.AMQPContext(),
154
 
                          QuantumSharedDBContext(),
 
179
        'hook_contexts': [context.AMQPContext(ssl_dir=NOVA_CONF_DIR),
 
180
                          context.SharedDBContext(ssl_dir=NOVA_CONF_DIR),
 
181
                          context.PostgresqlDBContext(),
155
182
                          NetworkServiceContext(),
156
183
                          QuantumGatewayContext(),
157
184
                          SyslogContext()],
191
218
 
192
219
QUANTUM_OVS_CONFIG_FILES = {
193
220
    QUANTUM_CONF: {
194
 
        'hook_contexts': [context.AMQPContext(),
 
221
        'hook_contexts': [context.AMQPContext(ssl_dir=QUANTUM_CONF_DIR),
195
222
                          QuantumGatewayContext(),
196
223
                          SyslogContext()],
197
224
        'services': ['quantum-l3-agent',
200
227
                     'quantum-plugin-openvswitch-agent']
201
228
    },
202
229
    QUANTUM_L3_AGENT_CONF: {
203
 
        'hook_contexts': [NetworkServiceContext()],
 
230
        'hook_contexts': [NetworkServiceContext(),
 
231
                          QuantumGatewayContext()],
204
232
        'services': ['quantum-l3-agent']
205
233
    },
206
 
    # TODO: Check to see if this is actually required
207
234
    QUANTUM_OVS_PLUGIN_CONF: {
208
 
        'hook_contexts': [QuantumSharedDBContext(),
209
 
                          QuantumGatewayContext()],
 
235
        'hook_contexts': [QuantumGatewayContext()],
210
236
        'services': ['quantum-plugin-openvswitch-agent']
211
237
    },
212
238
    EXT_PORT_CONF: {
218
244
 
219
245
NEUTRON_OVS_CONFIG_FILES = {
220
246
    NEUTRON_CONF: {
221
 
        'hook_contexts': [context.AMQPContext(),
 
247
        'hook_contexts': [context.AMQPContext(ssl_dir=NEUTRON_CONF_DIR),
222
248
                          QuantumGatewayContext(),
223
249
                          SyslogContext()],
224
250
        'services': ['neutron-l3-agent',
225
251
                     'neutron-dhcp-agent',
226
252
                     'neutron-metadata-agent',
227
 
                     'neutron-plugin-openvswitch-agent']
 
253
                     'neutron-plugin-openvswitch-agent',
 
254
                     'neutron-plugin-metering-agent',
 
255
                     'neutron-metering-agent',
 
256
                     'neutron-lbaas-agent',
 
257
                     'neutron-plugin-vpn-agent',
 
258
                     'neutron-vpn-agent']
228
259
    },
229
260
    NEUTRON_L3_AGENT_CONF: {
230
261
        'hook_contexts': [NetworkServiceContext(),
231
 
                          L3AgentContext()],
232
 
        'services': ['neutron-l3-agent']
233
 
    },
234
 
    # TODO: Check to see if this is actually required
 
262
                          L3AgentContext(),
 
263
                          QuantumGatewayContext()],
 
264
        'services': ['neutron-l3-agent']
 
265
    },
 
266
    NEUTRON_METERING_AGENT_CONF: {
 
267
        'hook_contexts': [QuantumGatewayContext()],
 
268
        'services': ['neutron-plugin-metering-agent',
 
269
                     'neutron-metering-agent']
 
270
    },
 
271
    NEUTRON_LBAAS_AGENT_CONF: {
 
272
        'hook_contexts': [QuantumGatewayContext()],
 
273
        'services': ['neutron-lbaas-agent']
 
274
    },
 
275
    NEUTRON_VPNAAS_AGENT_CONF: {
 
276
        'hook_contexts': [QuantumGatewayContext()],
 
277
        'services': ['neutron-plugin-vpn-agent',
 
278
                     'neutron-vpn-agent']
 
279
    },
 
280
    NEUTRON_FWAAS_CONF: {
 
281
        'hook_contexts': [QuantumGatewayContext()],
 
282
        'services': ['neutron-l3-agent']
 
283
    },
235
284
    NEUTRON_OVS_PLUGIN_CONF: {
236
 
        'hook_contexts': [QuantumSharedDBContext(),
237
 
                          QuantumGatewayContext()],
 
285
        'hook_contexts': [QuantumGatewayContext()],
 
286
        'services': ['neutron-plugin-openvswitch-agent']
 
287
    },
 
288
    NEUTRON_ML2_PLUGIN_CONF: {
 
289
        'hook_contexts': [QuantumGatewayContext()],
238
290
        'services': ['neutron-plugin-openvswitch-agent']
239
291
    },
240
292
    EXT_PORT_CONF: {
246
298
 
247
299
QUANTUM_NVP_CONFIG_FILES = {
248
300
    QUANTUM_CONF: {
249
 
        'hook_contexts': [context.AMQPContext()],
 
301
        'hook_contexts': [context.AMQPContext(ssl_dir=QUANTUM_CONF_DIR)],
250
302
        'services': ['quantum-dhcp-agent', 'quantum-metadata-agent']
251
303
    },
252
304
}
254
306
 
255
307
NEUTRON_NVP_CONFIG_FILES = {
256
308
    NEUTRON_CONF: {
257
 
        'hook_contexts': [context.AMQPContext()],
 
309
        'hook_contexts': [context.AMQPContext(ssl_dir=NEUTRON_CONF_DIR)],
258
310
        'services': ['neutron-dhcp-agent', 'neutron-metadata-agent']
259
311
    },
260
312
}
280
332
 
281
333
    plugin = config('plugin')
282
334
    name = networking_name()
 
335
    if plugin == 'ovs':
 
336
        # NOTE: deal with switch to ML2 plugin for >= icehouse
 
337
        drop_config = NEUTRON_ML2_PLUGIN_CONF
 
338
        if release >= 'icehouse':
 
339
            drop_config = NEUTRON_OVS_PLUGIN_CONF
 
340
        if drop_config in CONFIG_FILES[name][plugin]:
 
341
            CONFIG_FILES[name][plugin].pop(drop_config)
 
342
 
283
343
    for conf in CONFIG_FILES[name][plugin]:
284
344
        configs.register(conf,
285
345
                         CONFIG_FILES[name][plugin][conf]['hook_contexts'])
305
365
                    that should be restarted when file changes.
306
366
    '''
307
367
    _map = {}
 
368
    plugin = config('plugin')
308
369
    name = networking_name()
309
 
    for f, ctxt in CONFIG_FILES[name][config('plugin')].iteritems():
 
370
    for f, ctxt in CONFIG_FILES[name][plugin].iteritems():
310
371
        svcs = []
311
372
        for svc in ctxt['services']:
312
373
            svcs.append(svc)
335
396
        ''' Try to import neutronclient instead for havana+ '''
336
397
        from neutronclient.v2_0 import client
337
398
 
338
 
    # TODO: Fixup for https keystone
339
 
    auth_url = 'http://%(keystone_host)s:%(auth_port)s/v2.0' % env
 
399
    auth_url = '%(auth_protocol)s://%(keystone_host)s:%(auth_port)s/v2.0' % env
340
400
    quantum = client.Client(username=env['service_username'],
341
401
                            password=env['service_password'],
342
402
                            tenant_name=env['service_tenant'],
404
464
        index += 1
405
465
 
406
466
 
407
 
def do_openstack_upgrade(configs):
 
467
def services():
 
468
    ''' Returns a list of services associate with this charm '''
 
469
    _services = []
 
470
    for v in restart_map().values():
 
471
        _services = _services + v
 
472
    return list(set(_services))
 
473
 
 
474
 
 
475
def do_openstack_upgrade():
408
476
    """
409
477
    Perform an upgrade.  Takes care of upgrading packages, rewriting
410
478
    configs, database migrations and potentially any other post-upgrade
411
479
    actions.
412
 
 
413
 
    :param configs: The charms main OSConfigRenderer object.
414
480
    """
415
481
    new_src = config('openstack-origin')
416
482
    new_os_rel = get_os_codename_install_source(new_src)
417
 
 
418
483
    log('Performing OpenStack upgrade to %s.' % (new_os_rel))
419
484
 
420
485
    configure_installation_source(new_src)
423
488
        '--option', 'Dpkg::Options::=--force-confdef',
424
489
    ]
425
490
    apt_update(fatal=True)
426
 
    apt_install(packages=get_early_packages(),
427
 
                options=dpkg_opts,
428
 
                fatal=True)
429
 
    apt_install(packages=get_packages(),
430
 
                options=dpkg_opts,
431
 
                fatal=True)
 
491
    apt_upgrade(options=dpkg_opts,
 
492
                fatal=True, dist=True)
 
493
    apt_install(get_early_packages(), fatal=True)
 
494
    apt_install(get_packages(), fatal=True)
432
495
 
433
496
    # set CONFIGS to load templates from new release
434
 
    configs.set_release(openstack_release=new_os_rel)
 
497
    configs = register_configs()
 
498
    configs.write_all()
 
499
    [service_restart(s) for s in services()]
 
500
    return configs
435
501
 
436
502
 
437
503
def configure_ovs():