~openstack-charmers-next/charms/wily/glance-simplestreams-sync/trunk

« back to all changes in this revision

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

  • Committer: james.page at ubuntu
  • Date: 2015-09-08 16:26:21 UTC
  • Revision ID: james.page@ubuntu.com-20150908162621-25gebqljve63h45a
Resync helpers

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 (
171
172
            'services': ['calico-felix',
172
173
                         'bird',
173
174
                         'neutron-dhcp-agent',
174
 
                         'nova-api-metadata'],
 
175
                         'nova-api-metadata',
 
176
                         'etcd'],
175
177
            'packages': [[headers_package()] + determine_dkms_package(),
176
178
                         ['calico-compute',
177
179
                          'bird',
178
180
                          'neutron-dhcp-agent',
179
 
                          'nova-api-metadata']],
180
 
            'server_packages': ['neutron-server', 'calico-control'],
 
181
                          'nova-api-metadata',
 
182
                          'etcd']],
 
183
            'server_packages': ['neutron-server', 'calico-control', 'etcd'],
 
184
            'server_services': ['neutron-server', 'etcd']
 
185
        },
 
186
        'vsp': {
 
187
            'config': '/etc/neutron/plugins/nuage/nuage_plugin.ini',
 
188
            'driver': 'neutron.plugins.nuage.plugin.NuagePlugin',
 
189
            'contexts': [
 
190
                context.SharedDBContext(user=config('neutron-database-user'),
 
191
                                        database=config('neutron-database'),
 
192
                                        relation_prefix='neutron',
 
193
                                        ssl_dir=NEUTRON_CONF_DIR)],
 
194
            'services': [],
 
195
            'packages': [],
 
196
            'server_packages': ['neutron-server', 'neutron-plugin-nuage'],
 
197
            'server_services': ['neutron-server']
 
198
        },
 
199
        'plumgrid': {
 
200
            'config': '/etc/neutron/plugins/plumgrid/plumgrid.ini',
 
201
            'driver': 'neutron.plugins.plumgrid.plumgrid_plugin.plumgrid_plugin.NeutronPluginPLUMgridV2',
 
202
            'contexts': [
 
203
                context.SharedDBContext(user=config('database-user'),
 
204
                                        database=config('database'),
 
205
                                        ssl_dir=NEUTRON_CONF_DIR)],
 
206
            'services': [],
 
207
            'packages': [['plumgrid-lxc'],
 
208
                         ['iovisor-dkms']],
 
209
            'server_packages': ['neutron-server',
 
210
                                'neutron-plugin-plumgrid'],
181
211
            'server_services': ['neutron-server']
182
212
        }
183
213
    }
237
267
    else:
238
268
        # ensure accurate naming for all releases post-H
239
269
        return 'neutron'
 
270
 
 
271
 
 
272
def parse_mappings(mappings, key_rvalue=False):
 
273
    """By default mappings are lvalue keyed.
 
274
 
 
275
    If key_rvalue is True, the mapping will be reversed to allow multiple
 
276
    configs for the same lvalue.
 
277
    """
 
278
    parsed = {}
 
279
    if mappings:
 
280
        mappings = mappings.split()
 
281
        for m in mappings:
 
282
            p = m.partition(':')
 
283
 
 
284
            if key_rvalue:
 
285
                key_index = 2
 
286
                val_index = 0
 
287
                # if there is no rvalue skip to next
 
288
                if not p[1]:
 
289
                    continue
 
290
            else:
 
291
                key_index = 0
 
292
                val_index = 2
 
293
 
 
294
            key = p[key_index].strip()
 
295
            parsed[key] = p[val_index].strip()
 
296
 
 
297
    return parsed
 
298
 
 
299
 
 
300
def parse_bridge_mappings(mappings):
 
301
    """Parse bridge mappings.
 
302
 
 
303
    Mappings must be a space-delimited list of provider:bridge mappings.
 
304
 
 
305
    Returns dict of the form {provider:bridge}.
 
306
    """
 
307
    return parse_mappings(mappings)
 
308
 
 
309
 
 
310
def parse_data_port_mappings(mappings, default_bridge='br-data'):
 
311
    """Parse data port mappings.
 
312
 
 
313
    Mappings must be a space-delimited list of port:bridge mappings.
 
314
 
 
315
    Returns dict of the form {port:bridge} where port may be an mac address or
 
316
    interface name.
 
317
    """
 
318
 
 
319
    # NOTE(dosaboy): we use rvalue for key to allow multiple values to be
 
320
    # proposed for <port> since it may be a mac address which will differ
 
321
    # across units this allowing first-known-good to be chosen.
 
322
    _mappings = parse_mappings(mappings, key_rvalue=True)
 
323
    if not _mappings or list(_mappings.values()) == ['']:
 
324
        if not mappings:
 
325
            return {}
 
326
 
 
327
        # For backwards-compatibility we need to support port-only provided in
 
328
        # config.
 
329
        _mappings = {mappings.split()[0]: default_bridge}
 
330
 
 
331
    ports = _mappings.keys()
 
332
    if len(set(ports)) != len(ports):
 
333
        raise Exception("It is not allowed to have the same port configured "
 
334
                        "on more than one bridge")
 
335
 
 
336
    return _mappings
 
337
 
 
338
 
 
339
def parse_vlan_range_mappings(mappings):
 
340
    """Parse vlan range mappings.
 
341
 
 
342
    Mappings must be a space-delimited list of provider:start:end mappings.
 
343
 
 
344
    The start:end range is optional and may be omitted.
 
345
 
 
346
    Returns dict of the form {provider: (start, end)}.
 
347
    """
 
348
    _mappings = parse_mappings(mappings)
 
349
    if not _mappings:
 
350
        return {}
 
351
 
 
352
    mappings = {}
 
353
    for p, r in six.iteritems(_mappings):
 
354
        mappings[p] = tuple(r.split(':'))
 
355
 
 
356
    return mappings