本文整理匯總了Python中virtinst.VirtualDisk.path方法的典型用法代碼示例。如果您正苦於以下問題:Python VirtualDisk.path方法的具體用法?Python VirtualDisk.path怎麽用?Python VirtualDisk.path使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類virtinst.VirtualDisk
的用法示例。
在下文中一共展示了VirtualDisk.path方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _make_disks
# 需要導入模塊: from virtinst import VirtualDisk [as 別名]
# 或者: from virtinst.VirtualDisk import path [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)
示例2: get_floppy
# 需要導入模塊: from virtinst import VirtualDisk [as 別名]
# 或者: from virtinst.VirtualDisk import path [as 別名]
def get_floppy(path=None):
if not path:
path = "/dev/default-pool/testvol1.img"
d = VirtualDisk(_conn)
d.path = path
d.device = d.DEVICE_FLOPPY
d.validate()
return d
示例3: get_filedisk
# 需要導入模塊: from virtinst import VirtualDisk [as 別名]
# 或者: from virtinst.VirtualDisk import path [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
示例4: testManyDisks2
# 需要導入模塊: from virtinst import VirtualDisk [as 別名]
# 或者: from virtinst.VirtualDisk import path [as 別名]
def testManyDisks2(self):
i = utils.make_pxe_installer()
g = utils.get_basic_fullyvirt_guest(installer=i)
g.add_device(utils.get_filedisk())
g.add_device(utils.get_blkdisk())
d = VirtualDisk(g.conn)
d.path = "/dev/loop0"
d.device = d.DEVICE_CDROM
d.driver_type = "raw"
d.validate()
g.add_device(d)
d = VirtualDisk(g.conn)
d.path = "/dev/loop0"
d.device = d.DEVICE_DISK
d.driver_name = "qemu"
d.validate()
g.add_device(d)
d = VirtualDisk(g.conn)
d.path = None
d.device = d.DEVICE_CDROM
d.bus = "scsi"
d.validate()
g.add_device(d)
d = VirtualDisk(g.conn)
d.path = None
d.device = d.DEVICE_FLOPPY
d.iotune_tbs = 1
d.iotune_tis = 2
d.validate()
g.add_device(d)
d = VirtualDisk(g.conn)
d.path = "/dev/loop0"
d.device = d.DEVICE_FLOPPY
d.driver_name = "phy"
d.driver_cache = "none"
d.iotune_rbs = 5555
d.iotune_ris = 1234
d.iotune_wbs = 3
d.iotune_wis = 4
d.validate()
g.add_device(d)
d = VirtualDisk(g.conn)
d.path = "/dev/loop0"
d.bus = "virtio"
d.driver_name = "qemu"
d.driver_type = "qcow2"
d.driver_cache = "none"
d.driver_io = "threads"
d.validate()
g.add_device(d)
self._compare(g, "boot-many-disks2", False)
示例5: testManyVirtio
# 需要導入模塊: from virtinst import VirtualDisk [as 別名]
# 或者: from virtinst.VirtualDisk import path [as 別名]
def testManyVirtio(self):
d = VirtualDisk(utils.get_conn())
d.bus = "virtio"
d.path = "/dev/default-pool/testvol1.img"
targetlist = []
for ignore in range(0, (26 * 2) + 1):
d.target = None
d.generate_target(targetlist)
targetlist.append(d.target)
self.assertEquals("vdaa", targetlist[26])
self.assertEquals("vdba", targetlist[26 * 2])
示例6: testCreateDisk
# 需要導入模塊: from virtinst import VirtualDisk [as 別名]
# 或者: from virtinst.VirtualDisk import path [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)
示例7: get_blkdisk
# 需要導入模塊: from virtinst import VirtualDisk [as 別名]
# 或者: from virtinst.VirtualDisk import path [as 別名]
def get_blkdisk(path="/dev/disk-pool/diskvol1"):
d = VirtualDisk(_conn)
d.path = path
d.validate()
return d
示例8: _make_guest
# 需要導入模塊: from virtinst import VirtualDisk [as 別名]
# 或者: from virtinst.VirtualDisk import path [as 別名]
def _make_guest(installer=None, conn=None):
if conn is None:
conn = _default_conn
g = virtinst.Guest(conn)
g.type = "kvm"
g.name = "TestGuest"
g.memory = int(200 * 1024)
g.maxmemory = int(400 * 1024)
g.uuid = "12345678-1234-1234-1234-123456789012"
gdev = virtinst.VirtualGraphics(conn)
gdev.type = "vnc"
gdev.keymap = "ja"
g.add_device(gdev)
g.features.pae = False
g.vcpus = 5
if not installer:
installer = _make_installer(conn=conn)
g.installer = installer
g.emulator = "/usr/lib/xen/bin/qemu-dm"
g.os.arch = "i686"
g.os.os_type = "hvm"
g.add_default_input_device()
g.add_default_console_device()
g.add_device(virtinst.VirtualAudio(g.conn))
# Floppy disk
path = "/dev/default-pool/testvol1.img"
d = VirtualDisk(conn)
d.path = path
d.device = d.DEVICE_FLOPPY
d.validate()
g.add_device(d)
# File disk
path = "/dev/default-pool/new-test-suite.img"
d = virtinst.VirtualDisk(conn)
d.path = path
if d.wants_storage_creation():
parent_pool = d.get_parent_pool()
vol_install = virtinst.VirtualDisk.build_vol_install(conn,
os.path.basename(path), parent_pool, .0000001, True)
d.set_vol_install(vol_install)
d.validate()
g.add_device(d)
# Block disk
path = "/dev/disk-pool/diskvol1"
d = virtinst.VirtualDisk(conn)
d.path = path
d.validate()
g.add_device(d)
# Network device
dev = virtinst.VirtualNetworkInterface(conn)
dev.macaddr = "22:22:33:44:55:66"
dev.type = virtinst.VirtualNetworkInterface.TYPE_VIRTUAL
dev.source = "default"
g.add_device(dev)
return g
示例9: _upload_file
# 需要導入模塊: from virtinst import VirtualDisk [as 別名]
# 或者: from virtinst.VirtualDisk import path [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