From 469126c759c1e965ce0e29b10143f1bcafb02a30 Mon Sep 17 00:00:00 2001 From: linggao Date: Fri, 4 Apr 2014 06:32:07 -0400 Subject: [PATCH] added verbose output for opsaddimage and opsaddbmnode commands. --- .../lib/perl/xCAT_plugin/openstack.pm | 71 +++++++++++++++++-- .../pods/man1/opsaddbmnode.1.pod | 4 +- .../pods/man1/opsaddimage.1.pod | 4 +- 3 files changed, 72 insertions(+), 7 deletions(-) diff --git a/xCAT-OpenStack-baremetal/lib/perl/xCAT_plugin/openstack.pm b/xCAT-OpenStack-baremetal/lib/perl/xCAT_plugin/openstack.pm index 47086ca75..8a576001b 100644 --- a/xCAT-OpenStack-baremetal/lib/perl/xCAT_plugin/openstack.pm +++ b/xCAT-OpenStack-baremetal/lib/perl/xCAT_plugin/openstack.pm @@ -67,11 +67,13 @@ sub opsaddbmnode { my $help; my $version; + my $verbose; my $host; if(!GetOptions( 'h|help' => \$help, 'v|version' => \$version, + 'V|verbose' => \$verbose, 's=s' => \$host, )) { @@ -243,7 +245,18 @@ sub opsaddbmnode { $disk = 1; } - #print "$bmc, $bmc_user, $bmc_password, $mac, $cpu, $memory, $disk\n"; + if ($verbose) { + my $rsp; + push @{$rsp->{data}}, "Attributes gathered from the xCAT database:"; + push @{$rsp->{data}}, " bmc=$bmc"; + push @{$rsp->{data}}, " bmc_user=$bmc_user"; + push @{$rsp->{data}}, " bmc_password=$bmc_password"; + push @{$rsp->{data}}, " mac=$mac"; + push @{$rsp->{data}}, " cpu=$cpu"; + push @{$rsp->{data}}, " memory=$memory"; + push @{$rsp->{data}}, " disk=$disk"; + xCAT::MsgUtils->message("I", $rsp, $callback); + } #call OpenStack command to add the node into the OpenStack as #a baremetal node. @@ -264,6 +277,13 @@ sub opsaddbmnode { $cmd_tmp .= " $host $cpu $memory $disk $mac"; my $cmd = qq~source \~/openrc;$cmd_tmp~; + if ($verbose) { + my $rsp; + push @{$rsp->{data}}, "The command to run on $host:"; + push @{$rsp->{data}}, " $cmd"; + push @{$rsp->{data}}, " "; + xCAT::MsgUtils->message("I", $rsp, $callback); + } #print "cmd=$cmd\n"; my $output = xCAT::InstUtils->xcmd($callback, $doreq, "xdsh", [$host], $cmd, 0); @@ -271,8 +291,17 @@ sub opsaddbmnode { my $rsp; push @{$rsp->{data}}, "OpenStack creating baremetal node $node:"; push @{$rsp->{data}}, "$output"; + push @{$rsp->{data}}, "The command was: $cmd"; xCAT::MsgUtils->message("E", $rsp, $callback); + } else { + if (($verbose) && ($output)) { + my $rsp; + push @{$rsp->{data}}, "$output"; + push @{$rsp->{data}}, " "; + xCAT::MsgUtils->message("I", $rsp, $callback); + } } + } } @@ -296,6 +325,7 @@ sub opsaddimage { my $help; my $version; + my $verbose; #my $cloud; my $ops_img_names; my $controller; @@ -303,6 +333,7 @@ sub opsaddimage { if(!GetOptions( 'h|help' => \$help, 'v|version' => \$version, + 'V|verbose' => \$verbose, 'c=s' => \$controller, 'n=s' => \$ops_img_names, )) @@ -391,16 +422,46 @@ sub opsaddimage { } my $cmd_tmp = "glance image-create --name $new_name --public --disk-format qcow2 --container-format bare --property xcat_image_name=\'$image\' < /tmp/$image.qcow2"; - my $cmd = qq~touch /tmp/$image.qcow2;source \~/openrc;$cmd_tmp;rm /tmp/$image.qcow2~; - #print "cmd=$cmd\ncontroller=$controller\n"; + my $cmd = qq~touch /tmp/$image.qcow2;source \~/openrc;$cmd_tmp~; + if ($verbose) { + my $rsp; + push @{$rsp->{data}}, "The command to run on $controller:"; + push @{$rsp->{data}}, " $cmd"; + push @{$rsp->{data}}, " "; + xCAT::MsgUtils->message("I", $rsp, $callback); + } my $output = xCAT::InstUtils->xcmd($callback, $doreq, "xdsh", [$controller], $cmd, 0); if ($::RUNCMD_RC != 0) { my $rsp; push @{$rsp->{data}}, "OpenStack creating image $new_name:"; push @{$rsp->{data}}, "$output"; + push @{$rsp->{data}}, "The command was: $cmd"; xCAT::MsgUtils->message("E", $rsp, $callback); + } else { + if (($verbose) && ($output)) { + my $rsp; + push @{$rsp->{data}}, "$output"; + push @{$rsp->{data}}, " "; + xCAT::MsgUtils->message("I", $rsp, $callback); + } } + my $cmd1 = qq~rm /tmp/$image.qcow2~; + if ($verbose) { + my $rsp; + push @{$rsp->{data}}, "The command to run on $controller:"; + push @{$rsp->{data}}, " $cmd1"; + push @{$rsp->{data}}, " "; + xCAT::MsgUtils->message("I", $rsp, $callback); + } + my $output1 = + xCAT::InstUtils->xcmd($callback, $doreq, "xdsh", [$controller], $cmd1, 0); + if (($verbose) && ($output1)) { + my $rsp; + push @{$rsp->{data}}, "$output1"; + push @{$rsp->{data}}, " "; + xCAT::MsgUtils->message("I", $rsp, $callback); + } } } @@ -845,7 +906,7 @@ sub opsaddbmnode_usage { $rsp->{data}->[0]= "Usage: opsaddbmnode -h"; $rsp->{data}->[1]= " opsaddbmnode -v"; - $rsp->{data}->[2]= " opsaddbmnode -s "; + $rsp->{data}->[2]= " opsaddbmnode -s [-V]"; $cb->($rsp); } @@ -863,7 +924,7 @@ sub opsaddimage_usage { $rsp->{data}->[0]= "Usage: opsaddimage -h"; $rsp->{data}->[1]= " opsaddimage -v"; - $rsp->{data}->[2]= " opsaddimage [-n -c "; + $rsp->{data}->[2]= " opsaddimage [-n -c [-V]"; $cb->($rsp); } diff --git a/xCAT-OpenStack-baremetal/pods/man1/opsaddbmnode.1.pod b/xCAT-OpenStack-baremetal/pods/man1/opsaddbmnode.1.pod index 3f9015380..39cf1f424 100644 --- a/xCAT-OpenStack-baremetal/pods/man1/opsaddbmnode.1.pod +++ b/xCAT-OpenStack-baremetal/pods/man1/opsaddbmnode.1.pod @@ -4,7 +4,7 @@ B - It adds xCAT baremetal nodes to an OpenStack cloud. =head1 SYNOPSIS -B I B<-s> I +B I B<-s> I [B<-V>|B<--verbose>] B [B<-h>|B<--help>] @@ -59,6 +59,8 @@ I is a comma separated node or node group names. =item B<-v|--version> The Command Version. +=item B<-V|--verbose> Verbose output. + =back =head1 RETURN VALUE diff --git a/xCAT-OpenStack-baremetal/pods/man1/opsaddimage.1.pod b/xCAT-OpenStack-baremetal/pods/man1/opsaddimage.1.pod index 8d78ec2a7..511d68a0a 100644 --- a/xCAT-OpenStack-baremetal/pods/man1/opsaddimage.1.pod +++ b/xCAT-OpenStack-baremetal/pods/man1/opsaddimage.1.pod @@ -4,7 +4,7 @@ B - It adds or removes nodes for the vlan. =head1 SYNOPSIS -B I B<-n> I [B<-c> I] +B I B<-n> I [B<-c> I] [B<-V>|B<--verbose>] B [B<-h>|B<--help>] @@ -35,6 +35,8 @@ I a comma separated xCAT images names. =item B<-v|--version> The Command Version. +=item B<-V|--verbose> Verbose output. + =back =head1 RETURN VALUE