networking-tricircle core plugin and security group

Initial implementation include option to use ML2 but it seem that it
will be better to use a core plugin (more control) over the process.

This just includes the Neutron side plugin. It replaces the ML2 plugin
with one that doesn't do any actual network changes, instead only
forwards it to the Cascade Service.

Change-Id: Ic63e7a3d0a1b171d43aff535b65c949e9e51ff4f
This commit is contained in:
Saggi Mizrahi 2015-06-29 10:27:05 +03:00
parent 2013bc8642
commit 6341924b92
7 changed files with 309 additions and 3 deletions

View File

@ -1,9 +1,8 @@
#
# Sample DevStack local.conf.
#
# This sample file is intended to be used for your typical DevStack environment
# that's running all of OpenStack on a single host. This can also be used as
# the first host of a multi-host test environment.
# This sample file is intended to be used for your typical Cascade DevStack Top
# environment that's running all of OpenStack on a single host. This can also
#
# No changes to this sample configuration are required for this to work.
#

0
tricircle/__init__.py Normal file
View File

View File

@ -0,0 +1,76 @@
# Copyright 2015 Huawei Technologies Co., Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from oslo_log import log as logging
import oslo_messaging
from neutron.common import rpc as n_rpc
from tricircle.common import topics
from tricircle.common.serializer import CascadeSerializer as Serializer
LOG = logging.getLogger(__name__)
class CascadingNetworkingNotifyAPI(object):
"""API for to notify Cascading service for the networking API."""
def __init__(self, topic=topics.CASCADING_SERVICE):
target = oslo_messaging.Target(topic=topic,
exchange="tricircle",
namespace="networking",
version='1.0',
fanout=True)
self.client = n_rpc.get_client(
target,
serializer=Serializer(),
)
def _cast_message(self, context, method, payload):
"""Cast the payload to the running cascading service instances."""
cctx = self.client.prepare()
LOG.debug('Fanout notify at %(topic)s.%(namespace)s the message '
'%(method)s for CascadingNetwork. payload: %(payload)s',
{'topic': cctx.target.topic,
'namespace': cctx.target.namespace,
'payload': payload,
'method': method})
cctx.cast(context, method, payload=payload)
def create_network(self, context, network):
self._cast_message(context, "create_network", network)
def delete_network(self, context, network_id):
self._cast_message(context,
"delete_network",
{'network_id': network_id})
def update_network(self, context, network_id, network):
payload = {
'network_id': network_id,
'network': network
}
self._cast_message(context, "update_network", payload)
def create_port(self, context, port):
self._cast_message(context, "create_port", port)
def delete_port(self, context, port_id, l3_port_check=True):
payload = {
'port_id': port_id,
'l3_port_check': l3_port_check
}
self._cast_message(context, "delete_port", payload)

View File

@ -0,0 +1,82 @@
# Copyright 2015 Huawei Technologies Co., Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import six
from oslo_messaging import Serializer
from neutron.api.v2.attributes import ATTR_NOT_SPECIFIED
class Mapping(object):
def __init__(self, mapping):
self.direct_mapping = mapping
self.reverse_mapping = {}
for key, value in six.iteritems(mapping):
self.reverse_mapping[value] = key
_SINGLETON_MAPPING = Mapping({
ATTR_NOT_SPECIFIED: "@@**ATTR_NOT_SPECIFIED**@@",
})
class CascadeSerializer(Serializer):
def __init__(self, base=None):
super(CascadeSerializer, self).__init__()
self._base = base
def serialize_entity(self, context, entity):
if isinstance(entity, dict):
for key, value in six.iteritems(entity):
entity[key] = self.serialize_entity(context, value)
elif isinstance(entity, list):
for i, item in enumerate(entity):
entity[i] = self.serialize_entity(context, item)
elif entity in _SINGLETON_MAPPING.direct_mapping:
entity = _SINGLETON_MAPPING.direct_mapping[entity]
if self._base is not None:
entity = self._base.serialize_entity(context, entity)
return entity
def deserialize_entity(self, context, entity):
if isinstance(entity, dict):
for key, value in six.iteritems(entity):
entity[key] = self.deserialize_entity(context, value)
elif isinstance(entity, list):
for i, item in enumerate(entity):
entity[i] = self.deserialize_entity(context, item)
elif entity in _SINGLETON_MAPPING.reverse_mapping:
entity = _SINGLETON_MAPPING.reverse_mapping[entity]
if self._base is not None:
entity = self._base.deserialize_entity(context, entity)
return entity
def serialize_context(self, context):
if self._base is not None:
context = self._base.serialize_context(context)
return context
def deserialize_context(self, context):
if self._base is not None:
context = self._base.deserialize_context(context)
return context

View File

@ -0,0 +1,25 @@
# Copyright 2015 Huawei Technologies Co., Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
NETWORK = 'network'
SUBNET = 'subnet'
PORT = 'port'
SECURITY_GROUP = 'security_group'
CREATE = 'create'
DELETE = 'delete'
UPDATE = 'update'
CASCADING_SERVICE = 'k-cascading'

View File

@ -0,0 +1,124 @@
# Copyright 2015 Huawei Technologies Co., Ltd.
# All Rights Reserved
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from oslo_log import log
from neutron.extensions import portbindings
from neutron.db import agentschedulers_db
from neutron.db import db_base_plugin_v2
from neutron.db import external_net_db
from neutron.db import extradhcpopt_db
from neutron.db import l3_db
from neutron.db import portbindings_db
from neutron.db import securitygroups_db
from neutron.i18n import _LI
from tricircle.common import cascading_networking_api as c_net_api
LOG = log.getLogger(__name__)
class TricirclePlugin(db_base_plugin_v2.NeutronDbPluginV2,
securitygroups_db.SecurityGroupDbMixin,
l3_db.L3_NAT_dbonly_mixin,
external_net_db.External_net_db_mixin,
portbindings_db.PortBindingMixin,
extradhcpopt_db.ExtraDhcpOptMixin,
agentschedulers_db.DhcpAgentSchedulerDbMixin):
__native_bulk_support = True
__native_pagination_support = True
__native_sorting_support = True
supported_extension_aliases = ["quotas",
"extra_dhcp_opt",
"binding",
"security-group",
"external-net",
"router"]
def __init__(self):
super(TricirclePlugin, self).__init__()
LOG.info(_LI("Starting TricirclePlugin"))
self.vif_type = portbindings.VIF_TYPE_OVS
# When set to True, Nova plugs the VIF directly into the ovs bridge
# instead of using the hybrid mode.
self.vif_details = {portbindings.CAP_PORT_FILTER: True}
self._cascading_rpc_api = c_net_api.CascadingNetworkingNotifyAPI()
def create_network(self, context, network):
with context.session.begin(subtransactions=True):
result = super(TricirclePlugin, self).create_network(
context,
network)
self._process_l3_create(context, result, network['network'])
LOG.debug("New network %s ", network['network']['name'])
if self._cascading_rpc_api:
self._cascading_rpc_api.create_network(context, network)
return result
def delete_network(self, context, network_id):
net = super(TricirclePlugin, self).delete_network(
context,
network_id)
if self._cascading_rpc_api:
self._cascading_rpc_api.delete_network(context, network_id)
return net
def update_network(self, context, network_id, network):
with context.session.begin(subtransactions=True):
net = super(TricirclePlugin, self).update_network(
context,
network_id,
network)
if self._cascading_rpc_api:
self._cascading_rpc_api.delete_network(
context,
network_id,
network)
return net
def create_port(self, context, port):
with context.session.begin(subtransactions=True):
neutron_db = super(TricirclePlugin, self).create_port(
context, port)
self._process_portbindings_create_and_update(context,
port['port'],
neutron_db)
neutron_db[portbindings.VNIC_TYPE] = portbindings.VNIC_NORMAL
# Call create port to the cascading API
LOG.debug("New port %s ", port['port'])
if self._cascading_rpc_api:
self._cascading_rpc_api.create_port(context, port)
return neutron_db
def delete_port(self, context, port_id, l3_port_check=True):
with context.session.begin():
ret_val = super(TricirclePlugin, self).delete_port(
context, port_id)
if self._cascading_rpc_api:
self._cascading_rpc_api.delete_port(context,
port_id,
l3_port_checki=True)
return ret_val
def extend_port_dict_binding(self, port_res, port_db):
super(TricirclePlugin, self).extend_port_dict_binding(
port_res, port_db)
port_res[portbindings.VNIC_TYPE] = portbindings.VNIC_NORMAL