range lskit to support -K -R -C and theirs xml format

This commit is contained in:
baiyuan 2014-11-03 03:55:24 -05:00
parent 852fc3c164
commit 2ace529fee

View File

@ -2651,12 +2651,10 @@ sub rmkitcomp
# Remove each kitcomponent from osimage.
my @newosikitcomps;
my @myoskitcomps;
foreach my $osikitcomp ( @osikitcomps ) {
my $match = 0;
foreach my $kitcomponent (keys %kitcomps) {
if ( $kitcomponent eq $osikitcomp ) {
push @myoskitcomps, $osikitcomp;
$match = 1;
last;
}
@ -2778,6 +2776,8 @@ sub rmkitcomp
if ( !$match ) {
if ( $debianflag )
{
#Now we do not use moun --bind for kitrepo dir to otherpkgdir
#leave this line is support old way when using mount
system("umount -f $otherpkgdir/$kitcomps{$kitcomponent}{kitreponame} > /dev/null");
}
system("rm -rf $otherpkgdir/$kitcomps{$kitcomponent}{kitreponame}");
@ -3251,7 +3251,6 @@ sub rmkitcomp
# Write osimage table with all the above udpates.
$tabs{osimage}->setAttribs({imagename => $osimage }, \%{$osimagetable} );
#After all the data updated in osimage and linuximage table
#check if these kitcomponents are assigned to other osimage
#if these kitcomponents are not used by other osimage, find their kitrepo and kitrepo directory under otherpkg dir
@ -3302,8 +3301,9 @@ sub rmkitcomp
}
}
}
}
}
return;
}
@ -4256,6 +4256,8 @@ sub lskit {
my $kitrepo_hash = get_kitrepo_hash($::kitnames, $::kitrepoattrs);
my $kitcomp_hash = get_kitcomp_hash($::kitnames, $::kitcompattrs);
# Now display the output
my @kitnames = keys(%$kit_hash);
if (scalar @kitnames == 0) {
@ -4265,15 +4267,204 @@ sub lskit {
return 0;
}
if (defined($::opt_x)) {
create_lskit_xml_response($kit_hash, $kitrepo_hash, $kitcomp_hash);
} else {
create_lskit_stanza_response($kit_hash, $kitrepo_hash, $kitcomp_hash);
#lskit use options
if ( defined($::opt_K) || defined($::opt_R) || defined($::opt_C) ) {
if ( ! defined($::opt_x)) {
if ( defined($::opt_K) ){
lskit_K($kit_hash);
}
# Option -R for kit repo attributes
if ( defined($::opt_R) ) {
my @kitrepos = keys(%$kitrepo_hash);
if (scalar @kitrepos == 0) {
my $rsp = {};
push @{ $rsp->{data} }, "No kit repos were found.";
xCAT::MsgUtils->message("I", $rsp, $::CALLBACK);
return 0;
}
lskit_R($kit_hash,$kitrepo_hash);
}
if ( defined($::opt_C) ) {
my @kitcomplist = keys(%$kitcomp_hash);
if (scalar @kitcomplist == 0) {
my $rsp = {};
push @{ $rsp->{data} }, "No kit components were found.";
xCAT::MsgUtils->message("I", $rsp, $::CALLBACK);
return 0;
}
lskit_C($kit_hash,$kitcomp_hash);
}
}else
{
#To support xml format
if (defined($::opt_K)) {
create_lskit_K_xml_response($kit_hash);
}
if (defined($::opt_R)) {
create_lskit_R_xml_response($kit_hash,$kitrepo_hash);
}
if (defined($::opt_C)) {
create_lskit_C_xml_response($kit_hash,$kitcomp_hash);
}
}
}
else
{
#lskit use no options
if (defined($::opt_x)) {
create_lskit_xml_response($kit_hash, $kitrepo_hash, $kitcomp_hash);
} else {
create_lskit_stanza_response($kit_hash, $kitrepo_hash, $kitcomp_hash);
}
}
return 0;
}
#----------------------------------------------------------------------------
=head3 lskit_R
Support for listing kit repo
Arguments:
Returns:
0 - OK
1 - help
2 - error
=cut
#-----------------------------------------------------------------------------
sub lskit_R {
my $kit_hash = shift;
my $kitrepo_hash = shift;
my $rsp = {};
my $count = 0;
for my $kitname (sort(keys(%$kit_hash))) {
my $output .= "\nkit : $kitname\n----------------------------------------------------\n";
# Kit repository info
if (defined($kitrepo_hash->{$kitname})) {
for my $kitrepo (@{$kitrepo_hash->{$kitname}}) {
$output .= "kitrepo:\n";
for my $kitrepo_attr (sort(keys(%$kitrepo))) {
$output .= sprintf(" %s=%s\n", $kitrepo_attr, $kitrepo->{$kitrepo_attr});
}
$output .= "\n";
}
}
push @{ $rsp->{data} }, $output;
}
xCAT::MsgUtils->message("D", $rsp, $::CALLBACK);
}
#----------------------------------------------------------------------------
=head3 lskit_K
Support for listing kit
Arguments:
Returns:
0 - OK
1 - help
2 - error
=cut
#-----------------------------------------------------------------------------
sub lskit_K {
my $kit_hash = shift;
my $rsp = {};
my $count = 0;
for my $kitname (sort(keys(%$kit_hash))) {
my $output .= "\nkit : $kitname\n----------------------------------------------------\n";
# Kit info
if (defined($kit_hash->{$kitname})) {
my $kit = $kit_hash->{$kitname}->[0];
$output .= "kit:\n";
for my $kit_attr (sort(keys(%$kit))) {
$output .= sprintf(" %s=%s\n", $kit_attr, $kit->{$kit_attr});
}
$output .= "\n";
}
push @{ $rsp->{data} }, $output;
}
xCAT::MsgUtils->message("D", $rsp, $::CALLBACK);
}
#----------------------------------------------------------------------------
=head3 lskit_C
Support for listing kitcomponent
Arguments:
Returns:
0 - OK
1 - help
2 - error
=cut
#-----------------------------------------------------------------------------
sub lskit_C {
my $kit_hash = shift;
my $kitcomp_hash = shift;
my $rsp = {};
my $count = 0;
for my $kitname (sort(keys(%$kit_hash))) {
my $output .= "\nkit : $kitname\n----------------------------------------------------\n";
# Kit component info
if (defined($kitcomp_hash->{$kitname})) {
for my $kitcomp (@{$kitcomp_hash->{$kitname}}) {
$output .= "kitcomponent:\n";
for my $kitcomp_attr (sort(keys(%$kitcomp))) {
$output .= sprintf(" %s=%s\n", $kitcomp_attr, $kitcomp->{$kitcomp_attr});
}
$output .= "\n";
}
}
push @{ $rsp->{data} }, $output;
}
xCAT::MsgUtils->message("D", $rsp, $::CALLBACK);
}
#----------------------------------------------------------------------------
=head3 lskitcomp
@ -4936,6 +5127,122 @@ sub create_lskit_xml_response {
}
#----------------------------------------------------------------------------
=head3 create_lskit_K_xml_response
Prepare a response that returns the kit info in XML format.
Arguments:
kit hash table
Note: Hash tables are created by create_hash_from_table_rows()
=cut
#-----------------------------------------------------------------------------
sub create_lskit_K_xml_response {
my $kit_hash = shift;
my $rsp = {};
for my $kitname (sort(keys(%$kit_hash))) {
my $output_hash = {"kitinfo" => {"kit" => [], "kitrepo" => [], "kitcomponent" => [] } };
# Kit info
if (defined($kit_hash->{$kitname})) {
my $kit = $kit_hash->{$kitname}->[0];
push(@{$output_hash->{kitinfo}->{kit}}, $kit);
}
push @{ $rsp->{data} }, $output_hash;
}
xCAT::MsgUtils->message("D", $rsp, $::CALLBACK);
}
#----------------------------------------------------------------------------
=head3 create_lskit_R_xml_response
Prepare a response that returns the kit repository
info in XML format.
Arguments:
kit repo hash table
Note: Hash tables are created by create_hash_from_table_rows()
=cut
#-----------------------------------------------------------------------------
sub create_lskit_R_xml_response {
my $kit_hash = shift;
my $kitrepo_hash = shift;
my $rsp = {};
for my $kitname (sort(keys(%$kit_hash))) {
my $output_hash = {"kitinfo" => {"kit" => [], "kitrepo" => [], "kitcomponent" => [] } };
# Kit repository info
if (defined($kitrepo_hash->{$kitname})) {
for my $kitrepo (@{$kitrepo_hash->{$kitname}}) {
push(@{$output_hash->{kitinfo}->{kitrepo}}, $kitrepo);
}
}
push @{ $rsp->{data} }, $output_hash;
}
xCAT::MsgUtils->message("D", $rsp, $::CALLBACK);
}
#----------------------------------------------------------------------------
=head3 create_lskit_C_xml_response
Prepare a response that returns the
kit component info in XML format.
Arguments:
kit hash table
kit component hash table
Note: Hash tables are created by create_hash_from_table_rows()
=cut
#-----------------------------------------------------------------------------
sub create_lskit_C_xml_response {
my $kit_hash = shift;
my $kitcomp_hash = shift;
my $rsp = {};
for my $kitname (sort(keys(%$kit_hash))) {
my $output_hash = {"kitinfo" => {"kit" => [], "kitrepo" => [], "kitcomponent" => [] } };
# Kit component info
if (defined($kitcomp_hash->{$kitname})) {
for my $kitcomp (@{$kitcomp_hash->{$kitname}}) {
push(@{$output_hash->{kitinfo}->{kitcomp}}, $kitcomp);
}
}
push @{ $rsp->{data} }, $output_hash;
}
xCAT::MsgUtils->message("D", $rsp, $::CALLBACK);
}
#----------------------------------------------------------------------------
=head3 create_lskit_stanza_response