# vim: tabstop=4 shiftwidth=4 softtabstop=4 # Copyright 2013 Cloudbase Solutions SRL # 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. # @author: Alessandro Pilotti, Cloudbase Solutions Srl import sys from quantum.api.v2 import attributes from quantum.common import constants as q_const from quantum.common import exceptions as q_exc from quantum.common import rpc as q_rpc from quantum.common import topics from quantum.db import db_base_plugin_v2 from quantum.db import dhcp_rpc_base from quantum.db import l3_db from quantum.db import l3_rpc_base from quantum.extensions import portbindings from quantum.extensions import providernet as provider from quantum.openstack.common import cfg from quantum.openstack.common import log as logging from quantum.openstack.common import rpc from quantum.openstack.common.rpc import proxy from quantum.plugins.hyperv import db as hyperv_db from quantum.plugins.hyperv.common import constants from quantum import policy LOG = logging.getLogger(__name__) class HyperVRpcCallbacks( dhcp_rpc_base.DhcpRpcCallbackMixin, l3_rpc_base.L3RpcCallbackMixin): # Set RPC API version to 1.0 by default. RPC_API_VERSION = '1.0' def __init__(self, notifier): self.notifier = notifier self._db = hyperv_db.HyperVPluginDB() def create_rpc_dispatcher(self): '''Get the rpc dispatcher for this manager. If a manager would like to set an rpc API version, or support more than one class as the target of rpc messages, override this method. ''' return q_rpc.PluginRpcDispatcher([self]) def get_device_details(self, rpc_context, **kwargs): """Agent requests device details""" agent_id = kwargs.get('agent_id') device = kwargs.get('device') LOG.debug(_("Device %(device)s details requested from %(agent_id)s"), locals()) port = self._db.get_port(device) if port: binding = self._db.get_network_binding(None, port['network_id']) entry = {'device': device, 'network_id': port['network_id'], 'port_id': port['id'], 'admin_state_up': port['admin_state_up'], 'network_type': binding.network_type, 'segmentation_id': binding.segmentation_id, 'physical_network': binding.physical_network} # Set the port status to UP self._db.set_port_status(port['id'], q_const.PORT_STATUS_ACTIVE) else: entry = {'device': device} LOG.debug(_("%s can not be found in database"), device) return entry def update_device_down(self, rpc_context, **kwargs): """Device no longer exists on agent""" # (TODO) garyk - live migration and port status agent_id = kwargs.get('agent_id') device = kwargs.get('device') LOG.debug(_("Device %(device)s no longer exists on %(agent_id)s"), locals()) port = self._db.get_port(device) if port: entry = {'device': device, 'exists': True} # Set port status to DOWN self._db.set_port_status(port['id'], q_const.PORT_STATUS_DOWN) else: entry = {'device': device, 'exists': False} LOG.debug(_("%s can not be found in database"), device) return entry