• guestfs-python


    概要

    import guestfs
     g = guestfs.GuestFS(python_return_dict=True)
     g.add_drive_opts("disk.img", format="raw", readonly=1)
     g.launch()
    g = guestfs.GuestFS(python_return_dict=True)

    这表明您的程序希望接收返回哈希表的API中的方法的Python dicts。

    在libguestfs的未来版本中,这将成为默认版本。

    import guestfs    # python加载guestfs库
    output = "disk.img" 
    g = guestfs.GuestFS(python_return_dict=True)   # 创建一个GuestFS实例
    g.add_drive_opts("",format="qcow2",readonly=0)  # 挂载img到libguestfs
    g.launch()        # 后台运行libguestfs
     partitions = g.list_partitions()             #  获取所有分区
     g.mount(partitions[1],'/')                    # 第二个分区挂载到根目录
     g.upload("/etc/resolv.conf""/etc/resolv.conf")     # g.upload("src文件", "dst文件"),上传文件
     g.close()        # 虽然会自动close,还是再手工close最保险
    
    


    g.mkfs("ext4", partitions[0])    #在分区上创建文件系统。

     

    # Create some files and directories.
     g.touch("/empty")
     message = "Hello, world
    "
     g.write("/hello", message)
     g.mkdir("/foo")
     
     # This one uploads the local file /etc/resolv.conf into
     # the disk image.
     g.upload("/etc/resolv.conf", "/foo/resolv.conf")
     
     # Because we wrote to the disk and we want to detect write
     # errors, call g.shutdown.  You don't need to do this:
     # g.close will do it implicitly.
     g.shutdown()
     
     # Note also that handles are automatically closed if they are
     # reaped by reference counting.  You only need to call close
     # if you want to close the handle right away.
     g.close()

    自行翻译。。
     
  • 相关阅读:
    国内常用开源镜像
    spring中用到的常用设计模式
    微服务时代之网关及注册中心高可用架构设计
    查找字符串中相同连续字符串最多的子串,如果有两串长度相同取asc码 例如1233455 中是33
    mysql规范
    spring boot实现AOP登录拦截
    索引的类型及分类
    Im4java+ImageMagick/GraphicsMagick
    phpMyAdmin 应用程序“DEFAULT WEB SITE”中的服务器错误
    真机安装centos
  • 原文地址:https://www.cnblogs.com/heitaoq/p/9473062.html
Copyright © 2020-2023  润新知