本文整理匯總了Python中virtinst.VirtualDisk.setup方法的典型用法代碼示例。如果您正苦於以下問題:Python VirtualDisk.setup方法的具體用法?Python VirtualDisk.setup怎麽用?Python VirtualDisk.setup使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類virtinst.VirtualDisk
的用法示例。
在下文中一共展示了VirtualDisk.setup方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: testCreateDisk
# 需要導入模塊: from virtinst import VirtualDisk [as 別名]
# 或者: from virtinst.VirtualDisk import setup [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(conn=utils.get_conn(), path=path, size=sizegigs,
sparse=sparse)
disk.setup()
actualsize = long(os.path.getsize(path))
os.unlink(path)
self.assertEquals(sizebytes, actualsize)
示例2: _upload_file
# 需要導入模塊: from virtinst import VirtualDisk [as 別名]
# 或者: from virtinst.VirtualDisk import setup [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