[PATCH 6/6] update virt-install options for specifying managed storage

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The attached patch updates virt-install to allow specifying
libvirt managed storage.

--file can specified managed storage using:

- An absolute path to a managed volume
- A volume passed as --file volume:poolname:volname
- A pool to create storage on, using --file pool:poolname

--cdrom can use the first of the above two options (doesn't
make sense to create install media).

There is an obvious problem with this approach though:
Specifying pool:foo or volume:foo:bar could collide
with existing file names, and volume:foo:bar would
fail if the specified pool had a colon in it. This
was mostly my quick solution so I could test it all
out, i'm open to suggestions how to change it. Once an
interface is decided on I'll update the docs.

This is built on the patch to remove prompting from
virt-install, fyi.

Thanks,
Cole

# HG changeset patch
# User "Cole Robinson <crobinso@xxxxxxxxxx>"
# Date 1217990681 14400
# Node ID c14912e1ec71c7d276ee7789e2c4181d4a89494a
# Parent  01efca5886ba1ce923c75406b4d28dc26c79ebcc
Allow virt-install to specify managed storage for --file and --cdrom.

--file can be specified as pool:poolname to create new storage on that pool,
volume:poolname:volname to lookup an existing volume, or just the target
path of the volume.

--cdrom can use the later two options available for --file.

diff -r 01efca5886ba -r c14912e1ec71 virt-install
--- a/virt-install	Tue Aug 05 22:39:54 2008 -0400
+++ b/virt-install	Tue Aug 05 22:44:41 2008 -0400
@@ -44,26 +44,59 @@
 gettext.bindtextdomain(virtinst.gettext_app, virtinst.gettext_dir)
 gettext.install(virtinst.gettext_app, virtinst.gettext_dir, unicode=1)
 
+def parse_storage(guest, path, size):
+    """helper to build proper disk parameters"""
+    abspath = None
+    voltuple = None
+    volinst = None
+
+    #we return (path, poolname, volname, volinst)
+
+    if path.startswith("pool:"):
+        if not size:
+            raise ValueError(_("Size must be specified with all 'pool:' "
+                               "names"))
+        # FIXME: fix this to allow : escaping
+        poolname = path[5:]
+        vc = virtinst.Storage.StorageVolume.get_volume_for_pool(pool_name=poolname, conn=guest.conn)
+        goodname = virtinst.Storage.StorageVolume.find_free_name(conn=guest.conn, pool_name=poolname, name=guest.name)
+        volinst = vc(pool_name=poolname, name=goodname, conn=guest.conn,
+                     capacity=(size and size*1024*1024*1024))
+
+    elif path.startswith("volume:"):
+        # FIXME: fix this to allow : escaping
+        parsepath = path[7:]
+        if parsepath.count(":") != 1:
+            raise ValueError(_("Storage volume must be specified as "
+                               "volume:poolname:volname"))
+        (p, v) = parsepath.split(":")
+        voltuple = (p, v)
+        logging.debug("Parsed volume: as pool='%s' vol='%s'" % \
+                      (voltuple[0], voltuple[1]))
+
+    else:
+        abspath = os.path.abspath(path)
+
+
+    return (abspath, voltuple, volinst)
+
 ### General input gathering functions
 def get_disk(disk, size, sparse, guest, hvm, conn):
 
-    # Getting disk size
-    if not os.path.exists(disk) and size is None:
-        fail(_("Must specify size for non-existent disks"))
-    try:
-        size = float(size)
-    except Exception, e:
-        fail(e)
 
     # Build disk object
     try:
-        d = virtinst.VirtualDisk(disk, size, sparse = sparse)
+        # Get disk parameters
+        (path, voltuple, volinst) = parse_storage(guest, disk, size)
+        d = virtinst.VirtualDisk(path=path, size=size, sparse=sparse,
+                                 volInstall=volinst, volName=voltuple,
+                                 conn=guest.conn)
         # Default file backed PV guests to tap driver
         if d.type == virtinst.VirtualDisk.TYPE_FILE \
            and not(hvm) and virtinst.util.is_blktap_capable():
            d.driver_name = virtinst.VirtualDisk.DRIVER_TAP
     except ValueError, e:
-        fail(e)
+        fail(_("Error with storage parameters: %s" % str(e)))
 
     # Check disk conflicts
     if d.is_conflict_disk(conn) is True:
@@ -71,7 +104,7 @@
         if not cli.prompt_for_yes_or_no(warnmsg + _("Do you really want to use the disk (yes or no)? ")):
             cli.nice_exit()
 
-    ret = d.size_conflict()
+    ret = d.is_size_conflict()
     if ret[0]:
         fail(ret[1])
     elif ret[1]:
@@ -128,22 +161,33 @@
         if location is None:
             fail(_("location must be specified for paravirtualized guests."))
 
-    if not (pxe or location or cdpath):
+    if location and virtinst.util.is_remote(guest.conn.getURI()):
+        fail(_("--location can not be specified for remote connections."))
+
+    if not (pxe or cdpath or location):
         fail(_("One of --pxe, --location or --cdrom must be specified."))
     if pxe:
         return
     try:
+        voltuple = None
+        if cdpath:
+            if cdpath.startswith("pool:"):
+                raise ValueError(_("Cannot use 'pool:' for cdrom."))
+            (cdpath, voltuple, volinst) = parse_storage(guest, cdpath, None)
         # guest.cdrom is deprecated
-        guest.location = (location or cdpath)
-        if cdpath and os.path.exists(cdpath):
+        if location or cdpath or voltuple:
+            guest.location = (location or cdpath or voltuple)
+        if cdpath and os.path.exists(cdpath) or voltuple:
             # Build a throwaway disk for validation for local CDs only
-            cddisk = virtinst.VirtualDisk(path=guest.location, 
+            cddisk = virtinst.VirtualDisk(path=cdpath,
+                                          volName=voltuple,
+                                          conn=guest.conn,
                                           transient=True,
                                           device=virtinst.VirtualDisk.DEVICE_CDROM,
                                           readOnly=True)
             guest.installer.cdrom = True
     except ValueError, e:
-        fail(e)
+        fail(_("Error creating cdrom disk: %s" % str(e)))
 
 
 ### Option parsing
@@ -337,7 +381,6 @@
     conn = cli.getConnection(options.connect)
     capabilities = virtinst.CapabilitiesParser.parse(conn.getCapabilities())
 
-
     if options.fullvirt and options.paravirt:
         fail(_("Can't do both --hvm and --paravirt"))
 
@@ -372,11 +415,14 @@
     logging.debug("Hypervisor type is '%s'" % type)
 
     if options.livecd:
-        installer = virtinst.LiveCDInstaller(type = type, os_type = os_type)
+        installer = virtinst.LiveCDInstaller(type = type, os_type = os_type,
+                                             conn = conn)
     elif options.pxe:
-        installer = virtinst.PXEInstaller(type = type, os_type = os_type)
+        installer = virtinst.PXEInstaller(type = type, os_type = os_type,
+                                          conn = conn)
     else:
-        installer = virtinst.DistroInstaller(type = type, os_type = os_type)
+        installer = virtinst.DistroInstaller(type = type, os_type = os_type,
+                                             conn = conn)
 
 
     if hvm:
_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/et-mgmt-tools

[Index of Archives]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux