2012-10-26 17:56:42 +02:00
|
|
|
import subprocess
|
2013-01-18 08:51:11 +00:00
|
|
|
import os
|
|
|
|
import uuid
|
2012-12-03 15:16:55 +00:00
|
|
|
from utils import juju_log as log
|
2013-01-18 08:51:11 +00:00
|
|
|
from utils import get_os_version
|
2012-10-26 17:56:42 +02:00
|
|
|
|
2012-11-07 12:11:38 +00:00
|
|
|
|
2012-11-14 09:42:39 +00:00
|
|
|
OVS = "ovs"
|
|
|
|
NVP = "nvp"
|
2012-11-07 12:11:38 +00:00
|
|
|
|
2012-10-26 17:56:42 +02:00
|
|
|
OVS_PLUGIN = \
|
|
|
|
"quantum.plugins.openvswitch.ovs_quantum_plugin.OVSQuantumPluginV2"
|
|
|
|
NVP_PLUGIN = \
|
|
|
|
"quantum.plugins.nicira.nicira_nvp_plugin.QuantumPlugin.NvpPluginV2"
|
|
|
|
CORE_PLUGIN = {
|
2012-11-14 09:42:39 +00:00
|
|
|
OVS: OVS_PLUGIN,
|
|
|
|
NVP: NVP_PLUGIN
|
2012-10-26 17:56:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
OVS_PLUGIN_CONF = \
|
|
|
|
"/etc/quantum/plugins/openvswitch/ovs_quantum_plugin.ini"
|
|
|
|
NVP_PLUGIN_CONF = \
|
|
|
|
"/etc/quantum/plugins/nicira/nvp.ini"
|
|
|
|
PLUGIN_CONF = {
|
2012-11-14 09:42:39 +00:00
|
|
|
OVS: OVS_PLUGIN_CONF,
|
|
|
|
NVP: NVP_PLUGIN_CONF
|
2012-10-26 17:56:42 +02:00
|
|
|
}
|
|
|
|
|
2012-11-14 09:42:39 +00:00
|
|
|
GATEWAY_PKGS = {
|
|
|
|
OVS: [
|
2012-11-07 12:11:38 +00:00
|
|
|
"quantum-plugin-openvswitch-agent",
|
|
|
|
"quantum-l3-agent",
|
2012-11-14 09:42:39 +00:00
|
|
|
"quantum-dhcp-agent",
|
2013-01-18 08:51:11 +00:00
|
|
|
'python-mysqldb',
|
|
|
|
"nova-api-metadata"
|
2012-11-07 12:11:38 +00:00
|
|
|
],
|
2012-11-14 09:42:39 +00:00
|
|
|
NVP: [
|
2013-01-18 08:51:11 +00:00
|
|
|
"quantum-plugin-nicira",
|
|
|
|
"quantum-l3-agent",
|
|
|
|
"quantum-dhcp-agent",
|
|
|
|
'python-mysqldb',
|
|
|
|
"nova-api-metadata"
|
2012-11-07 12:11:38 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2013-01-18 08:51:11 +00:00
|
|
|
# TODO: conditionally add quantum-metadata-agent if
|
|
|
|
# running 2013.1 onwards. OR add some overrides
|
|
|
|
# start on starting quantum-l3-agent
|
|
|
|
# stop on stopping quantum-l3-agent
|
2012-11-07 12:11:38 +00:00
|
|
|
GATEWAY_AGENTS = {
|
2012-11-14 09:42:39 +00:00
|
|
|
OVS: [
|
|
|
|
"quantum-plugin-openvswitch-agent",
|
2012-11-07 12:11:38 +00:00
|
|
|
"quantum-l3-agent",
|
2013-01-18 08:51:11 +00:00
|
|
|
"quantum-dhcp-agent",
|
|
|
|
"nova-api-metadata"
|
|
|
|
],
|
|
|
|
NVP: [
|
|
|
|
"quantum-l3-agent",
|
|
|
|
"quantum-dhcp-agent",
|
|
|
|
"nova-api-metadata"
|
2012-11-07 12:11:38 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2013-01-18 08:51:11 +00:00
|
|
|
if get_os_version('quantum-common') >= "2013.1":
|
|
|
|
for plugin in GATEWAY_AGENTS:
|
|
|
|
GATEWAY_AGENTS[plugin].append("quantum-metadata-agent")
|
|
|
|
|
2012-10-26 17:56:42 +02:00
|
|
|
DB_USER = "quantum"
|
|
|
|
QUANTUM_DB = "quantum"
|
2012-11-07 12:11:38 +00:00
|
|
|
KEYSTONE_SERVICE = "quantum"
|
2013-01-18 08:51:11 +00:00
|
|
|
NOVA_DB_USER = "nova"
|
|
|
|
NOVA_DB = "nova"
|
2012-10-26 17:56:42 +02:00
|
|
|
|
|
|
|
QUANTUM_CONF = "/etc/quantum/quantum.conf"
|
|
|
|
L3_AGENT_CONF = "/etc/quantum/l3_agent.ini"
|
2012-11-05 11:59:27 +00:00
|
|
|
DHCP_AGENT_CONF = "/etc/quantum/dhcp_agent.ini"
|
2013-01-18 08:51:11 +00:00
|
|
|
METADATA_AGENT_CONF = "/etc/quantum/metadata_agent.ini"
|
|
|
|
NOVA_CONF = "/etc/nova/nova.conf"
|
2012-10-26 17:56:42 +02:00
|
|
|
|
2012-11-05 11:59:27 +00:00
|
|
|
RABBIT_USER = "nova"
|
|
|
|
RABBIT_VHOST = "nova"
|
2012-10-26 17:56:42 +02:00
|
|
|
|
2012-12-03 15:16:55 +00:00
|
|
|
INT_BRIDGE = "br-int"
|
|
|
|
EXT_BRIDGE = "br-ex"
|
|
|
|
|
2012-10-26 17:56:42 +02:00
|
|
|
|
|
|
|
def add_bridge(name):
|
|
|
|
status = subprocess.check_output(["ovs-vsctl", "show"])
|
|
|
|
if "Bridge {}".format(name) not in status:
|
2012-11-14 09:42:39 +00:00
|
|
|
log('INFO', 'Creating bridge {}'.format(name))
|
2012-10-26 17:56:42 +02:00
|
|
|
subprocess.check_call(["ovs-vsctl", "add-br", name])
|
|
|
|
|
|
|
|
|
|
|
|
def del_bridge(name):
|
|
|
|
status = subprocess.check_output(["ovs-vsctl", "show"])
|
|
|
|
if "Bridge {}".format(name) in status:
|
2012-11-14 09:42:39 +00:00
|
|
|
log('INFO', 'Deleting bridge {}'.format(name))
|
2012-10-26 17:56:42 +02:00
|
|
|
subprocess.check_call(["ovs-vsctl", "del-br", name])
|
|
|
|
|
|
|
|
|
|
|
|
def add_bridge_port(name, port):
|
|
|
|
status = subprocess.check_output(["ovs-vsctl", "show"])
|
2012-11-05 11:59:27 +00:00
|
|
|
if ("Bridge {}".format(name) in status and
|
|
|
|
"Interface \"{}\"".format(port) not in status):
|
2012-11-14 09:42:39 +00:00
|
|
|
log('INFO',
|
|
|
|
'Adding port {} to bridge {}'.format(port, name))
|
2012-10-26 17:56:42 +02:00
|
|
|
subprocess.check_call(["ovs-vsctl", "add-port", name, port])
|
2012-11-07 12:11:38 +00:00
|
|
|
subprocess.check_call(["ip", "link", "set", port, "up"])
|
2012-10-26 17:56:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
def del_bridge_port(name, port):
|
|
|
|
status = subprocess.check_output(["ovs-vsctl", "show"])
|
|
|
|
if ("Bridge {}".format(name) in status and
|
|
|
|
"Interface \"{}\"".format(port) in status):
|
2012-11-14 09:42:39 +00:00
|
|
|
log('INFO',
|
|
|
|
'Deleting port {} from bridge {}'.format(port, name))
|
2012-10-26 17:56:42 +02:00
|
|
|
subprocess.check_call(["ovs-vsctl", "del-port", name, port])
|
2012-11-07 12:11:38 +00:00
|
|
|
subprocess.check_call(["ip", "link", "set", port, "down"])
|
2013-01-18 08:51:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
SHARED_SECRET = "/etc/quantum/secret.txt"
|
|
|
|
|
|
|
|
|
|
|
|
def get_shared_secret():
|
|
|
|
secret = None
|
|
|
|
if not os.path.exists(SHARED_SECRET):
|
|
|
|
secret = str(uuid.uuid4())
|
|
|
|
with open(SHARED_SECRET, 'w') as secret_file:
|
|
|
|
secret_file.write(secret)
|
|
|
|
else:
|
|
|
|
with open(SHARED_SECRET, 'r') as secret_file:
|
|
|
|
secret = secret_file.read().strip()
|
|
|
|
return secret
|
2013-02-08 16:10:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
def flush_local_configuration():
|
|
|
|
if os.path.exists('/usr/bin/quantum-netns-cleanup'):
|
|
|
|
cmd = [
|
|
|
|
"quantum-netns-cleanup",
|
|
|
|
"--force"
|
|
|
|
]
|
|
|
|
subprocess.check_call(cmd)
|