[PATCH] Added a --replace option to virt-image which allows it to replace an existing machine if it is current running or defined

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

 



# HG changeset patch
# User "Bryan M. Kearney <bkearney@xxxxxxxxxx>"
# Date 1214497967 14400
# Node ID efba908eb79ad0bf2805c27f784de92578207f1b
# Parent  63aca2dbb3154a65505b1ccef080a8887742cef5
Added a --replace option to virt-image which allows it to replace an existing machine if it is current running or defined

diff -r 63aca2dbb315 -r efba908eb79a virt-image
--- a/virt-image	Tue Jun 24 12:30:24 2008 -0400
+++ b/virt-image	Thu Jun 26 12:32:47 2008 -0400
@@ -142,7 +142,10 @@ def parse_args():
                       help=_("The zero-based index of the boot record to use"))
     parser.add_option("", "--force", action="store_true", dest="force",
                       help=_("Do not prompt for input. Answers yes where applicable, terminates for all other prompts"),
-                      default=False)
+                      default=False)    
+    parser.add_option("", "--replace",action="store_true", dest="replace",
+                      help=_("Overwrite, or destroy, an existing image with the same name"),
+                      default=False)                      
 
     (options,args) = parser.parse_args()
     if len(args) < 1:
@@ -211,7 +214,7 @@ def main():
         try:
             print _("\n\nCreating guest %s...") % guest.name
 
-            dom = guest.start_install(None, progresscb)
+            dom = guest.start_install(None, progresscb, options.replace)
             if dom is None:
                 print _("Guest creation failed")
                 sys.exit(1)
diff -r 63aca2dbb315 -r efba908eb79a virtinst/Guest.py
--- a/virtinst/Guest.py	Tue Jun 24 12:30:24 2008 -0400
+++ b/virtinst/Guest.py	Thu Jun 26 12:32:47 2008 -0400
@@ -914,7 +914,7 @@ class Guest(object):
         "action": action }
 
 
-    def start_install(self, consolecb = None, meter = None):
+    def start_install(self, consolecb = None, meter = None, removeOld = False):
         """Do the startup of the guest installation."""
         self.validate_parms()
 
@@ -924,7 +924,7 @@ class Guest(object):
 
         self._prepare_install(meter)
         try:
-            return self._do_install(consolecb, meter)
+            return self._do_install(consolecb, meter, removeOld)
         finally:
             self._installer.cleanup()
 
@@ -932,10 +932,20 @@ class Guest(object):
         self._install_disks = self.disks[:]
         self._install_nics = self.nics[:]
 
-    def _do_install(self, consolecb, meter):
+    def _do_install(self, consolecb, meter, removeOld = False):
         try:
-            if self.conn.lookupByName(self.name) is not None:
-                raise RuntimeError, _("Domain named %s already exists!") %(self.name,)
+            vm = self.conn.lookupByName(self.name)
+            if removeOld:
+                if vm is not None:
+                    if vm.ID() == -1:
+                        logging.info("Removing old definition for image %s" %(self.name))
+                        vm.undefine()
+                    else:
+                        logging.info("Destroying image %s" %(self.name))           
+                        vm.destroy()
+            else:
+                if vm is not None:
+                    raise RuntimeError, _("Domain named %s already exists!") %(self.name,)
         except libvirt.libvirtError:
             pass
 

_______________________________________________
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