~corey.bryant/charms/trusty/openstack-dashboard/git-1531612

« back to all changes in this revision

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

  • Committer: Liam Young
  • Date: 2015-08-19 13:51:03 UTC
  • Revision ID: liam.young@canonical.com-20150819135103-3wd3o25lprfo1kf8
[gnuoy,trivial] Charmhelper sync (+1'd by mojo)

Show diffs side-by-side

added added

removed removed

Lines of Context:
255
255
        return 'neutron'
256
256
 
257
257
 
258
 
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
    """
259
264
    parsed = {}
260
265
    if mappings:
261
266
        mappings = mappings.split()
262
267
        for m in mappings:
263
268
            p = m.partition(':')
264
 
            key = p[0].strip()
265
 
            if p[1]:
266
 
                parsed[key] = 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
267
276
            else:
268
 
                parsed[key] = ''
 
277
                key_index = 0
 
278
                val_index = 2
 
279
 
 
280
            key = p[key_index].strip()
 
281
            parsed[key] = p[val_index].strip()
269
282
 
270
283
    return parsed
271
284
 
283
296
def parse_data_port_mappings(mappings, default_bridge='br-data'):
284
297
    """Parse data port mappings.
285
298
 
286
 
    Mappings must be a space-delimited list of bridge:port mappings.
 
299
    Mappings must be a space-delimited list of port:bridge mappings.
287
300
 
288
 
    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.
289
303
    """
290
 
    _mappings = parse_mappings(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)
291
309
    if not _mappings or list(_mappings.values()) == ['']:
292
310
        if not mappings:
293
311
            return {}
294
312
 
295
313
        # For backwards-compatibility we need to support port-only provided in
296
314
        # 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
 
 
 
315
        _mappings = {mappings.split()[0]: default_bridge}
 
316
 
 
317
    ports = _mappings.keys()
305
318
    if len(set(ports)) != len(ports):
306
319
        raise Exception("It is not allowed to have the same port configured "
307
320
                        "on more than one bridge")