本文整理汇总了Python中virtinst.VirtualDisk类的典型用法代码示例。如果您正苦于以下问题:Python VirtualDisk类的具体用法?Python VirtualDisk怎么用?Python VirtualDisk使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了VirtualDisk类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testManyDisks2
def testManyDisks2(self):
i = utils.make_pxe_installer()
g = utils.get_basic_fullyvirt_guest(installer=i)
g.disks.append(utils.get_filedisk())
g.disks.append(utils.get_blkdisk())
g.disks.append(VirtualDisk(conn=g.conn, path="/dev/loop0",
device=VirtualDisk.DEVICE_CDROM,
driverType="raw"))
g.disks.append(VirtualDisk(conn=g.conn, path="/dev/loop0",
device=VirtualDisk.DEVICE_DISK,
driverName="qemu", format="qcow2"))
g.disks.append(VirtualDisk(conn=g.conn, path=None,
device=VirtualDisk.DEVICE_CDROM,
bus="scsi"))
g.disks.append(VirtualDisk(conn=g.conn, path=None,
device=VirtualDisk.DEVICE_FLOPPY))
g.disks.append(VirtualDisk(conn=g.conn, path="/dev/loop0",
device=VirtualDisk.DEVICE_FLOPPY,
driverName="phy", driverCache="none"))
disk = VirtualDisk(conn=g.conn, path="/dev/loop0",
bus="virtio", driverName="qemu",
driverType="qcow2", driverCache="none")
disk.driver_io = "threads"
g.disks.append(disk)
self._compare(g, "boot-many-disks2", False)
示例2: get_floppy
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: testManyVirtio
def testManyVirtio(self):
d = VirtualDisk(conn=utils.get_conn(), bus="virtio",
path="/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])
示例4: _make_disks
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)
示例5: check_path_search_for_qemu
def check_path_search_for_qemu(parent, conn, path):
set_error_parent(parent)
if conn.is_remote() or not conn.is_qemu_system():
return
user = util.running_config.default_qemu_user
skip_paths = util.running_config.get_perms_fix_ignore()
broken_paths = VirtualDisk.check_path_search_for_user(conn.vmm, path, user)
for p in broken_paths:
if p in skip_paths:
broken_paths.remove(p)
if not broken_paths:
return
logging.debug("No search access for dirs: %s", broken_paths)
resp, chkres = err_dial.warn_chkbox(
_("The emulator may not have search permissions "
"for the path '%s'.") % path,
_("Do you want to correct this now?"),
_("Don't ask about these directories again."),
buttons=gtk.BUTTONS_YES_NO)
if chkres:
util.running_config.add_perms_fix_ignore(broken_paths)
if not resp:
return
logging.debug("Attempting to correct permission issues.")
errors = VirtualDisk.fix_path_search_for_user(conn.vmm, path, user)
if not errors:
return
errmsg = _("Errors were encountered changing permissions for the "
"following directories:")
details = ""
for path, error in errors.items():
if path not in broken_paths:
continue
details += "%s : %s\n" % (path, error)
logging.debug("Permission errors:\n%s", details)
ignore, chkres = err_dial.err_chkbox(errmsg, details,
_("Don't ask about these directories again."))
if chkres:
util.running_config.add_perms_fix_ignore(errors.keys())
示例6: testCreateDisk
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)
示例7: populate_storage_volumes
def populate_storage_volumes(list_widget, pool, sensitive_cb):
vols = pool and pool.get_volumes() or {}
model = list_widget.get_model()
model.clear()
for key in vols.keys():
vol = vols[key]
try:
path = vol.get_target_path()
name = vol.get_pretty_name(pool.get_type())
cap = vol.get_pretty_capacity()
fmt = vol.get_format() or ""
except:
logging.debug("Error getting volume info for '%s', "
"hiding it", key, exc_info=True)
continue
namestr = None
try:
if path:
names = VirtualDisk.path_in_use_by(vol.conn.get_backend(),
path)
namestr = ", ".join(names)
if not namestr:
namestr = None
except:
logging.exception("Failed to determine if storage volume in "
"use.")
row = [key, name, cap, fmt, namestr]
if sensitive_cb:
row.append(sensitive_cb(fmt))
model.append(row)
示例8: populate_storage_volumes
def populate_storage_volumes(self):
pool = self.current_pool()
model = self.widget("vol-list").get_model()
model.clear()
vols = pool.get_volumes()
for key in vols.keys():
vol = vols[key]
try:
path = vol.get_target_path()
name = vol.get_name()
cap = vol.get_pretty_capacity()
fmt = vol.get_format() or ""
except:
logging.debug("Error getting volume info for '%s', "
"hiding it", key, exc_info=True)
continue
namestr = None
try:
if path:
names = VirtualDisk.path_in_use_by(self.conn.vmm, path)
namestr = ", ".join(names)
if not namestr:
namestr = None
except:
logging.exception("Failed to determine if storage volume in "
"use.")
model.append([key, name, cap, fmt, namestr])
示例9: disk_prompt
def disk_prompt(prompt_txt, arg_dict, warn_overwrite=False, prompt_size=True,
path_to_clone=None):
retry_path = True
conn = arg_dict.get("conn")
passed_path = arg_dict.get("path")
size = arg_dict.get("size")
no_path_needed = (bool(arg_dict.get("volInstall")) or
bool(arg_dict.get("volName")))
while 1:
if not retry_path:
passed_path = None
size = None
retry_path = False
msg = None
patherr = _("A disk path must be specified.")
if path_to_clone:
patherr = (_("A disk path must be specified to clone '%s'.") %
path_to_clone)
if not prompt_txt:
msg = _("What would you like to use as the disk (file path)?")
if not size is None:
msg = _("Please enter the path to the file you would like to "
"use for storage. It will have size %sGB.") %(size,)
if not no_path_needed:
path = prompt_for_input(patherr, prompt_txt or msg, passed_path)
else:
path = None
arg_dict["path"] = path
sizeerr = _("A size must be specified for non-existent disks.")
if path and not size and prompt_size:
size_prompt = _("How large would you like the disk (%s) to "
"be (in gigabytes)?") % path
try:
if not VirtualDisk.path_exists(conn, path):
size = prompt_loop(size_prompt, sizeerr, size, None, None,
func=float)
except Exception, e:
# Path is probably bogus, raise the error
logging.error(str(e))
continue
arg_dict["size"] = size
# Build disk object for validation
try:
dev = VirtualDisk(**arg_dict)
except ValueError, e:
if is_prompt():
logging.error(e)
continue
else:
fail(_("Error with storage parameters: %s" % str(e)))
示例10: _populate_vols
def _populate_vols(self):
list_widget = self.widget("vol-list")
pool = self._current_pool()
vols = pool and pool.get_volumes() or []
model = list_widget.get_model()
list_widget.get_selection().unselect_all()
model.clear()
vadj = self.widget("vol-scroll").get_vadjustment()
vscroll_percent = vadj.get_value() / max(vadj.get_upper(), 1)
for vol in vols:
key = vol.get_connkey()
try:
path = vol.get_target_path()
name = vol.get_pretty_name(pool.get_type())
cap = str(vol.get_capacity())
sizestr = vol.get_pretty_capacity()
fmt = vol.get_format() or ""
except:
logging.debug("Error getting volume info for '%s', "
"hiding it", key, exc_info=True)
continue
namestr = None
try:
if path:
names = VirtualDisk.path_in_use_by(vol.conn.get_backend(),
path)
namestr = ", ".join(names)
if not namestr:
namestr = None
except:
logging.exception("Failed to determine if storage volume in "
"use.")
sensitive = True
if self._vol_sensitive_cb:
sensitive = self._vol_sensitive_cb(fmt)
row = [None] * VOL_NUM_COLUMNS
row[VOL_COLUMN_KEY] = key
row[VOL_COLUMN_NAME] = name
row[VOL_COLUMN_SIZESTR] = sizestr
row[VOL_COLUMN_CAPACITY] = cap
row[VOL_COLUMN_FORMAT] = fmt
row[VOL_COLUMN_INUSEBY] = namestr
row[VOL_COLUMN_SENSITIVE] = sensitive
model.append(row)
def _reset_vscroll_position():
vadj.set_value(vadj.get_upper() * vscroll_percent)
self.idle_add(_reset_vscroll_position)
示例11: testDiskNumbers
def testDiskNumbers(self):
self.assertEquals("a", VirtualDisk.num_to_target(1))
self.assertEquals("b", VirtualDisk.num_to_target(2))
self.assertEquals("z", VirtualDisk.num_to_target(26))
self.assertEquals("aa", VirtualDisk.num_to_target(27))
self.assertEquals("ab", VirtualDisk.num_to_target(28))
self.assertEquals("az", VirtualDisk.num_to_target(52))
self.assertEquals("ba", VirtualDisk.num_to_target(53))
self.assertEquals("zz", VirtualDisk.num_to_target(27 * 26))
self.assertEquals("aaa", VirtualDisk.num_to_target(27 * 26 + 1))
disk = virtinst.VirtualDisk(utils.get_conn())
disk.bus = "ide"
self.assertEquals("hda", disk.generate_target([]))
self.assertEquals("hdb", disk.generate_target(["hda"]))
self.assertEquals("hdc", disk.generate_target(["hdb", "sda"]))
self.assertEquals("hdb", disk.generate_target(["hda", "hdd"]))
示例12: get_filedisk
def get_filedisk(path=None, fake=True):
if not path:
path = "/dev/default-pool/new-test-suite.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
示例13: populate_storage_volumes
def populate_storage_volumes(self):
model = self.widget("vol-list").get_model()
model.clear()
dironly = self.browse_reason == self.config.CONFIG_DIR_FS
pool = self.current_pool()
if not pool:
return
vols = pool.get_volumes()
for key in vols.keys():
vol = vols[key]
sensitive = True
try:
path = vol.get_target_path()
fmt = vol.get_format() or ""
except Exception:
logging.exception("Failed to determine volume parameters, "
"skipping volume %s", key)
continue
namestr = None
try:
if path:
names = VirtualDisk.path_in_use_by(self.conn.get_backend(),
path)
namestr = ", ".join(names)
if not namestr:
namestr = None
except:
logging.exception("Failed to determine if storage volume in "
"use.")
if dironly and fmt != 'dir':
sensitive = False
elif not self.rhel6_defaults:
if fmt == "vmdk":
sensitive = False
model.append([key, vol.get_name(), vol.get_pretty_capacity(),
fmt, namestr, sensitive])
示例14: _make_guest
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
示例15: _upload_file
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