~1chb1n/charms/trusty/cinder-ceph/next.1601-test-update2

« back to all changes in this revision

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

  • Committer: Liam Young
  • Date: 2015-04-16 10:29:35 UTC
  • Revision ID: liam.young@canonical.com-20150416102935-od0wokkgjl6ccu81
[gnuoy,trivial] Pre-release charmhelper sync

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 (
179
180
                          'nova-api-metadata']],
180
181
            'server_packages': ['neutron-server', 'calico-control'],
181
182
            'server_services': ['neutron-server']
 
183
        },
 
184
        'vsp': {
 
185
            'config': '/etc/neutron/plugins/nuage/nuage_plugin.ini',
 
186
            'driver': 'neutron.plugins.nuage.plugin.NuagePlugin',
 
187
            'contexts': [
 
188
                context.SharedDBContext(user=config('neutron-database-user'),
 
189
                                        database=config('neutron-database'),
 
190
                                        relation_prefix='neutron',
 
191
                                        ssl_dir=NEUTRON_CONF_DIR)],
 
192
            'services': [],
 
193
            'packages': [],
 
194
            'server_packages': ['neutron-server', 'neutron-plugin-nuage'],
 
195
            'server_services': ['neutron-server']
182
196
        }
183
197
    }
184
198
    if release >= 'icehouse':
237
251
    else:
238
252
        # ensure accurate naming for all releases post-H
239
253
        return 'neutron'
 
254
 
 
255
 
 
256
def parse_mappings(mappings):
 
257
    parsed = {}
 
258
    if mappings:
 
259
        mappings = mappings.split(' ')
 
260
        for m in mappings:
 
261
            p = m.partition(':')
 
262
            if p[1] == ':':
 
263
                parsed[p[0].strip()] = p[2].strip()
 
264
 
 
265
    return parsed
 
266
 
 
267
 
 
268
def parse_bridge_mappings(mappings):
 
269
    """Parse bridge mappings.
 
270
 
 
271
    Mappings must be a space-delimited list of provider:bridge mappings.
 
272
 
 
273
    Returns dict of the form {provider:bridge}.
 
274
    """
 
275
    return parse_mappings(mappings)
 
276
 
 
277
 
 
278
def parse_data_port_mappings(mappings, default_bridge='br-data'):
 
279
    """Parse data port mappings.
 
280
 
 
281
    Mappings must be a space-delimited list of bridge:port mappings.
 
282
 
 
283
    Returns dict of the form {bridge:port}.
 
284
    """
 
285
    _mappings = parse_mappings(mappings)
 
286
    if not _mappings:
 
287
        if not mappings:
 
288
            return {}
 
289
 
 
290
        # For backwards-compatibility we need to support port-only provided in
 
291
        # 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
 
 
300
    if len(set(ports)) != len(ports):
 
301
        raise Exception("It is not allowed to have the same port configured "
 
302
                        "on more than one bridge")
 
303
 
 
304
    return _mappings
 
305
 
 
306
 
 
307
def parse_vlan_range_mappings(mappings):
 
308
    """Parse vlan range mappings.
 
309
 
 
310
    Mappings must be a space-delimited list of provider:start:end mappings.
 
311
 
 
312
    Returns dict of the form {provider: (start, end)}.
 
313
    """
 
314
    _mappings = parse_mappings(mappings)
 
315
    if not _mappings:
 
316
        return {}
 
317
 
 
318
    mappings = {}
 
319
    for p, r in six.iteritems(_mappings):
 
320
        mappings[p] = tuple(r.split(':'))
 
321
 
 
322
    return mappings