5
from charmhelpers.core.hookenv import (
10
from charmhelpers.fetch import (
13
from charmhelpers.contrib.openstack.context import (
17
from charmhelpers.contrib.openstack.utils import (
18
get_os_codename_install_source
20
from charmhelpers.contrib.hahelpers.cluster import(
23
from charmhelpers.contrib.network.ip import (
24
get_address_in_network,
28
QUANTUM_DB = "quantum"
32
QUANTUM_OVS_PLUGIN = \
33
"quantum.plugins.openvswitch.ovs_quantum_plugin.OVSQuantumPluginV2"
34
QUANTUM_NVP_PLUGIN = \
35
"quantum.plugins.nicira.nicira_nvp_plugin.QuantumPlugin.NvpPluginV2"
36
NEUTRON_OVS_PLUGIN = \
37
"neutron.plugins.openvswitch.ovs_neutron_plugin.OVSNeutronPluginV2"
38
NEUTRON_ML2_PLUGIN = \
39
"neutron.plugins.ml2.plugin.Ml2Plugin"
40
NEUTRON_NVP_PLUGIN = \
41
"neutron.plugins.nicira.nicira_nvp_plugin.NeutronPlugin.NvpPluginV2"
42
NEUTRON_N1KV_PLUGIN = \
43
"neutron.plugins.cisco.n1kv.n1kv_neutron_plugin.N1kvNeutronPluginV2"
44
NEUTRON_NSX_PLUGIN = "vmware"
50
def networking_name():
51
''' Determine whether neutron or quantum should be used for name '''
52
if get_os_codename_install_source(config('openstack-origin')) >= 'havana':
64
OVS: QUANTUM_OVS_PLUGIN,
65
NVP: QUANTUM_NVP_PLUGIN,
68
OVS: NEUTRON_OVS_PLUGIN,
69
NVP: NEUTRON_NVP_PLUGIN,
70
N1KV: NEUTRON_N1KV_PLUGIN,
71
NSX: NEUTRON_NSX_PLUGIN
76
def remap_plugin(plugin):
77
''' Remaps plugin name for renames/switches in packaging '''
78
release = get_os_codename_install_source(config('openstack-origin'))
79
if plugin == 'nvp' and release >= 'icehouse':
81
elif plugin == 'nsx' and release < 'icehouse':
87
plugin = remap_plugin(config('plugin'))
88
if (get_os_codename_install_source(config('openstack-origin'))
91
return NEUTRON_ML2_PLUGIN
93
return CORE_PLUGIN[networking_name()][plugin]
96
class L3AgentContext(OSContextGenerator):
99
api_settings = NeutronAPIContext()()
101
if config('run-internal-router') == 'leader':
102
ctxt['handle_internal_only_router'] = eligible_leader(None)
104
if config('run-internal-router') == 'all':
105
ctxt['handle_internal_only_router'] = True
107
if config('run-internal-router') == 'none':
108
ctxt['handle_internal_only_router'] = False
110
if config('external-network-id'):
111
ctxt['ext_net_id'] = config('external-network-id')
113
ctxt['plugin'] = config('plugin')
114
if api_settings['enable_dvr']:
115
ctxt['agent_mode'] = 'dvr_snat'
117
ctxt['agent_mode'] = 'legacy'
121
class QuantumGatewayContext(OSContextGenerator):
124
api_settings = NeutronAPIContext()()
126
'shared_secret': get_shared_secret(),
128
get_address_in_network(config('os-data-network'),
129
get_host_ip(unit_get('private-address'))),
130
'core_plugin': core_plugin(),
131
'plugin': config('plugin'),
132
'debug': config('debug'),
133
'verbose': config('verbose'),
134
'instance_mtu': config('instance-mtu'),
135
'l2_population': api_settings['l2_population'],
136
'enable_dvr': api_settings['enable_dvr'],
137
'enable_l3ha': api_settings['enable_l3ha'],
138
'overlay_network_type':
139
api_settings['overlay_network_type'],
142
mappings = config('bridge-mappings')
144
ctxt['bridge_mappings'] = ','.join(mappings.split())
146
flat_providers = config('flat-network-providers')
148
ctxt['network_providers'] = ','.join(flat_providers.split())
150
vlan_ranges = config('vlan-ranges')
152
ctxt['vlan_ranges'] = ','.join(vlan_ranges.split())
154
net_dev_mtu = api_settings['network_device_mtu']
156
ctxt['network_device_mtu'] = net_dev_mtu
157
ctxt['veth_mtu'] = net_dev_mtu
163
def get_host_ip(hostname=None):
167
apt_install('python-dnspython', fatal=True)
169
hostname = hostname or unit_get('private-address')
171
# Test to see if already an IPv4 address
172
socket.inet_aton(hostname)
175
answers = dns.resolver.query(hostname, 'A')
177
return answers[0].address
180
SHARED_SECRET = "/etc/{}/secret.txt"
183
def get_shared_secret():
185
_path = SHARED_SECRET.format(networking_name())
186
if not os.path.exists(_path):
187
secret = str(uuid.uuid4())
188
with open(_path, 'w') as secret_file:
189
secret_file.write(secret)
191
with open(_path, 'r') as secret_file:
192
secret = secret_file.read().strip()