rmimage code drop
git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@7444 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
parent
2f1b041298
commit
138b9ec928
89
xCAT-client/pods/man1/rmimage.1.pod
Normal file
89
xCAT-client/pods/man1/rmimage.1.pod
Normal file
@ -0,0 +1,89 @@
|
||||
=head1 NAME
|
||||
|
||||
B<rmimage> - Removes the Linux stateless or statelite image from the file system.
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
I<rmimage [-h | --help]>
|
||||
|
||||
|
||||
I<rmimage [-V | --verbose]> I<-o <OS>> I<-a <architecture>> I<-p <profile>>
|
||||
|
||||
I<rmimage [-V | --verbose] imagename [--xcatdef]>
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Removes the Linux stateless or statelite image from the file system.
|
||||
The install dir is setup by using "installdir" attribute set in the site table.
|
||||
|
||||
If I<imagename> is specified, this command uses the information in the I<imagename>
|
||||
to calculate the image root directory; otherwise, this command uses the operating system name,
|
||||
architecture and profile name to calculate the image root directory.
|
||||
|
||||
The osimage definition will not be removed from the xCAT tables by default,
|
||||
specifying the flag --xcatdef will remove the osimage definition,
|
||||
or you can use rmdef -t osimage to remove the osimage definition.
|
||||
|
||||
The statelite image files on the diskful service nodes will not be removed,
|
||||
remove the image files on the service nodes manually if necessary,
|
||||
for example, use command "rsync -az --delete /install <sn>:/" to remove the image files on the service nodes,
|
||||
where the <sn> is the hostname of the service node.
|
||||
|
||||
=head1 Parameters
|
||||
|
||||
I<imagename> specifies the name of an os image definition to be used. The specification for the image is stored in the I<osimage> table and I<linuximage> table.
|
||||
|
||||
=head1 OPTIONS
|
||||
|
||||
|
||||
B<-h | --help> Display usage message.
|
||||
|
||||
B<-V | --verbose> Verbose mode.
|
||||
|
||||
B<-o> Operating system (fedora9,rhels5.5,sles11,etc)
|
||||
|
||||
B<-p> Profile (compute,service,etc)
|
||||
|
||||
B<-a> Architecture (ppc64,x86_64,etc)
|
||||
|
||||
B<--xcatdef> Remove the xCAT osimage definition
|
||||
|
||||
|
||||
=head1 RETURN VALUE
|
||||
|
||||
0 The command completed successfully.
|
||||
|
||||
1 An error has occurred.
|
||||
|
||||
=head1 EXAMPLES
|
||||
|
||||
1. To remove a fedora9 stateless image for a compute node architecture x86_64, enter:
|
||||
|
||||
I<rmimage fedora9-x86_64-netboot-compute>
|
||||
|
||||
or
|
||||
|
||||
I<rmimage -o fedora9 -p compute -a x86_64>
|
||||
|
||||
2. To remove a rhels5.5 statelite image for a compute node architecture ppc64 and the osimage definition, enter:
|
||||
|
||||
I<rmimage rhels5.5-ppc64-statelite-compute --xcatdef>
|
||||
|
||||
or
|
||||
|
||||
I<rmimage -o rhels5.5 -p compute -a ppc64 --xcatdef>
|
||||
|
||||
=head1 FILES
|
||||
|
||||
/opt/xcat/sbin/rmimage
|
||||
|
||||
|
||||
=head1 NOTES
|
||||
|
||||
This command is part of the xCAT software product.
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
L<genimage(1)|genimage.1>, L<packimage(1)|packimage.1>
|
||||
|
||||
|
@ -147,6 +147,7 @@ ln -sf ../bin/xcatclientnnr $RPM_BUILD_ROOT/%{prefix}/bin/nodegrpch
|
||||
ln -sf ../bin/xcatclientnnr $RPM_BUILD_ROOT/%{prefix}/sbin/tabdump
|
||||
ln -sf ../bin/xcatclientnnr $RPM_BUILD_ROOT/%{prefix}/sbin/tabprune
|
||||
ln -sf ../bin/xcatclientnnr $RPM_BUILD_ROOT/%{prefix}/sbin/packimage
|
||||
ln -sf ../bin/xcatclientnnr $RPM_BUILD_ROOT/%{prefix}/sbin/rmimage
|
||||
ln -sf ../bin/xcatclient $RPM_BUILD_ROOT/%{prefix}/sbin/makedns
|
||||
ln -sf ../bin/xcatclientnnr $RPM_BUILD_ROOT/%{prefix}/bin/gettab
|
||||
ln -sf ../bin/xcatclientnnr $RPM_BUILD_ROOT/%{prefix}/sbin/nodeadd
|
||||
|
197
xCAT-server/lib/xcat/plugins/rmimage.pm
Normal file
197
xCAT-server/lib/xcat/plugins/rmimage.pm
Normal file
@ -0,0 +1,197 @@
|
||||
#!/usr/bin/env perl
|
||||
# IBM(c) 2010 EPL license http://www.eclipse.org/legal/epl-v10.html
|
||||
package xCAT_plugin::rmimage;
|
||||
|
||||
BEGIN
|
||||
{
|
||||
$::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : '/opt/xcat';
|
||||
}
|
||||
|
||||
use lib "$::XCATROOT/lib/perl";
|
||||
use Getopt::Long;
|
||||
use File::Path;
|
||||
use xCAT::Utils;
|
||||
use xCAT::DBobjUtils;
|
||||
|
||||
Getopt::Long::Configure("bundling");
|
||||
Getopt::Long::Configure("pass_through");
|
||||
|
||||
sub handled_commands {
|
||||
return {
|
||||
rmimage => "rmimage",
|
||||
}
|
||||
}
|
||||
|
||||
sub process_request {
|
||||
my $request = shift;
|
||||
my $callback = shift;
|
||||
my $doreq = shift;
|
||||
my $installroot = xCAT::Utils->getInstallDir();
|
||||
my $tftproot = xCAT::Utils->getTftpDir();
|
||||
|
||||
my $usage = "\nUsage:\n rmimage [-h | --help]\n rmimage [-V | --verbose] -o <OS> -a <architecture> -p <profile>\n rmimage [-V | --verbose] imagename [--xcatde]";
|
||||
|
||||
@ARGV = @{$request->{arg}};
|
||||
|
||||
my $osver;
|
||||
my $arch;
|
||||
my $profile;
|
||||
my $method;
|
||||
my $xcatdef;
|
||||
my $imagename;
|
||||
my $imagedir;
|
||||
|
||||
if (!xCAT::Utils->isLinux()) {
|
||||
$callback->({error=>["The rmimage command is only supported on Linux."],errorcode=>[1]});
|
||||
return;
|
||||
}
|
||||
|
||||
if (!GetOptions(
|
||||
'o=s' => \$osver,
|
||||
'a=s' => \$arch,
|
||||
'p=s' => \$profile,
|
||||
'h|help' => \$help,
|
||||
'V|verbose' => \$verbose,
|
||||
'xcatdef' => \$xcatdef
|
||||
)) {
|
||||
$callback->({error=>["$usage"],errorcode=>[1]});
|
||||
exit 1;
|
||||
}
|
||||
|
||||
if ($help) {
|
||||
$callback->({info=>["$usage"]});
|
||||
return;
|
||||
}
|
||||
|
||||
if (@ARGV > 0) {
|
||||
$imagename=$ARGV[0];
|
||||
if($verbose) {
|
||||
$callback->({info=>["image name is $imagename"]});
|
||||
}
|
||||
|
||||
if ($arch or $osver or $profile) {
|
||||
$callback->({error=>["-o, -a and -p options are not allowed when a image name is specified."],errorcode=>[1]});
|
||||
return;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if (!$osver or !$arch or !$profile) {
|
||||
$callback->({error=>["Missing flag -o, -a or -p"],errorcode=>[1]});
|
||||
return;
|
||||
}
|
||||
|
||||
if ($xcatdef) {
|
||||
$callback->({error=>["--xcatdef can not be used with the -o, -a or -p"],errorcode=>[1]});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ($imagename) {
|
||||
#Check the provemethod when imagename is specified
|
||||
my $osimagetab = xCAT::Table->new('osimage', -create=>1);
|
||||
if (!$osimagetab) {
|
||||
$callback->({error=>["Can not open osimage table."],errorcode=>[1]});
|
||||
return;
|
||||
}
|
||||
(my $ref) = $osimagetab->getAttribs({imagename => $imagename}, 'osvers', 'osarch', 'profile', 'provmethod');
|
||||
if ($ref) {
|
||||
$osver = $ref->{'osvers'};
|
||||
$arch = $ref->{'osarch'};
|
||||
$profile = $ref->{'profile'};
|
||||
$method = $ref->{'provmethod'};;
|
||||
}
|
||||
if($verbose) {
|
||||
$callback->({info=>["For osimage $imagename: osver = $osver, arch = $arch, profile = $profile, method = $method in osimage table"]});
|
||||
}
|
||||
if (($method) && ($method ne "netboot") && ($method ne "statelite")) {
|
||||
$callback->({error=>["Invalid method \"$method\", the rmimage command can only be used to remove the netboot or statelite image files"],errorcode=>[1]});
|
||||
return;
|
||||
}
|
||||
|
||||
#Check the rootimgdir when imagename is specified
|
||||
my $linuximagetab = xCAT::Table->new('linuximage', -create=>1);
|
||||
if (!$linuximagetab) {
|
||||
$callback->({error=>["Can not open linuximage table."],errorcode=>[1]});
|
||||
return;
|
||||
}
|
||||
(my $ref1) = $linuximagetab->getAttribs({imagename => $imagename}, 'rootimgdir');
|
||||
if (($ref1) && ($ref1->{'rootimgdir'})) {
|
||||
$imagedir = $ref1->{'rootimgdir'};
|
||||
}
|
||||
|
||||
if($verbose) {
|
||||
$callback->({info=>["For osimage $imagename: rootimgdir = $imagedir in linuximage table"]});
|
||||
}
|
||||
|
||||
# If the rootimgdir is empty, use the osver, arch and profile to form the rootimgdir
|
||||
if (!$imagedir) {
|
||||
# If any of the osver, arch or profile is empty in osimage table,
|
||||
# use the imagename to get the attributes
|
||||
if (!$osver or !$arch or !$profile) {
|
||||
#split the imagename
|
||||
($osver, $arch, $method, $profile) = split(/-/, $imagename, 4);
|
||||
if (!$osver or !$arch or !$profile or !$method) {
|
||||
$callback->({error=>["Invalid image name $imagename"],errorcode=>[1]});
|
||||
return;
|
||||
}
|
||||
if (($method ne "netboot") && ($method ne "statelite")) {
|
||||
$callback->({error=>["Invalid method \"$method\", the rmimage command can only be used to remove the netboot or statelite image files"],errorcode=>[1]});
|
||||
return;
|
||||
}
|
||||
}
|
||||
$imagedir = "$installroot/netboot/$osver/$arch/$profile";
|
||||
}
|
||||
} else { # imagename is not specified
|
||||
$imagedir = "$installroot/netboot/$osver/$arch/$profile";
|
||||
}
|
||||
|
||||
if($verbose) {
|
||||
$callback->({info=>["image directory is $imagedir"]});
|
||||
}
|
||||
|
||||
if (! -d $imagedir) {
|
||||
$callback->({error=>["Image directory $imagedir does not exist"],errorcode=>[1]});
|
||||
return;
|
||||
}
|
||||
|
||||
my $tftpdir = "$tftproot/xcat/netboot/$osver/$arch/$profile";
|
||||
my @filestoremove = ("$imagedir/rootimg.gz", "$imagedir/kernel", "$imagedir/initrd.gz", "$tftpdir/initrd.gz", "$tftpdir/kernel");
|
||||
|
||||
#some rpms like atftp mount the rootimg/proc to /proc, we need to make sure rootimg/proc is free of junk
|
||||
`umount -l $imagedir/rootimg/proc 2>&1 1>/dev/null`;
|
||||
|
||||
#Start removing the rootimg directory and files
|
||||
if (-d "$imagedir/rootimg") {
|
||||
$callback->({info=>["Removing directory $imagedir/rootimg"]});
|
||||
rmtree "$imagedir/rootimg";
|
||||
}
|
||||
|
||||
foreach my $fremove (@filestoremove) {
|
||||
if (-f $fremove) {
|
||||
$callback->({info=>["Removing file $fremove"]});
|
||||
unlink("$fremove");
|
||||
}
|
||||
}
|
||||
|
||||
$callback->({info=>["Image files have been removed successfully from this management node."]});
|
||||
|
||||
if (!$imagename || ($method eq "statelite")) {
|
||||
$callback->({info=>["Please be aware that the statelite image files on the diskful service nodes are not removed, you can remove the image files on the service nodes manually if necessary, for example, use command \"rsync -az --delete $installroot <sn>:/\" to remove the image files on the service nodes, where the <sn> is the hostname of the service node."]});
|
||||
}
|
||||
|
||||
if ($xcatdef && $imagename) {
|
||||
$callback->({info=>["Removing osimage definition for $imagename."]});
|
||||
my %objhash = ();
|
||||
$objhash{$imagename} = 'osimage';
|
||||
# remove the objects
|
||||
if (xCAT::DBobjUtils->rmobjdefs(\%objhash) != 0)
|
||||
{
|
||||
$callback->({error=>["Failed to remove the osimage definition for $imagename"],errorcode=>[1]});
|
||||
} else {
|
||||
$callback->({info=>["osimage definition for $imagename is removed successfully."]});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
Loading…
Reference in New Issue
Block a user