diff --git a/perl-xCAT/xCAT/zvmCPUtils.pm b/perl-xCAT/xCAT/zvmCPUtils.pm index c47f14437..f68d28e67 100644 --- a/perl-xCAT/xCAT/zvmCPUtils.pm +++ b/perl-xCAT/xCAT/zvmCPUtils.pm @@ -19,588 +19,588 @@ use warnings; #------------------------------------------------------- -=head3 getUserId - - Description : Get the userID of a given node - Arguments : Node - Returns : UserID - Example : my $userID = xCAT::zvmCPUtils->getUserId($node); - -=cut - -#------------------------------------------------------- -sub getUserId { - - # Get inputs - my ( $class, $node ) = @_; - - # Get userId using VMCP - my $out = `ssh -o ConnectTimeout=5 $node "vmcp q userid"`; - my @results = split( ' ', $out ); - - return ( $results[0] ); -} - -#------------------------------------------------------- - -=head3 getHost - - Description : Get the z/VM host for a given node - Arguments : Node - Returns : z/VM host - Example : my $host = xCAT::zvmCPUtils->getHost($node); - -=cut - -#------------------------------------------------------- -sub getHost { - - # Get inputs - my ( $class, $node ) = @_; - - # Get host using VMCP - my $out = `ssh -o ConnectTimeout=5 $node "vmcp q userid"`; - my @results = split( ' ', $out ); - my $host = $results[2]; - - return ($host); -} - -#------------------------------------------------------- - -=head3 getPrivileges - - Description : Get the privilege class of a given node - Arguments : Node - Returns : Privilege class - Example : my $memory = xCAT::zvmCPUtils->getPrivileges($node); - -=cut - -#------------------------------------------------------- -sub getPrivileges { - - # Get inputs - my ( $class, $node ) = @_; - - # Get privilege class - my $out = `ssh -o ConnectTimeout=5 $node "vmcp q priv"`; - my @out = split( '\n', $out ); - $out[1] = xCAT::zvmUtils->trimStr( $out[1] ); - $out[2] = xCAT::zvmUtils->trimStr( $out[2] ); - my $str = " $out[1]\n $out[2]\n"; - - return ($str); -} - -#------------------------------------------------------- - -=head3 getMemory - - Description : Get the memory of a given node - Arguments : Node - Returns : Memory - Example : my $memory = xCAT::zvmCPUtils->getMemory($node); - -=cut - -#------------------------------------------------------- -sub getMemory { - - # Get inputs - my ( $class, $node ) = @_; - - # Get memory - my $out = `ssh -o ConnectTimeout=5 $node "vmcp q virtual storage"`; - my @out = split( '=', $out ); - - return ( xCAT::zvmUtils->trimStr( $out[1] ) ); -} - -#------------------------------------------------------- - -=head3 getCpu - - Description : Get the processor(s) of a given node - Arguments : Node - Returns : Processor(s) - Example : my $proc = xCAT::zvmCPUtils->getCpu($node); - -=cut - -#------------------------------------------------------- -sub getCpu { - - # Get inputs - my ( $class, $node ) = @_; - - # Get processors - my $out = `ssh -o ConnectTimeout=5 $node "vmcp q virtual cpus"`; - my $str = xCAT::zvmUtils->tabStr($out); - - return ($str); -} - -#------------------------------------------------------- - -=head3 getNic - - Description : Get the network interface card (NIC) of a given node - Arguments : Node - Returns : NIC(s) - Example : my $nic = xCAT::zvmCPUtils->getNic($node); - -=cut - -#------------------------------------------------------- -sub getNic { - - # Get inputs - my ( $class, $node ) = @_; - - # Get NIC - my $out = `ssh -o ConnectTimeout=5 $node "vmcp q virtual nic"`; - my $str = xCAT::zvmUtils->tabStr($out); - - return ($str); -} - -#------------------------------------------------------- - -=head3 getNetworkNames - - Description : Get a list of network names - Arguments : Node - Returns : Network names - Example : my $lans = xCAT::zvmCPUtils->getNetworkNames($node); - -=cut - -#------------------------------------------------------- -sub getNetworkNames { - - # Get inputs - my ( $class, $node ) = @_; - - # Get network names - my $out = `ssh -o ConnectTimeout=5 $node "vmcp q lan | egrep 'LAN|VSWITCH'"`; - my @lines = split( '\n', $out ); - my @parms; - my $names; - foreach (@lines) { - - # Trim output - $_ = xCAT::zvmUtils->trimStr($_); - @parms = split( ' ', $_ ); - - # Get the network name - if ( $parms[0] eq "LAN" || $parms[0] eq "VSWITCH" ) { - $names .= $parms[0] . " " . $parms[2] . "\n"; - } - } - - return ($names); -} - -#------------------------------------------------------- - -=head3 getNetwork - - Description : Get the network configuration - Arguments : Node - Network name - Returns : Network configuration - Example : my $config = xCAT::zvmCPUtils->getNetwork($node, $netName); - -=cut - -#------------------------------------------------------- -sub getNetwork { - - # Get inputs - my ( $class, $node, $netName ) = @_; - - # Get network configuration - my $out; - if ( $netName eq "all" ) { - $out = `ssh -o ConnectTimeout=5 $node "vmcp q lan"`; - } - else { - $out = `ssh -o ConnectTimeout=5 $node "vmcp q lan $netName"`; - } - - return ($out); -} - -#------------------------------------------------------- - -=head3 getDisks - - Description : Get the disk(s) of given node - Arguments : Node - Returns : Disk(s) - Example : my $storage = xCAT::zvmCPUtils->getDisks($node); - -=cut - -#------------------------------------------------------- -sub getDisks { - - # Get inputs - my ( $class, $node ) = @_; - - # Get disks - my $out = `ssh -o ConnectTimeout=5 $node "vmcp q virtual dasd"`; - my $str = xCAT::zvmUtils->tabStr($out); - - return ($str); -} - -#------------------------------------------------------- - -=head3 loadVmcp - - Description : Load Linux VMCP module on a given node - Arguments : Node - Returns : Nothing - Example : xCAT::zvmCPUtils->loadVmcp($node); - -=cut - -#------------------------------------------------------- -sub loadVmcp { - - # Get inputs - my ( $class, $node ) = @_; - - # Load Linux VMCP module - my $out = `ssh -o ConnectTimeout=5 $node "modprobe vmcp"`; - return; -} - -#------------------------------------------------------- - -=head3 getVswitchId - - Description : Get the VSWITCH ID(s) of given node - Arguments : Node - Returns : VSwitch IDs - Example : my @vswitch = xCAT::zvmCPUtils->getVswitchId($node); - -=cut - -#------------------------------------------------------- -sub getVswitchId { - - # Get inputs - my ( $class, $node ) = @_; - - # Get VSwitch - my $out = `ssh -o ConnectTimeout=5 $node "vmcp q nic" | grep "VSWITCH"`; - my @lines = split( '\n', $out ); - my @parms; - my @vswitch; - foreach (@lines) { - @parms = split( ' ', $_ ); - push( @vswitch, $parms[4] ); - } - - return @vswitch; -} - -#------------------------------------------------------- - -=head3 grantVSwitch - - Description : Grant access to a virtual switch (VSWITCH) for given userID - Arguments : HCP node - User ID - VSWITCH ID - Returns : Operation results (Done/Failed) - Example : my $out = xCAT::zvmCPUtils->grantVswitch($callback, $hcp, $userId, $vswitchId); - -=cut - -#------------------------------------------------------- -sub grantVSwitch { - - # Get inputs - my ( $class, $callback, $hcp, $userId, $vswitchId ) = @_; - - # Grant VSwitch for specified userID - my $out = `ssh $hcp "vmcp set vswitch $vswitchId grant $userId"`; - $out = xCAT::zvmUtils->trimStr($out); - - # If return string contains 'Command complete' -- Operation was successful - my $retStr; - if ( $out =~ m/Command complete/i ) { - $retStr = "Done\n"; - } - else { - $retStr = "Failed\n"; - return $retStr; - } - - return $retStr; -} - -#------------------------------------------------------- - -=head3 flashCopy - - Description : Flash copy (Class B users only) - Arguments : Node - Source address - Target address - Returns : Operation results (Done/Failed) - Example : my $results = xCAT::zvmCPUtils->flashCopy($node, $srcAddr, $targetAddr); - -=cut - -#------------------------------------------------------- -sub flashCopy { - - # Get inputs - my ( $class, $node, $srcAddr, $targetAddr ) = @_; - - # Flash copy - my $out = `ssh $node "vmcp flashcopy $srcAddr 0 end to $targetAddr 0 end"`; - $out = xCAT::zvmUtils->trimStr($out); - - # If return string contains 'Command complete' -- Operation was successful - my $retStr = ""; - if ( $out =~ m/Command complete/i ) { - $retStr = "Done\n"; - } - else { - $retStr = "Failed\n"; - } - - return $retStr; -} - -#------------------------------------------------------- - -=head3 punch2Reader - - Description : Write file to z/VM punch and transfer it to reader - Arguments : HCP node - UserID to receive file - Source file - Target file name and type to be created by punch (e.g. sles.parm) - Options (e.g. -t -- Convert EBCDIC to ASCII) - Returns : Operation results (Done/Failed) - Example : my $rc = xCAT::zvmCPUtils->punch2Reader($hcp, $userId, $srcFile, $trgtFile, $options); - -=cut - -#------------------------------------------------------- -sub punch2Reader { - my ( $class, $hcp, $userId, $srcFile, $trgtFile, $options ) = @_; - - # Punch to reader - my $out = `ssh -o ConnectTimeout=5 $hcp "vmur punch $options -u $userId -r $srcFile -N $trgtFile"`; - - # If punch is successful -- Look for this string - my $searchStr = "created and transferred"; - if ( !( $out =~ m/$searchStr/i ) ) { - $out = "Failed\n"; - } - else { - $out = "Done\n"; - } - - return $out; -} - -#------------------------------------------------------- - -=head3 purgeReader - - Description : Purge reader (Class D users only) - Arguments : HCP node - UserID to purge reader for - Returns : Nothing - Example : my $rc = xCAT::zvmCPUtils->purgeReader($hcp, $userId); - -=cut - -#------------------------------------------------------- -sub purgeReader { - my ( $class, $hcp, $userId ) = @_; - - # Purge reader - my $out = `ssh -o ConnectTimeout=5 $hcp "vmcp purge $userId rdr all"`; - - return; -} - -#------------------------------------------------------- - -=head3 sendCPCmd - - Description : Send CP command to a given userID (Class C users only) - Arguments : HCP node - UserID to send CP command - Returns : Nothing - Example : xCAT::zvmCPUtils->sendCPCmd($hcp, $userId, $cmd); - -=cut - -#------------------------------------------------------- -sub sendCPCmd { - my ( $class, $hcp, $userId, $cmd ) = @_; - - # Send CP command to given userID - my $out = `ssh $hcp "vmcp send cp $userId $cmd"`; - - return; -} - -#------------------------------------------------------- - -=head3 getNetworkLayer - - Description : Get the network layer for a given node - Arguments : Node - Network name (Optional) - Returns : 2 -- Layer 2 - 3 -- Layer 3 - -1 -- Failed to get network layer - Example : my $layer = xCAT::zvmCPUtils->getNetworkLayer($node); - -=cut - -#------------------------------------------------------- -sub getNetworkLayer { - my ( $class, $node, $netName ) = @_; - - # Get node properties from 'zvm' table - my @propNames = ('hcp'); - my $propVals = xCAT::zvmUtils->getNodeProps( 'zvm', $node, @propNames ); - - # Get HCP - my $hcp = $propVals->{'hcp'}; - if ( !$hcp ) { - return -1; - } - - # Get network name - my $out = `ssh -o ConnectTimeout=5 $node "vmcp q v nic" | egrep -i "VSWITCH|LAN"`; - my @lines = split( '\n', $out ); - - # Go through each line and extract VSwitch and Lan names - # Get the first network name found - if ( !$netName ) { - my $i; - my @vars; - for ( $i = 0 ; $i < @lines ; $i++ ) { - - # Extract VSwitch name - if ( $lines[$i] =~ m/VSWITCH/i ) { - @vars = split( ' ', $lines[$i] ); - $netName = $vars[4]; - last; - } - - # Extract Lan name - elsif ( $lines[$i] =~ m/LAN/i ) { - @vars = split( ' ', $lines[$i] ); - $netName = $vars[4]; - last; - } - } # End of for - } # End of if ( !$netName ) - - # If the network name could not be found - if ( !$netName ) { - return -1; - } - - # Get network type (Layer 2 or 3) - $out = `ssh -o ConnectTimeout=5 $hcp "vmcp q lan $netName"`; - if ( !$out ) { - return -1; - } - - # Go through each line - my $layer = 3; # Default to layer 3 - @lines = split( '\n', $out ); - foreach (@lines) { - - # If the line contains ETHERNET, then it is a layer 2 network - if ( $_ =~ m/ETHERNET/i ) { - $layer = 2; - } - } - - return $layer; -} - -#------------------------------------------------------- - -=head3 getNetworkType - - Description : Get the network type for a given network name - Arguments : HCP node - Name of network - Returns : Network type (VSWITCH/HIPERS/QDIO) - Example : my $netType = xCAT::zvmCPUtils->getNetworkType($hcp, $netName); - -=cut - -#------------------------------------------------------- -sub getNetworkType { - my ( $class, $hcp, $netName ) = @_; - - # Get network details - my $out = - `ssh -o ConnectTimeout=5 $hcp "vmcp q lan $netName" | grep "Type"`; - - # Go through each line and determine network type - my @lines = split( '\n', $out ); - my $netType = ""; - foreach (@lines) { - - # Virtual switch - if ( $_ =~ m/VSWITCH/i ) { - $netType = "VSWITCH"; - } - - # HiperSocket guest LAN - elsif ( $_ =~ m/HIPERS/i ) { - $netType = "HIPERS"; - } - - # QDIO guest LAN - elsif ( $_ =~ m/QDIO/i ) { - $netType = "QDIO"; - } - } - - return $netType; -} - -#------------------------------------------------------- - -=head3 defineCpu - - Description : Add processor(s) to given node - Arguments : Node - Returns : Nothing - Example : my $out = xCAT::zvmCPUtils->defineCpu($node, $addr, $type); - -=cut - -#------------------------------------------------------- -sub defineCpu { - - # Get inputs - my ( $class, $node, $addr, $type ) = @_; - - # Define processor(s) - my $out = - `ssh -o ConnectTimeout=5 $node "vmcp define cpu $addr type $type"`; - - return ($out); -} +=head3 getUserId + + Description : Get the userID of a given node + Arguments : Node + Returns : UserID + Example : my $userID = xCAT::zvmCPUtils->getUserId($node); + +=cut + +#------------------------------------------------------- +sub getUserId { + + # Get inputs + my ( $class, $node ) = @_; + + # Get userId using VMCP + my $out = `ssh -o ConnectTimeout=5 $node "vmcp q userid"`; + my @results = split( ' ', $out ); + + return ( $results[0] ); +} + +#------------------------------------------------------- + +=head3 getHost + + Description : Get the z/VM host for a given node + Arguments : Node + Returns : z/VM host + Example : my $host = xCAT::zvmCPUtils->getHost($node); + +=cut + +#------------------------------------------------------- +sub getHost { + + # Get inputs + my ( $class, $node ) = @_; + + # Get host using VMCP + my $out = `ssh -o ConnectTimeout=5 $node "vmcp q userid"`; + my @results = split( ' ', $out ); + my $host = $results[2]; + + return ($host); +} + +#------------------------------------------------------- + +=head3 getPrivileges + + Description : Get the privilege class of a given node + Arguments : Node + Returns : Privilege class + Example : my $memory = xCAT::zvmCPUtils->getPrivileges($node); + +=cut + +#------------------------------------------------------- +sub getPrivileges { + + # Get inputs + my ( $class, $node ) = @_; + + # Get privilege class + my $out = `ssh -o ConnectTimeout=5 $node "vmcp q priv"`; + my @out = split( '\n', $out ); + $out[1] = xCAT::zvmUtils->trimStr( $out[1] ); + $out[2] = xCAT::zvmUtils->trimStr( $out[2] ); + my $str = " $out[1]\n $out[2]\n"; + + return ($str); +} + +#------------------------------------------------------- + +=head3 getMemory + + Description : Get the memory of a given node + Arguments : Node + Returns : Memory + Example : my $memory = xCAT::zvmCPUtils->getMemory($node); + +=cut + +#------------------------------------------------------- +sub getMemory { + + # Get inputs + my ( $class, $node ) = @_; + + # Get memory + my $out = `ssh -o ConnectTimeout=5 $node "vmcp q virtual storage"`; + my @out = split( '=', $out ); + + return ( xCAT::zvmUtils->trimStr( $out[1] ) ); +} + +#------------------------------------------------------- + +=head3 getCpu + + Description : Get the processor(s) of a given node + Arguments : Node + Returns : Processor(s) + Example : my $proc = xCAT::zvmCPUtils->getCpu($node); + +=cut + +#------------------------------------------------------- +sub getCpu { + + # Get inputs + my ( $class, $node ) = @_; + + # Get processors + my $out = `ssh -o ConnectTimeout=5 $node "vmcp q virtual cpus"`; + my $str = xCAT::zvmUtils->tabStr($out); + + return ($str); +} + +#------------------------------------------------------- + +=head3 getNic + + Description : Get the network interface card (NIC) of a given node + Arguments : Node + Returns : NIC(s) + Example : my $nic = xCAT::zvmCPUtils->getNic($node); + +=cut + +#------------------------------------------------------- +sub getNic { + + # Get inputs + my ( $class, $node ) = @_; + + # Get NIC + my $out = `ssh -o ConnectTimeout=5 $node "vmcp q virtual nic"`; + my $str = xCAT::zvmUtils->tabStr($out); + + return ($str); +} + +#------------------------------------------------------- + +=head3 getNetworkNames + + Description : Get a list of network names + Arguments : Node + Returns : Network names + Example : my $lans = xCAT::zvmCPUtils->getNetworkNames($node); + +=cut + +#------------------------------------------------------- +sub getNetworkNames { + + # Get inputs + my ( $class, $node ) = @_; + + # Get network names + my $out = `ssh -o ConnectTimeout=5 $node "vmcp q lan | egrep 'LAN|VSWITCH'"`; + my @lines = split( '\n', $out ); + my @parms; + my $names; + foreach (@lines) { + + # Trim output + $_ = xCAT::zvmUtils->trimStr($_); + @parms = split( ' ', $_ ); + + # Get the network name + if ( $parms[0] eq "LAN" || $parms[0] eq "VSWITCH" ) { + $names .= $parms[0] . " " . $parms[2] . "\n"; + } + } + + return ($names); +} + +#------------------------------------------------------- + +=head3 getNetwork + + Description : Get the network configuration + Arguments : Node + Network name + Returns : Network configuration + Example : my $config = xCAT::zvmCPUtils->getNetwork($node, $netName); + +=cut + +#------------------------------------------------------- +sub getNetwork { + + # Get inputs + my ( $class, $node, $netName ) = @_; + + # Get network configuration + my $out; + if ( $netName eq "all" ) { + $out = `ssh -o ConnectTimeout=5 $node "vmcp q lan"`; + } + else { + $out = `ssh -o ConnectTimeout=5 $node "vmcp q lan $netName"`; + } + + return ($out); +} + +#------------------------------------------------------- + +=head3 getDisks + + Description : Get the disk(s) of given node + Arguments : Node + Returns : Disk(s) + Example : my $storage = xCAT::zvmCPUtils->getDisks($node); + +=cut + +#------------------------------------------------------- +sub getDisks { + + # Get inputs + my ( $class, $node ) = @_; + + # Get disks + my $out = `ssh -o ConnectTimeout=5 $node "vmcp q virtual dasd"`; + my $str = xCAT::zvmUtils->tabStr($out); + + return ($str); +} + +#------------------------------------------------------- + +=head3 loadVmcp + + Description : Load Linux VMCP module on a given node + Arguments : Node + Returns : Nothing + Example : xCAT::zvmCPUtils->loadVmcp($node); + +=cut + +#------------------------------------------------------- +sub loadVmcp { + + # Get inputs + my ( $class, $node ) = @_; + + # Load Linux VMCP module + my $out = `ssh -o ConnectTimeout=5 $node "modprobe vmcp"`; + return; +} + +#------------------------------------------------------- + +=head3 getVswitchId + + Description : Get the VSWITCH ID(s) of given node + Arguments : Node + Returns : VSwitch IDs + Example : my @vswitch = xCAT::zvmCPUtils->getVswitchId($node); + +=cut + +#------------------------------------------------------- +sub getVswitchId { + + # Get inputs + my ( $class, $node ) = @_; + + # Get VSwitch + my $out = `ssh -o ConnectTimeout=5 $node "vmcp q nic" | grep "VSWITCH"`; + my @lines = split( '\n', $out ); + my @parms; + my @vswitch; + foreach (@lines) { + @parms = split( ' ', $_ ); + push( @vswitch, $parms[4] ); + } + + return @vswitch; +} + +#------------------------------------------------------- + +=head3 grantVSwitch + + Description : Grant access to a virtual switch (VSWITCH) for given userID + Arguments : HCP node + User ID + VSWITCH ID + Returns : Operation results (Done/Failed) + Example : my $out = xCAT::zvmCPUtils->grantVswitch($callback, $hcp, $userId, $vswitchId); + +=cut + +#------------------------------------------------------- +sub grantVSwitch { + + # Get inputs + my ( $class, $callback, $hcp, $userId, $vswitchId ) = @_; + + # Grant VSwitch for specified userID + my $out = `ssh $hcp "vmcp set vswitch $vswitchId grant $userId"`; + $out = xCAT::zvmUtils->trimStr($out); + + # If return string contains 'Command complete' -- Operation was successful + my $retStr; + if ( $out =~ m/Command complete/i ) { + $retStr = "Done\n"; + } + else { + $retStr = "Failed\n"; + return $retStr; + } + + return $retStr; +} + +#------------------------------------------------------- + +=head3 flashCopy + + Description : Flash copy (Class B users only) + Arguments : Node + Source address + Target address + Returns : Operation results (Done/Failed) + Example : my $results = xCAT::zvmCPUtils->flashCopy($node, $srcAddr, $targetAddr); + +=cut + +#------------------------------------------------------- +sub flashCopy { + + # Get inputs + my ( $class, $node, $srcAddr, $targetAddr ) = @_; + + # Flash copy + my $out = `ssh $node "vmcp flashcopy $srcAddr 0 end to $targetAddr 0 end"`; + $out = xCAT::zvmUtils->trimStr($out); + + # If return string contains 'Command complete' -- Operation was successful + my $retStr = ""; + if ( $out =~ m/Command complete/i ) { + $retStr = "Done\n"; + } + else { + $retStr = "Failed\n"; + } + + return $retStr; +} + +#------------------------------------------------------- + +=head3 punch2Reader + + Description : Write file to z/VM punch and transfer it to reader + Arguments : HCP node + UserID to receive file + Source file + Target file name and type to be created by punch (e.g. sles.parm) + Options (e.g. -t -- Convert EBCDIC to ASCII) + Returns : Operation results (Done/Failed) + Example : my $rc = xCAT::zvmCPUtils->punch2Reader($hcp, $userId, $srcFile, $trgtFile, $options); + +=cut + +#------------------------------------------------------- +sub punch2Reader { + my ( $class, $hcp, $userId, $srcFile, $trgtFile, $options ) = @_; + + # Punch to reader + my $out = `ssh -o ConnectTimeout=5 $hcp "vmur punch $options -u $userId -r $srcFile -N $trgtFile"`; + + # If punch is successful -- Look for this string + my $searchStr = "created and transferred"; + if ( !( $out =~ m/$searchStr/i ) ) { + $out = "Failed\n"; + } + else { + $out = "Done\n"; + } + + return $out; +} + +#------------------------------------------------------- + +=head3 purgeReader + + Description : Purge reader (Class D users only) + Arguments : HCP node + UserID to purge reader for + Returns : Nothing + Example : my $rc = xCAT::zvmCPUtils->purgeReader($hcp, $userId); + +=cut + +#------------------------------------------------------- +sub purgeReader { + my ( $class, $hcp, $userId ) = @_; + + # Purge reader + my $out = `ssh -o ConnectTimeout=5 $hcp "vmcp purge $userId rdr all"`; + + return; +} + +#------------------------------------------------------- + +=head3 sendCPCmd + + Description : Send CP command to a given userID (Class C users only) + Arguments : HCP node + UserID to send CP command + Returns : Nothing + Example : xCAT::zvmCPUtils->sendCPCmd($hcp, $userId, $cmd); + +=cut + +#------------------------------------------------------- +sub sendCPCmd { + my ( $class, $hcp, $userId, $cmd ) = @_; + + # Send CP command to given userID + my $out = `ssh $hcp "vmcp send cp $userId $cmd"`; + + return; +} + +#------------------------------------------------------- + +=head3 getNetworkLayer + + Description : Get the network layer for a given node + Arguments : Node + Network name (Optional) + Returns : 2 -- Layer 2 + 3 -- Layer 3 + -1 -- Failed to get network layer + Example : my $layer = xCAT::zvmCPUtils->getNetworkLayer($node); + +=cut + +#------------------------------------------------------- +sub getNetworkLayer { + my ( $class, $node, $netName ) = @_; + + # Get node properties from 'zvm' table + my @propNames = ('hcp'); + my $propVals = xCAT::zvmUtils->getNodeProps( 'zvm', $node, @propNames ); + + # Get HCP + my $hcp = $propVals->{'hcp'}; + if ( !$hcp ) { + return -1; + } + + # Get network name + my $out = `ssh -o ConnectTimeout=5 $node "vmcp q v nic" | egrep -i "VSWITCH|LAN"`; + my @lines = split( '\n', $out ); + + # Go through each line and extract VSwitch and Lan names + # Get the first network name found + if ( !$netName ) { + my $i; + my @vars; + for ( $i = 0 ; $i < @lines ; $i++ ) { + + # Extract VSwitch name + if ( $lines[$i] =~ m/VSWITCH/i ) { + @vars = split( ' ', $lines[$i] ); + $netName = $vars[4]; + last; + } + + # Extract Lan name + elsif ( $lines[$i] =~ m/LAN/i ) { + @vars = split( ' ', $lines[$i] ); + $netName = $vars[4]; + last; + } + } # End of for + } # End of if ( !$netName ) + + # If the network name could not be found + if ( !$netName ) { + return -1; + } + + # Get network type (Layer 2 or 3) + $out = `ssh -o ConnectTimeout=5 $hcp "vmcp q lan $netName"`; + if ( !$out ) { + return -1; + } + + # Go through each line + my $layer = 3; # Default to layer 3 + @lines = split( '\n', $out ); + foreach (@lines) { + + # If the line contains ETHERNET, then it is a layer 2 network + if ( $_ =~ m/ETHERNET/i ) { + $layer = 2; + } + } + + return $layer; +} + +#------------------------------------------------------- + +=head3 getNetworkType + + Description : Get the network type for a given network name + Arguments : HCP node + Name of network + Returns : Network type (VSWITCH/HIPERS/QDIO) + Example : my $netType = xCAT::zvmCPUtils->getNetworkType($hcp, $netName); + +=cut + +#------------------------------------------------------- +sub getNetworkType { + my ( $class, $hcp, $netName ) = @_; + + # Get network details + my $out = + `ssh -o ConnectTimeout=5 $hcp "vmcp q lan $netName" | grep "Type"`; + + # Go through each line and determine network type + my @lines = split( '\n', $out ); + my $netType = ""; + foreach (@lines) { + + # Virtual switch + if ( $_ =~ m/VSWITCH/i ) { + $netType = "VSWITCH"; + } + + # HiperSocket guest LAN + elsif ( $_ =~ m/HIPERS/i ) { + $netType = "HIPERS"; + } + + # QDIO guest LAN + elsif ( $_ =~ m/QDIO/i ) { + $netType = "QDIO"; + } + } + + return $netType; +} + +#------------------------------------------------------- + +=head3 defineCpu + + Description : Add processor(s) to given node + Arguments : Node + Returns : Nothing + Example : my $out = xCAT::zvmCPUtils->defineCpu($node, $addr, $type); + +=cut + +#------------------------------------------------------- +sub defineCpu { + + # Get inputs + my ( $class, $node, $addr, $type ) = @_; + + # Define processor(s) + my $out = + `ssh -o ConnectTimeout=5 $node "vmcp define cpu $addr type $type"`; + + return ($out); +} diff --git a/perl-xCAT/xCAT/zvmUtils.pm b/perl-xCAT/xCAT/zvmUtils.pm index c769b1e85..7d4f5e6ca 100644 --- a/perl-xCAT/xCAT/zvmUtils.pm +++ b/perl-xCAT/xCAT/zvmUtils.pm @@ -1,938 +1,938 @@ -# IBM(c) 2010 EPL license http://www.eclipse.org/legal/epl-v10.html -#------------------------------------------------------- - -=head1 - - This is a utility plugin for z/VM. - -=cut - -#------------------------------------------------------- -package xCAT::zvmUtils; -use xCAT::MsgUtils; -use xCAT::Utils; -use xCAT::Table; -use strict; -use warnings; -1; - -#------------------------------------------------------- - -=head3 getNodeProps - Description : Get node properties - Arguments : Table - Node - Properties - Returns : Node properties from given table - Example : my $propVals = xCAT::zvmUtils->getNodeProps($tabName, $node, $propNames); - -=cut - -#------------------------------------------------------- -sub getNodeProps { - - # Get inputs - my ( $class, $tabName, $node, @propNames ) = @_; - - # Get table - my $tab = xCAT::Table->new($tabName); - - # Get property values - my $propVals = $tab->getNodeAttribs( $node, [@propNames] ); - - return ($propVals); -} - -#------------------------------------------------------- - -=head3 getTabPropsByKey - Description : Get table entry properties by key - Arguments : Table - Key name - Key value - Requested properties - Returns : Table entry properties - Example : my $propVals = xCAT::zvmUtils->getTabPropsByKey($tabName, $key, $keyValue, @reqProps); - -=cut - -#------------------------------------------------------- -sub getTabPropsByKey { - - # Get inputs - my ( $class, $tabName, $key, $keyVal, @propNames ) = @_; - - # Get table - my $tab = xCAT::Table->new($tabName); - my $propVals; - - # Get table attributes matching given key - $propVals = $tab->getAttribs( { $key => $keyVal }, @propNames ); - return ($propVals); -} - -#------------------------------------------------------- - -=head3 getAllTabEntries - Description : Get all entries within given table - Arguments : Table - Returns : All table entries - Example : my $entries = xCAT::zvmUtils->getAllTabEntries($tabName); - -=cut - -#------------------------------------------------------- -sub getAllTabEntries { - - # Get inputs - my ( $class, $tabName ) = @_; - - # Get table - my $tab = xCAT::Table->new($tabName); - my $entries; - - # Get all entries within given table - $entries = $tab->getAllEntries(); - return ($entries); -} - -#------------------------------------------------------- - -=head3 setNodeProp - - Description : Set node property in a given table - Arguments : Table - Node - Property - Returns : Nothing - Example : xCAT::zvmUtils->setNodeProp($tabName, $node, $propName, $propVal); - -=cut - -#------------------------------------------------------- -sub setNodeProp { - - # Get inputs - my ( $class, $tabName, $node, $propName, $propVal ) = @_; - - # Get table - my $tab = xCAT::Table->new( $tabName, -create => 1, -autocommit => 0 ); - - # Set property - $tab->setAttribs( { 'node' => $node }, { $propName => $propVal } ); - - # Save table - $tab->commit; - - return; -} - -#------------------------------------------------------- - -=head3 delTabEntry - - Description : Delete a table entry - Arguments : Table - Key name - Key value - Returns : Nothing - Example : xCAT::zvmUtils->delTabEntry($tabName, $keyName, $keyVal); - -=cut - -#------------------------------------------------------- -sub delTabEntry { - - # Get inputs - my ( $class, $tabName, $keyName, $keyVal ) = @_; - - # Get table - my $tab = xCAT::Table->new( $tabName, -create => 1, -autocommit => 0 ); - - # Delete entry from table - my %key = ( $keyName => $keyVal ); - $tab->delEntries( \%key ); - - # Save table - $tab->commit; - - return; -} - -#------------------------------------------------------- - -=head3 tabStr - - Description : Tab string (4 spaces) - Arguments : String - Returns : Tabbed string - Example : my $str = xCAT::zvmUtils->tabStr($str); - -=cut - -#------------------------------------------------------- -sub tabStr { - - # Get inputs - my ( $class, $inStr ) = @_; - my @lines = split( "\n", $inStr ); - - # Tab output - my $outStr; - foreach (@lines) { - $outStr .= " $_\n"; - } - - return ($outStr); -} - -#------------------------------------------------------- - -=head3 trimStr - - Description : Trim whitespaces within a string - Arguments : String - Returns : Trimmed string - Example : my $str = xCAT::zvmUtils->trimStr($str); - -=cut - -#------------------------------------------------------- -sub trimStr { - - # Get string - my ( $class, $str ) = @_; - - # Trim right - $str =~ s/\s*$//; - - # Trim left - $str =~ s/^\s*//; - - return ($str); -} - -#------------------------------------------------------- - -=head3 replaceStr - - Description : Replace a given pattern within a string - Arguments : String - Returns : String with given pattern replaced - Example : my $str = xCAT::zvmUtils->replaceStr($str, $pattern, $replacement); - -=cut - -#------------------------------------------------------- -sub replaceStr { - - # Get string - my ( $class, $str, $pattern, $replacement ) = @_; - - # Replace string - $str =~ s/$pattern/$replacement/g; - - return ($str); -} - -#------------------------------------------------------- - -=head3 printLn - - Description : Print string to stdout - Arguments : String - Returns : Nothing - Example : xCAT::zvmUtils->printLn($callback, $str); - -=cut - -#------------------------------------------------------- -sub printLn { - - # Get inputs - my ( $class, $callback, $str ) = @_; - - # Print string - my $rsp; - $rsp->{data}->[0] = "$str"; - xCAT::MsgUtils->message( "I", $rsp, $callback ); - - return; -} - -#------------------------------------------------------- - -=head3 isZvmNode - - Description : Checks if a given node is in the 'zvm' table - Arguments : Node - Returns : TRUE Node exists - FALSE Node does not exists - Example : my $out = xCAT::zvmUtils->isZvmNode($node); - -=cut - -#------------------------------------------------------- -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'); - } - } - - return ('FALSE'); -} - -#------------------------------------------------------- - -=head3 getHwcfg - - Description : Get the hardware configuration file path - e.g. /etc/sysconfig/hardwarehwcfg-qeth-bus-ccw-0.0.0600 - Arguments : Node - Returns : Hardware configuration file path - Example : my $hwcfg = xCAT::zvmUtils->getHwcfg($node); - -=cut - -#------------------------------------------------------- -sub getHwcfg { - - # Get inputs - my ( $class, $node ) = @_; - - # Get OS - my $os = xCAT::zvmUtils->getOs($node); - - # Get network configuration file path - my $out; - my @parms; - - # If it is SUSE -- hwcfg-qeth file is in /etc/sysconfig/hardware - if ( $os =~ m/SUSE/i ) { - $out = `ssh -o ConnectTimeout=5 $node "ls /etc/sysconfig/hardware/hwcfg-qeth*"`; - @parms = split( '\n', $out ); - return ( $parms[0] ); - } - - # If no file is found -- Return nothing - return; -} - -#------------------------------------------------------- - -=head3 getIp - - Description : Get the IP address of a given node - Arguments : Node - Returns : IP address of given node - Example : my $ip = xCAT::zvmUtils->getIp($node); - -=cut - -#------------------------------------------------------- -sub getIp { - - # Get inputs - my ( $class, $node ) = @_; - - # Get IP address - # You need the extra space in the pattern, - # else it will confuse gpok2 with gpok21 - my $out = `cat /etc/hosts | grep "$node "`; - my @parms = split( ' ', $out ); - - return $parms[0]; -} - -#------------------------------------------------------- - -=head3 getIfcfg - - Description : Get the network configuration file path of a given node - Red Hat -- /etc/sysconfig/network-scripts/ifcfg-eth - SUSE -- /etc/sysconfig/network/ifcfg-qeth - Arguments : Node - Returns : Network configuration file path - Example : my $ifcfg = xCAT::zvmUtils->getIfcfg($node); - -=cut - -#------------------------------------------------------- -sub getIfcfg { - - # Get inputs - my ( $class, $node ) = @_; - - # Get OS - my $os = xCAT::zvmUtils->getOs($node); - - # Get network configuration file path - my $out; - my @parms; - - # If it is Red Hat -- ifcfg-qeth file is in /etc/sysconfig/network-scripts - if ( $os =~ m/Red Hat/i ) { - $out = `ssh -o ConnectTimeout=5 $node "ls /etc/sysconfig/network-scripts/ifcfg-eth*"`; - @parms = split( '\n', $out ); - return ( $parms[0] ); - } - - # If it is SUSE -- ifcfg-qeth file is in /etc/sysconfig/network - elsif ( $os =~ m/SUSE/i ) { - $out = `ssh -o ConnectTimeout=5 $node "ls /etc/sysconfig/network/ifcfg-qeth*"`; - @parms = split( '\n', $out ); - return ( $parms[0] ); - } - - # If no file is found -- Return nothing - return; -} - -#------------------------------------------------------- - -=head3 getIfcfgByNic - - Description : Get the network configuration file path of a given node by its NIC address - Arguments : Node - NIC address - Returns : Network configuration file path - Example : my $ifcfg = xCAT::zvmUtils->getIfcfgByNic($node, $nic); - -=cut - -#------------------------------------------------------- -sub getIfcfgByNic { - - # Get inputs - my ( $class, $node, $nic ) = @_; - - # Get OS - my $os = xCAT::zvmUtils->getOs($node); - - # Get network configuration file path - my $out; - my @parms; - - # If it is Red Hat -- ifcfg-qeth file is in /etc/sysconfig/network-scripts - if ( $os =~ m/Red Hat/i ) { - $out = `ssh -o ConnectTimeout=5 $node "ls /etc/sysconfig/network-scripts/ifcfg-eth*"`; - @parms = split( '\n', $out ); - - # Go through each line - foreach( @parms ) { - - # If the network file contains the NIC address - $out = `ssh -o ConnectTimeout=5 $node "cat $_" | grep "$nic"`; - if ( $out ) { - # Return network file path - return ( $_ ); - } - } - } - - # If it is SUSE -- ifcfg-qeth file is in /etc/sysconfig/network - elsif ( $os =~ m/SUSE/i ) { - $out = `ssh -o ConnectTimeout=5 $node "ls /etc/sysconfig/network/ifcfg-qeth*" | grep "$nic"`; - @parms = split( '\n', $out ); - return ( $parms[0] ); - } - - # If no file is found -- Return nothing - return; -} - -#------------------------------------------------------- - -=head3 sendFile - - Description : Send a file to a given node using SCP - Arguments : Node - Source file - Target file - Returns : Nothing - Example : xCAT::zvmUtils->sendFile($node, $srcFile, $trgtFile); - -=cut - -#------------------------------------------------------- -sub sendFile { - - # Get inputs - my ( $class, $node, $srcFile, $trgtFile ) = @_; - - # Create destination string - my $dest = "root@" . $node; - - # SCP directory entry file over to HCP - my $out = `scp $srcFile $dest:$trgtFile`; - - return; -} - -#------------------------------------------------------- - -=head3 getRootDiskAddr - - Description : Get root disk address of given node - Arguments : Node name - Returns : Root disk address - Example : my $deviceNode = xCAT::zvmUtils->getRootDiskAddr($node); - -=cut - -#------------------------------------------------------- -sub getRootDiskAddr { - - # Get inputs - my ( $class, $node ) = @_; - - # Get device node mounted on (/) - my $out = `ssh $node "mount" | grep "/ type" | sed 's/1//'`; - my @parms = split( " ", $out ); - @parms = split( "/", xCAT::zvmUtils->trimStr( $parms[0] ) ); - my $devNode = $parms[0]; - - # Get disk address - $out = `ssh $node "cat /proc/dasd/devices" | grep "$devNode" | sed 's/(ECKD)//' | sed 's/(FBA )//' | sed 's/0.0.//'`; - @parms = split( " ", $out ); - return ( $parms[0] ); -} - -#------------------------------------------------------- - -=head3 disableEnableDisk - - Description : Disable/enable a disk for a given node - Arguments : Device address - Option [-d|-e] - Returns : Nothing - Example : my $out = xCAT::zvmUtils->disableEnableDisk($callback, $node, $option, $devAddr); - -=cut - -#------------------------------------------------------- -sub disableEnableDisk { - - # Get inputs - my ( $class, $callback, $node, $option, $devAddr ) = @_; - - # Disable/enable disk - if ( $option eq "-d" || $option eq "-e" ) { - my $out = `ssh $node "chccwdev $option $devAddr"`; - } - - return; -} - -#------------------------------------------------------- - -=head3 getMdisks - - Description : Get the MDisk statements in the user entry of a given node - Arguments : Node - Returns : MDisk statements - Example : my @mdisks = xCAT::zvmUtils->getMdisks($callback, $node); - -=cut - -#------------------------------------------------------- -sub getMdisks { - - # Get inputs - my ( $class, $callback, $node ) = @_; - - # Directory where executables are - my $dir = '/opt/zhcp/bin'; - - # Get HCP - my @propNames = ( 'hcp', 'userid' ); - my $propVals = xCAT::zvmUtils->getNodeProps( 'zvm', $node, @propNames ); - my $hcp = $propVals->{'hcp'}; - - # Get node userID - my $userId = $propVals->{'userid'}; - - my $out = `ssh $hcp "$dir/getuserentry $userId" | grep "MDISK"`; - - # Get MDISK statements - my @lines = split( '\n', $out ); - my @disks; - foreach (@lines) { - $_ = xCAT::zvmUtils->trimStr($_); - - # Save MDISK statements - push( @disks, $_ ); - } - - return (@disks); -} - -#------------------------------------------------------- - -=head3 getUserEntryWODisk - - Description : Get the user entry of a given node - without MDISK statments, and save it to a file - Arguments : Node - File name to save user entry under - Returns : Nothing - Example : my $out = xCAT::zvmUtils->getUserEntryWODisk($callback, $node, $file); - -=cut - -#------------------------------------------------------- -sub getUserEntryWODisk { - - # Get inputs - my ( $class, $callback, $node, $file ) = @_; - - # Directory where executables are - my $dir = '/opt/zhcp/bin'; - - # Get node properties from 'zvm' table - my @propNames = ( 'hcp', 'userid' ); - my $propVals = xCAT::zvmUtils->getNodeProps( 'zvm', $node, @propNames ); - - # Get HCP - my $hcp = $propVals->{'hcp'}; - if ( !$hcp ) { - xCAT::zvmUtils->printLn( $callback, "Error: Missing node HCP" ); - return; - } - - # Get node userID - my $userId = $propVals->{'userid'}; - if ( !$userId ) { - xCAT::zvmUtils->printLn( $callback, "Error: Missing node ID" ); - return; - } - - my $out = `ssh $hcp "$dir/getuserentry $userId" | grep -v "MDISK"`; - - # Create a file to save output - open( DIRENTRY, ">$file" ); - - # Save output - my @lines = split( '\n', $out ); - foreach (@lines) { - - # Trim line - $_ = xCAT::zvmUtils->trimStr($_); - - # Write directory entry into file - print DIRENTRY "$_\n"; - } - close(DIRENTRY); - - return; -} - -#------------------------------------------------------- - -=head3 appendHostname - - Description : Append a specified hostname in front of a given string - Arguments : Hostname - String - Returns : String with hostname in front - Example : my $str = xCAT::zvmUtils->appendHostname($hostname, $str); - -=cut - -#------------------------------------------------------- -sub appendHostname { - my ( $class, $hostname, $str ) = @_; - - # Append hostname to every line - my @outLn = split( "\n", $str ); - $str = ""; - foreach (@outLn) { - $str .= "$hostname: " . $_ . "\n"; - } - - return $str; -} - -#------------------------------------------------------- - -=head3 checkOutput - - Description : Check return of given output - Arguments : Output string - Returns : 0 Good output - -1 Bad output - Example : my $ans = xCAT::zvmUtils->checkOutput($callback, $out); - -=cut - -#------------------------------------------------------- -sub checkOutput { - my ( $class, $callback, $out ) = @_; - - # Check output string - my @outLn = split( "\n", $out ); - foreach (@outLn) { - - # If output contains 'Failed' return -1 - if ( $_ =~ m/Failed/i ) { - return -1; - } - } - - return 0; -} - -#------------------------------------------------------- - -=head3 isAddressUsed - - Description : Check if given an address is used - Arguments : Node - Disk address - Returns : 0 Address used - -1 Address not used - Example : my $ans = xCAT::zvmUtils->isAddressUsed($node, $address); - -=cut - -#------------------------------------------------------- -sub isAddressUsed { - my ( $class, $node, $address ) = @_; - - # Search for disk address - my $out = `ssh -o ConnectTimeout=5 $node "vmcp q v dasd" | grep "DASD $address"`; - if ($out) { - return 0; - } - - return -1; -} - -#------------------------------------------------------- - -=head3 getMacID - - Description : Get the MACID from /opt/zhcp/conf/next_macid on the HCP - Arguments : HCP node - Returns : MACID - Example : my $macId = xCAT::zvmUtils->getMacID($hcp); - -=cut - -#------------------------------------------------------- -sub getMacID { - my ( $class, $hcp ) = @_; - - # Check /opt/zhcp/conf directory on HCP - my $out = `ssh -o ConnectTimeout=5 $hcp "test -d /opt/zhcp/conf && echo 'Directory exists'"`; - if ( $out =~ m/Directory exists/i ) { - - # Check next_macid file - $out = `ssh -o ConnectTimeout=5 $hcp "test -e /opt/zhcp/conf/next_macid && echo 'File exists'"`; - if ( $out =~ m/File exists/i ) { - - # Do nothing - } - else { - - # Create next_macid file - $out = `ssh -o ConnectTimeout=5 $hcp "echo 'FFFFFF' > /opt/zhcp/conf/next_macid"`; - } - } - else { - - # Create /opt/zhcp/conf directory - # Create next_mac -- Contains next MAC address to use - $out = `ssh -o ConnectTimeout=5 $hcp "mkdir /opt/zhcp/conf"`; - $out = `ssh -o ConnectTimeout=5 $hcp "echo 'FFFFFF' > /opt/zhcp/conf/next_macid"`; - } - - # Read /opt/zhcp/conf/next_macid file - $out = `ssh -o ConnectTimeout=5 $hcp "cat /opt/zhcp/conf/next_macid"`; - my $macId = xCAT::zvmUtils->trimStr($out); - - return $macId; -} - -#------------------------------------------------------- - -=head3 generateMacId - - Description : Generate a MACID - Arguments : HCP node - Returns : Nothing - Example : my $macId = xCAT::zvmUtils->generateMacId($hcp); - -=cut - -#------------------------------------------------------- -sub generateMacId { - my ( $class, $hcp ) = @_; - - # Check /opt/zhcp/conf directory on HCP - my $out = `ssh -o ConnectTimeout=5 $hcp "test -d /opt/zhcp/conf && echo 'Directory exists'"`; - if ( $out =~ m/Directory exists/i ) { - - # Check next_macid file - $out = `ssh -o ConnectTimeout=5 $hcp "test -e /opt/zhcp/conf/next_macid && echo 'File exists'"`; - if ( $out =~ m/File exists/i ) { - - # Do nothing - } - else { - - # Create next_macid file - $out = `ssh -o ConnectTimeout=5 $hcp "echo 'FFFFFF' > /opt/zhcp/conf/next_macid"`; - } - } - else { - - # Create /opt/zhcp/conf directory - # Create next_mac -- Contains next MAC address to use - $out = `ssh -o ConnectTimeout=5 $hcp "mkdir /opt/zhcp/conf"`; - $out = `ssh -o ConnectTimeout=5 $hcp "echo 'FFFFFF' > /opt/zhcp/conf/next_macid"`; - } - - # Read /opt/zhcp/conf/next_macid file - $out = `ssh -o ConnectTimeout=5 $hcp "cat /opt/zhcp/conf/next_macid"`; - my $macId = xCAT::zvmUtils->trimStr($out); - my $int; - - if ($macId) { - - # Convert hexadecimal -- decimal - $int = hex($macId); - $macId = sprintf( "%d", $int ); - - # Generate new MAC suffix - $macId = $macId - 1; - - # Convert decimal -- hexadecimal - $macId = sprintf( "%X", $macId ); - - # Save new MACID - $out = `ssh -o ConnectTimeout=5 $hcp "echo $macId > /opt/zhcp/conf/next_macid"`; - } - - return; -} - -#------------------------------------------------------- - -=head3 createMacAddr - - Description : Create a MAC address using HCP MAC prefix of given node - and given MAC suffix - Arguments : Node - MAC suffix - Returns : MAC address - Example : my $mac = xCAT::zvmUtils->createMacAddr($node, $suffix); - -=cut - -#------------------------------------------------------- -sub createMacAddr { - my ( $class, $node, $suffix ) = @_; - - # Get node properties from 'zvm' table - my @propNames = ('hcp'); - my $propVals = xCAT::zvmUtils->getNodeProps( 'zvm', $node, @propNames ); - - # Get HCP - my $hcp = $propVals->{'hcp'}; - if ( !$hcp ) { - return -1; - } - - # Get HCP MAC address - # Get the first MAC address found - my $out = `ssh -o ConnectTimeout=5 $hcp "vmcp q nic" | grep "MAC:"`; - my @lines = split( "\n", $out ); - my @vars = split( " ", $lines[0] ); - - # Extract MAC prefix - my $prefix = $vars[1]; - $prefix = xCAT::zvmUtils->replaceStr( $prefix, "-", "" ); - $prefix = substr( $prefix, 0, 6 ); - - # Generate MAC address of source node - my $mac = $prefix . $suffix; - - # If length is less than 12, append a zero - if ( length($mac) != 12 ) { - $mac = "0" . $mac; - } - - $mac = - substr( $mac, 0, 2 ) . ":" - . substr( $mac, 2, 2 ) . ":" - . substr( $mac, 4, 2 ) . ":" - . substr( $mac, 6, 2 ) . ":" - . substr( $mac, 8, 2 ) . ":" - . substr( $mac, 10, 2 ); - - return $mac; -} - -#------------------------------------------------------- - -=head3 getOs - - Description : Get the operating system name of a given node - Arguments : Node - Returns : Operating system name - Example : my $osName = xCAT::zvmUtils->getOs($node); - -=cut - -#------------------------------------------------------- -sub getOs { - - # Get inputs - my ( $class, $node ) = @_; - - # Get operating system - my $out = `ssh -o ConnectTimeout=10 $node "cat /etc/*release"`; - my @results = split( '\n', $out ); - return ( xCAT::zvmUtils->trimStr( $results[0] ) ); -} - -#------------------------------------------------------- - -=head3 getArch - - Description : Get the architecture of a given node - Arguments : Node - Returns : Architecture of node - Example : my $arch = xCAT::zvmUtils->getArch($node); - -=cut - -#------------------------------------------------------- -sub getArch { - - # Get inputs - my ( $class, $node ) = @_; - - # Get host using VMCP - my $arch = `ssh $node "uname -p"`; - - return ( xCAT::zvmUtils->trimStr($arch) ); -} +# IBM(c) 2010 EPL license http://www.eclipse.org/legal/epl-v10.html +#------------------------------------------------------- + +=head1 + + This is a utility plugin for z/VM. + +=cut + +#------------------------------------------------------- +package xCAT::zvmUtils; +use xCAT::MsgUtils; +use xCAT::Utils; +use xCAT::Table; +use strict; +use warnings; +1; + +#------------------------------------------------------- + +=head3 getNodeProps + Description : Get node properties + Arguments : Table + Node + Properties + Returns : Node properties from given table + Example : my $propVals = xCAT::zvmUtils->getNodeProps($tabName, $node, $propNames); + +=cut + +#------------------------------------------------------- +sub getNodeProps { + + # Get inputs + my ( $class, $tabName, $node, @propNames ) = @_; + + # Get table + my $tab = xCAT::Table->new($tabName); + + # Get property values + my $propVals = $tab->getNodeAttribs( $node, [@propNames] ); + + return ($propVals); +} + +#------------------------------------------------------- + +=head3 getTabPropsByKey + Description : Get table entry properties by key + Arguments : Table + Key name + Key value + Requested properties + Returns : Table entry properties + Example : my $propVals = xCAT::zvmUtils->getTabPropsByKey($tabName, $key, $keyValue, @reqProps); + +=cut + +#------------------------------------------------------- +sub getTabPropsByKey { + + # Get inputs + my ( $class, $tabName, $key, $keyVal, @propNames ) = @_; + + # Get table + my $tab = xCAT::Table->new($tabName); + my $propVals; + + # Get table attributes matching given key + $propVals = $tab->getAttribs( { $key => $keyVal }, @propNames ); + return ($propVals); +} + +#------------------------------------------------------- + +=head3 getAllTabEntries + Description : Get all entries within given table + Arguments : Table + Returns : All table entries + Example : my $entries = xCAT::zvmUtils->getAllTabEntries($tabName); + +=cut + +#------------------------------------------------------- +sub getAllTabEntries { + + # Get inputs + my ( $class, $tabName ) = @_; + + # Get table + my $tab = xCAT::Table->new($tabName); + my $entries; + + # Get all entries within given table + $entries = $tab->getAllEntries(); + return ($entries); +} + +#------------------------------------------------------- + +=head3 setNodeProp + + Description : Set node property in a given table + Arguments : Table + Node + Property + Returns : Nothing + Example : xCAT::zvmUtils->setNodeProp($tabName, $node, $propName, $propVal); + +=cut + +#------------------------------------------------------- +sub setNodeProp { + + # Get inputs + my ( $class, $tabName, $node, $propName, $propVal ) = @_; + + # Get table + my $tab = xCAT::Table->new( $tabName, -create => 1, -autocommit => 0 ); + + # Set property + $tab->setAttribs( { 'node' => $node }, { $propName => $propVal } ); + + # Save table + $tab->commit; + + return; +} + +#------------------------------------------------------- + +=head3 delTabEntry + + Description : Delete a table entry + Arguments : Table + Key name + Key value + Returns : Nothing + Example : xCAT::zvmUtils->delTabEntry($tabName, $keyName, $keyVal); + +=cut + +#------------------------------------------------------- +sub delTabEntry { + + # Get inputs + my ( $class, $tabName, $keyName, $keyVal ) = @_; + + # Get table + my $tab = xCAT::Table->new( $tabName, -create => 1, -autocommit => 0 ); + + # Delete entry from table + my %key = ( $keyName => $keyVal ); + $tab->delEntries( \%key ); + + # Save table + $tab->commit; + + return; +} + +#------------------------------------------------------- + +=head3 tabStr + + Description : Tab string (4 spaces) + Arguments : String + Returns : Tabbed string + Example : my $str = xCAT::zvmUtils->tabStr($str); + +=cut + +#------------------------------------------------------- +sub tabStr { + + # Get inputs + my ( $class, $inStr ) = @_; + my @lines = split( "\n", $inStr ); + + # Tab output + my $outStr; + foreach (@lines) { + $outStr .= " $_\n"; + } + + return ($outStr); +} + +#------------------------------------------------------- + +=head3 trimStr + + Description : Trim whitespaces within a string + Arguments : String + Returns : Trimmed string + Example : my $str = xCAT::zvmUtils->trimStr($str); + +=cut + +#------------------------------------------------------- +sub trimStr { + + # Get string + my ( $class, $str ) = @_; + + # Trim right + $str =~ s/\s*$//; + + # Trim left + $str =~ s/^\s*//; + + return ($str); +} + +#------------------------------------------------------- + +=head3 replaceStr + + Description : Replace a given pattern within a string + Arguments : String + Returns : String with given pattern replaced + Example : my $str = xCAT::zvmUtils->replaceStr($str, $pattern, $replacement); + +=cut + +#------------------------------------------------------- +sub replaceStr { + + # Get string + my ( $class, $str, $pattern, $replacement ) = @_; + + # Replace string + $str =~ s/$pattern/$replacement/g; + + return ($str); +} + +#------------------------------------------------------- + +=head3 printLn + + Description : Print string to stdout + Arguments : String + Returns : Nothing + Example : xCAT::zvmUtils->printLn($callback, $str); + +=cut + +#------------------------------------------------------- +sub printLn { + + # Get inputs + my ( $class, $callback, $str ) = @_; + + # Print string + my $rsp; + $rsp->{data}->[0] = "$str"; + xCAT::MsgUtils->message( "I", $rsp, $callback ); + + return; +} + +#------------------------------------------------------- + +=head3 isZvmNode + + Description : Checks if a given node is in the 'zvm' table + Arguments : Node + Returns : TRUE Node exists + FALSE Node does not exists + Example : my $out = xCAT::zvmUtils->isZvmNode($node); + +=cut + +#------------------------------------------------------- +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'); + } + } + + return ('FALSE'); +} + +#------------------------------------------------------- + +=head3 getHwcfg + + Description : Get the hardware configuration file path + e.g. /etc/sysconfig/hardwarehwcfg-qeth-bus-ccw-0.0.0600 + Arguments : Node + Returns : Hardware configuration file path + Example : my $hwcfg = xCAT::zvmUtils->getHwcfg($node); + +=cut + +#------------------------------------------------------- +sub getHwcfg { + + # Get inputs + my ( $class, $node ) = @_; + + # Get OS + my $os = xCAT::zvmUtils->getOs($node); + + # Get network configuration file path + my $out; + my @parms; + + # If it is SUSE -- hwcfg-qeth file is in /etc/sysconfig/hardware + if ( $os =~ m/SUSE/i ) { + $out = `ssh -o ConnectTimeout=5 $node "ls /etc/sysconfig/hardware/hwcfg-qeth*"`; + @parms = split( '\n', $out ); + return ( $parms[0] ); + } + + # If no file is found -- Return nothing + return; +} + +#------------------------------------------------------- + +=head3 getIp + + Description : Get the IP address of a given node + Arguments : Node + Returns : IP address of given node + Example : my $ip = xCAT::zvmUtils->getIp($node); + +=cut + +#------------------------------------------------------- +sub getIp { + + # Get inputs + my ( $class, $node ) = @_; + + # Get IP address + # You need the extra space in the pattern, + # else it will confuse gpok2 with gpok21 + my $out = `cat /etc/hosts | grep "$node "`; + my @parms = split( ' ', $out ); + + return $parms[0]; +} + +#------------------------------------------------------- + +=head3 getIfcfg + + Description : Get the network configuration file path of a given node + Red Hat -- /etc/sysconfig/network-scripts/ifcfg-eth + SUSE -- /etc/sysconfig/network/ifcfg-qeth + Arguments : Node + Returns : Network configuration file path + Example : my $ifcfg = xCAT::zvmUtils->getIfcfg($node); + +=cut + +#------------------------------------------------------- +sub getIfcfg { + + # Get inputs + my ( $class, $node ) = @_; + + # Get OS + my $os = xCAT::zvmUtils->getOs($node); + + # Get network configuration file path + my $out; + my @parms; + + # If it is Red Hat -- ifcfg-qeth file is in /etc/sysconfig/network-scripts + if ( $os =~ m/Red Hat/i ) { + $out = `ssh -o ConnectTimeout=5 $node "ls /etc/sysconfig/network-scripts/ifcfg-eth*"`; + @parms = split( '\n', $out ); + return ( $parms[0] ); + } + + # If it is SUSE -- ifcfg-qeth file is in /etc/sysconfig/network + elsif ( $os =~ m/SUSE/i ) { + $out = `ssh -o ConnectTimeout=5 $node "ls /etc/sysconfig/network/ifcfg-qeth*"`; + @parms = split( '\n', $out ); + return ( $parms[0] ); + } + + # If no file is found -- Return nothing + return; +} + +#------------------------------------------------------- + +=head3 getIfcfgByNic + + Description : Get the network configuration file path of a given node by its NIC address + Arguments : Node + NIC address + Returns : Network configuration file path + Example : my $ifcfg = xCAT::zvmUtils->getIfcfgByNic($node, $nic); + +=cut + +#------------------------------------------------------- +sub getIfcfgByNic { + + # Get inputs + my ( $class, $node, $nic ) = @_; + + # Get OS + my $os = xCAT::zvmUtils->getOs($node); + + # Get network configuration file path + my $out; + my @parms; + + # If it is Red Hat -- ifcfg-qeth file is in /etc/sysconfig/network-scripts + if ( $os =~ m/Red Hat/i ) { + $out = `ssh -o ConnectTimeout=5 $node "ls /etc/sysconfig/network-scripts/ifcfg-eth*"`; + @parms = split( '\n', $out ); + + # Go through each line + foreach( @parms ) { + + # If the network file contains the NIC address + $out = `ssh -o ConnectTimeout=5 $node "cat $_" | grep "$nic"`; + if ( $out ) { + # Return network file path + return ( $_ ); + } + } + } + + # If it is SUSE -- ifcfg-qeth file is in /etc/sysconfig/network + elsif ( $os =~ m/SUSE/i ) { + $out = `ssh -o ConnectTimeout=5 $node "ls /etc/sysconfig/network/ifcfg-qeth*" | grep "$nic"`; + @parms = split( '\n', $out ); + return ( $parms[0] ); + } + + # If no file is found -- Return nothing + return; +} + +#------------------------------------------------------- + +=head3 sendFile + + Description : Send a file to a given node using SCP + Arguments : Node + Source file + Target file + Returns : Nothing + Example : xCAT::zvmUtils->sendFile($node, $srcFile, $trgtFile); + +=cut + +#------------------------------------------------------- +sub sendFile { + + # Get inputs + my ( $class, $node, $srcFile, $trgtFile ) = @_; + + # Create destination string + my $dest = "root@" . $node; + + # SCP directory entry file over to HCP + my $out = `scp $srcFile $dest:$trgtFile`; + + return; +} + +#------------------------------------------------------- + +=head3 getRootDiskAddr + + Description : Get root disk address of given node + Arguments : Node name + Returns : Root disk address + Example : my $deviceNode = xCAT::zvmUtils->getRootDiskAddr($node); + +=cut + +#------------------------------------------------------- +sub getRootDiskAddr { + + # Get inputs + my ( $class, $node ) = @_; + + # Get device node mounted on (/) + my $out = `ssh $node "mount" | grep "/ type" | sed 's/1//'`; + my @parms = split( " ", $out ); + @parms = split( "/", xCAT::zvmUtils->trimStr( $parms[0] ) ); + my $devNode = $parms[0]; + + # Get disk address + $out = `ssh $node "cat /proc/dasd/devices" | grep "$devNode" | sed 's/(ECKD)//' | sed 's/(FBA )//' | sed 's/0.0.//'`; + @parms = split( " ", $out ); + return ( $parms[0] ); +} + +#------------------------------------------------------- + +=head3 disableEnableDisk + + Description : Disable/enable a disk for a given node + Arguments : Device address + Option [-d|-e] + Returns : Nothing + Example : my $out = xCAT::zvmUtils->disableEnableDisk($callback, $node, $option, $devAddr); + +=cut + +#------------------------------------------------------- +sub disableEnableDisk { + + # Get inputs + my ( $class, $callback, $node, $option, $devAddr ) = @_; + + # Disable/enable disk + if ( $option eq "-d" || $option eq "-e" ) { + my $out = `ssh $node "chccwdev $option $devAddr"`; + } + + return; +} + +#------------------------------------------------------- + +=head3 getMdisks + + Description : Get the MDisk statements in the user entry of a given node + Arguments : Node + Returns : MDisk statements + Example : my @mdisks = xCAT::zvmUtils->getMdisks($callback, $node); + +=cut + +#------------------------------------------------------- +sub getMdisks { + + # Get inputs + my ( $class, $callback, $node ) = @_; + + # Directory where executables are + my $dir = '/opt/zhcp/bin'; + + # Get HCP + my @propNames = ( 'hcp', 'userid' ); + my $propVals = xCAT::zvmUtils->getNodeProps( 'zvm', $node, @propNames ); + my $hcp = $propVals->{'hcp'}; + + # Get node userID + my $userId = $propVals->{'userid'}; + + my $out = `ssh $hcp "$dir/getuserentry $userId" | grep "MDISK"`; + + # Get MDISK statements + my @lines = split( '\n', $out ); + my @disks; + foreach (@lines) { + $_ = xCAT::zvmUtils->trimStr($_); + + # Save MDISK statements + push( @disks, $_ ); + } + + return (@disks); +} + +#------------------------------------------------------- + +=head3 getUserEntryWODisk + + Description : Get the user entry of a given node + without MDISK statments, and save it to a file + Arguments : Node + File name to save user entry under + Returns : Nothing + Example : my $out = xCAT::zvmUtils->getUserEntryWODisk($callback, $node, $file); + +=cut + +#------------------------------------------------------- +sub getUserEntryWODisk { + + # Get inputs + my ( $class, $callback, $node, $file ) = @_; + + # Directory where executables are + my $dir = '/opt/zhcp/bin'; + + # Get node properties from 'zvm' table + my @propNames = ( 'hcp', 'userid' ); + my $propVals = xCAT::zvmUtils->getNodeProps( 'zvm', $node, @propNames ); + + # Get HCP + my $hcp = $propVals->{'hcp'}; + if ( !$hcp ) { + xCAT::zvmUtils->printLn( $callback, "Error: Missing node HCP" ); + return; + } + + # Get node userID + my $userId = $propVals->{'userid'}; + if ( !$userId ) { + xCAT::zvmUtils->printLn( $callback, "Error: Missing node ID" ); + return; + } + + my $out = `ssh $hcp "$dir/getuserentry $userId" | grep -v "MDISK"`; + + # Create a file to save output + open( DIRENTRY, ">$file" ); + + # Save output + my @lines = split( '\n', $out ); + foreach (@lines) { + + # Trim line + $_ = xCAT::zvmUtils->trimStr($_); + + # Write directory entry into file + print DIRENTRY "$_\n"; + } + close(DIRENTRY); + + return; +} + +#------------------------------------------------------- + +=head3 appendHostname + + Description : Append a specified hostname in front of a given string + Arguments : Hostname + String + Returns : String with hostname in front + Example : my $str = xCAT::zvmUtils->appendHostname($hostname, $str); + +=cut + +#------------------------------------------------------- +sub appendHostname { + my ( $class, $hostname, $str ) = @_; + + # Append hostname to every line + my @outLn = split( "\n", $str ); + $str = ""; + foreach (@outLn) { + $str .= "$hostname: " . $_ . "\n"; + } + + return $str; +} + +#------------------------------------------------------- + +=head3 checkOutput + + Description : Check return of given output + Arguments : Output string + Returns : 0 Good output + -1 Bad output + Example : my $ans = xCAT::zvmUtils->checkOutput($callback, $out); + +=cut + +#------------------------------------------------------- +sub checkOutput { + my ( $class, $callback, $out ) = @_; + + # Check output string + my @outLn = split( "\n", $out ); + foreach (@outLn) { + + # If output contains 'Failed' return -1 + if ( $_ =~ m/Failed/i ) { + return -1; + } + } + + return 0; +} + +#------------------------------------------------------- + +=head3 isAddressUsed + + Description : Check if given an address is used + Arguments : Node + Disk address + Returns : 0 Address used + -1 Address not used + Example : my $ans = xCAT::zvmUtils->isAddressUsed($node, $address); + +=cut + +#------------------------------------------------------- +sub isAddressUsed { + my ( $class, $node, $address ) = @_; + + # Search for disk address + my $out = `ssh -o ConnectTimeout=5 $node "vmcp q v dasd" | grep "DASD $address"`; + if ($out) { + return 0; + } + + return -1; +} + +#------------------------------------------------------- + +=head3 getMacID + + Description : Get the MACID from /opt/zhcp/conf/next_macid on the HCP + Arguments : HCP node + Returns : MACID + Example : my $macId = xCAT::zvmUtils->getMacID($hcp); + +=cut + +#------------------------------------------------------- +sub getMacID { + my ( $class, $hcp ) = @_; + + # Check /opt/zhcp/conf directory on HCP + my $out = `ssh -o ConnectTimeout=5 $hcp "test -d /opt/zhcp/conf && echo 'Directory exists'"`; + if ( $out =~ m/Directory exists/i ) { + + # Check next_macid file + $out = `ssh -o ConnectTimeout=5 $hcp "test -e /opt/zhcp/conf/next_macid && echo 'File exists'"`; + if ( $out =~ m/File exists/i ) { + + # Do nothing + } + else { + + # Create next_macid file + $out = `ssh -o ConnectTimeout=5 $hcp "echo 'FFFFFF' > /opt/zhcp/conf/next_macid"`; + } + } + else { + + # Create /opt/zhcp/conf directory + # Create next_mac -- Contains next MAC address to use + $out = `ssh -o ConnectTimeout=5 $hcp "mkdir /opt/zhcp/conf"`; + $out = `ssh -o ConnectTimeout=5 $hcp "echo 'FFFFFF' > /opt/zhcp/conf/next_macid"`; + } + + # Read /opt/zhcp/conf/next_macid file + $out = `ssh -o ConnectTimeout=5 $hcp "cat /opt/zhcp/conf/next_macid"`; + my $macId = xCAT::zvmUtils->trimStr($out); + + return $macId; +} + +#------------------------------------------------------- + +=head3 generateMacId + + Description : Generate a MACID + Arguments : HCP node + Returns : Nothing + Example : my $macId = xCAT::zvmUtils->generateMacId($hcp); + +=cut + +#------------------------------------------------------- +sub generateMacId { + my ( $class, $hcp ) = @_; + + # Check /opt/zhcp/conf directory on HCP + my $out = `ssh -o ConnectTimeout=5 $hcp "test -d /opt/zhcp/conf && echo 'Directory exists'"`; + if ( $out =~ m/Directory exists/i ) { + + # Check next_macid file + $out = `ssh -o ConnectTimeout=5 $hcp "test -e /opt/zhcp/conf/next_macid && echo 'File exists'"`; + if ( $out =~ m/File exists/i ) { + + # Do nothing + } + else { + + # Create next_macid file + $out = `ssh -o ConnectTimeout=5 $hcp "echo 'FFFFFF' > /opt/zhcp/conf/next_macid"`; + } + } + else { + + # Create /opt/zhcp/conf directory + # Create next_mac -- Contains next MAC address to use + $out = `ssh -o ConnectTimeout=5 $hcp "mkdir /opt/zhcp/conf"`; + $out = `ssh -o ConnectTimeout=5 $hcp "echo 'FFFFFF' > /opt/zhcp/conf/next_macid"`; + } + + # Read /opt/zhcp/conf/next_macid file + $out = `ssh -o ConnectTimeout=5 $hcp "cat /opt/zhcp/conf/next_macid"`; + my $macId = xCAT::zvmUtils->trimStr($out); + my $int; + + if ($macId) { + + # Convert hexadecimal -- decimal + $int = hex($macId); + $macId = sprintf( "%d", $int ); + + # Generate new MAC suffix + $macId = $macId - 1; + + # Convert decimal -- hexadecimal + $macId = sprintf( "%X", $macId ); + + # Save new MACID + $out = `ssh -o ConnectTimeout=5 $hcp "echo $macId > /opt/zhcp/conf/next_macid"`; + } + + return; +} + +#------------------------------------------------------- + +=head3 createMacAddr + + Description : Create a MAC address using HCP MAC prefix of given node + and given MAC suffix + Arguments : Node + MAC suffix + Returns : MAC address + Example : my $mac = xCAT::zvmUtils->createMacAddr($node, $suffix); + +=cut + +#------------------------------------------------------- +sub createMacAddr { + my ( $class, $node, $suffix ) = @_; + + # Get node properties from 'zvm' table + my @propNames = ('hcp'); + my $propVals = xCAT::zvmUtils->getNodeProps( 'zvm', $node, @propNames ); + + # Get HCP + my $hcp = $propVals->{'hcp'}; + if ( !$hcp ) { + return -1; + } + + # Get HCP MAC address + # Get the first MAC address found + my $out = `ssh -o ConnectTimeout=5 $hcp "vmcp q nic" | grep "MAC:"`; + my @lines = split( "\n", $out ); + my @vars = split( " ", $lines[0] ); + + # Extract MAC prefix + my $prefix = $vars[1]; + $prefix = xCAT::zvmUtils->replaceStr( $prefix, "-", "" ); + $prefix = substr( $prefix, 0, 6 ); + + # Generate MAC address of source node + my $mac = $prefix . $suffix; + + # If length is less than 12, append a zero + if ( length($mac) != 12 ) { + $mac = "0" . $mac; + } + + $mac = + substr( $mac, 0, 2 ) . ":" + . substr( $mac, 2, 2 ) . ":" + . substr( $mac, 4, 2 ) . ":" + . substr( $mac, 6, 2 ) . ":" + . substr( $mac, 8, 2 ) . ":" + . substr( $mac, 10, 2 ); + + return $mac; +} + +#------------------------------------------------------- + +=head3 getOs + + Description : Get the operating system name of a given node + Arguments : Node + Returns : Operating system name + Example : my $osName = xCAT::zvmUtils->getOs($node); + +=cut + +#------------------------------------------------------- +sub getOs { + + # Get inputs + my ( $class, $node ) = @_; + + # Get operating system + my $out = `ssh -o ConnectTimeout=10 $node "cat /etc/*release"`; + my @results = split( '\n', $out ); + return ( xCAT::zvmUtils->trimStr( $results[0] ) ); +} + +#------------------------------------------------------- + +=head3 getArch + + Description : Get the architecture of a given node + Arguments : Node + Returns : Architecture of node + Example : my $arch = xCAT::zvmUtils->getArch($node); + +=cut + +#------------------------------------------------------- +sub getArch { + + # Get inputs + my ( $class, $node ) = @_; + + # Get host using VMCP + my $arch = `ssh $node "uname -p"`; + + return ( xCAT::zvmUtils->trimStr($arch) ); +} diff --git a/xCAT-server/share/xcat/install/rh/compute.rhel5.s390x.tmpl b/xCAT-server/share/xcat/install/rh/compute.rhel5.s390x.tmpl index 0575286b3..d0bf72d60 100644 --- a/xCAT-server/share/xcat/install/rh/compute.rhel5.s390x.tmpl +++ b/xCAT-server/share/xcat/install/rh/compute.rhel5.s390x.tmpl @@ -1,34 +1,34 @@ -# Kickstart file automatically generated by anaconda. - -install -url --url replace_url -key --skip -lang en_US.UTF-8 -network --bootproto dhcp -rootpw replace_rootpw -firewall --disabled -authconfig --enableshadow --enablemd5 -selinux --enforcing -timezone --utc America/New_York -bootloader --location=mbr -reboot -key --skip -# The following is the partition information you requested -# Note that any partitions you deleted are not expressed -# here so unless you clear all partitions first, this is -# not guaranteed to work -zerombr yes -clearpart --initlabel --drives=dasda,dasdb -part / --fstype ext3 --size=100 --grow --ondisk=dasda -part /usr --fstype ext3 --size=100 --grow --ondisk=dasdb - -%packages -@base -@core -@base-x -fipscheck -device-mapper-multipath -sgpio - -%post -echo ARP=no >> /etc/sysconfig/network-scripts/ifcfg-eth0 +# Kickstart file automatically generated by anaconda. + +install +url --url replace_url +key --skip +lang en_US.UTF-8 +network --bootproto dhcp +rootpw replace_rootpw +firewall --disabled +authconfig --enableshadow --enablemd5 +selinux --enforcing +timezone --utc America/New_York +bootloader --location=mbr +reboot +key --skip +# The following is the partition information you requested +# Note that any partitions you deleted are not expressed +# here so unless you clear all partitions first, this is +# not guaranteed to work +zerombr yes +clearpart --initlabel --drives=dasda,dasdb +part / --fstype ext3 --size=100 --grow --ondisk=dasda +part /usr --fstype ext3 --size=100 --grow --ondisk=dasdb + +%packages +@base +@core +@base-x +fipscheck +device-mapper-multipath +sgpio + +%post +echo ARP=no >> /etc/sysconfig/network-scripts/ifcfg-eth0