
RPC has a version of itself. In Neutron a plugin implements several RPC interface, so a single RPC version doesn't work. In Mixin callback class approach, RPC versioning depends on each plugin implementation and it makes harder to maintain RPC version appropriately. This patch series replaces mixin RPC callback of server side with a separate class. This commit handles server-side callback of security group RPC interface. * The server-side callback of Security group RPC is moved to api/rpc/handler and db/securitygroups_rpc_base now only contains a mixin class to add agent-based security group implementation with db operations. * get_port_from_device method in server-side callback class is moved to a mixin class of plugin implementation (SecurityGroupServerRpcMixin) because it involves DB lookup and is tightly coupled with plugin implementation rather than RPC interface definition. Most unit tests for SGServerRpcCallBackTestCase were skipped in the base class before, but now they are no longer skipped. The following items will be planned in later patches to avoid drastic changes in a single patch. * Merge security group RPC API and agent callback classes in agent/securitygroups_rpc into api/rpc/handlers/securitygroup_rpc * Remove completely duplicated db access code in get_port_from_device and get_port_and_sgs Partial-Bug: #1359416 Change-Id: Ia6535217d2e3b849a95667c1b53dd09675002892
60 lines
2.0 KiB
Python
60 lines
2.0 KiB
Python
# 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 neutron.common import rpc as n_rpc
|
|
from neutron import manager
|
|
|
|
|
|
# TODO(amotoki): Move security group RPC API and agent callback
|
|
# from securitygroups_rpc.py.
|
|
|
|
|
|
class SecurityGroupServerRpcCallback(n_rpc.RpcCallback):
|
|
"""Callback for SecurityGroup agent RPC in plugin implementations.
|
|
|
|
Subclass which inherits this class must implement get_port_from_device().
|
|
"""
|
|
|
|
# API version history:
|
|
# 1.1 - Initial version
|
|
|
|
# NOTE: RPC_API_VERSION must not be overridden in subclasses
|
|
# to keep RPC API version consistent across plugins.
|
|
RPC_API_VERSION = '1.1'
|
|
|
|
@property
|
|
def plugin(self):
|
|
return manager.NeutronManager.get_plugin()
|
|
|
|
def security_group_rules_for_devices(self, context, **kwargs):
|
|
"""Callback method to return security group rules for each port.
|
|
|
|
also convert remote_group_id rule
|
|
to source_ip_prefix and dest_ip_prefix rule
|
|
|
|
:params devices: list of devices
|
|
:returns: port correspond to the devices with security group rules
|
|
"""
|
|
devices = kwargs.get('devices')
|
|
|
|
ports = {}
|
|
for device in devices:
|
|
port = self.plugin.get_port_from_device(device)
|
|
if not port:
|
|
continue
|
|
if port['device_owner'].startswith('network:'):
|
|
continue
|
|
ports[port['id']] = port
|
|
return self.plugin.security_group_rules_for_ports(context, ports)
|