示例#1
0
文件: report.py 项目: Drooids/nova
    def update_resource_stats(self, context, name, stats):
        """Creates or updates stats for the desired service.

        :param context: local context
        :param name: name of resource to update
        :type name: immutable (str or tuple)
        :param stats: updated stats to send to scheduler
        :type stats: dict
        """

        if 'id' in stats:
            compute_node_id = stats['id']
            updates = stats.copy()
            del updates['id']
        else:
            raise exception.ComputeHostNotCreated(name=str(name))

        if 'stats' in updates:
            # NOTE(danms): This is currently pre-serialized for us,
            # which we don't want if we're using the object. So,
            # fix it here, and follow up with removing this when the
            # RT is converted to proper objects.
            updates['stats'] = jsonutils.loads(updates['stats'])
        compute_node = objects.ComputeNode(context=context, id=compute_node_id)
        compute_node.obj_reset_changes()
        for k, v in updates.items():
            setattr(compute_node, k, v)
        compute_node.save()

        LOG.info(_LI('Compute_service record updated for ' '%s') % str(name))
示例#2
0
    def update_resource_stats(self, context, name, stats):
        """Creates or updates stats for the desired service.

        :param context: local context
        :param name: name of resource to update
        :type name: immutable (str or tuple)
        :param stats: updated stats to send to scheduler
        :type stats: dict
        """

        if 'id' in stats:
            compute_node_id = stats['id']
            updates = stats.copy()
            del updates['id']
        else:
            raise exception.ComputeHostNotCreated(name=str(name))

        if 'stats' in updates:
            # NOTE(danms): This is currently pre-serialized for us,
            # which we don't want if we're using the object. So,
            # fix it here, and follow up with removing this when the
            # RT is converted to proper objects.
            updates['stats'] = jsonutils.loads(updates['stats'])
        compute_node = objects.ComputeNode(context=context,
                                           id=compute_node_id)
        compute_node.obj_reset_changes()
        for k, v in updates.items():
            if k == 'pci_device_pools':
                # NOTE(danms): Since the updates are actually the result of
                # a obj_to_primitive() on some real objects, we need to convert
                # back to a real object (not from_dict() or _from_db_object(),
                # which expect a db-formatted object) but just an attr-based
                # reconstruction. When we start getting a ComputeNode from
                # scheduler this "bandage" can go away.
                if v:
                    devpools = [objects.PciDevicePool.from_dict(x) for x in v]
                else:
                    devpools = []
                compute_node.pci_device_pools = objects.PciDevicePoolList(
                    objects=devpools)
            else:
                setattr(compute_node, k, v)
        compute_node.save()

        LOG.info(_LI('Compute_service record updated for '
                 '%s') % str(name))
示例#3
0
    def update_resource_stats(self, context, name, stats):
        """Creates or updates stats for the desired service.

        :param context: local context
        :param name: name of resource to update
        :type name: immutable (str or tuple)
        :param stats: updated stats to send to scheduler
        :type stats: dict
        """

        if 'id' in stats:
            compute_node_id = stats['id']
            updates = stats.copy()
            del updates['id']
        else:
            raise exception.ComputeHostNotCreated(name=str(name))

        self.conductor_api.compute_node_update(context,
                                               {'id': compute_node_id},
                                               updates)

        LOG.info(_LI('Compute_service record updated for ' '%s') % str(name))