~1chb1n/charms/trusty/keystone/amulet-fix-lp1440950

« back to all changes in this revision

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

  • Committer: Edward Hope-Morley
  • Date: 2015-03-19 09:56:37 UTC
  • mfrom: (130.1.2 keystone.fix-ssl-inject)
  • Revision ID: edward.hope-morley@canonical.com-20150319095637-e1u22rzewl3anald
[hopem,r=wolsen]

Fixes SSL cert/key inject from config.

Closes-Bug: 1351401

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
# Various utilies for dealing with Neutron and the renaming from Quantum.
18
18
 
 
19
import six
19
20
from subprocess import check_output
20
21
 
21
22
from charmhelpers.core.hookenv import (
237
238
    else:
238
239
        # ensure accurate naming for all releases post-H
239
240
        return 'neutron'
 
241
 
 
242
 
 
243
def parse_mappings(mappings):
 
244
    parsed = {}
 
245
    if mappings:
 
246
        mappings = mappings.split(' ')
 
247
        for m in mappings:
 
248
            p = m.partition(':')
 
249
            if p[1] == ':':
 
250
                parsed[p[0].strip()] = p[2].strip()
 
251
 
 
252
    return parsed
 
253
 
 
254
 
 
255
def parse_bridge_mappings(mappings):
 
256
    """Parse bridge mappings.
 
257
 
 
258
    Mappings must be a space-delimited list of provider:bridge mappings.
 
259
 
 
260
    Returns dict of the form {provider:bridge}.
 
261
    """
 
262
    return parse_mappings(mappings)
 
263
 
 
264
 
 
265
def parse_data_port_mappings(mappings, default_bridge='br-data'):
 
266
    """Parse data port mappings.
 
267
 
 
268
    Mappings must be a space-delimited list of bridge:port mappings.
 
269
 
 
270
    Returns dict of the form {bridge:port}.
 
271
    """
 
272
    _mappings = parse_mappings(mappings)
 
273
    if not _mappings:
 
274
        if not mappings:
 
275
            return {}
 
276
 
 
277
        # For backwards-compatibility we need to support port-only provided in
 
278
        # config.
 
279
        _mappings = {default_bridge: mappings.split(' ')[0]}
 
280
 
 
281
    bridges = _mappings.keys()
 
282
    ports = _mappings.values()
 
283
    if len(set(bridges)) != len(bridges):
 
284
        raise Exception("It is not allowed to have more than one port "
 
285
                        "configured on the same bridge")
 
286
 
 
287
    if len(set(ports)) != len(ports):
 
288
        raise Exception("It is not allowed to have the same port configured "
 
289
                        "on more than one bridge")
 
290
 
 
291
    return _mappings
 
292
 
 
293
 
 
294
def parse_vlan_range_mappings(mappings):
 
295
    """Parse vlan range mappings.
 
296
 
 
297
    Mappings must be a space-delimited list of provider:start:end mappings.
 
298
 
 
299
    Returns dict of the form {provider: (start, end)}.
 
300
    """
 
301
    _mappings = parse_mappings(mappings)
 
302
    if not _mappings:
 
303
        return {}
 
304
 
 
305
    mappings = {}
 
306
    for p, r in six.iteritems(_mappings):
 
307
        mappings[p] = tuple(r.split(':'))
 
308
 
 
309
    return mappings