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

[virt-tools-list] [PATCH] virt-image: Add --define option



Hello

I created new option '--define' for virt-image. It define guest does not
start automatically.

Now, I'm using BoxGrinder on Fedora15. When I attempt to virt-image for
the guest(generated virtual appliance image) started up automatically.
-- BoxGrinder: http://boxgrinder.org/

Any other idea?

Thanks

-- 

Best regards,

Hajime Taira <htaira redhat com>
RHEL Solution Architect
Global Services
Red Hat K.K.

Ebisu Neonato 8F, 4-1-18, Ebisu,
Shibuya-ku, Tokyo, Japan 150-0013

diff --git a/virt-image b/virt-image
index f606b2e..a28085c 100755
--- a/virt-image
+++ b/virt-image
@@ -96,6 +96,9 @@ def parse_args():
                            "domain"))
     misc.add_option("", "--boot", type="int", dest="boot",
                     help=_("The zero-based index of the boot record to use"))
+    misc.add_option("", "--define", action="store_true", dest="define_only",
+                    help=_("Define guest does not start automatically"),
+                    default=False)
     misc.add_option("", "--replace", action="store_true", dest="replace",
                     default=False,
                     help=_("Overwrite, or destroy, an existing image with "
@@ -194,9 +197,13 @@ def main():
 
     try:
         print_stdout("\n")
-        print_stdout(_("Creating guest %s...") % guest.name)
 
-        guest.start_install(None, meter)
+        if options.define_only:
+            print_stdout(_("Defining guest %s...") % guest.name)
+            guest.start_install(None, meter, define_only=True)
+        else:
+            print_stdout(_("Creating guest %s...") % guest.name)
+            guest.start_install(None, meter)
     except RuntimeError:
         raise
     except Exception, e:
diff --git a/virtinst/Guest.py b/virtinst/Guest.py
index 26a5678..063f84c 100644
--- a/virtinst/Guest.py
+++ b/virtinst/Guest.py
@@ -1162,7 +1162,7 @@ class Guest(XMLBuilderDomain.XMLBuilderDomain):
     ##########################
 
     def start_install(self, consolecb=None, meter=None, removeOld=None,
-                      wait=True, dry=False, return_xml=False):
+                      wait=True, dry=False, return_xml=False, define_only=False):
         """
         Begin the guest install (stage1).
         @param return_xml: Don't create the guest, just return generated XML
@@ -1190,7 +1190,7 @@ class Guest(XMLBuilderDomain.XMLBuilderDomain):
             self._replace_original_vm(removeOld)
 
             self.domain = self._create_guest(consolecb, meter, wait,
-                                             start_xml, final_xml, is_initial)
+                                             start_xml, final_xml, is_initial, define_only)
 
             # Set domain autostart flag if requested
             self._flag_autostart()
@@ -1231,40 +1231,52 @@ class Guest(XMLBuilderDomain.XMLBuilderDomain):
         return start_xml, final_xml
 
     def _create_guest(self, consolecb, meter, wait,
-                      start_xml, final_xml, is_initial):
+                      start_xml, final_xml, is_initial, define_only=False):
         """
         Actually do the XML logging, guest defining/creating, console
         launching and waiting
 
         @param is_initial: If running initial guest creation, else we
                            are continuing the install
+
+        @param define_only: If you set True, we define guest does not
+                           start automatically.
         """
-        if is_initial:
-            meter_label = _("Creating domain...")
+        if define_only:
+            meter_label = _("Defining domain...")
         else:
-            meter_label = _("Starting domain...")
+            if is_initial:
+                meter_label = _("Creating domain...")
+            else:
+                meter_label = _("Starting domain...")
 
         if meter == None:
             meter = progress.BaseMeter()
         meter.start(size=None, text=meter_label)
 
-        if is_initial:
-            dom = self.conn.createLinux(start_xml or final_xml, 0)
+        if define_only:
+                dom = self.conn.defineXML(start_xml or final_xml)
         else:
-            dom = self.conn.defineXML(start_xml or final_xml)
-            dom.create()
+            if is_initial:
+                dom = self.conn.createLinux(start_xml or final_xml, 0)
+            else:
+                dom = self.conn.defineXML(start_xml or final_xml)
+                dom.create()
 
         self.domain = dom
         meter.end(0)
 
-        logging.debug("Started guest, connecting to console if requested")
-        (self.domain,
-         self._consolechild) = self._wait_and_connect_console(consolecb)
+        if define_only:
+            logging.debug("Defined guest")
+        else:
+            logging.debug("Started guest, connecting to console if requested")
+            (self.domain,
+            self._consolechild) = self._wait_and_connect_console(consolecb)
 
-        self.domain = self.conn.defineXML(final_xml)
+            self.domain = self.conn.defineXML(final_xml)
 
-        # if we connected the console, wait for it to finish
-        self._waitpid_console(self._consolechild, wait)
+            # if we connected the console, wait for it to finish
+            self._waitpid_console(self._consolechild, wait)
 
         return self.conn.lookupByName(self.name)
 

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