2014-06-05 11:59:23 +01:00
|
|
|
from charmhelpers.core.hookenv import (
|
2014-06-19 10:56:25 +01:00
|
|
|
relation_ids,
|
|
|
|
related_units,
|
|
|
|
relation_get,
|
|
|
|
config,
|
|
|
|
unit_get,
|
2014-06-05 11:59:23 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
from charmhelpers.contrib.openstack import context
|
|
|
|
from charmhelpers.core.host import service_running, service_start
|
|
|
|
from charmhelpers.contrib.network.ovs import add_bridge
|
|
|
|
from charmhelpers.contrib.openstack.utils import get_host_ip
|
|
|
|
OVS_BRIDGE = 'br-int'
|
|
|
|
|
2014-06-19 10:56:25 +01:00
|
|
|
|
2014-06-05 11:59:23 +01:00
|
|
|
def _neutron_security_groups():
|
|
|
|
'''
|
2014-06-23 12:49:58 +01:00
|
|
|
Inspects current neutron-plugin relation and determine if neutron-api has
|
2014-06-05 11:59:23 +01:00
|
|
|
instructed us to use neutron security groups.
|
|
|
|
'''
|
2014-06-17 16:14:17 +01:00
|
|
|
for rid in relation_ids('neutron-plugin-api'):
|
2014-06-05 11:59:23 +01:00
|
|
|
for unit in related_units(rid):
|
2014-06-23 13:50:23 +01:00
|
|
|
sec_group = relation_get('neutron-security-groups',
|
2014-06-19 10:56:25 +01:00
|
|
|
rid=rid,
|
|
|
|
unit=unit)
|
2014-06-17 16:14:17 +01:00
|
|
|
if sec_group is not None:
|
|
|
|
return sec_group
|
2014-06-05 11:59:23 +01:00
|
|
|
return False
|
|
|
|
|
2014-06-19 10:56:25 +01:00
|
|
|
|
2014-06-05 11:59:23 +01:00
|
|
|
class OVSPluginContext(context.NeutronContext):
|
|
|
|
interfaces = []
|
|
|
|
|
|
|
|
@property
|
|
|
|
def plugin(self):
|
|
|
|
return 'ovs'
|
|
|
|
|
|
|
|
@property
|
|
|
|
def network_manager(self):
|
|
|
|
return 'neutron'
|
|
|
|
|
|
|
|
@property
|
|
|
|
def neutron_security_groups(self):
|
|
|
|
return _neutron_security_groups()
|
|
|
|
|
|
|
|
def _ensure_bridge(self):
|
|
|
|
if not service_running('openvswitch-switch'):
|
|
|
|
service_start('openvswitch-switch')
|
|
|
|
add_bridge(OVS_BRIDGE)
|
|
|
|
|
|
|
|
def ovs_ctxt(self):
|
|
|
|
# In addition to generating config context, ensure the OVS service
|
|
|
|
# is running and the OVS bridge exists. Also need to ensure
|
|
|
|
# local_ip points to actual IP, not hostname.
|
|
|
|
ovs_ctxt = super(OVSPluginContext, self).ovs_ctxt()
|
|
|
|
if not ovs_ctxt:
|
|
|
|
return {}
|
|
|
|
|
|
|
|
self._ensure_bridge()
|
|
|
|
|
2014-06-05 14:16:54 +00:00
|
|
|
conf = config()
|
2014-06-05 11:59:23 +01:00
|
|
|
ovs_ctxt['local_ip'] = get_host_ip(unit_get('private-address'))
|
|
|
|
ovs_ctxt['neutron_security_groups'] = self.neutron_security_groups
|
2014-06-23 12:49:58 +01:00
|
|
|
# TODO: We need to sort out the syslog and debug/verbose options as a
|
2014-06-23 13:50:23 +01:00
|
|
|
# general context helper
|
2014-06-05 14:16:54 +00:00
|
|
|
ovs_ctxt['use_syslog'] = conf['use-syslog']
|
2014-06-17 15:31:03 +01:00
|
|
|
ovs_ctxt['verbose'] = conf['verbose']
|
|
|
|
ovs_ctxt['debug'] = conf['debug']
|
2014-06-05 11:59:23 +01:00
|
|
|
return ovs_ctxt
|