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)))
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
def testManyDisks2(self): i = make_pxe_installer() g = get_basic_fullyvirt_guest(installer=i) g.disks.append(get_filedisk()) g.disks.append(get_blkdisk()) g.disks.append(VirtualDisk(conn=g.conn, path="/dev/loop0", device=VirtualDisk.DEVICE_CDROM)) 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)) g.disks.append(VirtualDisk(conn=g.conn, path="/dev/loop0", bus="virtio")) self._compare(g, "boot-many-disks2", False)
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
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])
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)
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)
def testManyDevices(self): i = utils.make_pxe_installer() g = utils.get_basic_fullyvirt_guest(installer=i) g.description = "foooo barrrr somedesc" g.hugepage = True # Hostdevs dev1 = VirtualHostDeviceUSB(g.conn) dev1.product = "0x1234" dev1.vendor = "0x4321" g.hostdevs.append(dev1) # Sound devices g.sound_devs.append(VirtualAudio("sb16", conn=g.conn)) g.sound_devs.append(VirtualAudio("es1370", conn=g.conn)) # Disk devices g.disks.append(VirtualDisk(conn=g.conn, path="/dev/loop0", device=VirtualDisk.DEVICE_FLOPPY)) g.disks.append(VirtualDisk(conn=g.conn, path="/dev/loop0", bus="scsi")) g.disks.append(VirtualDisk(conn=g.conn, path="/tmp", device="floppy")) d3 = VirtualDisk(conn=g.conn, path="/default-pool/testvol1.img", bus="scsi", driverName="qemu") g.disks.append(d3) # Controller devices c1 = VirtualController.get_class_for_type(VirtualController.CONTROLLER_TYPE_IDE)(g.conn) c1.index = "3" c2 = VirtualController.get_class_for_type(VirtualController.CONTROLLER_TYPE_VIRTIOSERIAL)(g.conn) c2.ports = "32" c2.vectors = "17" g.add_device(c1) g.add_device(c2) # Network devices net1 = utils.get_virtual_network() net1.model = "e1000" net2 = VirtualNetworkInterface(type="user", macaddr="11:11:11:11:11:11") g.nics.append(net1) g.nics.append(net2) # Character devices cdev1 = VirtualCharDevice.get_dev_instance(g.conn, VirtualCharDevice.DEV_SERIAL, VirtualCharDevice.CHAR_NULL) cdev2 = VirtualCharDevice.get_dev_instance(g.conn, VirtualCharDevice.DEV_PARALLEL, VirtualCharDevice.CHAR_UNIX) cdev2.source_path = "/tmp/foobar" cdev3 = VirtualCharDevice.get_dev_instance(g.conn, VirtualCharDevice.DEV_CHANNEL, VirtualCharDevice.CHAR_SPICEVMC) g.add_device(cdev1) g.add_device(cdev2) g.add_device(cdev3) # Video Devices vdev1 = VirtualVideoDevice(g.conn) vdev1.model_type = "vmvga" vdev2 = VirtualVideoDevice(g.conn) vdev2.model_type = "cirrus" vdev2.vram = 10 * 1024 vdev2.heads = 3 vdev3 = VirtualVideoDevice(g.conn) vdev4 = VirtualVideoDevice(g.conn) vdev4.model_type = "qxl" g.add_device(vdev1) g.add_device(vdev2) g.add_device(vdev3) g.add_device(vdev4) wdev2 = VirtualWatchdog(g.conn) wdev2.model = "ib700" wdev2.action = "none" g.add_device(wdev2) # Check keymap autoconfig gdev1 = virtinst.VirtualGraphics(conn=g.conn, type="vnc") self.assertTrue(gdev1.keymap != None) gdev1.keymap = "en-us" # Check keymap None gdev2 = virtinst.VirtualGraphics(conn=g.conn, type="vnc") gdev2.keymap = None gdev3 = virtinst.VirtualGraphics(conn=g.conn, type="sdl") gdev4 = virtinst.VirtualGraphics(conn=g.conn, type="spice") gdev5 = virtinst.VirtualGraphics(conn=g.conn, type="sdl") gdev5.xauth = "fooxauth" gdev5.display = "foodisplay" g.add_device(gdev1) g.add_device(gdev2) g.add_device(gdev3) g.add_device(gdev4) g.add_device(gdev5) g.clock.offset = "localtime" g.seclabel.type = g.seclabel.SECLABEL_TYPE_STATIC g.seclabel.model = "selinux" g.seclabel.label = "foolabel" g.seclabel.imagelabel = "imagelabel" self._compare(g, "boot-many-devices", False)
def testDiskValidation(self): disk = VirtualDisk("/dev/loop0") self._testArgs(disk, VirtualDisk, 'disk')
def get_blkdisk(path="/dev/loop0"): return VirtualDisk(path, conn=_conn)
def get_filedisk(path=None): if not path: path = "/tmp/test.img" return VirtualDisk(path, size=.0001, conn=_conn)
def testManyDevices(self): i = make_pxe_installer() g = get_basic_fullyvirt_guest(installer=i) g.description = "foooo barrrr \n baz && snarf. '' \"\" @@$\n" # Hostdevs dev1 = VirtualHostDeviceUSB(g.conn) dev1.product = "0x1234" dev1.vendor = "0x4321" g.hostdevs.append(dev1) # Sound devices g.sound_devs.append(VirtualAudio("sb16", conn=g.conn)) g.sound_devs.append(VirtualAudio("es1370", conn=g.conn)) # Disk devices g.disks.append(VirtualDisk(conn=g.conn, path="/dev/loop0", device=VirtualDisk.DEVICE_FLOPPY)) g.disks.append(VirtualDisk(conn=g.conn, path="/dev/loop0", bus="scsi")) g.disks.append(VirtualDisk(conn=g.conn, path="/tmp", device="floppy")) d3 = VirtualDisk(conn=g.conn, path="/default-pool/testvol1.img", bus="scsi", driverName="qemu") g.disks.append(d3) # Controller devices c1 = VirtualController.get_class_for_type(VirtualController.CONTROLLER_TYPE_IDE)(g.conn) c1.index = "3" c2 = VirtualController.get_class_for_type(VirtualController.CONTROLLER_TYPE_VIRTIOSERIAL)(g.conn) c2.ports = "32" c2.vectors = "17" g.add_device(c1) g.add_device(c2) # Network devices net1 = get_virtual_network() net1.model = "e1000" net2 = VirtualNetworkInterface(type="user", macaddr="11:11:11:11:11:11") g.nics.append(net1) g.nics.append(net2) # Character devices cdev1 = VirtualCharDevice.get_dev_instance(g.conn, VirtualCharDevice.DEV_SERIAL, VirtualCharDevice.CHAR_NULL) cdev2 = VirtualCharDevice.get_dev_instance(g.conn, VirtualCharDevice.DEV_PARALLEL, VirtualCharDevice.CHAR_UNIX) cdev2.source_path = "/tmp/foobar" g.add_device(cdev1) g.add_device(cdev2) # Video Devices vdev1 = VirtualVideoDevice(g.conn) vdev1.model_type = "vmvga" vdev2 = VirtualVideoDevice(g.conn) vdev2.model_type = "cirrus" vdev2.vram = 10 * 1024 vdev2.heads = 3 vdev3 = VirtualVideoDevice(g.conn) g.add_device(vdev1) g.add_device(vdev2) g.add_device(vdev3) wdev2 = VirtualWatchdog(g.conn) wdev2.model = "ib700" wdev2.action = "none" g.add_device(wdev2) g.clock.offset = "localtime" seclabel = virtinst.Seclabel(g.conn) seclabel.type = seclabel.SECLABEL_TYPE_STATIC seclabel.model = "selinux" seclabel.label = "foolabel" seclabel.imagelabel = "imagelabel" g.seclabel = seclabel self._compare(g, "boot-many-devices", False)
def get_blkdisk(): return VirtualDisk("/dev/loop0", conn=conn)
def testManyDevices(self): i = utils.make_pxe_installer() g = utils.get_basic_fullyvirt_guest(installer=i) g.description = "foooo barrrr somedesc" g.memoryBacking.hugepages = True # Hostdevs dev1 = VirtualHostDevice(g.conn) dev1.type = "usb" dev1.vendor = "0x4321" dev1.product = "0x1234" g.add_device(dev1) # Sound devices d = VirtualAudio(g.conn) d.model = "sb16" g.add_device(d) d = VirtualAudio(g.conn) d.model = "es1370" g.add_device(d) # Disk devices d = VirtualDisk(g.conn) d.type = "block" d.path = "/dev/null" d.device = d.DEVICE_FLOPPY d.validate() g.add_device(d) d = VirtualDisk(g.conn) d.type = "block" d.path = "/dev/null" d.bus = "scsi" d.validate() g.add_device(d) d = VirtualDisk(g.conn) d.path = "/tmp" d.device = d.DEVICE_FLOPPY d.validate() g.add_device(d) d = VirtualDisk(g.conn) d.path = "/dev/default-pool/testvol1.img" d.bus = "scsi" d.driver_name = "qemu" d.address.type = "spapr-vio" d.validate() g.add_device(d) # Controller devices c1 = VirtualController(g.conn) c1.type = "ide" c1.index = "3" c2 = VirtualController(g.conn) c2.type = "virtio-serial" c2.ports = "32" c2.vectors = "17" g.add_device(c1) g.add_device(c2) # Network devices net1 = utils.get_virtual_network() net1.model = "e1000" net2 = VirtualNetworkInterface(g.conn) net2.type = "user" net2.macaddr = "22:11:11:11:11:11" net3 = VirtualNetworkInterface(g.conn) net3.type = virtinst.VirtualNetworkInterface.TYPE_VIRTUAL net3.macaddr = "22:22:22:22:22:22" net3.source = "default" net3.model = "spapr-vlan" net3.address.set_addrstr("spapr-vio") g.add_device(net1) g.add_device(net2) g.add_device(net3) # Character devices cdev1 = VirtualSerialDevice(g.conn) cdev1.type = "null" cdev2 = VirtualParallelDevice(g.conn) cdev2.type = "unix" cdev2.source_path = "/dev/default-pool/foobar" cdev3 = VirtualChannelDevice(g.conn) cdev3.type = "spicevmc" g.add_device(cdev1) g.add_device(cdev2) g.add_device(cdev3) # Video Devices vdev1 = VirtualVideoDevice(g.conn) vdev1.model = "vmvga" vdev2 = VirtualVideoDevice(g.conn) vdev2.model = "cirrus" vdev2.vram = 10 * 1024 vdev2.heads = 3 vdev3 = VirtualVideoDevice(g.conn) vdev4 = VirtualVideoDevice(g.conn) vdev4.model = "qxl" g.add_device(vdev1) g.add_device(vdev2) g.add_device(vdev3) g.add_device(vdev4) # Watchdog Devices wdev2 = VirtualWatchdog(g.conn) wdev2.model = "ib700" wdev2.action = "none" g.add_device(wdev2) # Memballoon Devices mdev1 = VirtualMemballoon(g.conn) mdev1.model = "virtio" g.add_device(mdev1) # Check keymap autoconfig gdev1 = virtinst.VirtualGraphics(g.conn) gdev1.type = "vnc" self.assertTrue(gdev1.keymap is not None) gdev1.keymap = "en-us" # Check keymap None gdev2 = virtinst.VirtualGraphics(g.conn) gdev2.type = "vnc" gdev2.keymap = None gdev3 = virtinst.VirtualGraphics(g.conn) gdev3.type = "sdl" gdev3.xauth = "/dev/default-pool/.Xauthority" gdev3.display = ":3.4" gdev4 = virtinst.VirtualGraphics(g.conn) gdev4.type = "spice" gdev4.passwdValidTo = "foobar" gdev5 = virtinst.VirtualGraphics(g.conn) gdev5.type = "sdl" gdev5.xauth = "fooxauth" gdev5.display = "foodisplay" g.add_device(gdev1) g.add_device(gdev2) g.add_device(gdev3) g.add_device(gdev4) g.add_device(gdev5) g.clock.offset = "localtime" g.seclabel.type = g.seclabel.TYPE_STATIC g.seclabel.model = "selinux" g.seclabel.label = "foolabel" g.seclabel.imagelabel = "imagelabel" redir1 = virtinst.VirtualRedirDevice(g.conn) redir1.type = "spicevmc" redir2 = virtinst.VirtualRedirDevice(g.conn) redir2.type = "tcp" redir2.parse_friendly_server("foobar.com:1234") g.add_device(redir1) g.add_device(redir2) # Panic Notifier device pdev = VirtualPanicDevice(g.conn) g.add_device(pdev) self._compare(g, "boot-many-devices", False)
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.type = "block" d.path = "/dev/null" d.device = d.DEVICE_CDROM d.driver_type = "raw" d.validate() g.add_device(d) d = VirtualDisk(g.conn) d.type = "block" d.path = "/dev/null" 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.type = "block" d.path = "/dev/null" 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.type = "block" d.path = "/dev/null" 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)
def get_blkdisk(path="/dev/disk-pool/diskvol1"): d = VirtualDisk(_conn) d.path = path d.validate() return d
def _make_guest(installer=None, conn=None, os_variant=None): if conn is None: conn = _default_conn g = conn.caps.lookup_virtinst_guest() 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" if os_variant: g.os_variant = os_variant 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
def get_floppy(path=None): if not path: path = "/default-pool/testvol1.img" return VirtualDisk(path, conn=_conn, device=VirtualDisk.DEVICE_FLOPPY)