nova中的localfs

使用guestfs 可以在不用mount的情况下直接处理虚拟机的镜像文件,而使用localfs的话就需要将虚拟机的
镜像文件mount到host中才能编辑镜像文件.
localfs的实现路径为E:\nova\nova\virt\disk\vfs\localfs.py
class VFSLocalFS(vfs.VFS):

    def __init__(self, image, partition=None, imgdir=None):
        """Create a new local VFS instance

        :param image: instance of nova.virt.image.model.Image
        :param partition: the partition number of access
        :param imgdir: the directory to mount the image at
        """

        super(VFSLocalFS, self).__init__(image, partition)
		#从其__init__函数可以看出会指定要mount的路径imgdir.
        self.imgdir = imgdir
        self.mount = None

    def setup(self, mount=True):
        self.imgdir = tempfile.mkdtemp(prefix="openstack-vfs-localfs")
        try:
			#将虚拟机镜像文件mount到host中
            mnt = mount_api.Mount.instance_for_format(self.image,
                                                      self.imgdir,
            #默认mount 为true                                         self.partition)
            if mount:
				#检查是否mount成功
                if not mnt.do_mount():
                    raise exception.NovaException(mnt.error)
			#保存mount结果
            self.mount = mnt
        except Exception as e:
            with excutils.save_and_reraise_exception():
                LOG.debug("Failed to mount image: %(ex)s", {'ex': e})
                self.teardown()

 def get_image_fs(self):
		#这样在使用的时候,会先调用get_image_fs得到已经mount到host的路径,然后就可以直接编辑镜像文件了.
		
        if self.mount.device or self.mount.get_dev():
            out, err = nova.privsep.fs.get_filesystem_type(self.mount.device)
            return out.strip()
        return ""

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值