示例#1
0
    def _delete_port_profile(self, handle, port_profile, ucsm_ip):
        """Deletes Port Profile from UCS Manager."""
        port_profile_dest = (const.PORT_PROFILESETDN + const.VNIC_PATH_PREFIX +
                             port_profile)

        try:
            handle.StartTransaction()

            # Find port profile on the UCS Manager
            p_profile = handle.GetManagedObject(
                None, self.ucsmsdk.VnicProfile.ClassId(), {
                    self.ucsmsdk.VnicProfile.NAME: port_profile,
                    self.ucsmsdk.VnicProfile.DN: port_profile_dest
                })

            if not p_profile:
                LOG.warning(
                    _LW('UCS Manager network driver did not find '
                        'Port Profile %s to delete.'), port_profile)
                return

            handle.RemoveManagedObject(p_profile)
            handle.CompleteTransaction()

        except Exception as e:
            # Raise a Neutron exception. Include a description of
            # the original  exception.
            raise cexc.UcsmConfigDeleteFailed(config=port_profile,
                                              ucsm_ip=ucsm_ip,
                                              exc=e)
    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 = (
            self.ucsm_conf.get_sp_template_list_for_ucsm(ucsm_ip))

        vlan_name = self.make_vlan_name(vlan_id)
        virtio_port_list = self.ucsm_conf.get_ucsm_eth_port_list(ucsm_ip)

        try:
            handle.StartTransaction()
            # 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[1]
                sp_template = sp_template_info[2]

                sp_template_full_path = (sp_template_path +
                    const.SP_TEMPLATE_PREFIX + sp_template)

                obj = handle.GetManagedObject(
                    None,
                    self.ucsmsdk.LsServer.ClassId(),
                    {self.ucsmsdk.LsServer.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.GetManagedObject(
                        obj, self.ucsmsdk.VnicEther.ClassId(),
                        {self.ucsmsdk.VnicEther.DN: eth_port_path}, True)

                    if eth:
                        vlan_path = (eth_port_path +
                            const.VLAN_PATH_PREFIX + 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)
                        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.CompleteTransaction()
                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)
    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 = self.ucsm_conf.get_ucsm_eth_port_list(
                    ucsm_ip)
                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 conifg 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)
    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:
            for service_profile in service_profile_list:
                virtio_port_list = self.ucsm_conf.get_ucsm_eth_port_list(
                    ucsm_ip)
                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 conifg found, remove it.
                obj = handle.query_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.query_dn(eth_port_path)
                        if eth:
                            vlan_name = self.make_vlan_name(vlan_id)
                            vlan_path = eth_port_path + "/if-" + vlan_name
                            vlan = handle.query_dn(vlan_path)
                            if vlan:
                                # Found vlan config. Now remove it.
                                handle.remove_mo(vlan)
            handle.commit()

        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)