~james-sapara/charms/precise/aws-ec2-elb/trunk

« back to all changes in this revision

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

  • Committer: James Sapara
  • Date: 2013-10-31 17:15:50 UTC
  • Revision ID: james.sapara@gmail.com-20131031171550-ssomsmi7uyfhup67
initial commit, still some work to do

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Various utilies for dealing with Neutron and the renaming from Quantum.
 
2
 
 
3
from subprocess import check_output
 
4
 
 
5
from charmhelpers.core.hookenv import (
 
6
    config,
 
7
    log,
 
8
    ERROR,
 
9
)
 
10
 
 
11
from charmhelpers.contrib.openstack.utils import os_release
 
12
 
 
13
 
 
14
def headers_package():
 
15
    """Ensures correct linux-headers for running kernel are installed,
 
16
    for building DKMS package"""
 
17
    kver = check_output(['uname', '-r']).strip()
 
18
    return 'linux-headers-%s' % kver
 
19
 
 
20
 
 
21
# legacy
 
22
def quantum_plugins():
 
23
    from charmhelpers.contrib.openstack import context
 
24
    return {
 
25
        'ovs': {
 
26
            'config': '/etc/quantum/plugins/openvswitch/'
 
27
                      'ovs_quantum_plugin.ini',
 
28
            'driver': 'quantum.plugins.openvswitch.ovs_quantum_plugin.'
 
29
                      'OVSQuantumPluginV2',
 
30
            'contexts': [
 
31
                context.SharedDBContext(user=config('neutron-database-user'),
 
32
                                        database=config('neutron-database'),
 
33
                                        relation_prefix='neutron')],
 
34
            'services': ['quantum-plugin-openvswitch-agent'],
 
35
            'packages': [[headers_package(), 'openvswitch-datapath-dkms'],
 
36
                         ['quantum-plugin-openvswitch-agent']],
 
37
        },
 
38
        'nvp': {
 
39
            'config': '/etc/quantum/plugins/nicira/nvp.ini',
 
40
            'driver': 'quantum.plugins.nicira.nicira_nvp_plugin.'
 
41
                      'QuantumPlugin.NvpPluginV2',
 
42
            'services': [],
 
43
            'packages': [],
 
44
        }
 
45
    }
 
46
 
 
47
 
 
48
def neutron_plugins():
 
49
    from charmhelpers.contrib.openstack import context
 
50
    return {
 
51
        'ovs': {
 
52
            'config': '/etc/neutron/plugins/openvswitch/'
 
53
                      'ovs_neutron_plugin.ini',
 
54
            'driver': 'neutron.plugins.openvswitch.ovs_neutron_plugin.'
 
55
                      'OVSNeutronPluginV2',
 
56
            'contexts': [
 
57
                context.SharedDBContext(user=config('neutron-database-user'),
 
58
                                        database=config('neutron-database'),
 
59
                                        relation_prefix='neutron')],
 
60
            'services': ['neutron-plugin-openvswitch-agent'],
 
61
            'packages': [[headers_package(), 'openvswitch-datapath-dkms'],
 
62
                         ['quantum-plugin-openvswitch-agent']],
 
63
        },
 
64
        'nvp': {
 
65
            'config': '/etc/neutron/plugins/nicira/nvp.ini',
 
66
            'driver': 'neutron.plugins.nicira.nicira_nvp_plugin.'
 
67
                      'NeutronPlugin.NvpPluginV2',
 
68
            'services': [],
 
69
            'packages': [],
 
70
        }
 
71
    }
 
72
 
 
73
 
 
74
def neutron_plugin_attribute(plugin, attr, net_manager=None):
 
75
    manager = net_manager or network_manager()
 
76
    if manager == 'quantum':
 
77
        plugins = quantum_plugins()
 
78
    elif manager == 'neutron':
 
79
        plugins = neutron_plugins()
 
80
    else:
 
81
        log('Error: Network manager does not support plugins.')
 
82
        raise Exception
 
83
 
 
84
    try:
 
85
        _plugin = plugins[plugin]
 
86
    except KeyError:
 
87
        log('Unrecognised plugin for %s: %s' % (manager, plugin), level=ERROR)
 
88
        raise Exception
 
89
 
 
90
    try:
 
91
        return _plugin[attr]
 
92
    except KeyError:
 
93
        return None
 
94
 
 
95
 
 
96
def network_manager():
 
97
    '''
 
98
    Deals with the renaming of Quantum to Neutron in H and any situations
 
99
    that require compatability (eg, deploying H with network-manager=quantum,
 
100
    upgrading from G).
 
101
    '''
 
102
    release = os_release('nova-common')
 
103
    manager = config('network-manager').lower()
 
104
 
 
105
    if manager not in ['quantum', 'neutron']:
 
106
        return manager
 
107
 
 
108
    if release in ['essex']:
 
109
        # E does not support neutron
 
110
        log('Neutron networking not supported in Essex.', level=ERROR)
 
111
        raise Exception
 
112
    elif release in ['folsom', 'grizzly']:
 
113
        # neutron is named quantum in F and G
 
114
        return 'quantum'
 
115
    else:
 
116
        # ensure accurate naming for all releases post-H
 
117
        return 'neutron'