258
def parse_mappings(mappings):
258
def parse_mappings(mappings, key_rvalue=False):
259
"""By default mappings are lvalue keyed.
261
If key_rvalue is True, the mapping will be reversed to allow multiple
262
configs for the same lvalue.
261
266
mappings = mappings.split()
262
267
for m in mappings:
263
268
p = m.partition(':')
266
parsed[key] = p[2].strip()
273
# if there is no rvalue skip to next
280
key = p[key_index].strip()
281
parsed[key] = p[val_index].strip()
283
296
def parse_data_port_mappings(mappings, default_bridge='br-data'):
284
297
"""Parse data port mappings.
286
Mappings must be a space-delimited list of bridge:port mappings.
299
Mappings must be a space-delimited list of port:bridge mappings.
288
Returns dict of the form {bridge:port}.
301
Returns dict of the form {port:bridge} where port may be an mac address or
290
_mappings = parse_mappings(mappings)
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()) == ['']:
295
313
# For backwards-compatibility we need to support port-only provided in
297
_mappings = {default_bridge: mappings.split()[0]}
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")
315
_mappings = {mappings.split()[0]: default_bridge}
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")