示例#1
0
    def _prov_reqs_for_uri(self, uri):
        """Returns set of ProvisionRequests for a URI.

        When the API indicates that a URI is invalid, it will return a
        List of ProvisionRequests for a given URI.  If the URI is not valid
        for a ClientNetworkAdapter (CNA) then an empty list will be returned.
        """
        try:
            if not pvm_util.is_instance_path(uri):
                return []
        except Exception:
            LOG.warn(_LW('Unable to parse URI %s for provision request '
                         'assessment.'), uri)
            return []

        # The event queue will only return URI's for 'root like' objects.
        # This is essentially just the LogicalPartition, you can't get the
        # ClientNetworkAdapter.  So if we find an add/invalidate for the
        # LogicalPartition, we'll get all the CNAs.
        #
        # This check will throw out everything that doesn't include the
        # LogicalPartition's
        uuid = pvm_util.get_req_path_uuid(uri, preserve_case=True)
        if not uri.endswith('LogicalPartition/' + uuid):
            return []

        # For the LPAR, get the CNAs.
        cna_wraps = utils.list_cnas(self.adapter, self.host_uuid, uuid)
        resp = []
        for cna_w in cna_wraps:
            # Build a provision request for each type
            device_mac = utils.norm_mac(cna_w.mac)
            device_detail = self.agent.get_device_details(device_mac)

            # A device detail will always come back...even if neutron has
            # no idea what the port is.  This WILL happen for PowerVM, maybe
            # an event for the mgmt partition or the secure RMC VIF.  We can
            # detect if Neutron has full device details by simply querying for
            # the mac from the device_detail
            if not device_detail.get('mac_address'):
                continue

            # Must be good!
            resp.append(agent_base.ProvisionRequest(device_detail, uuid))
        return resp
示例#2
0
    def for_wrappers(cls, agent, lpar_vif_map, action):
        """Factory method to produce ProvisionRequests from VIF wrappers.

        :param agent: The neutron agent making the request.
        :param lpar_vif_map: Dict of {lpar_uuid: [vif_w, ...]), where lpar_uuid
                             is the UUID of the LPAR owning the VIF; and each
                             vif_w is a pypowervm wrapper of a VIF-ish type
                             (CNA, VNIC, etc.)
        :param action: What kind of provision requests, either PLUG or UNPLUG.
        :return: A list of new ProvisionRequest instances for each "valid"
                 LPAR/VIF tuple in lpar_vif_list.  Here "valid" means the VIF's
                 corresponding device can be found in neutron, and its instance
                 match the LPAR.
        """
        # Dict mapping {mac: device_detail}
        macs = [vif.mac for vifs in lpar_vif_map.values() for vif in vifs]
        device_details = {
            dev.get('mac_address'): dev
            for dev in agent.get_devices_details_list(macs)
        }
        ret = []
        for lpar, viflist in lpar_vif_map.items():
            for vif_w in viflist:
                mac = utils.norm_mac(vif_w.mac)
                if mac not in device_details:
                    # A VIF with no corresponding neutron port
                    continue
                detail = device_details[mac]
                if not utils.device_detail_valid(detail, mac):
                    continue
                LOG.info(
                    "Creating wrapper-based %(action)s ProvisionRequest for "
                    "%(vif_type)s VIF with MAC %(mac)s associated with LPAR "
                    "%(lpar_name)s (%(lpar_uuid)s).", {
                        'action': action,
                        'vif_type': vif_w.schema_type,
                        'mac': vif_w.mac,
                        'lpar_name': lpar.name,
                        'lpar_uuid': lpar.uuid
                    })
                ret.append(cls(action, detail, lpar.uuid))

        return ret
示例#3
0
 def test_norm_mac(self):
     EXPECTED = "12:34:56:78:90:ab"
     self.assertEqual(EXPECTED, utils.norm_mac("12:34:56:78:90:ab"))
     self.assertEqual(EXPECTED, utils.norm_mac("1234567890ab"))
     self.assertEqual(EXPECTED, utils.norm_mac("12:34:56:78:90:AB"))
     self.assertEqual(EXPECTED, utils.norm_mac("1234567890AB"))
示例#4
0
    def heal_and_optimize(self, is_boot):
        """Heals the system's network bridges and optimizes.

        Will query neutron for all the ports in use on this host.  Ensures that
        all of the VLANs needed for those ports are available on the correct
        network bridge.

        Finally, it optimizes the system by removing any VLANs that may no
        longer be required.  The VLANs that are removed must meet the following
        conditions:
         - Are not in use by ANY virtual machines on the system.  OpenStack
           managed or not.
         - Are not part of the primary load group on the Network Bridge.

        :param is_boot: Indicates if this is the first call on boot up of the
                        agent.
        """
        # List all our clients
        client_adpts = utils.list_cnas(self.adapter, self.host_uuid)

        # Get all the devices that Neutron knows for this host.  Note that
        # we pass in all of the macs on the system.  For VMs that neutron does
        # not know about, we get back an empty structure with just the mac.
        client_macs = [utils.norm_mac(x.mac) for x in client_adpts]
        devs = self.get_devices_details_list(client_macs)

        # Dictionary of the required VLANs on the Network Bridge
        nb_req_vlans = {}
        nb_wraps = utils.list_bridges(self.adapter, self.host_uuid)
        for nb_wrap in nb_wraps:
            nb_req_vlans[nb_wrap.uuid] = set()

        for dev in devs:
            nb_uuid, req_vlan = self._get_nb_and_vlan(dev, emit_warnings=False)

            # This can happen for ports that are on the host, but not in
            # Neutron.
            if nb_uuid is None or req_vlan is None:
                continue

            # If that list does not contain my VLAN, add it
            nb_req_vlans[nb_uuid].add(req_vlan)

        # Lets ensure that all VLANs for the openstack VMs are on the network
        # bridges.
        for nb_uuid in nb_req_vlans.keys():
            net_br.ensure_vlans_on_nb(self.adapter, self.host_uuid, nb_uuid,
                                      nb_req_vlans[nb_uuid])

        # We should clean up old VLANs as well.  However, we only want to clean
        # up old VLANs that are not in use by ANYTHING in the system.
        #
        # The first step is to identify the VLANs that are needed.  That can
        # be done by extending our nb_req_vlans map.
        #
        # We first extend that map by listing all the VMs on the system
        # (whether managed by OpenStack or not) and then seeing what Network
        # Bridge uses them.
        vswitch_map = utils.get_vswitch_map(self.adapter, self.host_uuid)
        for client_adpt in client_adpts:
            nb = utils.find_nb_for_cna(nb_wraps, client_adpt, vswitch_map)
            # Could occur if a system is internal only.
            if nb is None:
                LOG.debug("Client Adapter with mac %s is internal only.",
                          client_adpt.mac)
                continue

            # Make sure that it is on the nb_req_vlans list, as it is now
            # considered required.
            nb_req_vlans[nb.uuid].add(client_adpt.pvid)

            # Extend for each additional vlans as well
            for addl_vlan in client_adpt.tagged_vlans:
                nb_req_vlans[nb.uuid].add(addl_vlan)

        # We will have a list of CNAs that are not yet created, but are pending
        # provisioning from Nova.  Keep track of those so that we don't tear
        # those off the SEA.
        pending_vlans = self.pvid_updater.pending_vlans

        # The list of required VLANs on each network bridge also includes
        # everything on the primary VEA.
        for nb in nb_wraps:
            prim_ld_grp = nb.load_grps[0]
            vlans = [prim_ld_grp.pvid]
            vlans.extend(prim_ld_grp.tagged_vlans)
            for vlan in vlans:
                nb_req_vlans[nb.uuid].add(vlan)

        # If the configuration is set.
        if ACONF.automated_powervm_vlan_cleanup:
            # Loop through and remove VLANs that are no longer needed.
            for nb in nb_wraps:
                # Join the required vlans on the network bridge (already in
                # use) with the pending VLANs.
                req_vlans = nb_req_vlans[nb.uuid] | pending_vlans

                # Get ALL the VLANs on the bridge
                existing_vlans = set(nb.list_vlans())

                # To determine the ones no longer needed, subtract from all the
                # VLANs the ones that are no longer needed.
                vlans_to_del = existing_vlans - req_vlans
                for vlan_to_del in vlans_to_del:
                    LOG.warn(_LW("Cleaning up VLAN %(vlan)s from the system.  "
                                 "It is no longer in use."),
                             {'vlan': vlan_to_del})
                    net_br.remove_vlan_from_nb(self.adapter, self.host_uuid,
                                               nb.uuid, vlan_to_del)
示例#5
0
 def test_norm_mac(self):
     EXPECTED = "12:34:56:78:90:ab"
     self.assertEqual(EXPECTED, utils.norm_mac("12:34:56:78:90:ab"))
     self.assertEqual(EXPECTED, utils.norm_mac("1234567890ab"))
     self.assertEqual(EXPECTED, utils.norm_mac("12:34:56:78:90:AB"))
     self.assertEqual(EXPECTED, utils.norm_mac("1234567890AB"))