示例#1
0
 def _get_host_name_for_rsvd_intf(self, tenant_id, instance_id):
     """
     Return the hostname of the blade with a reserved instance
     for this tenant
     """
     for ucsm_ip in self._inventory_state.keys():
         ucsm = self._inventory_state[ucsm_ip]
         for chassis_id in ucsm.keys():
             for blade_id in ucsm[chassis_id]:
                 blade_data = ucsm[chassis_id][blade_id]
                 blade_intf_data = blade_data[const.BLADE_INTF_DATA]
                 for blade_intf in blade_intf_data.keys():
                     tmp = deepcopy(blade_intf_data[blade_intf])
                     intf_data = blade_intf_data[blade_intf]
                     if (intf_data[const.BLADE_INTF_RESERVATION] ==
                             const.BLADE_INTF_RESERVED and
                             intf_data[const.TENANTID] == tenant_id and
                             intf_data[const.INSTANCE_ID] is None):
                         intf_data[const.INSTANCE_ID] = instance_id
                         host_name = self._get_host_name(ucsm_ip,
                                                         chassis_id,
                                                         blade_id)
                         port_binding = udb.get_portbinding_dn(blade_intf)
                         port_id = port_binding[const.PORTID]
                         udb.update_portbinding(port_id,
                                                instance_id=instance_id)
                         return host_name
     LOG.warn("Could not find a reserved dynamic nic for tenant: %s" %
              tenant_id)
     return None
 def _get_host_name_for_rsvd_intf(self, tenant_id, instance_id):
     """
     Return the hostname of the blade with a reserved instance
     for this tenant
     """
     for ucsm_ip in self._inventory_state.keys():
         ucsm = self._inventory_state[ucsm_ip]
         for chassis_id in ucsm.keys():
             for blade_id in ucsm[chassis_id]:
                 blade_data = ucsm[chassis_id][blade_id]
                 blade_intf_data = blade_data[const.BLADE_INTF_DATA]
                 for blade_intf in blade_intf_data.keys():
                     tmp = deepcopy(blade_intf_data[blade_intf])
                     intf_data = blade_intf_data[blade_intf]
                     if (intf_data[const.BLADE_INTF_RESERVATION] ==
                             const.BLADE_INTF_RESERVED and
                             intf_data[const.TENANTID] == tenant_id and
                             intf_data[const.INSTANCE_ID] is None):
                         intf_data[const.INSTANCE_ID] = instance_id
                         host_name = self._get_host_name(ucsm_ip,
                                                         chassis_id,
                                                         blade_id)
                         port_binding = udb.get_portbinding_dn(blade_intf)
                         port_id = port_binding[const.PORTID]
                         udb.update_portbinding(port_id,
                                                instance_id=instance_id)
                         return host_name
     LOG.warn("Could not find a reserved dynamic nic for tenant: %s" %
              tenant_id)
     return None
示例#3
0
    def _get_instance_port(self, tenant_id, instance_id, vif_id):
        """
        Return the device name for a reserved interface
        """
        found_blade_intf_data = None
        for ucsm_ip in self._inventory_state.keys():
            ucsm = self._inventory_state[ucsm_ip]
            for chassis_id in ucsm.keys():
                for blade_id in ucsm[chassis_id]:
                    blade_data = ucsm[chassis_id][blade_id]
                    blade_intf_data = blade_data[const.BLADE_INTF_DATA]
                    for blade_intf in blade_intf_data.keys():
                        intf_data = blade_intf_data[blade_intf]
                        if (intf_data[const.BLADE_INTF_RESERVATION] ==
                                const.BLADE_INTF_RESERVED and
                                intf_data[const.TENANTID] == tenant_id and
                                intf_data[const.INSTANCE_ID] == instance_id):
                            found_blade_intf_data = blade_intf_data
                            LOG.debug(("Found blade %s associated with this"
                                       " instance: %s") % (blade_id,
                                                           instance_id))
                            break

        if found_blade_intf_data:
            blade_intf_data = found_blade_intf_data
            for blade_intf in blade_intf_data.keys():
                intf_data = blade_intf_data[blade_intf]
                if (intf_data[const.BLADE_INTF_RESERVATION] ==
                        const.BLADE_INTF_RESERVED and
                        intf_data[const.TENANTID] == tenant_id and
                        (not intf_data[const.VIF_ID])):
                    intf_data[const.VIF_ID] = vif_id
                    intf_data[const.INSTANCE_ID] = instance_id
                    port_binding = udb.get_portbinding_dn(blade_intf)
                    port_id = port_binding[const.PORTID]
                    udb.update_portbinding(port_id, instance_id=instance_id,
                                           vif_id=vif_id)
                    device_name = intf_data[const.BLADE_INTF_RHEL_DEVICE_NAME]
                    profile_name = port_binding[const.PORTPROFILENAME]
                    dynamicnic_details = {
                        const.DEVICENAME: device_name,
                        const.UCSPROFILE: profile_name,
                    }
                    LOG.debug(("Found reserved dynamic nic: %s"
                               "associated with port %s") %
                              (intf_data, port_id))
                    LOG.debug("Returning dynamic nic details: %s" %
                              dynamicnic_details)
                    return dynamicnic_details

        LOG.warn("Could not find a reserved dynamic nic for tenant: %s" %
                 tenant_id)
        return None
    def _get_instance_port(self, tenant_id, instance_id, vif_id):
        """
        Return the device name for a reserved interface
        """
        found_blade_intf_data = None
        for ucsm_ip in self._inventory_state.keys():
            ucsm = self._inventory_state[ucsm_ip]
            for chassis_id in ucsm.keys():
                for blade_id in ucsm[chassis_id]:
                    blade_data = ucsm[chassis_id][blade_id]
                    blade_intf_data = blade_data[const.BLADE_INTF_DATA]
                    for blade_intf in blade_intf_data.keys():
                        intf_data = blade_intf_data[blade_intf]
                        if (intf_data[const.BLADE_INTF_RESERVATION] ==
                                const.BLADE_INTF_RESERVED and
                                intf_data[const.TENANTID] == tenant_id and
                                intf_data[const.INSTANCE_ID] == instance_id):
                            found_blade_intf_data = blade_intf_data
                            LOG.debug(("Found blade %s associated with this"
                                       " instance: %s") % (blade_id,
                                                           instance_id))
                            break

        if found_blade_intf_data:
            blade_intf_data = found_blade_intf_data
            for blade_intf in blade_intf_data.keys():
                intf_data = blade_intf_data[blade_intf]
                if (intf_data[const.BLADE_INTF_RESERVATION] ==
                        const.BLADE_INTF_RESERVED and
                        intf_data[const.TENANTID] == tenant_id and
                        (not intf_data[const.VIF_ID])):
                    intf_data[const.VIF_ID] = vif_id
                    intf_data[const.INSTANCE_ID] = instance_id
                    port_binding = udb.get_portbinding_dn(blade_intf)
                    port_id = port_binding[const.PORTID]
                    udb.update_portbinding(port_id, instance_id=instance_id,
                                           vif_id=vif_id)
                    device_name = intf_data[const.BLADE_INTF_RHEL_DEVICE_NAME]
                    profile_name = port_binding[const.PORTPROFILENAME]
                    dynamicnic_details = {
                        const.DEVICENAME: device_name,
                        const.UCSPROFILE: profile_name,
                    }
                    LOG.debug(("Found reserved dynamic nic: %s"
                               "associated with port %s") %
                              (intf_data, port_id))
                    LOG.debug("Returning dynamic nic details: %s" %
                              dynamicnic_details)
                    return dynamicnic_details

        LOG.warn("Could not find a reserved dynamic nic for tenant: %s" %
                 tenant_id)
        return None
示例#5
0
 def create_multiport(self, tenant_id, net_id_list, ports_num,
                      port_id_list, **kwargs):
     """
     Creates a port on the specified Virtual Network.
     """
     LOG.debug("UCSVICPlugin:create_multiport() called\n")
     self._set_ucsm(kwargs[const.DEVICE_IP])
     qos = None
     ucs_inventory = kwargs[const.UCS_INVENTORY]
     least_rsvd_blade_dict = kwargs[const.LEAST_RSVD_BLADE_DICT]
     chassis_id = least_rsvd_blade_dict[const.LEAST_RSVD_BLADE_CHASSIS]
     blade_id = least_rsvd_blade_dict[const.LEAST_RSVD_BLADE_ID]
     blade_data_dict = least_rsvd_blade_dict[const.LEAST_RSVD_BLADE_DATA]
     port_binding_list = []
     for port_id, net_id in zip(port_id_list, net_id_list):
         new_port_profile = self._create_port_profile(
             tenant_id, net_id, port_id,
             conf.DEFAULT_VLAN_NAME,
             conf.DEFAULT_VLAN_ID)
         profile_name = new_port_profile[const.PROFILE_NAME]
         rsvd_nic_dict = ucs_inventory.reserve_blade_interface(
             self._ucsm_ip, chassis_id,
             blade_id, blade_data_dict,
             tenant_id, port_id,
             profile_name)
         port_binding = udb.update_portbinding(
             port_id,
             portprofile_name=profile_name,
             vlan_name=conf.DEFAULT_VLAN_NAME,
             vlan_id=conf.DEFAULT_VLAN_ID,
             qos=qos)
         port_binding_list.append(port_binding)
     return port_binding_list
示例#6
0
 def create_multiport(self, tenant_id, net_id_list, ports_num, port_id_list,
                      **kwargs):
     """
     Creates a port on the specified Virtual Network.
     """
     LOG.debug("UCSVICPlugin:create_multiport() called\n")
     self._set_ucsm(kwargs[const.DEVICE_IP])
     qos = None
     ucs_inventory = kwargs[const.UCS_INVENTORY]
     least_rsvd_blade_dict = kwargs[const.LEAST_RSVD_BLADE_DICT]
     chassis_id = least_rsvd_blade_dict[const.LEAST_RSVD_BLADE_CHASSIS]
     blade_id = least_rsvd_blade_dict[const.LEAST_RSVD_BLADE_ID]
     blade_data_dict = least_rsvd_blade_dict[const.LEAST_RSVD_BLADE_DATA]
     port_binding_list = []
     for port_id, net_id in zip(port_id_list, net_id_list):
         new_port_profile = self._create_port_profile(
             tenant_id, net_id, port_id, conf.DEFAULT_VLAN_NAME,
             conf.DEFAULT_VLAN_ID)
         profile_name = new_port_profile[const.PROFILE_NAME]
         rsvd_nic_dict = ucs_inventory.reserve_blade_interface(
             self._ucsm_ip, chassis_id, blade_id, blade_data_dict,
             tenant_id, port_id, profile_name)
         port_binding = udb.update_portbinding(
             port_id,
             portprofile_name=profile_name,
             vlan_name=conf.DEFAULT_VLAN_NAME,
             vlan_id=conf.DEFAULT_VLAN_ID,
             qos=qos)
         port_binding_list.append(port_binding)
     return port_binding_list
示例#7
0
 def _disassociate_vifid_from_port(self, tenant_id, instance_id, vif_id):
     """
     Disassociate a VIF-ID from a port, this happens when a
     VM is destroyed
     """
     for ucsm_ip in self._inventory_state.keys():
         ucsm = self._inventory_state[ucsm_ip]
         for chassis_id in ucsm.keys():
             for blade_id in ucsm[chassis_id]:
                 blade_data = ucsm[chassis_id][blade_id]
                 blade_intf_data = blade_data[const.BLADE_INTF_DATA]
                 for blade_intf in blade_intf_data.keys():
                     intf_data = blade_intf_data[blade_intf]
                     if (intf_data[const.BLADE_INTF_RESERVATION] ==
                             const.BLADE_INTF_RESERVED and
                             intf_data[const.TENANTID] == tenant_id and
                             blade_intf_data[blade_intf][const.INSTANCE_ID]
                             == instance_id and
                             intf_data[const.VIF_ID][:const.UUID_LENGTH] ==
                             vif_id):
                         intf_data[const.VIF_ID] = None
                         intf_data[const.INSTANCE_ID] = None
                         port_binding = udb.get_portbinding_dn(blade_intf)
                         port_id = port_binding[const.PORTID]
                         udb.update_portbinding(port_id, instance_id=None,
                                                vif_id=None)
                         LOG.debug(
                             ("Disassociated VIF-ID: %s "
                              "from port: %s"
                              "in UCS inventory state for blade: %s") %
                             (vif_id, port_id, intf_data))
                         device_params = {const.DEVICE_IP: [ucsm_ip],
                                          const.PORTID: port_id}
                         return device_params
     LOG.warn(("Disassociating VIF-ID in UCS inventory failed. "
               "Could not find a reserved dynamic nic for tenant: %s") %
              tenant_id)
     return None
 def _disassociate_vifid_from_port(self, tenant_id, instance_id, vif_id):
     """
     Disassociate a VIF-ID from a port, this happens when a
     VM is destroyed
     """
     for ucsm_ip in self._inventory_state.keys():
         ucsm = self._inventory_state[ucsm_ip]
         for chassis_id in ucsm.keys():
             for blade_id in ucsm[chassis_id]:
                 blade_data = ucsm[chassis_id][blade_id]
                 blade_intf_data = blade_data[const.BLADE_INTF_DATA]
                 for blade_intf in blade_intf_data.keys():
                     intf_data = blade_intf_data[blade_intf]
                     if (intf_data[const.BLADE_INTF_RESERVATION] ==
                             const.BLADE_INTF_RESERVED and
                             intf_data[const.TENANTID] == tenant_id and
                             blade_intf_data[blade_intf][const.INSTANCE_ID]
                             == instance_id and
                             intf_data[const.VIF_ID][:const.UUID_LENGTH] ==
                             vif_id):
                         intf_data[const.VIF_ID] = None
                         intf_data[const.INSTANCE_ID] = None
                         port_binding = udb.get_portbinding_dn(blade_intf)
                         port_id = port_binding[const.PORTID]
                         udb.update_portbinding(port_id, instance_id=None,
                                                vif_id=None)
                         LOG.debug(
                             ("Disassociated VIF-ID: %s "
                              "from port: %s"
                              "in UCS inventory state for blade: %s") %
                             (vif_id, port_id, intf_data))
                         device_params = {const.DEVICE_IP: [ucsm_ip],
                                          const.PORTID: port_id}
                         return device_params
     LOG.warn(("Disassociating VIF-ID in UCS inventory failed. "
               "Could not find a reserved dynamic nic for tenant: %s") %
              tenant_id)
     return None
示例#9
0
 def unplug_interface(self, tenant_id, net_id, port_id, **kwargs):
     """
     Detaches a remote interface from the specified port on the
     specified Virtual Network.
     """
     LOG.debug("UCSVICPlugin:unplug_interface() called\n")
     self._set_ucsm(kwargs[const.DEVICE_IP])
     port_binding = udb.get_portbinding(port_id)
     profile_name = port_binding[const.PORTPROFILENAME]
     old_vlan_name = port_binding[const.VLANNAME]
     new_vlan_name = conf.DEFAULT_VLAN_NAME
     self._driver.change_vlan_in_profile(profile_name, old_vlan_name,
                                         new_vlan_name, self._ucsm_ip,
                                         self._ucsm_username,
                                         self._ucsm_password)
     return udb.update_portbinding(port_id, vlan_name=new_vlan_name,
                                   vlan_id=conf.DEFAULT_VLAN_ID)
示例#10
0
 def unplug_interface(self, tenant_id, net_id, port_id, **kwargs):
     """
     Detaches a remote interface from the specified port on the
     specified Virtual Network.
     """
     LOG.debug("UCSVICPlugin:unplug_interface() called\n")
     self._set_ucsm(kwargs[const.DEVICE_IP])
     port_binding = udb.get_portbinding(port_id)
     profile_name = port_binding[const.PORTPROFILENAME]
     old_vlan_name = port_binding[const.VLANNAME]
     new_vlan_name = conf.DEFAULT_VLAN_NAME
     self._driver.change_vlan_in_profile(profile_name, old_vlan_name,
                                         new_vlan_name, self._ucsm_ip,
                                         self._ucsm_username,
                                         self._ucsm_password)
     return udb.update_portbinding(port_id,
                                   vlan_name=new_vlan_name,
                                   vlan_id=conf.DEFAULT_VLAN_ID)
示例#11
0
 def plug_interface(self, tenant_id, net_id, port_id, remote_interface_id,
                    **kwargs):
     """
     Attaches a remote interface to the specified port on the
     specified Virtual Network.
     """
     LOG.debug(_("UCSVICPlugin:plug_interface() called"))
     self._set_ucsm(kwargs[const.DEVICE_IP])
     port_binding = udb.get_portbinding(port_id)
     profile_name = port_binding[const.PORTPROFILENAME]
     old_vlan_name = port_binding[const.VLANNAME]
     new_vlan_name = self._get_vlan_name_for_network(tenant_id, net_id)
     new_vlan_id = self._get_vlan_id_for_network(tenant_id, net_id)
     self._driver.change_vlan_in_profile(profile_name, old_vlan_name,
                                         new_vlan_name, self._ucsm_ip,
                                         self._ucsm_username,
                                         self._ucsm_password)
     return udb.update_portbinding(port_id, vlan_name=new_vlan_name,
                                   vlan_id=new_vlan_id)
示例#12
0
    def reserve_blade_interface(self, ucsm_ip, chassis_id, blade_id,
                                blade_data_dict, tenant_id, port_id,
                                portprofile_name):
        """Reserve an interface on a blade"""
        ucsm_username = cred.Store.get_username(ucsm_ip)
        ucsm_password = cred.Store.get_password(ucsm_ip)
        """
        We are first getting the updated UCSM-specific blade
        interface state
        """
        blade_data = self._get_blade_state(chassis_id, blade_id, ucsm_ip,
                                           ucsm_username, ucsm_password)
        blade_intf_data = blade_data[const.BLADE_INTF_DATA]
        chassis_data = self._inventory_state[ucsm_ip][chassis_id]
        old_blade_intf_data = chassis_data[blade_id][const.BLADE_INTF_DATA]

        """
        We will now copy the older non-UCSM-specific blade
        interface state
        """
        for blade_intf in blade_intf_data.keys():
            old_intf_data = old_blade_intf_data[blade_intf]
            blade_intf_data[blade_intf][const.BLADE_INTF_RESERVATION] = (
                old_intf_data[const.BLADE_INTF_RESERVATION])
            blade_intf_data[blade_intf][const.TENANTID] = (
                old_intf_data[const.TENANTID])
            blade_intf_data[blade_intf][const.PORTID] = (
                old_intf_data[const.PORTID])
            blade_intf_data[blade_intf][const.PROFILE_ID] = (
                old_intf_data[const.PROFILE_ID])
            blade_intf_data[blade_intf][const.INSTANCE_ID] = (
                old_intf_data[const.INSTANCE_ID])
            blade_intf_data[blade_intf][const.VIF_ID] = (
                old_intf_data[const.VIF_ID])

        blade_data[const.BLADE_UNRESERVED_INTF_COUNT] = (
            chassis_data[blade_id][const.BLADE_UNRESERVED_INTF_COUNT])
        """
        Now we will reserve an interface if its available
        """
        for blade_intf in blade_intf_data.keys():
            intf_data = blade_intf_data[blade_intf]
            if (intf_data[const.BLADE_INTF_RESERVATION] ==
                    const.BLADE_INTF_UNRESERVED):
                intf_data[const.BLADE_INTF_RESERVATION] = (
                    const.BLADE_INTF_RESERVED)
                intf_data[const.TENANTID] = tenant_id
                intf_data[const.PORTID] = port_id
                intf_data[const.INSTANCE_ID] = None
                dev_eth_name = intf_data[const.BLADE_INTF_RHEL_DEVICE_NAME]
                """
                We are replacing the older blade interface state with new
                """
                chassis_data[blade_id][const.BLADE_INTF_DATA] = blade_intf_data
                chassis_data[blade_id][const.BLADE_UNRESERVED_INTF_COUNT] -= 1
                host_name = self._get_host_name(ucsm_ip, chassis_id, blade_id)
                reserved_nic_dict = {
                    const.RESERVED_NIC_HOSTNAME: host_name,
                    const.RESERVED_NIC_NAME: dev_eth_name,
                    const.BLADE_INTF_DN: blade_intf,
                }
                port_binding = udb.add_portbinding(port_id, blade_intf, None,
                                                   None, None, None)
                udb.update_portbinding(port_id,
                                       tenant_id=intf_data[const.TENANTID])
                LOG.debug("Reserved blade interface: %s\n" % reserved_nic_dict)
                return reserved_nic_dict

        LOG.warn("Dynamic nic %s could not be reserved for port-id: %s" %
                 (blade_data, port_id))
        return False
示例#13
0
    def reserve_blade_interface(self, ucsm_ip, chassis_id, blade_id,
                                blade_data_dict, tenant_id, port_id,
                                portprofile_name):
        """Reserve an interface on a blade"""
        ucsm_username = cred.Store.get_username(ucsm_ip)
        ucsm_password = cred.Store.get_password(ucsm_ip)
        """
        We are first getting the updated UCSM-specific blade
        interface state
        """
        blade_data = self._get_blade_state(chassis_id, blade_id, ucsm_ip,
                                           ucsm_username, ucsm_password)
        blade_intf_data = blade_data[const.BLADE_INTF_DATA]
        chassis_data = self._inventory_state[ucsm_ip][chassis_id]
        old_blade_intf_data = chassis_data[blade_id][const.BLADE_INTF_DATA]

        """
        We will now copy the older non-UCSM-specific blade
        interface state
        """
        for blade_intf in blade_intf_data.keys():
            old_intf_data = old_blade_intf_data[blade_intf]
            blade_intf_data[blade_intf][const.BLADE_INTF_RESERVATION] = (
                old_intf_data[const.BLADE_INTF_RESERVATION])
            blade_intf_data[blade_intf][const.TENANTID] = (
                old_intf_data[const.TENANTID])
            blade_intf_data[blade_intf][const.PORTID] = (
                old_intf_data[const.PORTID])
            blade_intf_data[blade_intf][const.PROFILE_ID] = (
                old_intf_data[const.PROFILE_ID])
            blade_intf_data[blade_intf][const.INSTANCE_ID] = (
                old_intf_data[const.INSTANCE_ID])
            blade_intf_data[blade_intf][const.VIF_ID] = (
                old_intf_data[const.VIF_ID])

        blade_data[const.BLADE_UNRESERVED_INTF_COUNT] = (
            chassis_data[blade_id][const.BLADE_UNRESERVED_INTF_COUNT])
        """
        Now we will reserve an interface if its available
        """
        for blade_intf in blade_intf_data.keys():
            intf_data = blade_intf_data[blade_intf]
            if (intf_data[const.BLADE_INTF_RESERVATION] ==
                    const.BLADE_INTF_UNRESERVED):
                intf_data[const.BLADE_INTF_RESERVATION] = (
                    const.BLADE_INTF_RESERVED)
                intf_data[const.TENANTID] = tenant_id
                intf_data[const.PORTID] = port_id
                intf_data[const.INSTANCE_ID] = None
                dev_eth_name = intf_data[const.BLADE_INTF_RHEL_DEVICE_NAME]
                """
                We are replacing the older blade interface state with new
                """
                chassis_data[blade_id][const.BLADE_INTF_DATA] = blade_intf_data
                chassis_data[blade_id][const.BLADE_UNRESERVED_INTF_COUNT] -= 1
                host_name = self._get_host_name(ucsm_ip, chassis_id, blade_id)
                reserved_nic_dict = {
                    const.RESERVED_NIC_HOSTNAME: host_name,
                    const.RESERVED_NIC_NAME: dev_eth_name,
                    const.BLADE_INTF_DN: blade_intf,
                }
                port_binding = udb.add_portbinding(port_id, blade_intf, None,
                                                   None, None, None)
                udb.update_portbinding(port_id,
                                       tenant_id=intf_data[const.TENANTID])
                LOG.debug("Reserved blade interface: %s\n" % reserved_nic_dict)
                return reserved_nic_dict

        LOG.warn("Dynamic nic %s could not be reserved for port-id: %s" %
                 (blade_data, port_id))
        return False