Nova snapshot 流程分析

本文档作为个人学习笔记,探讨了OpenStack Nova中实例快照的流程,包括live和cold两种方式,并指出nova会根据虚拟机状态自动选择。核心实现位于nova/virt/libvirt/driver.py。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

作为个人学习笔记分享,有任何问题欢迎交流!

实例快照的流程如其他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', {}):
    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值