def treat_devices_added_or_updated(self, devices, check_ports):
        resync = False
        all_ports = dict((p.normalized_port_name(), p) for p in self._get_ports(self.int_br) if p.is_neutron_port())
        for device in devices:
            LOG.debug("Processing port %s", device)
            if device not in all_ports:
                # The port has disappeared and should not be processed
                # There is no need to put the port DOWN in the plugin as
                # it never went up in the first place
                LOG.info(
                    _LI("Port %s was not found on the integration bridge " "and will therefore not be processed"),
                    device,
                )
                continue
            port = all_ports[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 device in check_ports:
                ps = check_ports[device]
                if port.ofport != ps.port.ofport:
                    ps.port.vif_mac = details.get("mac_address")
                    LOG.debug(
                        "Repair ofport changed old port " "ofport: %(ofport)s vif_mac: %(mac)s",
                        {"ofport": ps.port.ofport, "mac": ps.port.vif_mac},
                    )
                    LOG.debug(
                        "Repair ofport changed new port " "ofport: %(ofport)s vif_mac: %(mac)s",
                        {"ofport": port.ofport, "mac": port.vif_mac},
                    )
                    self._repair_ofport_change(ps.port, details["network_id"])
            if "port_id" in details:
                LOG.info(_LI("Port %(device)s updated. Details: %(details)s"), {"device": device, "details": details})
                port.vif_mac = details.get("mac_address")
                self.treat_vif_port(
                    port,
                    details["port_id"],
                    details["network_id"],
                    details["network_type"],
                    details["physical_network"],
                    details["segmentation_id"],
                    details["admin_state_up"],
                )

                # update plugin about port status
                if details.get("admin_state_up"):
                    LOG.debug("Setting status for %s to UP", device)
                    self.plugin_rpc.update_device_up(self.context, device, self.agent_id, cfg.CONF.host)
                else:
                    LOG.debug("Setting status for %s to DOWN", device)
                    self.plugin_rpc.update_device_down(self.context, device, self.agent_id, cfg.CONF.host)
                LOG.info(_LI("Configuration for device %s completed."), device)
            else:
                LOG.warn(_LW("Device %s not defined on plugin"), device)
                if port and port.ofport != -1:
                    self.port_dead(port)
        return resync
    def treat_devices_added_or_updated(self, devices):
        resync = False
        all_ports = dict((p.normalized_port_name(), p)
                         for p in self._get_ports(self.int_br)
                         if p.is_neutron_port())
        for device in devices:
            LOG.debug("Processing port %s", device)
            if device not in all_ports:
                # The port has disappeared and should not be processed
                # There is no need to put the port DOWN in the plugin as
                # it never went up in the first place
                LOG.info(
                    _LI("Port %s was not found on the integration bridge "
                        "and will therefore not be processed"), device)
                continue
            port = all_ports[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(_LI("Port %(device)s updated. Details: %(details)s"),
                         {
                             'device': device,
                             'details': details
                         })
                port.vif_mac = details.get('mac_address')
                self.treat_vif_port(port, details['port_id'],
                                    details['network_id'],
                                    details['network_type'],
                                    details['physical_network'],
                                    details['segmentation_id'],
                                    details['admin_state_up'])

                # update plugin about port status
                if details.get('admin_state_up'):
                    LOG.debug("Setting status for %s to UP", device)
                    self.plugin_rpc.update_device_up(self.context, device,
                                                     self.agent_id,
                                                     cfg.CONF.host)
                else:
                    LOG.debug("Setting status for %s to DOWN", device)
                    self.plugin_rpc.update_device_down(self.context, device,
                                                       self.agent_id,
                                                       cfg.CONF.host)
                LOG.info(_LI("Configuration for device %s completed."), device)
            else:
                LOG.warn(_LW("Device %s not defined on plugin"), device)
                if (port and port.ofport != -1):
                    self.port_dead(port)
        return resync
 def treat_vif_port(self, vif_port, port_id, network_id, network_type,
                    physical_network, segmentation_id, admin_state_up):
     if vif_port:
         # When this function is called for a port, the port should have
         # an OVS ofport configured, as only these ports were considered
         # for being treated. If that does not happen, it is a potential
         # error condition of which operators should be aware
         if not vif_port.ofport:
             LOG.warn(_LW("VIF port: %s has no ofport configured, "
                          "and might not be able to transmit"),
                      vif_port.port_name)
         if admin_state_up:
             self.port_bound(vif_port, network_id, network_type,
                             physical_network, segmentation_id)
         else:
             self.port_dead(vif_port, network_id)
     else:
         LOG.debug("No VIF port for port %s defined on agent.", port_id)
Example #4
0
 def treat_vif_port(self, vif_port, port_id, network_id, network_type,
                    physical_network, segmentation_id, admin_state_up):
     if vif_port:
         # When this function is called for a port, the port should have
         # an OVS ofport configured, as only these ports were considered
         # for being treated. If that does not happen, it is a potential
         # error condition of which operators should be aware
         if not vif_port.ofport:
             LOG.warn(
                 _LW("VIF port: %s has no ofport configured, "
                     "and might not be able to transmit"),
                 vif_port.port_name)
         if admin_state_up:
             self.port_bound(vif_port, network_id, network_type,
                             physical_network, segmentation_id)
         else:
             self.port_dead(vif_port, network_id)
     else:
         LOG.debug("No VIF port for port %s defined on agent.", port_id)