예제 #1
0
 def disk_gb(self):
     """if the vm is boot from volume, just return ephemeral_gb"""
     if h_utils.is_boot_from_volume(self.context, self.instance):
         return self.instance_type['ephemeral_gb']
     else:
         return (self.instance_type['root_gb'] +
                 self.instance_type['ephemeral_gb'])
예제 #2
0
 def disk_gb(self):
     """if the vm is boot from volume, just return ephemeral_gb"""
     if h_utils.is_boot_from_volume(self.context, self.instance):
         return self.instance_type['ephemeral_gb']
     else:
         return (self.instance_type['root_gb'] +
                 self.instance_type['ephemeral_gb'])
예제 #3
0
    def consume_from_instance(self, instance, filter_properties=None):
        """
        Inherit and overrider for instance booted from volume. If instance
        booted from volume, we should add the root gb.
        :param instance: the instance object
        :param filter_properties: the filter properties for filtering.
        :return:
        """

        context = filter_properties['context']
        if h_utils.is_boot_from_volume(context, instance):
            # deep copy to avoid changing original instance object.
            instance_tmp = copy.deepcopy(instance)
            instance_tmp['root_gb'] = 0
        else:
            instance_tmp = instance
        if self.numa_topology:
            cell_siblings = {}
            numa_topology = jsonutils.loads(self.numa_topology)
            cells = numa_topology.get('nova_object.data', {}).get('cells', [])
            for cell in cells:
                cell_data = cell.get('nova_object.data')
                cell_siblings[cell_data['id']] = copy.deepcopy(
                    cell_data.get('siblings', []))

        super(HuaweiHostState, self).consume_from_instance(instance_tmp)

        if self.numa_topology:
            numa_topology = jsonutils.loads(self.numa_topology)
            cells = numa_topology.get('nova_object.data', {}).get('cells', [])
            for cell in cells:
                cell_data = cell.get('nova_object.data')
                cell_data['siblings'] = cell_siblings[cell_data['id']]
            self.numa_topology = jsonutils.dumps(numa_topology)

        vm_state = instance.get('vm_state', vm_states.BUILDING)
        task_state = instance.get('task_state')
        if vm_state != vm_states.BUILDING and task_state in [
                task_states.REBUILD_SPAWNING, task_states.IMAGE_UPLOADING
        ]:
            self.num_io_ops += 1

        # consume physical network resource
        physical_network_request = instance.get("stats").get("network", {})
        for phy_net in self.physical_networks.keys():
            if phy_net in physical_network_request:
                self.physical_networks[phy_net][
                    'used'] += physical_network_request[phy_net]
        LOG.debug("after consume is %s", self.physical_networks)
예제 #4
0
    def consume_from_instance(self, instance, filter_properties=None):
        """
        Inherit and overrider for instance booted from volume. If instance
        booted from volume, we should add the root gb.
        :param instance: the instance object
        :param filter_properties: the filter properties for filtering.
        :return:
        """

        context = filter_properties['context']
        if h_utils.is_boot_from_volume(context, instance):
            # deep copy to avoid changing original instance object.
            instance_tmp = copy.deepcopy(instance)
            instance_tmp['root_gb'] = 0
        else:
            instance_tmp = instance
        if self.numa_topology:
            cell_siblings = {}
            numa_topology = jsonutils.loads(self.numa_topology)
            cells = numa_topology.get('nova_object.data', {}).get('cells', [])
            for cell in cells:
                cell_data = cell.get('nova_object.data')
                cell_siblings[cell_data['id']] = copy.deepcopy(
                    cell_data.get('siblings', []))

        super(HuaweiHostState, self).consume_from_instance(instance_tmp)

        if self.numa_topology:
            numa_topology = jsonutils.loads(self.numa_topology)
            cells = numa_topology.get('nova_object.data', {}).get('cells', [])
            for cell in cells:
                cell_data = cell.get('nova_object.data')
                cell_data['siblings'] = cell_siblings[cell_data['id']]
            self.numa_topology = jsonutils.dumps(numa_topology)

        vm_state = instance.get('vm_state', vm_states.BUILDING)
        task_state = instance.get('task_state')
        if vm_state != vm_states.BUILDING and task_state in [
            task_states.REBUILD_SPAWNING,
            task_states.IMAGE_UPLOADING]:
            self.num_io_ops += 1

        # consume physical network resource
        physical_network_request = instance.get("stats").get("network", {})
        for phy_net in self.physical_networks.keys():
            if phy_net in physical_network_request:
                self.physical_networks[phy_net][
                    'used'] += physical_network_request[phy_net]
        LOG.debug("after consume is %s", self.physical_networks)
예제 #5
0
    def _update_usage(self, context, resources, usage, sign=1):
        """override the parent method for vm boot from volume case

        """
        mem_usage = usage['memory_mb']

        overhead = self.driver.estimate_instance_overhead(usage)
        mem_usage += overhead['memory_mb']

        resources['memory_mb_used'] += sign * mem_usage

        #if the vm is boot form volume, we shouldn't calculate the disk usage
        if not h_utils.is_boot_from_volume(context, usage):
            resources['local_gb_used'] += sign * usage.get('root_gb', 0)

        resources['local_gb_used'] += sign * usage.get('ephemeral_gb', 0)

        # free ram and disk may be negative, depending on policy:
        resources['free_ram_mb'] = (resources['memory_mb'] -
                                    resources['memory_mb_used'])
        resources['free_disk_gb'] = (resources['local_gb'] -
                                     resources['local_gb_used'])

        resources['running_vms'] = self.stats.num_instances
        self.ext_resources_handler.update_from_instance(usage, sign)

        # Calculate the numa usage
        free = sign == -1
        updated_numa_topology = hardware.get_host_numa_usage_from_instance(
            resources, usage, free)
        if updated_numa_topology:
            updated_numa_topology = jsonutils.loads(updated_numa_topology)
            # The following statements is to keep numa siblings in resources
            resource_numa_topology= jsonutils.loads(resources['numa_topology'])
            updated_cells = updated_numa_topology.get(
                'nova_object.data', {}).get('cells', [])
            res_cells = resource_numa_topology.get(
                'nova_object.data', {}).get('cells', [])
            # NOTE, we assume the order is constant
            for res_cell, updated_cell in zip(res_cells, updated_cells):
                res_cell_date = res_cell.get('nova_object.data')
                updated_cell_date = updated_cell.get('nova_object.data')
                if res_cell_date['id'] == updated_cell_date['id']:
                    updated_cell_date['siblings'] = res_cell_date['siblings']
            updated_numa_topology = jsonutils.dumps(updated_numa_topology)
        resources['numa_topology'] = updated_numa_topology
    def _update_usage(self, context, resources, usage, sign=1):
        """override the parent method for vm boot from volume case

        """
        mem_usage = usage['memory_mb']

        overhead = self.driver.estimate_instance_overhead(usage)
        mem_usage += overhead['memory_mb']

        resources['memory_mb_used'] += sign * mem_usage

        #if the vm is boot form volume, we shouldn't calculate the disk usage
        if not h_utils.is_boot_from_volume(context, usage):
            resources['local_gb_used'] += sign * usage.get('root_gb', 0)

        resources['local_gb_used'] += sign * usage.get('ephemeral_gb', 0)

        # free ram and disk may be negative, depending on policy:
        resources['free_ram_mb'] = (resources['memory_mb'] -
                                    resources['memory_mb_used'])
        resources['free_disk_gb'] = (resources['local_gb'] -
                                     resources['local_gb_used'])

        resources['running_vms'] = self.stats.num_instances
        self.ext_resources_handler.update_from_instance(usage, sign)

        # Calculate the numa usage
        free = sign == -1
        updated_numa_topology = hardware.get_host_numa_usage_from_instance(
            resources, usage, free)
        if updated_numa_topology:
            updated_numa_topology = jsonutils.loads(updated_numa_topology)
            # The following statements is to keep numa siblings in resources
            resource_numa_topology= jsonutils.loads(resources['numa_topology'])
            updated_cells = updated_numa_topology.get(
                'nova_object.data', {}).get('cells', [])
            res_cells = resource_numa_topology.get(
                'nova_object.data', {}).get('cells', [])
            # NOTE, we assume the order is constant
            for res_cell, updated_cell in zip(res_cells, updated_cells):
                res_cell_date = res_cell.get('nova_object.data')
                updated_cell_date = updated_cell.get('nova_object.data')
                if res_cell_date['id'] == updated_cell_date['id']:
                    updated_cell_date['siblings'] = res_cell_date['siblings']
            updated_numa_topology = jsonutils.dumps(updated_numa_topology)
        resources['numa_topology'] = updated_numa_topology
예제 #7
0
    def host_passes(self, host_state, filter_properties):
        """Filter based on disk usage."""

        #deep copy a filter properties to avoid changing
        filter_properties_tmp = copy.deepcopy(filter_properties)

        context = filter_properties_tmp['context']
        instance = filter_properties_tmp['request_spec']['instance_properties']
        if h_utils.is_boot_from_volume(context, instance):
            # just process local disk(ephemeral and swap), so set
            # root_gb to zero
            filter_properties_tmp.get('instance_type')['root_gb'] = 0

            # if the request disk size is zero, we should return true.
            # In negative free disk size condition, the instance booted volume
            # is not create successfully.
            instance_type = filter_properties.get('instance_type')
            requested_disk = (1024 * (instance_type['ephemeral_gb']) +
                             instance_type['swap'])
            if requested_disk == 0:
                return True

        return super(HuaweiDiskFilter, self).host_passes(host_state,
                                                filter_properties_tmp)