From 4a7d0e4fdce0f524aa33c79ea44e93415abe2a15 Mon Sep 17 00:00:00 2001 From: phamt Date: Tue, 30 Oct 2012 14:48:40 +0000 Subject: [PATCH] Added inventory support for z/VM hypervisor. Cleaned up code. git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@14163 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- perl-xCAT/xCAT/zvmUtils.pm | 61 +++++++++++++----- xCAT-server/lib/xcat/plugins/zvm.pm | 99 +++++++++++++++++++++++------ 2 files changed, 125 insertions(+), 35 deletions(-) diff --git a/perl-xCAT/xCAT/zvmUtils.pm b/perl-xCAT/xCAT/zvmUtils.pm index 5ba02ce3a..eb7270e17 100644 --- a/perl-xCAT/xCAT/zvmUtils.pm +++ b/perl-xCAT/xCAT/zvmUtils.pm @@ -310,25 +310,19 @@ sub isZvmNode { # Get inputs my ( $class, $node ) = @_; - # zVM guest ID - my $id; - # Look in 'zvm' table my $tab = xCAT::Table->new( 'zvm', -create => 1, -autocommit => 0 ); my @results = $tab->getAllAttribsWhere( "node like '%" . $node . "%'", 'userid' ); foreach (@results) { - # Get userID - $id = $_->{'userid'}; - # Return 'TRUE' if given node is in the table - if ($id) { - return ('TRUE'); + if ($_->{'userid'}) { + return 1; } } - return ('FALSE'); + return 0; } #------------------------------------------------------- @@ -1203,14 +1197,14 @@ sub getOsVersion { #------------------------------------------------------- sub getZfcpInfo { - # Get inputs + # Get inputs my ( $class, $node ) = @_; # Get zFCP device info my $info = `ssh -o ConnectTimeout=2 $node "lszfcp -D"`; my @zfcp = split("\n", $info); if (!$info || $info =~ m/No zfcp support/i) { - return; + return; } # Get SCSI device and their attributes @@ -1226,12 +1220,12 @@ sub getZfcpInfo { my $size; foreach (@zfcp) { - @args = split(" ", $_); - $id = $args[1]; - @args = split("/", $args[0]); - - $device = $args[0]; - $wwpn = $args[1]; + @args = split(" ", $_); + $id = $args[1]; + @args = split("/", $args[0]); + + $device = $args[0]; + $wwpn = $args[1]; $lun = $args[2]; # Make sure WWPN and LUN do not have 0x prefix @@ -1254,4 +1248,37 @@ sub getZfcpInfo { $info = xCAT::zvmUtils->tabStr($info); return ($info); +} + +#------------------------------------------------------- + +=head3 isHypervisor + + Description : Determines if a given node is in the 'hypervisor' table + Arguments : Node + Returns : 1 Node exists + 0 Node does not exists + Example : my $out = xCAT::zvmUtils->isHypervisor($node); + +=cut + +#------------------------------------------------------- +sub isHypervisor { + + # Get inputs + my ( $class, $node ) = @_; + + # Look in 'zvm' table + my $tab = xCAT::Table->new( "hypervisor", -create => 1, -autocommit => 0 ); + + my @results = $tab->getAllAttribsWhere( "node like '%" . $node . "%'", 'type' ); + foreach (@results) { + + # Return 'TRUE' if given node is in the table + if ($_->{"type"} eq "zvm") { + return 1; + } + } + + return 0; } \ No newline at end of file diff --git a/xCAT-server/lib/xcat/plugins/zvm.pm b/xCAT-server/lib/xcat/plugins/zvm.pm index 5917dc95f..9034e809c 100644 --- a/xCAT-server/lib/xcat/plugins/zvm.pm +++ b/xCAT-server/lib/xcat/plugins/zvm.pm @@ -191,8 +191,12 @@ sub process_request { # Child process elsif ( $pid == 0 ) { - inventoryVM( $callback, $_, $args ); - + if (xCAT::zvmUtils->isHypervisor($_)) { + inventoryHypervisor( $callback, $_, $args ); + } else { + inventoryVM( $callback, $_, $args ); + } + # Exit process exit(0); } @@ -209,13 +213,13 @@ sub process_request { elsif ( $command eq "mkvm" ) { # Determine if the argument is a node - my $clone = 'FALSE'; + my $clone = 0; if ( $args->[0] ) { $clone = xCAT::zvmUtils->isZvmNode( $args->[0] ); } #*** Clone virtual server *** - if ( $clone eq 'TRUE' ) { + if ( $clone ) { cloneVM( $callback, \@nodes, $args ); } @@ -581,8 +585,8 @@ sub removeVM { my $update; my $expression; foreach (@pools) { - $pool = xCAT::zvmUtils->replaceStr( $_, ".conf", "" ); - + $pool = xCAT::zvmUtils->replaceStr( $_, ".conf", "" ); + @luns = split("\n", `ssh $hcp "cat $::ZFCPPOOL/$_" | egrep -i $node`); foreach (@luns) { # Update entry: status,wwpn,lun,size,owner,channel,tag @@ -759,7 +763,7 @@ sub changeVM { # Translate QDIO or Hipersocket into correct type if ($type =~m/QDIO/i) { - $type = 2; + $type = 2; } elsif ($type =~m/HIPER/i) { $type = 1; } @@ -811,7 +815,7 @@ sub changeVM { my $loaddev = int($args->[3]); if ($loaddev != 0 && $loaddev != 1) { - xCAT::zvmUtils->printLn( $callback, "$node: (Error) The loaddev can be 0 or 1" ); + xCAT::zvmUtils->printLn( $callback, "$node: (Error) The loaddev can be 0 or 1" ); return; } @@ -998,8 +1002,8 @@ sub changeVM { # Set loaddev statement in directory entry if ($loaddev) { - $out = `chvm $node --setloaddev $wwpn $lun`; - xCAT::zvmUtils->printLn($callback, "$out"); + $out = `chvm $node --setloaddev $wwpn $lun`; + xCAT::zvmUtils->printLn($callback, "$out"); } $out = ""; @@ -1413,7 +1417,7 @@ sub changeVM { # removezfcpfrompool [pool] [lun] elsif ( $args->[0] eq "--removezfcpfrompool" ) { - # This is no longer supported in chvm. Using chhypervisor instead. + # This is no longer supported in chvm. Using chhypervisor instead. changeHypervisor( $callback, $node, $args ); } @@ -1616,7 +1620,7 @@ sub changeVM { # resetsmapi elsif ( $args->[0] eq "--resetsmapi" ) { - # This is no longer supported in chvm. Using chhypervisor instead. + # This is no longer supported in chvm. Using chhypervisor instead. changeHypervisor( $callback, $node, $args ); } @@ -1631,7 +1635,7 @@ sub changeVM { my $parms = "''"; if ($args->[3]) { - $parms = $args->[3]; + $parms = $args->[3]; } $out = `ssh $hcp "$::DIR/smcli Image_IPL_Set_DM -T $userId -s $trgt -l $loadparms -p $parms"`; @@ -2059,7 +2063,7 @@ sub inventoryVM { my $str = ""; # Check if node is pingable - if (`nodestat $node | egrep -i "noping"`) { + if (`pping $node | egrep -i "noping"`) { $str = "$node: (Error) Host is unreachable"; xCAT::zvmUtils->printLn( $callback, "$str" ); return; @@ -3003,7 +3007,7 @@ sub clone { # It is Ok not have a password my $tgtPw = "''"; if ($inputs{"pw"}) { - $tgtPw = $inputs{"pw"}; + $tgtPw = $inputs{"pw"}; } # Set IP address @@ -5478,7 +5482,7 @@ sub changeHypervisor { $out .= "$_\n"; } } else { - xCAT::zvmUtils->printLn( $callback, "$node: (Error) Query supported on active, free, offline, or agent devices" ); + xCAT::zvmUtils->printLn( $callback, "$node: (Error) Query supported on active, free, offline, or agent devices" ); } } @@ -5501,10 +5505,69 @@ sub changeHypervisor { # Only print if there is content if ($out) { - $out = xCAT::zvmUtils->appendHostname( $node, $out ); - chomp($out); + $out = xCAT::zvmUtils->appendHostname( $node, $out ); + chomp($out); xCAT::zvmUtils->printLn( $callback, "$out" ); } return; } + +#------------------------------------------------------- + +=head3 inventoryHypervisor + + Description : Get hardware and software inventory of a given hypervisor + Arguments : Node + Type of inventory (config|all) + Returns : Nothing + Example : inventoryHypervisor($callback, $node, $args); + +=cut + +#------------------------------------------------------- +sub inventoryHypervisor { + + # Get inputs + my ( $callback, $node, $args ) = @_; + + # Output string + my $str = ""; + + # Get node properties from 'zvm' table + my @propNames = ( 'hcp' ); + my $propVals = xCAT::zvmUtils->getNodeProps( 'zvm', $node, @propNames ); + + # Get zHCP + my $hcp = $propVals->{'hcp'}; + if ( !$hcp ) { + xCAT::zvmUtils->printLn( $callback, "$node: (Error) Missing node zHCP" ); + return; + } + + # Load VMCP module + xCAT::zvmCPUtils->loadVmcp($hcp); + + # Get configuration + if ( $args->[0] eq 'config' ) { + + # Create output string + $str .= "z/VM Host: " . uc($node) . "\n"; + $str .= "zHCP: $hcp\n"; + } elsif ( $args->[0] eq 'all' ) { + + # Create output string + $str .= "z/VM Host: " . uc($node) . "\n"; + $str .= "zHCP: $hcp\n"; + } else { + $str = "$node: (Error) Option not supported"; + xCAT::zvmUtils->printLn( $callback, "$str" ); + return; + } + + # Append hostname (e.g. pokdev61) in front + $str = xCAT::zvmUtils->appendHostname( $node, $str ); + + xCAT::zvmUtils->printLn( $callback, "$str" ); + return; +}