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

[et-mgmt-tools] [PATCH 2/2] Add virt-install --import option

This patch adds the --import option to virt-install. --import is a new
install method, which arranges for the guest to boot off the first
specified storage device.

So, given an existing disk image '/home/user/myvm.img', an example
command line could be:

virt-install --name myvm --ram 512 \
             --disk path=/home/user/myvm.img --import

# HG changeset patch
# User Cole Robinson <crobinso redhat com>
# Date 1235006852 18000
# Node ID 216b907240c03328103419302c04303431822bd8
# Parent  38db2ccaff913afb4c4ef823e58f2ce7d609b73f
Add virt-install --import option, to use the ImportInstaller

diff -r 38db2ccaff91 -r 216b907240c0 man/en/virt-install.pod
--- a/man/en/virt-install.pod	Wed Feb 18 20:16:03 2009 -0500
+++ b/man/en/virt-install.pod	Wed Feb 18 20:27:32 2009 -0500
@@ -309,6 +309,12 @@
 needs to be configured to boot off the CDROM device permanently. It
 may be desirable to also use the C<--nodisks> flag in combination.
+=item  --import
+Skip the OS installation process, and build a guest around an existing
+disk image. The device used for booting is the first device specified via
+C<--disk> or C<--file>.
 =item  -v, --hvm             This guest should be a fully virtualized guest
 Request the use of full virtualization, if both para & full virtualization are
@@ -667,8 +673,16 @@
        --nographics \
        --location http://download.fedora.redhat.com/pub/fedora/linux/core/6/x86_64/os/
+Create a guest from an existing disk image 'mydisk.img' using defaults for
+the rest of the options.
-=head1 AUTHOR
+  # virt-install \
+       --name demo
+       --ram 512
+       --disk path=/home/user/VMs/mydisk.img
+       --import
+=head1 AUTHORS
 Written by Daniel P. Berrange, Hugh Brock, Jeremy Katz, Cole Robinson and a
 team of many other contributors. See the AUTHORS file in the source
@@ -687,7 +701,7 @@
-Copyright (C) 2006-2007 Red Hat, Inc, and various contributors. 
+Copyright (C) 2006-2009 Red Hat, Inc, and various contributors. 
 This is free software. You may redistribute copies of it under the terms of the GNU General 
 Public License C<http://www.gnu.org/licenses/gpl.html>. There is NO WARRANTY, to the extent 
 permitted by law.
diff -r 38db2ccaff91 -r 216b907240c0 virt-install
--- a/virt-install	Wed Feb 18 20:16:03 2009 -0500
+++ b/virt-install	Wed Feb 18 20:27:32 2009 -0500
@@ -260,10 +260,16 @@
     guest.extraargs = extra
-def get_install_media(location, cdpath, pxe, livecd, guest, ishvm):
+def get_install_media(location, cdpath, pxe, livecd, import_install,
+                      guest, ishvm):
-    if (pxe and location) or (location and cdpath) or (cdpath and pxe):
-        fail(_("Only one of --pxe, --location and --cdrom can be used"))
+    found = False
+    for m in [pxe, location, cdpath, import_install]:
+        if m:
+            if found:
+                fail(_("Only one install method (%s) can be used") %
+                       "--pxe, --location, --cdrom, --import")
+            found = True
     if not ishvm:
         if pxe:
@@ -271,22 +277,21 @@
         if cdpath or livecd:
             fail(_("Paravirtualized guests cannot install off cdrom media."))
-        if location is None:
-            fail(_("location must be specified for paravirtualized guests."))
     if location and virtinst.util.is_uri_remote(guest.conn.getURI()):
         fail(_("--location can not be specified for remote connections."))
     cdinstall = (cdpath or False)
-    if not (pxe or cdpath or location):
+    if not (pxe or cdpath or location or import_install):
         # Look at Guest disks: if there is a cdrom, use for install
         for disk in guest.disks:
             if disk.device == virtinst.VirtualDisk.DEVICE_CDROM:
                 cdinstall = True
         if not cdinstall:
-            fail(_("One of --pxe, --location, or cdrom media must be "
-                    "specified."))
-    if pxe:
+            fail(_("One of %s, or cdrom media must be specified.") %
+                  "--pxe, --location, --import")
+    if pxe or import_install:
         if location or cdpath:
@@ -391,6 +396,8 @@
                     help=_("Boot from the network using the PXE protocol"))
     insg.add_option("", "--livecd", action="store_true", dest="livecd",
                     help=_("Treat the CD-ROM media as a Live CD"))
+    insg.add_option("", "--import", action="store_true", dest="import_install",
+                    help=_("Build guest around an existing disk image"))
     insg.add_option("-x", "--extra-args", type="string", dest="extra",
                     help=_("Additional arguments to pass to the kernel "
@@ -555,6 +562,8 @@
             fail(_("Can't use --pxe with --nonetworks"))
         instclass = virtinst.PXEInstaller
+    elif options.import_install:
+        instclass = virtinst.ImportInstaller
         instclass = virtinst.DistroInstaller
     installer = instclass(type=hv_name, os_type=virt_type, conn=conn)
@@ -595,7 +604,7 @@
     # and now for the full-virt vs paravirt specific questions
     get_install_media(options.location, options.cdrom, options.pxe,
-                      options.livecd, guest, ishvm)
+                      options.livecd, options.import_install, guest, ishvm)
     if not ishvm: # paravirt
         continue_inst = False

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