作为个人学习笔记分享,有任何问题欢迎交流!
实例快照的流程如其他nova命令的流程相似,快照动作分为live和cold两种,根据虚拟化技术的不同和虚拟机运行的状态,上述两种快照动作不需要人工指定,nova根据具体情况决定。
底层实现主要在:nova/virt/libvirt/driver.py
def snapshot(self, context, instance, image_href, update_task_state):
"""Create snapshot from a running VM instance.
This command only works with qemu 0.14+
"""
try:
virt_dom = self._lookup_by_name(instance['name'])#获取域
except exception.InstanceNotFound:
raise exception.InstanceNotRunning(instance_id=instance['uuid'])
(image_service, image_id) = glance.get_remote_image_service(
context, instance['image_ref'])
try:
base = image_service.show(context, image_id)#获取实例镜像的base
except exception.ImageNotFound:
base = {}
#image_href是一个url,包括网页上输入的信息
_image_service = glance.get_remote_image_service(context, image_href)#create一个image_service这个类对象,并从image_href中解析出一个image id
snapshot_image_service, snapshot_image_id = _image_service
snapshot = snapshot_image_service.show(context, snapshot_image_id)
metadata = {'is_public': False,
'status': 'active',
'name': snapshot['name'],
'properties': {
'kernel_id': instance['kernel_id'],
'image_location': 'snapshot',
'image_state': 'available',
'owner_id': instance['project_id'],
'ramdisk_id': instance['ramdisk_id'],
}
}
if 'architecture' in base.get('properties', {}):