一、nova-compute在计算节点上运行负责虚拟机的生命周期的管理,虚拟机的创建、迁移、删除、重调度等操作,在对虚拟机的生命周期进行管理时,需要对虚拟机占用的资源进行管理,创建虚拟机要申请资源,资源不足创建虚拟机失败,删除虚拟机需要释放资源。主机资源信息存储在数据库中,包括cpu、内存、磁盘、PCI设备、CPU拓扑、NUMA拓扑等信息,虚拟机的整个生命周期需要对数据库中的资源进行同步。nova-compute为每一个主机创建一个ResourceTracker对象,用于管理主机资源信息,主机占用的资源存储在compute_nodes表中。有两种更新数据库的操作,一种是当虚拟机的状态发生变化时的主动上报机制claim记机制,另一种是周期任务定时将主机资源进行上报存入数据库。
二、claim机制
def instance_claim(self, context, instance, nodename, allocations,
limits=None):
"""Indicate that some resources are needed for an upcoming compute
instance build operation.
This should be called before the compute node is about to perform
an instance build operation that will consume additional resources.
:param context: security context
:param instance: instance to reserve resources for.
:type instance: nova.objects.instance.Instance object
:param nodename: The Ironic nodename selected by the scheduler
:param allocations: The placement allocation records for the instance.
:param limits: Dict of oversubscription limits for memory, disk,
and CPUs.
:returns: A Claim ticket