使用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 ""
nova中的localfs
最新推荐文章于 2023-01-09 19:04:27 发布