Exemplo n.º 1
0
 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
Exemplo n.º 2
0
 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
Exemplo n.º 3
0
 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)
Exemplo n.º 4
0
 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, **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
                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)
            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)
        except rpc_common.Timeout:
            LOG.error(_("RPC timeout while updating port %s"), port['id'])
Exemplo n.º 6
0
 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
             })
             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)
                 self.br_mgr.add_interface(details['network_id'],
                                           network_type,
                                           details['physical_network'],
                                           segmentation_id,
                                           details['port_id'])
             else:
                 self.remove_port_binding(details['network_id'],
                                          details['port_id'])
         else:
             LOG.info(_("Device %s not defined on plugin"), device)
     return resync
Exemplo n.º 7
0
    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
                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)
            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)
        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})
             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)
                 self.br_mgr.add_interface(details['network_id'],
                                           network_type,
                                           details['physical_network'],
                                           segmentation_id,
                                           details['port_id'])
             else:
                 self.remove_port_binding(details['network_id'],
                                          details['port_id'])
         else:
             LOG.info(_("Device %s not defined on plugin"), device)
     return resync