~ivoks/charms/trusty/contrail-analytics/host-private-address

« back to all changes in this revision

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

  • Committer: Robert Ayres
  • Date: 2015-08-28 11:03:51 UTC
  • Revision ID: robert.ayres@canonical.com-20150828110351-g20rec150sofg9ag
Sync charm helpers

Show diffs side-by-side

added added

removed removed

Lines of Context:
172
172
            'services': ['calico-felix',
173
173
                         'bird',
174
174
                         'neutron-dhcp-agent',
175
 
                         'nova-api-metadata'],
 
175
                         'nova-api-metadata',
 
176
                         'etcd'],
176
177
            'packages': [[headers_package()] + determine_dkms_package(),
177
178
                         ['calico-compute',
178
179
                          'bird',
179
180
                          'neutron-dhcp-agent',
180
 
                          'nova-api-metadata']],
181
 
            'server_packages': ['neutron-server', 'calico-control'],
182
 
            'server_services': ['neutron-server']
 
181
                          'nova-api-metadata',
 
182
                          'etcd']],
 
183
            'server_packages': ['neutron-server', 'calico-control', 'etcd'],
 
184
            'server_services': ['neutron-server', 'etcd']
183
185
        },
184
186
        'vsp': {
185
187
            'config': '/etc/neutron/plugins/nuage/nuage_plugin.ini',
253
255
        return 'neutron'
254
256
 
255
257
 
256
 
def parse_mappings(mappings):
 
258
def parse_mappings(mappings, key_rvalue=False):
 
259
    """By default mappings are lvalue keyed.
 
260
 
 
261
    If key_rvalue is True, the mapping will be reversed to allow multiple
 
262
    configs for the same lvalue.
 
263
    """
257
264
    parsed = {}
258
265
    if mappings:
259
 
        mappings = mappings.split(' ')
 
266
        mappings = mappings.split()
260
267
        for m in mappings:
261
268
            p = m.partition(':')
262
 
            if p[1] == ':':
263
 
                parsed[p[0].strip()] = p[2].strip()
 
269
 
 
270
            if key_rvalue:
 
271
                key_index = 2
 
272
                val_index = 0
 
273
                # if there is no rvalue skip to next
 
274
                if not p[1]:
 
275
                    continue
 
276
            else:
 
277
                key_index = 0
 
278
                val_index = 2
 
279
 
 
280
            key = p[key_index].strip()
 
281
            parsed[key] = p[val_index].strip()
264
282
 
265
283
    return parsed
266
284
 
278
296
def parse_data_port_mappings(mappings, default_bridge='br-data'):
279
297
    """Parse data port mappings.
280
298
 
281
 
    Mappings must be a space-delimited list of bridge:port mappings.
 
299
    Mappings must be a space-delimited list of port:bridge mappings.
282
300
 
283
 
    Returns dict of the form {bridge:port}.
 
301
    Returns dict of the form {port:bridge} where port may be an mac address or
 
302
    interface name.
284
303
    """
285
 
    _mappings = parse_mappings(mappings)
286
 
    if not _mappings:
 
304
 
 
305
    # NOTE(dosaboy): we use rvalue for key to allow multiple values to be
 
306
    # proposed for <port> since it may be a mac address which will differ
 
307
    # across units this allowing first-known-good to be chosen.
 
308
    _mappings = parse_mappings(mappings, key_rvalue=True)
 
309
    if not _mappings or list(_mappings.values()) == ['']:
287
310
        if not mappings:
288
311
            return {}
289
312
 
290
313
        # For backwards-compatibility we need to support port-only provided in
291
314
        # config.
292
 
        _mappings = {default_bridge: mappings.split(' ')[0]}
293
 
 
294
 
    bridges = _mappings.keys()
295
 
    ports = _mappings.values()
296
 
    if len(set(bridges)) != len(bridges):
297
 
        raise Exception("It is not allowed to have more than one port "
298
 
                        "configured on the same bridge")
299
 
 
 
315
        _mappings = {mappings.split()[0]: default_bridge}
 
316
 
 
317
    ports = _mappings.keys()
300
318
    if len(set(ports)) != len(ports):
301
319
        raise Exception("It is not allowed to have the same port configured "
302
320
                        "on more than one bridge")
309
327
 
310
328
    Mappings must be a space-delimited list of provider:start:end mappings.
311
329
 
 
330
    The start:end range is optional and may be omitted.
 
331
 
312
332
    Returns dict of the form {provider: (start, end)}.
313
333
    """
314
334
    _mappings = parse_mappings(mappings)