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"), {'device': device, 'agent_id': agent_id}) port = self.get_port_from_device(device) if port: binding = db.get_network_binding(db_api.get_session(), port['network_id']) (network_type, segmentation_id) = constants.interpret_vlan_id(binding.vlan_id) entry = {'device': device, 'network_type': network_type, 'physical_network': binding.physical_network, 'segmentation_id': segmentation_id, 'network_id': port['network_id'], 'port_id': port['id'], 'admin_state_up': port['admin_state_up']} if cfg.CONF.AGENT.rpc_support_old_agents: entry['vlan_id'] = binding.vlan_id new_status = (q_const.PORT_STATUS_ACTIVE if port['admin_state_up'] else q_const.PORT_STATUS_DOWN) if port['status'] != new_status: db.set_port_status(port['id'], new_status) else: entry = {'device': device} LOG.debug(_("%s can not be found in database"), device) return entry
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"), {"device": device, "agent_id": agent_id}) port = self.get_port_from_device(device) if port: binding = db.get_network_binding(db_api.get_session(), port["network_id"]) (network_type, segmentation_id) = constants.interpret_vlan_id(binding.vlan_id) entry = { "device": device, "network_type": network_type, "physical_network": binding.physical_network, "segmentation_id": segmentation_id, "network_id": port["network_id"], "port_id": port["id"], "admin_state_up": port["admin_state_up"], } if cfg.CONF.AGENT.rpc_support_old_agents: entry["vlan_id"] = binding.vlan_id new_status = q_const.PORT_STATUS_ACTIVE if port["admin_state_up"] else q_const.PORT_STATUS_DOWN if port["status"] != new_status: db.set_port_status(port["id"], new_status) else: entry = {"device": device} LOG.debug(_("%s can not be found in database"), device) return entry
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"), {'device': device, 'agent_id': agent_id}) port = self.get_port_from_device(device) if port: binding = db.get_network_binding(db_api.get_session(), port['network_id']) (network_type, segmentation_id) = constants.interpret_vlan_id(binding.vlan_id) entry = {'device': device, 'network_type': network_type, 'physical_network': binding.physical_network, 'segmentation_id': segmentation_id, 'network_id': port['network_id'], 'port_id': port['id'], 'admin_state_up': port['admin_state_up']} if cfg.CONF.AGENT.rpc_support_old_agents: entry['vlan_id'] = binding.vlan_id new_status = (q_const.PORT_STATUS_ACTIVE if port['admin_state_up'] else q_const.PORT_STATUS_DOWN) if port['status'] != new_status: db.set_port_status(port['id'], new_status) else: entry = {'device': device} LOG.debug(_("%s can not be found in database"), device) return entry
def port_update(self, context, **kwargs): '''Update the port in response to a port update message from the controlling node. ''' LOG.debug(_("port_update received %s, %s"), context, kwargs) # Check port exists on node port = kwargs.get('port') tap_device_name = self.agent.routing_mgr.get_tap_device_name(port['id']) devices = self.agent.routing_mgr.get_tap_devices() if tap_device_name not in devices: return if 'security_groups' in port: self.sg_agent.refresh_firewall() try: if port['admin_state_up']: network_type = kwargs.get('network_type') if network_type: segmentation_id = kwargs.get('segmentation_id') else: # compatibility with pre-Havana RPC vlan_id encoding vlan_id = kwargs.get('vlan_id') (network_type, segmentation_id) = lconst.interpret_vlan_id(vlan_id) physical_network = kwargs.get('physical_network') # create the networking for the port if self.agent.routing_mgr.add_interface(port['network_id'], network_type, physical_network, segmentation_id, port['id'], port['fixed_ips'], port['mac_address']): # update plugin about port status self.agent.plugin_rpc.update_device_up(self.context, tap_device_name, self.agent.agent_id, cfg.CONF.host) else: self.agent.plugin_rpc.update_device_down( self.context, tap_device_name, self.agent.agent_id, cfg.CONF.host ) else: self.agent.routing_mgr.remove_interface(port['network_id'], None, None, None, port['id'], port['fixed_ips'], port['mac_address']) # update plugin about port status self.agent.plugin_rpc.update_device_down(self.context, tap_device_name, self.agent.agent_id, cfg.CONF.host) except rpc_common.Timeout: LOG.error(_("RPC timeout while updating port %s"), port['id'])
def port_update(self, context, **kwargs): LOG.debug(_("port_update received")) # Check port exists on node port = kwargs.get('port') tap_device_name = self.agent.br_mgr.get_tap_device_name(port['id']) devices = self.agent.br_mgr.get_tap_devices() if tap_device_name not in devices: return if 'security_groups' in port: self.sg_agent.refresh_firewall() try: LOG.debug('Update of port %s' % port) updown = self.agent.br_mgr.update_device_link(port_id=port['id'], dom_id=port.get('device_id'), hw_addr=port.get('mac_address'), owner=port.get('device_owner'), state=port['admin_state_up']) if port['admin_state_up']: network_type = kwargs.get('network_type') if network_type: segmentation_id = kwargs.get('segmentation_id') else: # compatibility with pre-Havana RPC vlan_id encoding vlan_id = kwargs.get('vlan_id') (network_type, segmentation_id) = lconst.interpret_vlan_id(vlan_id) physical_network = kwargs.get('physical_network') # create the networking for the port if self.agent.br_mgr.add_interface(port['network_id'], network_type, physical_network, segmentation_id, port['id']): # update plugin about port status self.agent.plugin_rpc.update_device_up(self.context, tap_device_name, self.agent.agent_id, cfg.CONF.host) else: self.agent.plugin_rpc.update_device_down( self.context, tap_device_name, self.agent.agent_id, cfg.CONF.host ) else: bridge_name = self.agent.br_mgr.get_bridge_name( port['network_id']) self.agent.br_mgr.remove_interface(bridge_name, tap_device_name) # update plugin about port status self.agent.plugin_rpc.update_device_down(self.context, tap_device_name, self.agent.agent_id, cfg.CONF.host) except rpc_common.Timeout: LOG.error(_("RPC timeout while updating port %s"), port['id'])
def treat_devices_added(self, devices): resync = False self.prepare_devices_filter(devices) for device in devices: LOG.debug(_("Port %s added"), device) try: details = self.plugin_rpc.get_device_details( self.context, device, self.agent_id) except Exception as e: LOG.debug( _("Unable to get port details for " "%(device)s: %(e)s"), { 'device': device, 'e': e }) resync = True continue if 'port_id' in details: LOG.info(_("Port %(device)s updated. Details: %(details)s"), { 'device': device, 'details': details }) updown = self.br_mgr.update_device_link( port_id=details['port_id'], dom_id=details.get('device_id'), hw_addr=details.get('mac_address'), owner=details.get('device_owner'), state=details['admin_state_up']) if details['admin_state_up']: # create the networking for the port network_type = details.get('network_type') if network_type: segmentation_id = details.get('segmentation_id') else: # compatibility with pre-Havana RPC vlan_id encoding vlan_id = details.get('vlan_id') (network_type, segmentation_id) = lconst.interpret_vlan_id(vlan_id) if self.br_mgr.add_interface(details['network_id'], network_type, details['physical_network'], segmentation_id, details['port_id']): # update plugin about port status self.plugin_rpc.update_device_up( self.context, device, self.agent_id, cfg.CONF.host) else: self.plugin_rpc.update_device_down( self.context, device, self.agent_id, cfg.CONF.host) else: self.remove_port_binding(details['network_id'], details['port_id']) else: LOG.info(_("Device %s not defined on plugin"), device) return resync
def treat_devices_added(self, devices): resync = False self.prepare_devices_filter(devices) for device in devices: LOG.debug(_("Port %s added"), device) try: details = self.plugin_rpc.get_device_details(self.context, device, self.agent_id) except Exception as e: LOG.debug(_("Unable to get port details for " "%(device)s: %(e)s"), {'device': device, 'e': e}) resync = True continue if 'port_id' in details: LOG.info(_("Port %(device)s updated. Details: %(details)s"), {'device': device, 'details': details}) updown = self.br_mgr.update_device_link( port_id=details['port_id'], dom_id=details.get('device_id'), hw_addr=details.get('mac_address'), owner=details.get('device_owner'), state=details['admin_state_up']) if details['admin_state_up']: # create the networking for the port network_type = details.get('network_type') if network_type: segmentation_id = details.get('segmentation_id') else: # compatibility with pre-Havana RPC vlan_id encoding vlan_id = details.get('vlan_id') (network_type, segmentation_id) = lconst.interpret_vlan_id(vlan_id) if self.br_mgr.add_interface(details['network_id'], network_type, details['physical_network'], segmentation_id, details['port_id']): # update plugin about port status self.plugin_rpc.update_device_up(self.context, device, self.agent_id, cfg.CONF.host) else: self.plugin_rpc.update_device_down(self.context, device, self.agent_id, cfg.CONF.host) else: self.remove_port_binding(details['network_id'], details['port_id']) else: LOG.info(_("Device %s not defined on plugin"), device) return resync
def treat_devices_added_updated(self, devices): try: devices_details_list = self.plugin_rpc.get_devices_details_list( self.context, devices, self.agent_id) except Exception as e: LOG.debug("Unable to get port details for " "%(devices)s: %(e)s", {'devices': devices, 'e': e}) # resync is needed return True for device_details in devices_details_list: device = device_details['device'] LOG.debug("Port %s added", device) if 'port_id' in device_details: LOG.info(_LI("Port %(device)s updated. Details: %(details)s"), {'device': device, 'details': device_details}) if self.prevent_arp_spoofing: port = self.br_mgr.get_tap_device_name( device_details['port_id']) arp_protect.setup_arp_spoofing_protection(port, device_details) if device_details['admin_state_up']: # create the networking for the port network_type = device_details.get('network_type') if network_type: segmentation_id = device_details.get('segmentation_id') else: # compatibility with pre-Havana RPC vlan_id encoding vlan_id = device_details.get('vlan_id') (network_type, segmentation_id) = lconst.interpret_vlan_id(vlan_id) if self.br_mgr.add_interface( device_details['network_id'], network_type, device_details['physical_network'], segmentation_id, device_details['port_id']): # update plugin about port status self.plugin_rpc.update_device_up(self.context, device, self.agent_id, cfg.CONF.host) else: self.plugin_rpc.update_device_down(self.context, device, self.agent_id, cfg.CONF.host) else: self.remove_port_binding(device_details['network_id'], device_details['port_id']) else: LOG.info(_LI("Device %s not defined on plugin"), device) return False
def port_update(self, context, **kwargs): LOG.debug(_("port_update received")) # Check port exists on node port = kwargs.get('port') tap_device_name = self.agent.br_mgr.get_tap_device_name(port['id']) devices = self.agent.br_mgr.get_tap_devices() if tap_device_name not in devices: return if 'security_groups' in port: self.sg_agent.refresh_firewall() try: LOG.debug('Update of port %s' % port) updown = self.agent.br_mgr.update_device_link( port_id=port['id'], dom_id=port.get('device_id'), hw_addr=port.get('mac_address'), owner=port.get('device_owner'), state=port['admin_state_up']) if port['admin_state_up']: network_type = kwargs.get('network_type') if network_type: segmentation_id = kwargs.get('segmentation_id') else: # compatibility with pre-Havana RPC vlan_id encoding vlan_id = kwargs.get('vlan_id') (network_type, segmentation_id) = lconst.interpret_vlan_id(vlan_id) physical_network = kwargs.get('physical_network') # create the networking for the port if self.agent.br_mgr.add_interface(port['network_id'], network_type, physical_network, segmentation_id, port['id']): # update plugin about port status self.agent.plugin_rpc.update_device_up( self.context, tap_device_name, self.agent.agent_id, cfg.CONF.host) else: self.agent.plugin_rpc.update_device_down( self.context, tap_device_name, self.agent.agent_id, cfg.CONF.host) else: bridge_name = self.agent.br_mgr.get_bridge_name( port['network_id']) self.agent.br_mgr.remove_interface(bridge_name, tap_device_name) # update plugin about port status self.agent.plugin_rpc.update_device_down( self.context, tap_device_name, self.agent.agent_id, cfg.CONF.host) except rpc_common.Timeout: LOG.error(_("RPC timeout while updating port %s"), port['id'])
def port_update(self, context, port, physical_network, vlan_id): network_type, segmentation_id = constants.interpret_vlan_id(vlan_id) kwargs = {'port': port, 'network_type': network_type, 'physical_network': physical_network, 'segmentation_id': segmentation_id} if cfg.CONF.AGENT.rpc_support_old_agents: kwargs['vlan_id'] = vlan_id msg = self.make_msg('port_update', **kwargs) self.fanout_cast(context, msg, topic=self.topic_port_update)
def port_update(self, context, port, physical_network, vlan_id): network_type, segmentation_id = constants.interpret_vlan_id(vlan_id) kwargs = {'port': port, 'network_type': network_type, 'physical_network': physical_network, 'segmentation_id': segmentation_id} if cfg.CONF.AGENT.rpc_support_old_agents: kwargs['vlan_id'] = vlan_id msg = self.make_msg('port_update', **kwargs) self.fanout_cast(context, msg, topic=self.topic_port_update)
def port_update(self, context, port, physical_network, vlan_id): network_type, segmentation_id = constants.interpret_vlan_id(vlan_id) kwargs = { "port": port, "network_type": network_type, "physical_network": physical_network, "segmentation_id": segmentation_id, } if cfg.CONF.AGENT.rpc_support_old_agents: kwargs["vlan_id"] = vlan_id msg = self.make_msg("port_update", **kwargs) self.fanout_cast(context, msg, topic=self.topic_port_update)
def treat_devices_added_updated(self, devices): try: devices_details_list = self.plugin_rpc.get_devices_details_list(self.context, devices, self.agent_id) except Exception as e: LOG.debug("Unable to get port details for " "%(devices)s: %(e)s", {"devices": devices, "e": e}) # resync is needed return True for device_details in devices_details_list: device = device_details["device"] LOG.debug("Port %s added", device) if "port_id" in device_details: LOG.info( _("Port %(device)s updated. Details: %(details)s"), {"device": device, "details": device_details} ) if device_details["admin_state_up"]: # create the networking for the port network_type = device_details.get("network_type") if network_type: segmentation_id = device_details.get("segmentation_id") else: # compatibility with pre-Havana RPC vlan_id encoding vlan_id = device_details.get("vlan_id") (network_type, segmentation_id) = lconst.interpret_vlan_id(vlan_id) if self.br_mgr.add_interface( device_details["network_id"], network_type, device_details["physical_network"], segmentation_id, device_details["port_id"], ): # update plugin about port status self.plugin_rpc.update_device_up(self.context, device, self.agent_id, cfg.CONF.host) else: self.plugin_rpc.update_device_down(self.context, device, self.agent_id, cfg.CONF.host) else: self.remove_port_binding(device_details["network_id"], device_details["port_id"]) else: LOG.info(_("Device %s not defined on plugin"), device) return False
def port_update(self, context, **kwargs): LOG.debug(_("port_update received")) # Check port exists on node port = kwargs.get("port") tap_device_name = self.agent.br_mgr.get_tap_device_name(port["id"]) devices = self.agent.br_mgr.udev_get_tap_devices() if tap_device_name not in devices: return if "security_groups" in port: self.sg_agent.refresh_firewall() try: if port["admin_state_up"]: network_type = kwargs.get("network_type") if network_type: segmentation_id = kwargs.get("segmentation_id") else: # compatibility with pre-Havana RPC vlan_id encoding vlan_id = kwargs.get("vlan_id") (network_type, segmentation_id) = lconst.interpret_vlan_id(vlan_id) physical_network = kwargs.get("physical_network") # create the networking for the port if self.agent.br_mgr.add_interface( port["network_id"], network_type, physical_network, segmentation_id, port["id"] ): # update plugin about port status self.agent.plugin_rpc.update_device_up( self.context, tap_device_name, self.agent.agent_id, cfg.CONF.host ) else: self.plugin_rpc.update_device_down( self.context, tap_device_name, self.agent.agent_id, cfg.CONF.host ) else: bridge_name = self.agent.br_mgr.get_bridge_name(port["network_id"]) self.agent.br_mgr.remove_interface(bridge_name, tap_device_name) # update plugin about port status self.agent.plugin_rpc.update_device_down( self.context, tap_device_name, self.agent.agent_id, cfg.CONF.host ) except rpc_common.Timeout: LOG.error(_("RPC timeout while updating port %s"), port["id"])
def treat_devices_added(self, devices): """ Called by the polling loop when we discover new devices have appeared. Checks if the new devices are known to OpenStack and configures them if needed. """ LOG.info(_("treat_devices_added %s"), devices) resync = False self.prepare_devices_filter(devices) for device in devices: LOG.debug(_("Port %s added"), device) try: details = self.plugin_rpc.get_device_details(self.context, device, self.agent_id) except Exception as e: LOG.debug(_("Unable to get port details for " "%(device)s: %(e)s"), {'device': device, 'e': e}) resync = True continue if 'port_id' in details: LOG.info(_("Port %(device)s updated. Details: %(details)s"), {'device': device, 'details': details}) # If a device has been added but it's not active, don't # do anything with it. We'll add it later. Otherwise, configure # it. if details['admin_state_up']: # create the networking for the port network_type = details.get('network_type') if network_type: segmentation_id = details.get('segmentation_id') else: # compatibility with pre-Havana RPC vlan_id encoding vlan_id = details.get('vlan_id') (network_type, segmentation_id) = lconst.interpret_vlan_id(vlan_id) if self.routing_mgr.add_interface(details['network_id'], network_type, details['physical_network'], segmentation_id, details['port_id'], details['fixed_ips'], details['mac_address']): # update plugin about port status resp = self.plugin_rpc.update_device_up(self.context, device, self.agent_id, cfg.CONF.host) else: resp = self.plugin_rpc.update_device_down(self.context, device, self.agent_id, cfg.CONF.host) LOG.info(_("Update device response: %s"), resp) else: LOG.info(_("Device %s not defined on plugin"), device) return resync