]> xenbits.xensource.com Git - people/dariof/xen-tools.git/commitdiff
Refactor some code duplication in xen-delete-image
authorAxel Beckert <abe@deuxchevaux.org>
Thu, 18 Apr 2013 13:03:17 +0000 (15:03 +0200)
committerAxel Beckert <abe@deuxchevaux.org>
Thu, 18 Apr 2013 14:21:25 +0000 (16:21 +0200)
bin/xen-delete-image

index b45e4c2e2b92a96101d6331f1780b1c2424ffcd1..eeaa28d674e13204dc9f862365defb6917f0cdbd 100755 (executable)
@@ -232,25 +232,17 @@ E_O_ROOT
 
 #
 #  Loop over the supplied arguments, and attempt to delete each
-# image.
+# image. Check both, bare parameters as well as --hostname options.
 #
-while ( my $name = shift )
-{
-    if ( $CONFIG{ 'no_xen_ok' } or !xenRunning($name, \%CONFIG) )
-    {
-        deleteXenImage($name);
-    }
-    else
-    {
-        print "Skipping xen guest '$name' - it appears to be running.\n";
-    }
+
+my @hosts = ();
+if (exists($CONFIG{ 'hostname' }) and defined($CONFIG{ 'hostname' })) {
+    my $hostname_option = $CONFIG{ 'hostname' };
+    @hosts = 'ARRAY' eq ref($hostname_option) ?
+        @$hostname_option : $hostname_option;
 }
 
-#
-#  Also delete any which were specified using the --hostname flag
-#
-my $hosts = $CONFIG{ 'hostname' };
-foreach my $name (@$hosts)
+foreach my $name (@ARGV, @hosts)
 {
     my %PER_HOST_CONFIG = %CONFIG;
     $PER_HOST_CONFIG{ 'hostname' } = $name;