From ea209f085b208ebe6d66256a18f93493f35700ba Mon Sep 17 00:00:00 2001 From: Axel Beckert Date: Thu, 18 Apr 2013 15:03:17 +0200 Subject: [PATCH] Refactor some code duplication in xen-delete-image --- bin/xen-delete-image | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/bin/xen-delete-image b/bin/xen-delete-image index b45e4c2..eeaa28d 100755 --- a/bin/xen-delete-image +++ b/bin/xen-delete-image @@ -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; -- 2.39.5