Re: Re-usage of existing disks/virt-install

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

 



Daniel P. Berrange wrote:
> On Wed, Feb 20, 2008 at 10:02:27AM -0500, Cole Robinson wrote:
>> Alexander Todorov wrote:
>>> -----BEGIN PGP SIGNED MESSAGE-----
>>> Hash: SHA512
>>>
>>> Hello,
>>> I've been using a shell script to help me with some testing which installs the
>>> same Xen guest over and over again. Now I've noticed that in
>>> python-virtinst-0.300.2-3.fc8 there's new functionality. virt-install will check
>>> if the file exists and ask to overwrite, then it will ask if you want to use the
>>> same file if it's being used by another guest (in my case inactive).
>>>
>>> That's breaking the cli by making it interactive. This has impact on old scripts
>>> which do not require further interaction.
>>>
>>> Can we consider a --yes or a similar option to deal with this problem?
>>> Any opinions are welcome.
>>>
>>> Thanks,
>>> Alexander.
>> Complete agreement here, I actually cooked up something similar to this a while
>> ago and posted it to the list, but never committed it. There should probably
>> be an option to answer yes where applicable, but also an option to outright fail
>> on any prompt.
>>
>> Something like --noprompt={fail,yes}, defaults to fail. Unfortunately this doesn't
>> look very intuitive but my brain isn't thinking of anything cleaner at the moment.
> 
> Personally I think the check for a file existing on disk is an utter waste
> of time & just serves to seriously annoy & should be removed. Fine checking
> for it being in use in an existing guest though.
> 
> The -f, or --force is the common nomenculture used to rm/cp/mv to stop it
> prompting
> 
> Dan.

The file check is now gone upstream, but a --force option is still a good idea.

Patch below.

Thanks,
Cole

diff -r faf95c934129 virt-clone
--- a/virt-clone	Tue Mar 04 09:54:33 2008 -0500
+++ b/virt-clone	Wed Mar 05 16:49:08 2008 -0500
@@ -164,6 +164,9 @@ def parse_args():
     # Misc options
     parser.add_option("-d", "--debug", action="store_true", dest="debug",
                       help=_("Print debugging information"))
+    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)
 
     (options,args) = parser.parse_args()
     return options
@@ -173,6 +176,7 @@ def main():
     options = parse_args()
 
     cli.setupLogging("virt-clone", options.debug)
+    cli.set_force(options.force)
 
     logging.debug("start clone with HV " + options.connect)
 
diff -r faf95c934129 virt-image
--- a/virt-image	Tue Mar 04 09:54:33 2008 -0500
+++ b/virt-image	Wed Mar 05 16:49:08 2008 -0500
@@ -139,6 +139,9 @@ def parse_args():
                       help=_("Print the libvirt XML, but do not start the domain"))
     parser.add_option("", "--boot", type="int", dest="boot",
                       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)
 
     (options,args) = parser.parse_args()
     if len(args) < 1:
@@ -162,6 +165,7 @@ def main():
     options = parse_args()
 
     cli.setupLogging("virt-image", options.debug)
+    cli.set_force(options.force)
 
     conn = cli.getConnection(options.connect)
     type = None
diff -r faf95c934129 virt-install
--- a/virt-install	Tue Mar 04 09:54:33 2008 -0500
+++ b/virt-install	Wed Mar 05 16:49:08 2008 -0500
@@ -273,6 +273,9 @@ def parse_args():
                       help=_("Print debugging information"))
     parser.add_option("", "--noreboot", action="store_true", dest="noreboot",
                       help=_("Disables the automatic rebooting when the installation is complete."))
+    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)
 
 
     (options,args) = parser.parse_args()
@@ -338,6 +341,7 @@ def main():
     options = parse_args()
 
     cli.setupLogging("virt-install", options.debug)
+    cli.set_force(options.force)
     conn = cli.getConnection(options.connect)
     capabilities = virtinst.CapabilitiesParser.parse(conn.getCapabilities())
 
diff -r faf95c934129 virtinst/cli.py
--- a/virtinst/cli.py	Tue Mar 04 09:54:33 2008 -0500
+++ b/virtinst/cli.py	Wed Mar 05 16:49:08 2008 -0500
@@ -29,6 +29,7 @@ import Guest
 import Guest
 
 MIN_RAM = 64
+force = False
 
 #
 # Setup helpers
@@ -94,9 +95,15 @@ def getConnection(connect):
 # Prompting
 #
 
+def set_force(val=True):
+    global force
+    force = val
+
 def prompt_for_input(prompt = "", val = None):
     if val is not None:
         return val
+    if force:
+        raise RuntimeError(_("Force flag is set but input was required. Prompt was: %s" % prompt))
     print prompt + " ",
     return sys.stdin.readline().strip()
 
@@ -110,6 +117,10 @@ def yes_or_no(s):
 
 def prompt_for_yes_or_no(prompt):
     """catches yes_or_no errors and ensures a valid bool return"""
+    if force:
+        logging.debug("Forcing return value of True to prompt '%s'")
+        return True
+
     while 1:
         input = prompt_for_input(prompt, None)
         try:

_______________________________________________
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