• 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()

    自行翻译。。
     
  • 相关阅读:
    Java中获取键盘输入值的三种方法
    java多线程处理与数据集合
    Apachetomcat学习
    Java之枚举
    多例设计模式与枚举
    权限管理(数据库部分)
    hdu 2458(最大独立集)
    hdu 1507(最大匹配)
    hdu 1350+hdu 1960(最小路径覆盖)
    hdu 1845(最大匹配)
  • 原文地址:https://www.cnblogs.com/heitaoq/p/9473062.html
Copyright © 2020-2023  润新知