125 lines
3.4 KiB
Python
Raw Normal View History

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
OVS = "ovs"
2012-10-26 17:56:42 +02:00
OVS_PLUGIN = \
"quantum.plugins.openvswitch.ovs_quantum_plugin.OVSQuantumPluginV2"
CORE_PLUGIN = {
OVS: OVS_PLUGIN,
2012-10-26 17:56:42 +02:00
}
OVS_PLUGIN_CONF = \
"/etc/quantum/plugins/openvswitch/ovs_quantum_plugin.ini"
PLUGIN_CONF = {
OVS: OVS_PLUGIN_CONF,
2012-10-26 17:56:42 +02:00
}
GATEWAY_PKGS = {
OVS: [
"quantum-plugin-openvswitch-agent",
"quantum-l3-agent",
"quantum-dhcp-agent",
2013-01-18 08:51:11 +00:00
'python-mysqldb',
"nova-api-metadata"
],
}
GATEWAY_AGENTS = {
OVS: [
"quantum-plugin-openvswitch-agent",
"quantum-l3-agent",
2013-01-18 08:51:11 +00:00
"quantum-dhcp-agent",
"nova-api-metadata"
],
2013-02-08 16:20:03 +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"
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:
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:
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):
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])
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):
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])
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",
2013-02-18 09:14:49 +00:00
"--config-file=/etc/quantum/quantum.conf"
2013-02-08 16:10:48 +00:00
]
2013-02-18 09:14:49 +00:00
for agent_conf in ['l3_agent.ini', 'dhcp_agent.ini']:
agent_cmd = list(cmd)
agent_cmd.append('--config-file=/etc/quantum/{}'\
.format(agent_conf))
subprocess.call(agent_cmd)