当前位置: 首页>>代码示例>>Python>>正文


Python VirtualDisk.set_create_storage方法代码示例

本文整理汇总了Python中virtinst.VirtualDisk.set_create_storage方法的典型用法代码示例。如果您正苦于以下问题:Python VirtualDisk.set_create_storage方法的具体用法?Python VirtualDisk.set_create_storage怎么用?Python VirtualDisk.set_create_storage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在virtinst.VirtualDisk的用法示例。


在下文中一共展示了VirtualDisk.set_create_storage方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _make_disks

# 需要导入模块: from virtinst import VirtualDisk [as 别名]
# 或者: from virtinst.VirtualDisk import set_create_storage [as 别名]
    def _make_disks(self):
        for drive in self.boot_caps.drives:
            path = self.image.abspath(drive.disk.file)
            size = None
            if drive.disk.size is not None:
                size = float(drive.disk.size) / 1024

            # FIXME: This is awkward; the image should be able to express
            # whether the disk is expected to be there or not independently
            # of its classification, especially for user disks
            # FIXME: We ignore the target for the mapping in m.target
            if (drive.disk.use == Disk.USE_SYSTEM and
                not os.path.exists(path)):
                raise RuntimeError(_("System disk %s does not exist") % path)

            device = VirtualDisk.DEVICE_DISK
            if drive.disk.format == Disk.FORMAT_ISO:
                device = VirtualDisk.DEVICE_CDROM

            disk = VirtualDisk(self.conn)
            disk.path = path
            disk.device = device
            disk.target = drive.target

            disk.set_create_storage(size=size, fmt=drive.disk.format)
            disk.validate()
            self.install_devices.append(disk)
开发者ID:aurex-linux,项目名称:virt-manager,代码行数:29,代码来源:virtimage.py

示例2: get_filedisk

# 需要导入模块: from virtinst import VirtualDisk [as 别名]
# 或者: from virtinst.VirtualDisk import set_create_storage [as 别名]
def get_filedisk(path=None, fake=True):
    if not path:
        path = "/tmp/test.img"
    d = VirtualDisk(_conn)
    d.path = path
    size = None
    if not fake:
        size = .000001
    d.set_create_storage(fake=fake, size=size)
    d.validate()
    return d
开发者ID:DanLipsitt,项目名称:virt-manager,代码行数:13,代码来源:utils.py

示例3: testCreateDisk

# 需要导入模块: from virtinst import VirtualDisk [as 别名]
# 或者: from virtinst.VirtualDisk import set_create_storage [as 别名]
    def testCreateDisk(self):
        """
        Doesn't really belong here, but what the hell :)
        """
        path = "/tmp/__virtinst_create_test__.img"
        sizegigs = .001
        sizebytes = long(sizegigs * 1024L * 1024L * 1024L)

        for sparse in [True, False]:
            disk = VirtualDisk(utils.get_conn())
            disk.path = path
            disk.set_create_storage(size=sizegigs, sparse=sparse)
            disk.validate()
            disk.setup()

            actualsize = long(os.path.getsize(path))
            os.unlink(path)
            self.assertEquals(sizebytes, actualsize)
开发者ID:TelekomCloud,项目名称:virt-manager,代码行数:20,代码来源:xmlconfig.py

示例4: _upload_file

# 需要导入模块: from virtinst import VirtualDisk [as 别名]
# 或者: from virtinst.VirtualDisk import set_create_storage [as 别名]
def _upload_file(conn, meter, destpool, src):
    # Build stream object
    stream = conn.newStream(0)
    def safe_send(data):
        while True:
            ret = stream.send(data)
            if ret == 0 or ret == len(data):
                break
            data = data[ret:]

    if meter is None:
        meter = urlgrabber.progress.BaseMeter()

    # Build placeholder volume
    size = os.path.getsize(src)
    basename = os.path.basename(src)
    poolpath = util.xpath(destpool.XMLDesc(0), "/pool/target/path")
    name = Storage.StorageVolume.find_free_name(basename,
                                                pool_object=destpool)
    if name != basename:
        logging.debug("Generated non-colliding volume name %s", name)

    vol_install = VirtualDisk.build_vol_install(conn, name, destpool,
                    (float(size) / 1024.0 / 1024.0 / 1024.0), True)

    disk = VirtualDisk(conn)
    disk.path = os.path.join(poolpath, name)
    disk.set_create_storage(vol_install=vol_install)
    disk.validate()

    disk.setup(meter=meter)
    vol = disk.get_vol_object()
    if not vol:
        raise RuntimeError(_("Failed to lookup scratch media volume"))

    try:
        # Register upload
        offset = 0
        length = size
        flags = 0
        stream.upload(vol, offset, length, flags)

        # Open source file
        fileobj = file(src, "r")

        # Start transfer
        total = 0
        meter.start(size=size,
                    text=_("Transferring %s") % os.path.basename(src))
        while True:
            # blocksize = (1024 ** 2)
            blocksize = 1024
            data = fileobj.read(blocksize)
            if not data:
                break

            safe_send(data)
            total += len(data)
            meter.update(total)

        # Cleanup
        stream.finish()
        meter.end(size)
    except:
        if vol:
            vol.delete(0)
        raise

    return vol
开发者ID:TelekomCloud,项目名称:virt-manager,代码行数:71,代码来源:distroinstaller.py


注:本文中的virtinst.VirtualDisk.set_create_storage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。