Compare commits
2 Commits
bash-compl
...
proper-del
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9a81f9ddb5 | ||
|
|
e1a620237a |
@@ -172,7 +172,6 @@ my %CONFIG;
|
|||||||
my $RELEASE = '4.2rc1';
|
my $RELEASE = '4.2rc1';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Read the global configuration file if it exists.
|
# Read the global configuration file if it exists.
|
||||||
#
|
#
|
||||||
@@ -220,7 +219,21 @@ while ( my $name = shift )
|
|||||||
{
|
{
|
||||||
if ( !xenRunning($name) )
|
if ( !xenRunning($name) )
|
||||||
{
|
{
|
||||||
deleteXenImage($name);
|
#
|
||||||
|
# Partition layout information values read from the
|
||||||
|
# partitions file, or constructed automatically if no
|
||||||
|
# partitions file is specified.
|
||||||
|
#
|
||||||
|
|
||||||
|
my @PARTITIONS = undef;
|
||||||
|
|
||||||
|
#
|
||||||
|
# Check for partitions to delete by reading the DomU's
|
||||||
|
# configuration file
|
||||||
|
#
|
||||||
|
my @PARTITIONS = findPartitions($host
|
||||||
|
|
||||||
|
deleteXenImage($name, @PARTITIONS);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -449,6 +462,70 @@ sub xenRunning
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
=begin doc
|
||||||
|
|
||||||
|
Read the (usually to be deleted) DomU configuration file specified
|
||||||
|
and returns the list of used partitions found in the file.
|
||||||
|
|
||||||
|
=end doc
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub findPartitions
|
||||||
|
{
|
||||||
|
my ($hostname) = (@_);
|
||||||
|
my $file = "/etc/xen/$hostname.cfg";
|
||||||
|
|
||||||
|
if ( -e $file )
|
||||||
|
{
|
||||||
|
open( FILE, "<", $file ) or die "Cannot read file '$file' - $!";
|
||||||
|
|
||||||
|
my $line = "";
|
||||||
|
my $contents = "";
|
||||||
|
|
||||||
|
while ( defined( $line = <FILE> ) )
|
||||||
|
{
|
||||||
|
chomp $line;
|
||||||
|
if ( $line =~ s/\\$// )
|
||||||
|
{
|
||||||
|
$line .= <FILE>;
|
||||||
|
redo unless eof(FILE);
|
||||||
|
}
|
||||||
|
|
||||||
|
# Skip lines beginning with comments
|
||||||
|
next if ( $line =~ /^([ \t]*)\#/ );
|
||||||
|
|
||||||
|
# Skip blank lines
|
||||||
|
next if ( length($line) < 1 );
|
||||||
|
|
||||||
|
# Strip trailing comments.
|
||||||
|
if ( $line =~ /(.*)\#(.*)/ )
|
||||||
|
{
|
||||||
|
$line = $1;
|
||||||
|
}
|
||||||
|
|
||||||
|
$contents .= $line;
|
||||||
|
}
|
||||||
|
|
||||||
|
close(FILE);
|
||||||
|
|
||||||
|
if ($contents =~ /\ndisk\s*=\s*\[\s*(.*?)\s*\]\s*\n/) {
|
||||||
|
my $disks = $1;
|
||||||
|
my @disks = split(/\n/, $disks);
|
||||||
|
foreach (@disks) {
|
||||||
|
s/^\s*'phy:(.*),\w*,\w*',\s*$/$1/;
|
||||||
|
}
|
||||||
|
return @disks;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
warn "Couldn't find $file. May start guessing based on further parameters.\n";
|
||||||
|
return qw(GUESSING);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
=begin doc
|
=begin doc
|
||||||
|
|
||||||
Delete the named image, and the corresponding configuration file
|
Delete the named image, and the corresponding configuration file
|
||||||
@@ -460,7 +537,11 @@ sub xenRunning
|
|||||||
|
|
||||||
sub deleteXenImage
|
sub deleteXenImage
|
||||||
{
|
{
|
||||||
my ($hostname) = (@_);
|
my $hostname = shift;
|
||||||
|
my @partitions = @_;
|
||||||
|
my $guessing = ($#partitions == 0 and $partitions[0] eq 'GUESSING');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Collect the names of files to delete.
|
# Collect the names of files to delete.
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ function _find_xen_images
|
|||||||
#
|
#
|
||||||
_xen_create_image()
|
_xen_create_image()
|
||||||
{
|
{
|
||||||
local cur prev ip evmscontainers roles partitions dists vgs
|
local cur prev ip roles partitions dists vgs
|
||||||
|
|
||||||
COMPREPLY=()
|
COMPREPLY=()
|
||||||
cur=${COMP_WORDS[COMP_CWORD]}
|
cur=${COMP_WORDS[COMP_CWORD]}
|
||||||
@@ -158,7 +158,7 @@ complete -F _xen_create_image xen-create-image
|
|||||||
#
|
#
|
||||||
_xen_create_nfs()
|
_xen_create_nfs()
|
||||||
{
|
{
|
||||||
local cur prev
|
local cur prev ip roles dists vgs
|
||||||
|
|
||||||
COMPREPLY=()
|
COMPREPLY=()
|
||||||
cur=${COMP_WORDS[COMP_CWORD]}
|
cur=${COMP_WORDS[COMP_CWORD]}
|
||||||
@@ -208,7 +208,6 @@ _xen_delete_image()
|
|||||||
# Complete the options + all available hostnames.
|
# Complete the options + all available hostnames.
|
||||||
# Determine arguments dynamically. Avoids out-of-dateness.
|
# Determine arguments dynamically. Avoids out-of-dateness.
|
||||||
#
|
#
|
||||||
names=`_find_xen_images`
|
|
||||||
opts=$(xen-delete-image --help|grep -- --|awk '{print $1}'|grep -- -- | sort -u)
|
opts=$(xen-delete-image --help|grep -- --|awk '{print $1}'|grep -- -- | sort -u)
|
||||||
opts="${opts} ${names}"
|
opts="${opts} ${names}"
|
||||||
|
|
||||||
@@ -222,6 +221,7 @@ _xen_delete_image()
|
|||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
--hostname)
|
--hostname)
|
||||||
|
names=`_find_xen_images`
|
||||||
COMPREPLY=( $(compgen -W "${names}" -- ${cur}) )
|
COMPREPLY=( $(compgen -W "${names}" -- ${cur}) )
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
@@ -251,7 +251,7 @@ complete -F _xen_delete_image xen-delete-image
|
|||||||
#
|
#
|
||||||
_xen_update_image()
|
_xen_update_image()
|
||||||
{
|
{
|
||||||
local cur prev opts evmscontainers names vgs
|
local cur prev opts base names vgs
|
||||||
COMPREPLY=()
|
COMPREPLY=()
|
||||||
cur="${COMP_WORDS[COMP_CWORD]}"
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||||
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||||
@@ -303,7 +303,7 @@ complete -F _xen_update_image xen-update-image
|
|||||||
#
|
#
|
||||||
_xen_list_images()
|
_xen_list_images()
|
||||||
{
|
{
|
||||||
local cur prev opts
|
local cur prev opts vgs
|
||||||
COMPREPLY=()
|
COMPREPLY=()
|
||||||
cur="${COMP_WORDS[COMP_CWORD]}"
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||||
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||||
@@ -325,7 +325,7 @@ complete -F _xen_list_images xen-list-images
|
|||||||
#
|
#
|
||||||
_xt-create-xen-config()
|
_xt-create-xen-config()
|
||||||
{
|
{
|
||||||
local cur prev opts
|
local cur prev
|
||||||
|
|
||||||
COMPREPLY=()
|
COMPREPLY=()
|
||||||
cur=${COMP_WORDS[COMP_CWORD]}
|
cur=${COMP_WORDS[COMP_CWORD]}
|
||||||
@@ -360,7 +360,7 @@ complete -F _xt-create-xen-config xt-create-xen-config
|
|||||||
#
|
#
|
||||||
_xt-customize-image()
|
_xt-customize-image()
|
||||||
{
|
{
|
||||||
local cur prev dists opts
|
local cur prev dists
|
||||||
|
|
||||||
COMPREPLY=()
|
COMPREPLY=()
|
||||||
cur=${COMP_WORDS[COMP_CWORD]}
|
cur=${COMP_WORDS[COMP_CWORD]}
|
||||||
@@ -401,7 +401,7 @@ complete -F _xt-customize-image xt-customize-image
|
|||||||
#
|
#
|
||||||
_xt-install-image()
|
_xt-install-image()
|
||||||
{
|
{
|
||||||
local cur prev dists opts
|
local cur prev dists
|
||||||
|
|
||||||
COMPREPLY=()
|
COMPREPLY=()
|
||||||
cur=${COMP_WORDS[COMP_CWORD]}
|
cur=${COMP_WORDS[COMP_CWORD]}
|
||||||
|
|||||||
Reference in New Issue
Block a user