Example #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
Example #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
Example #5
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
Example #7
0
    def _get_initial_blade_state(self, chassis_id, blade_id, ucsm_ip,
                                 ucsm_username, ucsm_password):
        """Get the initial blade state"""
        blade_intf_data = self._client.get_blade_data(chassis_id, blade_id,
                                                      ucsm_ip, ucsm_username,
                                                      ucsm_password)

        unreserved_counter = 0

        for blade_intf in blade_intf_data.keys():
            dist_name = blade_intf_data[blade_intf][const.BLADE_INTF_DN]
            # We first make a pass through the state in UCSM
            # If a particular interface is showing as being allocated in
            # UCSM then it is definitely being used and so should be
            # marked as reserved, else we temporarily mark it as unreserved
            # based on the UCSM state, but may later change it if a port
            # association is found in the DB
            if not const.TENANTID in blade_intf_data[blade_intf].keys():
                blade_intf_data[blade_intf][const.TENANTID] = None
            if not const.PORTID in blade_intf_data[blade_intf].keys():
                blade_intf_data[blade_intf][const.PORTID] = None
            if not const.PROFILE_ID in blade_intf_data[blade_intf].keys():
                blade_intf_data[blade_intf][const.PROFILE_ID] = None
            if not const.INSTANCE_ID in blade_intf_data[blade_intf].keys():
                blade_intf_data[blade_intf][const.INSTANCE_ID] = None
            if not const.VIF_ID in blade_intf_data[blade_intf].keys():
                blade_intf_data[blade_intf][const.VIF_ID] = None

            if (blade_intf_data[blade_intf][const.BLADE_INTF_LINK_STATE] ==
                    const.BLADE_INTF_STATE_UNALLOCATED or
                    blade_intf_data[blade_intf][const.BLADE_INTF_LINK_STATE] ==
                    const.BLADE_INTF_STATE_UNKNOWN) and (
                    blade_intf_data[blade_intf][const.BLADE_INTF_OPER_STATE] ==
                    const.BLADE_INTF_STATE_UNKNOWN):
                blade_intf_data[blade_intf][const.BLADE_INTF_RESERVATION] = (
                    const.BLADE_INTF_UNRESERVED)
                unreserved_counter += 1
            else:
                blade_intf_data[blade_intf][const.BLADE_INTF_RESERVATION] = (
                    const.BLADE_INTF_RESERVED)

            port_binding = udb.get_portbinding_dn(dist_name)
            if port_binding:
                # We have found a port binding for this interface in the DB,
                # so we have earlier marked this interface as unreserved, we
                # need to change it, and also load the state from the DB for
                # other associations
                intf_data = blade_intf_data[blade_intf]
                if ((intf_data[const.BLADE_INTF_RESERVATION] == const.
                     BLADE_INTF_UNRESERVED)):
                    unreserved_counter -= 1
                    intf_data[const.BLADE_INTF_RESERVATION] = (
                        const.BLADE_INTF_RESERVED)
                intf_data[const.TENANTID] = port_binding[const.TENANTID]
                intf_data[const.PORTID] = port_binding[const.PORTID]
                intf_data[const.PROFILE_ID] = (
                    port_binding[const.PORTPROFILENAME])
                intf_data[const.INSTANCE_ID] = port_binding[const.INSTANCE_ID]
                intf_data[const.VIF_ID] = port_binding[const.VIF_ID]
        host_name = self._get_host_name(ucsm_ip, chassis_id, blade_id)
        blade_data = {const.BLADE_INTF_DATA: blade_intf_data,
                      const.BLADE_UNRESERVED_INTF_COUNT: unreserved_counter,
                      const.HOST_NAME: host_name}
        return blade_data
    def _get_initial_blade_state(self, chassis_id, blade_id, ucsm_ip,
                                 ucsm_username, ucsm_password):
        """Get the initial blade state"""
        blade_intf_data = self._client.get_blade_data(chassis_id, blade_id,
                                                      ucsm_ip, ucsm_username,
                                                      ucsm_password)

        unreserved_counter = 0

        for blade_intf in blade_intf_data.keys():
            dist_name = blade_intf_data[blade_intf][const.BLADE_INTF_DN]
            # We first make a pass through the state in UCSM
            # If a particular interface is showing as being allocated in
            # UCSM then it is definitely being used and so should be
            # marked as reserved, else we temporarily mark it as unreserved
            # based on the UCSM state, but may later change it if a port
            # association is found in the DB
            if not const.TENANTID in blade_intf_data[blade_intf].keys():
                blade_intf_data[blade_intf][const.TENANTID] = None
            if not const.PORTID in blade_intf_data[blade_intf].keys():
                blade_intf_data[blade_intf][const.PORTID] = None
            if not const.PROFILE_ID in blade_intf_data[blade_intf].keys():
                blade_intf_data[blade_intf][const.PROFILE_ID] = None
            if not const.INSTANCE_ID in blade_intf_data[blade_intf].keys():
                blade_intf_data[blade_intf][const.INSTANCE_ID] = None
            if not const.VIF_ID in blade_intf_data[blade_intf].keys():
                blade_intf_data[blade_intf][const.VIF_ID] = None

            if (blade_intf_data[blade_intf][const.BLADE_INTF_LINK_STATE] ==
                    const.BLADE_INTF_STATE_UNALLOCATED or
                    blade_intf_data[blade_intf][const.BLADE_INTF_LINK_STATE] ==
                    const.BLADE_INTF_STATE_UNKNOWN) and (
                    blade_intf_data[blade_intf][const.BLADE_INTF_OPER_STATE] ==
                    const.BLADE_INTF_STATE_UNKNOWN):
                blade_intf_data[blade_intf][const.BLADE_INTF_RESERVATION] = (
                    const.BLADE_INTF_UNRESERVED)
                unreserved_counter += 1
            else:
                blade_intf_data[blade_intf][const.BLADE_INTF_RESERVATION] = (
                    const.BLADE_INTF_RESERVED)

            port_binding = udb.get_portbinding_dn(dist_name)
            if port_binding:
                # We have found a port binding for this interface in the DB,
                # so we have earlier marked this interface as unreserved, we
                # need to change it, and also load the state from the DB for
                # other associations
                intf_data = blade_intf_data[blade_intf]
                if ((intf_data[const.BLADE_INTF_RESERVATION] == const.
                     BLADE_INTF_UNRESERVED)):
                    unreserved_counter -= 1
                    intf_data[const.BLADE_INTF_RESERVATION] = (
                        const.BLADE_INTF_RESERVED)
                intf_data[const.TENANTID] = port_binding[const.TENANTID]
                intf_data[const.PORTID] = port_binding[const.PORTID]
                intf_data[const.PROFILE_ID] = (
                    port_binding[const.PORTPROFILENAME])
                intf_data[const.INSTANCE_ID] = port_binding[const.INSTANCE_ID]
                intf_data[const.VIF_ID] = port_binding[const.VIF_ID]
        host_name = self._get_host_name(ucsm_ip, chassis_id, blade_id)
        blade_data = {const.BLADE_INTF_DATA: blade_intf_data,
                      const.BLADE_UNRESERVED_INTF_COUNT: unreserved_counter,
                      const.HOST_NAME: host_name}
        return blade_data