~openstack-charmers-archive/charms/trusty/neutron-gateway/trunk

« back to all changes in this revision

Viewing changes to hooks/charmhelpers/contrib/openstack/neutron.py

  • Committer: James Page
  • Date: 2015-10-22 13:23:58 UTC
  • Revision ID: james.page@ubuntu.com-20151022132358-qin1nvlnqn4aezaz
Tags: 15.10
15.10 Charm release

Show diffs side-by-side

added added

removed removed

Lines of Context:
195
195
            'packages': [],
196
196
            'server_packages': ['neutron-server', 'neutron-plugin-nuage'],
197
197
            'server_services': ['neutron-server']
 
198
        },
 
199
        'plumgrid': {
 
200
            'config': '/etc/neutron/plugins/plumgrid/plumgrid.ini',
 
201
            'driver': 'neutron.plugins.plumgrid.plumgrid_plugin.plumgrid_plugin.NeutronPluginPLUMgridV2',
 
202
            'contexts': [
 
203
                context.SharedDBContext(user=config('database-user'),
 
204
                                        database=config('database'),
 
205
                                        ssl_dir=NEUTRON_CONF_DIR)],
 
206
            'services': [],
 
207
            'packages': [['plumgrid-lxc'],
 
208
                         ['iovisor-dkms']],
 
209
            'server_packages': ['neutron-server',
 
210
                                'neutron-plugin-plumgrid'],
 
211
            'server_services': ['neutron-server']
 
212
        },
 
213
        'midonet': {
 
214
            'config': '/etc/neutron/plugins/midonet/midonet.ini',
 
215
            'driver': 'midonet.neutron.plugin.MidonetPluginV2',
 
216
            'contexts': [
 
217
                context.SharedDBContext(user=config('neutron-database-user'),
 
218
                                        database=config('neutron-database'),
 
219
                                        relation_prefix='neutron',
 
220
                                        ssl_dir=NEUTRON_CONF_DIR)],
 
221
            'services': [],
 
222
            'packages': [[headers_package()] + determine_dkms_package()],
 
223
            'server_packages': ['neutron-server',
 
224
                                'python-neutron-plugin-midonet'],
 
225
            'server_services': ['neutron-server']
198
226
        }
199
227
    }
200
228
    if release >= 'icehouse':
255
283
        return 'neutron'
256
284
 
257
285
 
258
 
def parse_mappings(mappings):
 
286
def parse_mappings(mappings, key_rvalue=False):
 
287
    """By default mappings are lvalue keyed.
 
288
 
 
289
    If key_rvalue is True, the mapping will be reversed to allow multiple
 
290
    configs for the same lvalue.
 
291
    """
259
292
    parsed = {}
260
293
    if mappings:
261
294
        mappings = mappings.split()
262
295
        for m in mappings:
263
296
            p = m.partition(':')
264
 
            key = p[0].strip()
265
 
            if p[1]:
266
 
                parsed[key] = p[2].strip()
 
297
 
 
298
            if key_rvalue:
 
299
                key_index = 2
 
300
                val_index = 0
 
301
                # if there is no rvalue skip to next
 
302
                if not p[1]:
 
303
                    continue
267
304
            else:
268
 
                parsed[key] = ''
 
305
                key_index = 0
 
306
                val_index = 2
 
307
 
 
308
            key = p[key_index].strip()
 
309
            parsed[key] = p[val_index].strip()
269
310
 
270
311
    return parsed
271
312
 
283
324
def parse_data_port_mappings(mappings, default_bridge='br-data'):
284
325
    """Parse data port mappings.
285
326
 
286
 
    Mappings must be a space-delimited list of bridge:port mappings.
 
327
    Mappings must be a space-delimited list of bridge:port.
287
328
 
288
 
    Returns dict of the form {bridge:port}.
 
329
    Returns dict of the form {port:bridge} where ports may be mac addresses or
 
330
    interface names.
289
331
    """
290
 
    _mappings = parse_mappings(mappings)
 
332
 
 
333
    # NOTE(dosaboy): we use rvalue for key to allow multiple values to be
 
334
    # proposed for <port> since it may be a mac address which will differ
 
335
    # across units this allowing first-known-good to be chosen.
 
336
    _mappings = parse_mappings(mappings, key_rvalue=True)
291
337
    if not _mappings or list(_mappings.values()) == ['']:
292
338
        if not mappings:
293
339
            return {}
294
340
 
295
341
        # For backwards-compatibility we need to support port-only provided in
296
342
        # config.
297
 
        _mappings = {default_bridge: mappings.split()[0]}
298
 
 
299
 
    bridges = _mappings.keys()
300
 
    ports = _mappings.values()
301
 
    if len(set(bridges)) != len(bridges):
302
 
        raise Exception("It is not allowed to have more than one port "
303
 
                        "configured on the same bridge")
304
 
 
 
343
        _mappings = {mappings.split()[0]: default_bridge}
 
344
 
 
345
    ports = _mappings.keys()
305
346
    if len(set(ports)) != len(ports):
306
347
        raise Exception("It is not allowed to have the same port configured "
307
348
                        "on more than one bridge")