def _remove_vlan_from_all_sp_templates(self, handle, vlan_id, ucsm_ip):
        """Deletes VLAN config from all SP Templates that have it."""
        sp_template_info_list = (
            CONF.ml2_cisco_ucsm.ucsms[ucsm_ip].sp_template_list.values())

        vlan_name = self.make_vlan_name(vlan_id)
        virtio_port_list = (
            CONF.ml2_cisco_ucsm.ucsms[ucsm_ip].ucsm_virtio_eth_ports)

        try:
            # sp_template_info_list is a list of tuples.
            # Each tuple is of the form :
            # (ucsm_ip, sp_template_path, sp_template)
            for sp_template_info in sp_template_info_list:
                sp_template_path = sp_template_info.path
                sp_template = sp_template_info.name

                sp_template_full_path = (sp_template_path +
                                         const.SP_TEMPLATE_PREFIX +
                                         sp_template)

                obj = handle.query_dn(sp_template_full_path)
                if not obj:
                    LOG.error(
                        'UCS Manager network driver could not '
                        'find Service Profile template %s',
                        sp_template_full_path)
                    continue

                eth_port_paths = [
                    "%s%s" % (sp_template_full_path, ep)
                    for ep in virtio_port_list
                ]
                for eth_port_path in eth_port_paths:
                    eth = handle.query_dn(eth_port_path)

                    if eth:
                        vlan_path = (eth_port_path + const.VLAN_PATH_PREFIX +
                                     vlan_name)
                        vlan = handle.query_dn(vlan_path)
                        if vlan:
                            # Found vlan config. Now remove it.
                            handle.remove_mo(vlan)
                        else:
                            LOG.debug(
                                'UCS Manager network driver did not '
                                'find VLAN %s at %s', vlan_name, eth_port_path)
                    else:
                        LOG.debug(
                            'UCS Manager network driver did not '
                            'find ethernet port at %s', eth_port_path)
                handle.commit()
                return True
        except Exception as e:
            # Raise a Neutron exception. Include a description of
            # the original  exception.
            raise cexc.UcsmConfigDeleteFailed(config=vlan_id,
                                              ucsm_ip=ucsm_ip,
                                              exc=e)
Пример #2
0
    def _remove_vlan_from_all_service_profiles(self, handle, vlan_id, ucsm_ip):
        """Deletes VLAN Profile config from server's ethernet ports."""
        service_profile_list = []
        for key, value in six.iteritems(self.ucsm_sp_dict):
            if (ucsm_ip in key) and value:
                service_profile_list.append(value)

        if not service_profile_list:
            # Nothing to do
            return

        try:
            handle.StartTransaction()
            for service_profile in service_profile_list:
                virtio_port_list = (
                    CONF.ml2_cisco_ucsm.ucsms[ucsm_ip].ucsm_virtio_eth_ports)
                eth_port_paths = ["%s%s" % (service_profile, ep)
                    for ep in virtio_port_list]

                # 1. From the Service Profile config, access the
                # configuration for its ports.
                # 2. Check if that Vlan has been configured on each port
                # 3. If Vlan config found, remove it.
                obj = handle.GetManagedObject(
                        None,
                        self.ucsmsdk.LsServer.ClassId(),
                        {self.ucsmsdk.LsServer.DN: service_profile})

                if obj:
                    # Check if this vlan_id has been configured on the
                    # ports in this Service profile
                    for eth_port_path in eth_port_paths:
                        eth = handle.GetManagedObject(
                            obj, self.ucsmsdk.VnicEther.ClassId(),
                            {self.ucsmsdk.VnicEther.DN: eth_port_path},
                            True)
                        if eth:
                            vlan_name = self.make_vlan_name(vlan_id)
                            vlan_path = eth_port_path + "/if-" + vlan_name
                            vlan = handle.GetManagedObject(eth,
                                self.ucsmsdk.VnicEtherIf.ClassId(),
                                {self.ucsmsdk.VnicEtherIf.DN: vlan_path})
                            if vlan:
                                # Found vlan config. Now remove it.
                                handle.RemoveManagedObject(vlan)
            handle.CompleteTransaction()

        except Exception as e:
            # Raise a Neutron exception. Include a description of
            # the original  exception.
            raise cexc.UcsmConfigDeleteFailed(config=vlan_id,
                                              ucsm_ip=ucsm_ip,
                                              exc=e)