66
by Liam Young
[gnuoy,trivial] Pre-release charmhelper sync |
1 |
# Copyright 2014-2015 Canonical Limited.
|
2 |
#
|
|
3 |
# This file is part of charm-helpers.
|
|
4 |
#
|
|
5 |
# charm-helpers is free software: you can redistribute it and/or modify
|
|
6 |
# it under the terms of the GNU Lesser General Public License version 3 as
|
|
7 |
# published by the Free Software Foundation.
|
|
8 |
#
|
|
9 |
# charm-helpers is distributed in the hope that it will be useful,
|
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
# GNU Lesser General Public License for more details.
|
|
13 |
#
|
|
14 |
# You should have received a copy of the GNU Lesser General Public License
|
|
15 |
# along with charm-helpers. If not, see <http://www.gnu.org/licenses/>.
|
|
16 |
||
29
by James Page
Rebase on charmhelpers |
17 |
# Various utilies for dealing with Neutron and the renaming from Quantum.
|
18 |
||
72.1.1
by Edward Hope-Morley
[hopem,r=] fix ssl cert inject |
19 |
import six |
29
by James Page
Rebase on charmhelpers |
20 |
from subprocess import check_output |
21 |
||
22 |
from charmhelpers.core.hookenv import ( |
|
23 |
config, |
|
24 |
log, |
|
25 |
ERROR, |
|
26 |
)
|
|
27 |
||
28 |
from charmhelpers.contrib.openstack.utils import os_release |
|
29 |
||
30 |
||
31 |
def headers_package(): |
|
32 |
"""Ensures correct linux-headers for running kernel are installed,
|
|
33 |
for building DKMS package"""
|
|
57.1.2
by Corey Bryant
Sync charm-helpers. |
34 |
kver = check_output(['uname', '-r']).decode('UTF-8').strip() |
29
by James Page
Rebase on charmhelpers |
35 |
return 'linux-headers-%s' % kver |
36 |
||
47.1.5
by James Page
Resynced helpers |
37 |
QUANTUM_CONF_DIR = '/etc/quantum' |
38 |
||
29
by James Page
Rebase on charmhelpers |
39 |
|
47.1.2
by James Page
Resynced helpers |
40 |
def kernel_version(): |
41 |
""" Retrieve the current major kernel version as a tuple e.g. (3, 13) """
|
|
57.1.2
by Corey Bryant
Sync charm-helpers. |
42 |
kver = check_output(['uname', '-r']).decode('UTF-8').strip() |
47.1.2
by James Page
Resynced helpers |
43 |
kver = kver.split('.') |
44 |
return (int(kver[0]), int(kver[1])) |
|
45 |
||
46 |
||
47 |
def determine_dkms_package(): |
|
48 |
""" Determine which DKMS package should be used based on kernel version """
|
|
49 |
# NOTE: 3.13 kernels have support for GRE and VXLAN native
|
|
50 |
if kernel_version() >= (3, 13): |
|
51 |
return [] |
|
52 |
else: |
|
53 |
return ['openvswitch-datapath-dkms'] |
|
54 |
||
55 |
||
29
by James Page
Rebase on charmhelpers |
56 |
# legacy
|
47.1.5
by James Page
Resynced helpers |
57 |
|
58 |
||
29
by James Page
Rebase on charmhelpers |
59 |
def quantum_plugins(): |
60 |
from charmhelpers.contrib.openstack import context |
|
61 |
return { |
|
62 |
'ovs': { |
|
63 |
'config': '/etc/quantum/plugins/openvswitch/' |
|
64 |
'ovs_quantum_plugin.ini', |
|
65 |
'driver': 'quantum.plugins.openvswitch.ovs_quantum_plugin.' |
|
66 |
'OVSQuantumPluginV2', |
|
67 |
'contexts': [ |
|
68 |
context.SharedDBContext(user=config('neutron-database-user'), |
|
69 |
database=config('neutron-database'), |
|
47.1.5
by James Page
Resynced helpers |
70 |
relation_prefix='neutron', |
71 |
ssl_dir=QUANTUM_CONF_DIR)], |
|
29
by James Page
Rebase on charmhelpers |
72 |
'services': ['quantum-plugin-openvswitch-agent'], |
47.1.2
by James Page
Resynced helpers |
73 |
'packages': [[headers_package()] + determine_dkms_package(), |
29
by James Page
Rebase on charmhelpers |
74 |
['quantum-plugin-openvswitch-agent']], |
45
by James Page
Resync helpers |
75 |
'server_packages': ['quantum-server', |
76 |
'quantum-plugin-openvswitch'], |
|
77 |
'server_services': ['quantum-server'] |
|
29
by James Page
Rebase on charmhelpers |
78 |
},
|
79 |
'nvp': { |
|
80 |
'config': '/etc/quantum/plugins/nicira/nvp.ini', |
|
81 |
'driver': 'quantum.plugins.nicira.nicira_nvp_plugin.' |
|
82 |
'QuantumPlugin.NvpPluginV2', |
|
45
by James Page
Resync helpers |
83 |
'contexts': [ |
84 |
context.SharedDBContext(user=config('neutron-database-user'), |
|
85 |
database=config('neutron-database'), |
|
47.1.5
by James Page
Resynced helpers |
86 |
relation_prefix='neutron', |
87 |
ssl_dir=QUANTUM_CONF_DIR)], |
|
29
by James Page
Rebase on charmhelpers |
88 |
'services': [], |
89 |
'packages': [], |
|
45
by James Page
Resync helpers |
90 |
'server_packages': ['quantum-server', |
91 |
'quantum-plugin-nicira'], |
|
92 |
'server_services': ['quantum-server'] |
|
29
by James Page
Rebase on charmhelpers |
93 |
}
|
94 |
}
|
|
95 |
||
47.1.5
by James Page
Resynced helpers |
96 |
NEUTRON_CONF_DIR = '/etc/neutron' |
97 |
||
29
by James Page
Rebase on charmhelpers |
98 |
|
99 |
def neutron_plugins(): |
|
100 |
from charmhelpers.contrib.openstack import context |
|
47.1.2
by James Page
Resynced helpers |
101 |
release = os_release('nova-common') |
102 |
plugins = { |
|
29
by James Page
Rebase on charmhelpers |
103 |
'ovs': { |
104 |
'config': '/etc/neutron/plugins/openvswitch/' |
|
105 |
'ovs_neutron_plugin.ini', |
|
106 |
'driver': 'neutron.plugins.openvswitch.ovs_neutron_plugin.' |
|
107 |
'OVSNeutronPluginV2', |
|
108 |
'contexts': [ |
|
109 |
context.SharedDBContext(user=config('neutron-database-user'), |
|
110 |
database=config('neutron-database'), |
|
47.1.5
by James Page
Resynced helpers |
111 |
relation_prefix='neutron', |
112 |
ssl_dir=NEUTRON_CONF_DIR)], |
|
29
by James Page
Rebase on charmhelpers |
113 |
'services': ['neutron-plugin-openvswitch-agent'], |
47.1.2
by James Page
Resynced helpers |
114 |
'packages': [[headers_package()] + determine_dkms_package(), |
115 |
['neutron-plugin-openvswitch-agent']], |
|
45
by James Page
Resync helpers |
116 |
'server_packages': ['neutron-server', |
117 |
'neutron-plugin-openvswitch'], |
|
118 |
'server_services': ['neutron-server'] |
|
29
by James Page
Rebase on charmhelpers |
119 |
},
|
120 |
'nvp': { |
|
121 |
'config': '/etc/neutron/plugins/nicira/nvp.ini', |
|
122 |
'driver': 'neutron.plugins.nicira.nicira_nvp_plugin.' |
|
123 |
'NeutronPlugin.NvpPluginV2', |
|
45
by James Page
Resync helpers |
124 |
'contexts': [ |
125 |
context.SharedDBContext(user=config('neutron-database-user'), |
|
126 |
database=config('neutron-database'), |
|
47.1.5
by James Page
Resynced helpers |
127 |
relation_prefix='neutron', |
128 |
ssl_dir=NEUTRON_CONF_DIR)], |
|
29
by James Page
Rebase on charmhelpers |
129 |
'services': [], |
130 |
'packages': [], |
|
45
by James Page
Resync helpers |
131 |
'server_packages': ['neutron-server', |
132 |
'neutron-plugin-nicira'], |
|
133 |
'server_services': ['neutron-server'] |
|
49
by james.page at ubuntu
resync helpers for juno support |
134 |
},
|
135 |
'nsx': { |
|
136 |
'config': '/etc/neutron/plugins/vmware/nsx.ini', |
|
137 |
'driver': 'vmware', |
|
138 |
'contexts': [ |
|
139 |
context.SharedDBContext(user=config('neutron-database-user'), |
|
140 |
database=config('neutron-database'), |
|
141 |
relation_prefix='neutron', |
|
142 |
ssl_dir=NEUTRON_CONF_DIR)], |
|
143 |
'services': [], |
|
144 |
'packages': [], |
|
145 |
'server_packages': ['neutron-server', |
|
146 |
'neutron-plugin-vmware'], |
|
147 |
'server_services': ['neutron-server'] |
|
49.1.2
by james.page at ubuntu
Resync helpers |
148 |
},
|
149 |
'n1kv': { |
|
150 |
'config': '/etc/neutron/plugins/cisco/cisco_plugins.ini', |
|
151 |
'driver': 'neutron.plugins.cisco.network_plugin.PluginV2', |
|
152 |
'contexts': [ |
|
153 |
context.SharedDBContext(user=config('neutron-database-user'), |
|
154 |
database=config('neutron-database'), |
|
155 |
relation_prefix='neutron', |
|
156 |
ssl_dir=NEUTRON_CONF_DIR)], |
|
157 |
'services': [], |
|
56.1.1
by Billy Olsen
Sync charm helpers code |
158 |
'packages': [[headers_package()] + determine_dkms_package(), |
159 |
['neutron-plugin-cisco']], |
|
49.1.2
by james.page at ubuntu
Resync helpers |
160 |
'server_packages': ['neutron-server', |
161 |
'neutron-plugin-cisco'], |
|
162 |
'server_services': ['neutron-server'] |
|
56.1.1
by Billy Olsen
Sync charm helpers code |
163 |
},
|
164 |
'Calico': { |
|
165 |
'config': '/etc/neutron/plugins/ml2/ml2_conf.ini', |
|
166 |
'driver': 'neutron.plugins.ml2.plugin.Ml2Plugin', |
|
167 |
'contexts': [ |
|
168 |
context.SharedDBContext(user=config('neutron-database-user'), |
|
169 |
database=config('neutron-database'), |
|
170 |
relation_prefix='neutron', |
|
171 |
ssl_dir=NEUTRON_CONF_DIR)], |
|
62.1.1
by Edward Hope-Morley
charmhelpers sync to get fix for apache ssl port selection |
172 |
'services': ['calico-felix', |
173 |
'bird', |
|
174 |
'neutron-dhcp-agent', |
|
175 |
'nova-api-metadata'], |
|
56.1.1
by Billy Olsen
Sync charm helpers code |
176 |
'packages': [[headers_package()] + determine_dkms_package(), |
62.1.1
by Edward Hope-Morley
charmhelpers sync to get fix for apache ssl port selection |
177 |
['calico-compute', |
178 |
'bird', |
|
179 |
'neutron-dhcp-agent', |
|
180 |
'nova-api-metadata']], |
|
56.1.1
by Billy Olsen
Sync charm helpers code |
181 |
'server_packages': ['neutron-server', 'calico-control'], |
182 |
'server_services': ['neutron-server'] |
|
77
by Liam Young
[gnuoy,trivial] Pre-release charmhelper sync |
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'] |
|
29
by James Page
Rebase on charmhelpers |
196 |
}
|
197 |
}
|
|
47.1.2
by James Page
Resynced helpers |
198 |
if release >= 'icehouse': |
49
by james.page at ubuntu
resync helpers for juno support |
199 |
# NOTE: patch in ml2 plugin for icehouse onwards
|
47.1.2
by James Page
Resynced helpers |
200 |
plugins['ovs']['config'] = '/etc/neutron/plugins/ml2/ml2_conf.ini' |
201 |
plugins['ovs']['driver'] = 'neutron.plugins.ml2.plugin.Ml2Plugin' |
|
202 |
plugins['ovs']['server_packages'] = ['neutron-server', |
|
203 |
'neutron-plugin-ml2'] |
|
49
by james.page at ubuntu
resync helpers for juno support |
204 |
# NOTE: patch in vmware renames nvp->nsx for icehouse onwards
|
205 |
plugins['nvp'] = plugins['nsx'] |
|
47.1.2
by James Page
Resynced helpers |
206 |
return plugins |
29
by James Page
Rebase on charmhelpers |
207 |
|
208 |
||
209 |
def neutron_plugin_attribute(plugin, attr, net_manager=None): |
|
210 |
manager = net_manager or network_manager() |
|
211 |
if manager == 'quantum': |
|
212 |
plugins = quantum_plugins() |
|
213 |
elif manager == 'neutron': |
|
214 |
plugins = neutron_plugins() |
|
215 |
else: |
|
57.1.2
by Corey Bryant
Sync charm-helpers. |
216 |
log("Network manager '%s' does not support plugins." % (manager), |
217 |
level=ERROR) |
|
29
by James Page
Rebase on charmhelpers |
218 |
raise Exception |
219 |
||
220 |
try: |
|
221 |
_plugin = plugins[plugin] |
|
222 |
except KeyError: |
|
223 |
log('Unrecognised plugin for %s: %s' % (manager, plugin), level=ERROR) |
|
38
by James Page
Switch to using openstack context templating |
224 |
raise Exception |
29
by James Page
Rebase on charmhelpers |
225 |
|
226 |
try: |
|
227 |
return _plugin[attr] |
|
228 |
except KeyError: |
|
229 |
return None |
|
230 |
||
231 |
||
232 |
def network_manager(): |
|
233 |
'''
|
|
234 |
Deals with the renaming of Quantum to Neutron in H and any situations
|
|
235 |
that require compatability (eg, deploying H with network-manager=quantum,
|
|
236 |
upgrading from G).
|
|
237 |
'''
|
|
238 |
release = os_release('nova-common') |
|
239 |
manager = config('network-manager').lower() |
|
240 |
||
241 |
if manager not in ['quantum', 'neutron']: |
|
242 |
return manager |
|
243 |
||
244 |
if release in ['essex']: |
|
245 |
# E does not support neutron
|
|
246 |
log('Neutron networking not supported in Essex.', level=ERROR) |
|
38
by James Page
Switch to using openstack context templating |
247 |
raise Exception |
29
by James Page
Rebase on charmhelpers |
248 |
elif release in ['folsom', 'grizzly']: |
249 |
# neutron is named quantum in F and G
|
|
250 |
return 'quantum' |
|
251 |
else: |
|
252 |
# ensure accurate naming for all releases post-H
|
|
253 |
return 'neutron' |
|
72.1.1
by Edward Hope-Morley
[hopem,r=] fix ssl cert inject |
254 |
|
255 |
||
256 |
def parse_mappings(mappings): |
|
257 |
parsed = {} |
|
258 |
if mappings: |
|
71.1.16
by Liam Young
Resync le charm helpers |
259 |
mappings = mappings.split() |
72.1.1
by Edward Hope-Morley
[hopem,r=] fix ssl cert inject |
260 |
for m in mappings: |
261 |
p = m.partition(':') |
|
71.1.16
by Liam Young
Resync le charm helpers |
262 |
key = p[0].strip() |
263 |
if p[1]: |
|
264 |
parsed[key] = p[2].strip() |
|
265 |
else: |
|
266 |
parsed[key] = '' |
|
72.1.1
by Edward Hope-Morley
[hopem,r=] fix ssl cert inject |
267 |
|
268 |
return parsed |
|
269 |
||
270 |
||
271 |
def parse_bridge_mappings(mappings): |
|
272 |
"""Parse bridge mappings.
|
|
273 |
||
274 |
Mappings must be a space-delimited list of provider:bridge mappings.
|
|
275 |
||
276 |
Returns dict of the form {provider:bridge}.
|
|
277 |
"""
|
|
278 |
return parse_mappings(mappings) |
|
279 |
||
280 |
||
281 |
def parse_data_port_mappings(mappings, default_bridge='br-data'): |
|
282 |
"""Parse data port mappings.
|
|
283 |
||
284 |
Mappings must be a space-delimited list of bridge:port mappings.
|
|
285 |
||
286 |
Returns dict of the form {bridge:port}.
|
|
287 |
"""
|
|
288 |
_mappings = parse_mappings(mappings) |
|
71.1.16
by Liam Young
Resync le charm helpers |
289 |
if not _mappings or list(_mappings.values()) == ['']: |
72.1.1
by Edward Hope-Morley
[hopem,r=] fix ssl cert inject |
290 |
if not mappings: |
291 |
return {} |
|
292 |
||
293 |
# For backwards-compatibility we need to support port-only provided in
|
|
294 |
# config.
|
|
71.1.16
by Liam Young
Resync le charm helpers |
295 |
_mappings = {default_bridge: mappings.split()[0]} |
72.1.1
by Edward Hope-Morley
[hopem,r=] fix ssl cert inject |
296 |
|
297 |
bridges = _mappings.keys() |
|
298 |
ports = _mappings.values() |
|
299 |
if len(set(bridges)) != len(bridges): |
|
300 |
raise Exception("It is not allowed to have more than one port " |
|
301 |
"configured on the same bridge") |
|
302 |
||
303 |
if len(set(ports)) != len(ports): |
|
304 |
raise Exception("It is not allowed to have the same port configured " |
|
305 |
"on more than one bridge") |
|
306 |
||
307 |
return _mappings |
|
308 |
||
309 |
||
310 |
def parse_vlan_range_mappings(mappings): |
|
311 |
"""Parse vlan range mappings.
|
|
312 |
||
313 |
Mappings must be a space-delimited list of provider:start:end mappings.
|
|
314 |
||
71.1.16
by Liam Young
Resync le charm helpers |
315 |
The start:end range is optional and may be omitted.
|
316 |
||
72.1.1
by Edward Hope-Morley
[hopem,r=] fix ssl cert inject |
317 |
Returns dict of the form {provider: (start, end)}.
|
318 |
"""
|
|
319 |
_mappings = parse_mappings(mappings) |
|
320 |
if not _mappings: |
|
321 |
return {} |
|
322 |
||
323 |
mappings = {} |
|
324 |
for p, r in six.iteritems(_mappings): |
|
325 |
mappings[p] = tuple(r.split(':')) |
|
326 |
||
327 |
return mappings |