diff --git a/perl-xCAT/xCAT/zvmCPUtils.pm b/perl-xCAT/xCAT/zvmCPUtils.pm index ee5861407..f51c8601b 100644 --- a/perl-xCAT/xCAT/zvmCPUtils.pm +++ b/perl-xCAT/xCAT/zvmCPUtils.pm @@ -18,8 +18,8 @@ use warnings; =head3 getUserId - Description : Get userID for specified node - Arguments : Node name + Description : Get userID of given node + Arguments : Node Returns : UserID Example : my $userID = xCAT::zvmCPUtils->getUserId($node); @@ -32,8 +32,9 @@ sub getUserId { my ( $class, $node ) = @_; # Get userId using VMCP - my $out = `ssh -o ConnectTimeout=5 $node "vmcp q userid"`; + my $out = `ssh -o ConnectTimeout=5 $node "vmcp q userid"`; my @results = split( ' ', $out ); + return ( $results[0] ); } @@ -41,8 +42,8 @@ sub getUserId { =head3 getSn - Description : Get serial number for specified node - Arguments : Node name + Description : Get serial number for given node + Arguments : Node Returns : Serial number Example : my $sn = xCAT::zvmCPUtils->getSn($node); @@ -100,8 +101,8 @@ sub getSn { =head3 getHost - Description : Get z/VM host for specified node - Arguments : Node name + Description : Get z/VM host for given node + Arguments : Node Returns : z/VM host Example : my $host = xCAT::zvmCPUtils->getHost($node); @@ -125,8 +126,8 @@ sub getHost { =head3 getOs - Description : Get operating system name of specified node - Arguments : Node name + Description : Get operating system name of given node + Arguments : Node Returns : Operating system name Example : my $osName = xCAT::zvmCPUtils->getOs($node); @@ -148,8 +149,8 @@ sub getOs { =head3 getArch - Description : Get architecture of specified node - Arguments : Node name + Description : Get architecture of given node + Arguments : Node Returns : Architecture of node Example : my $arch = xCAT::zvmCPUtils->getArch($node); @@ -171,8 +172,8 @@ sub getArch { =head3 getPrivileges - Description : Get privilege class of specified node - Arguments : Node name + Description : Get privilege class of given node + Arguments : Node Returns : Privilege class Example : my $memory = xCAT::zvmCPUtils->getPrivileges($node); @@ -190,6 +191,7 @@ sub getPrivileges { $out[1] = xCAT::zvmUtils->trimStr( $out[1] ); $out[2] = xCAT::zvmUtils->trimStr( $out[2] ); my $str = " $out[1]\n $out[2]\n"; + return ($str); } @@ -197,8 +199,8 @@ sub getPrivileges { =head3 getMemory - Description : Get memory of specified node - Arguments : Node name + Description : Get memory of given node + Arguments : Node Returns : Memory Example : my $memory = xCAT::zvmCPUtils->getMemory($node); @@ -213,6 +215,7 @@ sub getMemory { # Get memory my $out = `ssh -o ConnectTimeout=5 $node "vmcp q virtual storage"`; my @out = split( '=', $out ); + return ( xCAT::zvmUtils->trimStr( $out[1] ) ); } @@ -220,9 +223,9 @@ sub getMemory { =head3 getCpu - Description : Get processor of specified node - Arguments : Node name - Returns : Processor + Description : Get processor(s) of given node + Arguments : Node + Returns : Processor(s) Example : my $proc = xCAT::zvmCPUtils->getCpu($node); =cut @@ -244,9 +247,9 @@ sub getCpu { =head3 getNic - Description : Get network interface card (NIC) of specified node - Arguments : Node name - Returns : NIC + Description : Get network interface card (NIC) of given node + Arguments : Node + Returns : NIC(s) Example : my $nic = xCAT::zvmCPUtils->getNic($node); =cut @@ -260,6 +263,7 @@ sub getNic { # Get NIC my $out = `ssh -o ConnectTimeout=5 $node "vmcp q virtual nic"`; my $str = xCAT::zvmUtils->tabStr($out); + return ($str); } @@ -267,9 +271,9 @@ sub getNic { =head3 getDisks - Description : Get disk of specified node - Arguments : Node name - Returns : Disk + Description : Get disk(s) of given node + Arguments : Node + Returns : Disk(s) Example : my $storage = xCAT::zvmCPUtils->getDisks($node); =cut @@ -283,6 +287,7 @@ sub getDisks { # Get disks my $out = `ssh -o ConnectTimeout=5 $node "vmcp q virtual dasd"`; my $str = xCAT::zvmUtils->tabStr($out); + return ($str); } @@ -291,9 +296,9 @@ sub getDisks { =head3 loadVmcp Description : Load VMCP module on specified node - Arguments : Node name + Arguments : Node Returns : Nothing - Example : my $out = xCAT::zvmCPUtils->loadVmcp($node); + Example : xCAT::zvmCPUtils->loadVmcp($node); =cut @@ -312,8 +317,8 @@ sub loadVmcp { =head3 getVswitchId - Description : Get VSwitch ID of specified node - Arguments : Node name + Description : Get VSWITCH ID of given node + Arguments : Node Returns : VSwitch IDs Example : my @vswitch = xCAT::zvmCPUtils->getVswitchId($node); @@ -342,11 +347,11 @@ sub getVswitchId { =head3 grantVSwitch - Description : Grant access to VSwitch for specified userID - Arguments : zHCP node + Description : Grant access to virtual switch (VSWITCH) for given userID + Arguments : HCP node User ID - Vswitch ID - Returns : Output string + VSWITCH ID + Returns : Operation results (Done/Failed) Example : my $out = xCAT::zvmCPUtils->grantVswitch($callback, $hcp, $userId, $vswitchId); =cut @@ -361,29 +366,29 @@ sub grantVSwitch { my $out = `ssh $hcp "vmcp set vswitch $vswitchId grant $userId"`; $out = xCAT::zvmUtils->trimStr($out); - # If return string contains 'Command complete' + # 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; } - return ($retStr); + return $retStr; } #------------------------------------------------------- =head3 flashCopy - Description : Flash copy + Description : Flash copy (Class B users only) Arguments : Node Source address Target address - Returns : Output string - Example : my $out = xCAT::zvmCPUtils->flashCopy($node, $srcAddr, $targetAddr); + Returns : Operation results (Done/Failed) + Example : my $results = xCAT::zvmCPUtils->flashCopy($node, $srcAddr, $targetAddr); =cut @@ -397,42 +402,48 @@ sub flashCopy { my $out = `ssh $node "vmcp flashcopy $srcAddr 0 end to $targetAddr 0 end"`; $out = xCAT::zvmUtils->trimStr($out); - # If return string contains 'Command complete' - my $retStr; + # If return string contains 'Command complete' -- Operation was successful + my $retStr = ""; if ( $out =~ m/Command complete/i ) { - - # Done $retStr = "Done\n"; } else { $retStr = "Failed\n"; - return ($retStr); } - return ($retStr); + return $retStr; } #------------------------------------------------------- =head3 punch2Reader - Description : Write file to z/VM punch and transfer it to reader + Description : Write file to z/VM punch and transfer it to reader Arguments : HCP node UserID to receive file - File to transfer - File name and type to be created by punch (e.g. sles.parm) + 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 : Nothing - Example : my $rc = xCAT::zvmCPUtils->punch2Reader($hcp, $userId, $file, $fileName, $options); + Returns : Operation results (Done/Failed) + Example : my $rc = xCAT::zvmCPUtils->punch2Reader($hcp, $userId, $srcFile, $trgtFile, $options); =cut #------------------------------------------------------- sub punch2Reader { - my ( $class, $hcp, $userId, $file, $fileName, $options ) = @_; + my ( $class, $hcp, $userId, $srcFile, $trgtFile, $options ) = @_; # Punch to reader - my $out = `ssh -o ConnectTimeout=5 $hcp "vmur punch $options -u $userId -r $file -N $fileName"`; + 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; } @@ -453,7 +464,7 @@ sub punch2Reader { sub purgeReader { my ( $class, $hcp, $userId ) = @_; - # Punch to reader + # Purge reader my $out = `ssh -o ConnectTimeout=5 $hcp "vmcp purge $userId rdr all"`; return; @@ -467,7 +478,7 @@ sub purgeReader { Arguments : HCP node UserID to send CP command Returns : Nothing - Example : my $rc = xCAT::zvmCPUtils->sendCPCmd($hcp, $userId, $cmd); + Example : xCAT::zvmCPUtils->sendCPCmd($hcp, $userId, $cmd); =cut @@ -480,3 +491,126 @@ sub sendCPCmd { 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; +} diff --git a/perl-xCAT/xCAT/zvmUtils.pm b/perl-xCAT/xCAT/zvmUtils.pm index aa08d5eb8..7e9edbe3d 100644 --- a/perl-xCAT/xCAT/zvmUtils.pm +++ b/perl-xCAT/xCAT/zvmUtils.pm @@ -23,7 +23,7 @@ use warnings; Arguments : Table Node Properties - Returns : Properties from specifed table + Returns : Node properties from given table Example : my $propVals = xCAT::zvmUtils->getNodeProps($tabName, $node, $propNames); =cut @@ -34,23 +34,24 @@ sub getNodeProps { # Get inputs my ( $class, $tabName, $node, @propNames ) = @_; - # Get specified table + # Get table my $tab = xCAT::Table->new($tabName); - # Get value from column + # Get property values my $propVals = $tab->getNodeAttribs( $node, [@propNames] ); + return ($propVals); } #------------------------------------------------------- =head3 getTabPropsByKey - Description : Get node properties by key + Description : Get table entry properties by key Arguments : Table - Key + Key name Key value Requested properties - Returns : Properties from specifed table + Returns : Table entry properties Example : my $propVals = xCAT::zvmUtils->getTabPropsByKey($tabName, $key, $keyValue, @reqProps); =cut @@ -61,11 +62,11 @@ sub getTabPropsByKey { # Get inputs my ( $class, $tabName, $key, $keyVal, @propNames ) = @_; - # Get specified table + # Get table my $tab = xCAT::Table->new($tabName); my $propVals; - # Get table attributes matching specified key + # Get table attributes matching given key $propVals = $tab->getAttribs( { $key => $keyVal }, @propNames ); return ($propVals); } @@ -74,9 +75,9 @@ sub getTabPropsByKey { =head3 setNodeProp - Description : Set node property + Description : Set node property in a given table Arguments : Table - Node + Node Property Returns : Nothing Example : xCAT::zvmUtils->setNodeProp($tabName, $node, $propName, $propVal); @@ -89,7 +90,7 @@ sub setNodeProp { # Get inputs my ( $class, $tabName, $node, $propName, $propVal ) = @_; - # Get specified table + # Get table my $tab = xCAT::Table->new( $tabName, -create => 1, -autocommit => 0 ); # Set property @@ -105,11 +106,12 @@ sub setNodeProp { =head3 delTabEntry - Description : Delete node + Description : Delete a table entry Arguments : Table - Node + Key name + Key value Returns : Nothing - Example : xCAT::zvmUtils->delTabEntry($tabName, $node); + Example : xCAT::zvmUtils->delTabEntry($tabName, $keyName, $keyVal); =cut @@ -117,13 +119,13 @@ sub setNodeProp { sub delTabEntry { # Get inputs - my ( $class, $tabName, $node ) = @_; + my ( $class, $tabName, $keyName, $keyVal ) = @_; - # Get specified table + # Get table my $tab = xCAT::Table->new( $tabName, -create => 1, -autocommit => 0 ); - # Delete node from table - my %key = ( 'node' => $node ); + # Delete entry from table + my %key = ( $keyName => $keyVal ); $tab->delEntries( \%key ); # Save table @@ -163,7 +165,7 @@ sub tabStr { =head3 trimStr - Description : Trim whitespaces in string + Description : Trim whitespaces within a string Arguments : String Returns : Trimmed string Example : my $str = xCAT::zvmUtils->trimStr($str); @@ -189,9 +191,9 @@ sub trimStr { =head3 replaceStr - Description : Replace string + Description : Replace a given pattern within a string Arguments : String - Returns : Replaced string + Returns : String with given pattern replaced Example : my $str = xCAT::zvmUtils->replaceStr($str, $pattern, $replacement); =cut @@ -237,7 +239,7 @@ sub printLn { =head3 isZvmNode - Description : Check if a node is in the 'zvm' table + Description : Checks if a given node is in the 'zvm' table Arguments : Node Returns : TRUE Node exists FALSE Node does not exists @@ -259,9 +261,11 @@ sub isZvmNode { my @results = $tab->getAllAttribsWhere( "node like '%" . $node . "%'", 'userid' ); foreach (@results) { + + # Get userID $id = $_->{'userid'}; - # Get userID if one is not in the table + # Return 'TRUE' if given node is in the table if ($id) { return ('TRUE'); } @@ -274,9 +278,9 @@ sub isZvmNode { =head3 getIp - Description : Get IP address of given node + Description : Get the IP address of a given node Arguments : Node - Returns : IP address + Returns : IP address of given node Example : my $ip = xCAT::zvmUtils->getIp($node); =cut @@ -307,9 +311,45 @@ sub getIp { #------------------------------------------------------- +=head3 getHwcfg + + Description : Get hardware configuration file path of given node + SUSE -- /etc/sysconfig/hardware/hwcfg-qeth + 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::zvmCPUtils->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 getIfcfg - Description : Get network configuration file path for given node + Description : Get network configuration file path of given node Red Hat -- /etc/sysconfig/network-scripts/ifcfg-eth SUSE -- /etc/sysconfig/network/ifcfg-qeth Arguments : Node @@ -353,7 +393,7 @@ sub getIfcfg { =head3 getIfcfgByNic - Description : Get /etc/sysconfig/network/ifcfg-qeth file name for given NIC + Description : Get /etc/sysconfig/network/ifcfg-qeth file name of given NIC Arguments : Node NIC address Returns : /etc/sysconfig/network/ifcfg-qeth file name @@ -467,11 +507,12 @@ sub getGateway { =head3 sendFile - Description : SCP file to given node + Description : Send a file to a given node using SCP Arguments : Node - File + Source file + Target file Returns : Nothing - Example : my $out = xCAT::zvmUtils->sendFile($node, $file); + Example : xCAT::zvmUtils->sendFile($node, $srcFile, $trgtFile); =cut @@ -479,14 +520,13 @@ sub getGateway { sub sendFile { # Get inputs - my ( $class, $node, $file ) = @_; + my ( $class, $node, $srcFile, $trgtFile ) = @_; # Create destination string - my $dest = "root@"; - $dest .= $node; + my $dest = "root@" . $node; # SCP directory entry file over to HCP - my $out = `scp $file $dest:$file`; + my $out = `scp $srcFile $dest:$trgtFile`; return; } @@ -496,8 +536,8 @@ sub sendFile { =head3 getRootDiskAddr Description : Get root disk address of given node - Arguments : Node name - Returns : Root disk address + Arguments : Node name + Returns : Root disk address Example : my $deviceNode = xCAT::zvmUtils->getRootDiskAddr($node); =cut @@ -525,9 +565,9 @@ sub getRootDiskAddr { =head3 disableEnableDisk - Description : Disable or enable disk for given node + Description : Disable/enable a disk for given node Arguments : Device address - Option [-d | -e] + Option (-d|-e) Returns : Nothing Example : my $out = xCAT::zvmUtils->disableEnableDisk($callback, $node, $option, $devAddr); @@ -539,7 +579,7 @@ sub disableEnableDisk { # Get inputs my ( $class, $callback, $node, $option, $devAddr ) = @_; - # Disable or enable disk + # Disable/enable disk if ( $option eq "-d" || $option eq "-e" ) { my $out = `ssh $node "chccwdev $option $devAddr"`; } @@ -586,100 +626,25 @@ sub getMdisks { # Save MDISK statements push( @disks, $_ ); } + return (@disks); } #------------------------------------------------------- -=head3 readConfigFile +=head3 getUserEntryWODisk - Description : Read in configuration file + Description : Get user directory entry for given node + without MDISK statments, and save it to a file Arguments : Node - Configuration file - Returns : Hash arrary containing node configuration - Example : my %nodeConfig = xCAT::zvmUtils->readConfigFile($callback, $node, $file); - -=cut - -#------------------------------------------------------- -sub readConfigFile { - - # Get inputs - my ( $class, $callback, $node, $file ) = @_; - - # Hash array containing new node configuration - my %target; - - # Get configuration file - if ( !$file ) { - xCAT::zvmUtils->printLn( $callback, "Error: Missing configuration file" ); - return; - } - else { - - # Open configuration file - open( CONFIG, $file ) || die("Error: Could not open file"); - my @configFile = ; - close(CONFIG); - - # Read configuration file - my @parms; - my $pattern = $node . ":"; - my $save = 0; - foreach (@configFile) { - $_ = xCAT::zvmUtils->trimStr($_); - - # If the line contains specified node - if ( $_ =~ m/$pattern/i ) { - - # Save configuration - $save = 1; - - # Find ':' and replace with '' - $_ =~ s/://g; - $target{"Hostname"} = $_; - } - - # Stop saving at next line containing ':' - if ( $save == 1 && $_ =~ m/:/i ) { - $save = 0; - } - - # Save configuration - if ( $save == 1 ) { - - # Create hash array - @parms = split( "=", $_ ); - $target{"$parms[0]"} = "$parms[1]"; - } - - } # End of foreach - } # End of else - - # If there is not a new node configuration - if ( !$target{"Hostname"} ) { - xCAT::zvmUtils->printLn( $callback, "Error: Node configuration not found" ); - return; - } - - return %target; -} - -#------------------------------------------------------- - -=head3 saveDirEntryNoDisk - - Description : Get user directory entry for given node, - remove MDISK statments, and save it to a file - Arguments : Node name - File name + File name to save user entry under Returns : Nothing - Example : my $out = xCAT::zvmUtils->saveDirEntryNoDisk($callback, $node, $file); + Example : my $out = xCAT::zvmUtils->getUserEntryWODisk($callback, $node, $file); =cut #------------------------------------------------------- -sub saveDirEntryNoDisk { +sub getUserEntryWODisk { # Get inputs my ( $class, $callback, $node, $file ) = @_; @@ -729,7 +694,7 @@ sub saveDirEntryNoDisk { =head3 appendHostname - Description : Append specified hostname in front of given string + Description : Append specified hostname in front of a given string Arguments : Hostname String Returns : String with hostname in front @@ -753,18 +718,18 @@ sub appendHostname { #------------------------------------------------------- -=head3 isOutputGood +=head3 checkOutput Description : Check return of given output Arguments : Output string - Returns : 0 Good output + Returns : 0 Good output -1 Bad output - Example : my $ans = xCAT::zvmUtils->isOutputGood($callback, $out); + Example : my $ans = xCAT::zvmUtils->checkOutput($callback, $out); =cut #------------------------------------------------------- -sub isOutputGood { +sub checkOutput { my ( $class, $callback, $out ) = @_; # Check output string @@ -787,7 +752,7 @@ sub isOutputGood { Description : Check if given address is used Arguments : Node Disk address - Returns : 0 Address used + Returns : 0 Address used -1 Address not used Example : my $ans = xCAT::zvmUtils->isAddressUsed($node, $address); @@ -810,10 +775,10 @@ sub isAddressUsed { =head3 getMacID - Description : Get MACID from /opt/zhcp/conf/next_mac on HCP + Description : Get MACID from /opt/zhcp/conf/next_macid on HCP Arguments : HCP node Returns : MACID - Example : my $mac = xCAT::zvmUtils->getMacID($hcp); + Example : my $macId = xCAT::zvmUtils->getMacID($hcp); =cut @@ -825,166 +790,149 @@ sub getMacID { my $out = `ssh -o ConnectTimeout=5 $hcp "test -d /opt/zhcp/conf && echo 'Directory exists'"`; if ( $out =~ m/Directory exists/i ) { - # Read next_mac file - $out = `ssh -o ConnectTimeout=5 $hcp "cat /opt/zhcp/conf/next_mac"`; + # 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_mac"`; + $out = `ssh -o ConnectTimeout=5 $hcp "echo 'FFFFFF' > /opt/zhcp/conf/next_macid"`; } - # Create /opt/zhcp/conf/next_mac file on HCP - $out = `ssh -o ConnectTimeout=5 $hcp "cat /opt/zhcp/conf/next_mac"`; - my $mac = xCAT::zvmUtils->trimStr($out); + # 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 $mac; + return $macId; } #------------------------------------------------------- -=head3 generateMac +=head3 generateMacId - Description : Generate a MAC address - Arguments : HCP node - Returns : MAC suffix - Example : my $mac = xCAT::zvmUtils->generateMac($hcp); + Description : Generate a MACID + Arguments : HCP node + Returns : MACID + Example : my $macId = xCAT::zvmUtils->generateMacId($hcp); =cut #------------------------------------------------------- -sub generateMac { +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 ) { - # Read next_mac file - $out = `ssh -o ConnectTimeout=5 $hcp "cat /opt/zhcp/conf/next_mac"`; + # 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_mac"`; + $out = `ssh -o ConnectTimeout=5 $hcp "echo 'FFFFFF' > /opt/zhcp/conf/next_macid"`; } - # Read /opt/zhcp/conf/next_mac file - $out = `ssh -o ConnectTimeout=5 $hcp "cat /opt/zhcp/conf/next_mac"`; - my $mac = xCAT::zvmUtils->trimStr($out); + # 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 ($mac) { + if ($macId) { - # Convert hexadecimal to decimal - $int = hex($mac); - $mac = sprintf( "%d", $int ); + # Convert hexadecimal -- decimal + $int = hex($macId); + $macId = sprintf( "%d", $int ); # Generate new MAC suffix - $mac = $mac - 1; + $macId = $macId - 1; - # Convert decimal to hexadecimal - $mac = sprintf( "%X", $mac ); - $out = `ssh -o ConnectTimeout=5 $hcp "echo $mac > /opt/zhcp/conf/next_mac"`; + # Convert decimal -- hexadecimal + $macId = sprintf( "%X", $macId ); + + # Save new MACID + $out = `ssh -o ConnectTimeout=5 $hcp "echo $macId > /opt/zhcp/conf/next_macid"`; } - return $mac; - - # # Find the highest MAC address on given LAN - # my $newMac = 0; - # my $mac; - # my $temp; - # my $layer = -1; - # my @vars; - # my $out = `ssh -o ConnectTimeout=5 $hcp "vmcp --buffer 1000000 q lan $lanName details"`; - # my @outLn = split( "\n", $out ); - # - # # Go through each line - # foreach (@outLn) { - # - # # Get the MAC address for layer 3 LAN - # if ( $layer == 3 ) { - # @vars = split( " ", $_ ); - # $mac = $vars[2]; - # - # # Replace - with : - # $mac = xCAT::zvmUtils->replaceStr( $mac, "-", ":" ); - # - # # Convert to decimal - # if ($mac) { - # - # # Remove dash - # $temp = xCAT::zvmUtils->replaceStr( $mac, ":", "" ); - # - # $temp = hex($temp); - # $mac = sprintf( "%d", $temp ); - # } - # - # # Compare MAC address value to previous one - # # Save the highest MAC address - # if ( $mac > $newMac ) { - # $newMac = $mac; - # } - # - # $layer = -1; - # } - # - # # Get the MAC address for layer 2 LAN - # elsif ( $layer == 2 ) { - # @vars = split( " ", $_ ); - # $mac = $vars[0]; - # - # # Replace - with : - # $mac = xCAT::zvmUtils->replaceStr( $mac, "-", ":" ); - # - # # Convert to decimal - # if ($mac) { - # - # # Remove dash - # $temp = xCAT::zvmUtils->replaceStr( $mac, ":", "" ); - # - # $temp = hex($temp); - # $mac = sprintf( "%d", $temp ); - # } - # - # # Compare MAC address value to previous one - # # Save the highest MAC address - # if ( $mac > $newMac ) { - # $newMac = $mac; - # } - # - # $layer = -1; - # } - # - # # If the line contains 'Unicast IP/MAC Addresses' -- Then the next line contain a MAC address - # if ( $_ =~ m/Unicast IP Addresses/i ) { - # $layer = 3; - # } - # elsif ( $_ =~ m/ Unicast MAC Addresses/i ) { - # $layer = 2; - # } - # } - # - # # Convert the highest MAC address from decimal to hexadecimal - # $newMac = $newMac + 1; - # $newMac = sprintf( "%x", $newMac ); - # - # # Append a zero if length is less than 12 - # if ( length($newMac) != 12 ) { - # $newMac = "0" . $newMac; - # } - # - # $newMac = - # substr( $newMac, 0, 2 ) . ":" - # . substr( $newMac, 2, 2 ) . ":" - # . substr( $newMac, 4, 2 ) . ":" - # . substr( $newMac, 6, 2 ) . ":" - # . substr( $newMac, 8, 2 ) . ":" - # . substr( $newMac, 10, 2 ); - # - # return $newMac; + return $macId; +} + +#------------------------------------------------------- + +=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; } diff --git a/xCAT-server/lib/xcat/plugins/zvm.pm b/xCAT-server/lib/xcat/plugins/zvm.pm index b9aa24172..1e5627428 100644 --- a/xCAT-server/lib/xcat/plugins/zvm.pm +++ b/xCAT-server/lib/xcat/plugins/zvm.pm @@ -3,9 +3,8 @@ =head1 - xCAT plugin package to handle z/VM - Supported command: - zvm->zvm + xCAT plugin to support z/VM + =cut #------------------------------------------------------- @@ -21,7 +20,7 @@ use strict; # use warnings; -# If this line is not included, you get: +# If the following line is not included, you get: # /opt/xcat/lib/perl/xCAT_plugin/zvm.pm did not return a true value 1; @@ -126,9 +125,6 @@ sub process_request { my @nodes = @$nodes; my $host = hostname(); - # In order for any SSH command to be sent, you will need to run - # xdsh [group | node] -K - # Directory where executables are $::DIR = "/opt/zhcp/bin"; @@ -190,7 +186,7 @@ sub process_request { } # End of foreach } # End of case - # Creates zVM virtual server + # Creates virtual server elsif ( $command eq "mkvm" ) { foreach (@nodes) { @@ -233,7 +229,7 @@ sub process_request { } # End of foreach } # End of case - # Removes zVM virtual server + # Removes virtual server elsif ( $command eq "rmvm" ) { foreach (@nodes) { $pid = xCAT::Utils->xfork(); @@ -259,7 +255,7 @@ sub process_request { } # End of foreach } # End of case - # Lists zVM user directory entry + # Lists user directory entry elsif ( $command eq "lsvm" ) { foreach (@nodes) { $pid = xCAT::Utils->xfork(); @@ -285,7 +281,7 @@ sub process_request { } # End of foreach } # End of case - # Changes zVM user directory entry + # Changes user directory entry elsif ( $command eq "chvm" ) { foreach (@nodes) { $pid = xCAT::Utils->xfork(); @@ -401,7 +397,8 @@ sub process_request { =head3 removeVM - Description : Remove a virtual server + Description : Remove a virtual server + - This will delete the user entry from user directory Arguments : Node to remove Returns : Nothing Example : removeVM($callback, $node); @@ -436,13 +433,15 @@ sub removeVM { my $out = `ssh $hcp "$::DIR/stopvs $userId"`; xCAT::zvmUtils->printLn( $callback, "$out" ); - # Get device address of each MDISK + # Get MDISK statements my @disks = xCAT::zvmUtils->getMdisks( $callback, $node ); - my @parms; + my @vars; my $addr; foreach (@disks) { - @parms = split( ' ', $_ ); - $addr = $parms[1]; + + # Get device address of each MDISK + @vars = split( ' ', $_ ); + $addr = $vars[1]; # Remove MDISK # This cleans up the disks before it is put back in the pool @@ -451,25 +450,26 @@ sub removeVM { } # Sleep 5 seconds - # To let the z/VM user directory settle + # To let the z/VM user directory update sleep(5); - # Delete user directory entry + # Delete user entry $out = `ssh $hcp "$::DIR/deletevs $userId"`; xCAT::zvmUtils->printLn( $callback, "$out" ); # Check for errors - my $rc = xCAT::zvmUtils->isOutputGood( $callback, $out ); + my $rc = xCAT::zvmUtils->checkOutput( $callback, $out ); if ( $rc == -1 ) { return; } # Remove node from 'zvm', 'nodelist', 'nodetype', 'noderes', and 'nodehm' tables - xCAT::zvmUtils->delTabEntry( 'zvm', $node ); - xCAT::zvmUtils->delTabEntry( 'nodelist', $node ); - xCAT::zvmUtils->delTabEntry( 'nodetype', $node ); - xCAT::zvmUtils->delTabEntry( 'noderes', $node ); - xCAT::zvmUtils->delTabEntry( 'nodehm', $node ); + # Save node entry in 'mac' table + xCAT::zvmUtils->delTabEntry( 'zvm', 'node', $node ); + xCAT::zvmUtils->delTabEntry( 'nodelist', 'node', $node ); + xCAT::zvmUtils->delTabEntry( 'nodetype', 'node', $node ); + xCAT::zvmUtils->delTabEntry( 'noderes', 'node', $node ); + xCAT::zvmUtils->delTabEntry( 'nodehm', 'node', $node ); return; } @@ -478,27 +478,29 @@ sub removeVM { =head3 changeVM - Description : Changes server configuration + Description : Change a virtual server configuration Arguments : Node Option Options supported: - add3390 [disk pool] [device address] [mode] [cylinders] - add9336 [disk pool] [virtual device] [mode] [block size] [blocks] - addnic [address] [type] [device count] - addprocessor [address] - addvdisk [userID] [device address] [size] - connectnic2guestlan [address] [lan] [owner] - connectnic2vswitch [address] [vswitch] - dedicatedevice [virtual device] [real device] [mode] - deleteipl - disconnectnic [address] - removemdisk [virtual device] - removenic [address] - removeprocessor [address] - replacevs [file] - setipl [ipl target] [load parms] [parms] - setpassword [password] + add3390 [disk pool] [device address] [cylinders] [mode] [read password] [write password] [multi password] + add9336 [disk pool] [virtual device] [block size] [mode] [blocks] [read password] [write password] [multi password] + addnic [address] [type] [device count] + addprocessor [address] + addvdisk [userID] [device address] [size] + connectnic2guestlan [address] [lan] [owner] + connectnic2vswitch [address] [vswitch] + dedicatedevice [virtual device] [real device] [mode] + deleteipl + formatdisk [disk address] [multi password] + disconnectnic [address] + grantvswitch [VSwitch] + removedisk [virtual device] + removenic [address] + removeprocessor [address] + replacevs [user directory entry] + setipl [ipl target] [load parms] [parms] + setpassword [password] Returns : Nothing Example : changeVM($callback, $node, $args); @@ -542,7 +544,7 @@ sub changeVM { my $writePw = $args->[6]; my $multiPw = $args->[7]; - $out = `ssh $hcp "$::DIR/add3390 $userId $pool $addr $mode $cyl $readPw $writePw $multiPw"`; + $out = `ssh $hcp "$::DIR/add3390 $userId $pool $addr $cyl $mode $readPw $writePw $multiPw"`; } # add9336 [disk pool] [virtual device address] [block size] [blocks] [mode] [read password] [write password] [multi password] @@ -555,7 +557,7 @@ sub changeVM { my $readPw = $args->[6]; my $writePw = $args->[7]; my $multiPw = $args->[8]; - $out = `ssh $hcp "$::DIR/add9336 $userId $pool $addr $mode $blksize $blks $readPw $writePw $multiPw"`; + $out = `ssh $hcp "$::DIR/add9336 $userId $pool $addr $blksize $blks $mode $readPw $writePw $multiPw"`; } # addnic [address] [type] [device count] @@ -626,27 +628,28 @@ sub changeVM { my $lnkAddr = $addr + 1000; my $multiPw = $args->[2]; - # Check if there is an existing address (disk address) + # Check if new disk address is used my $rc = xCAT::zvmUtils->isAddressUsed( $hcp, $addr ); - # If there is an existing address + # If new disk address is used, generate new disk address while ( $rc == 0 ) { - # Generate a new address # Sleep 2 seconds to let existing disk appear sleep(2); $lnkAddr = $lnkAddr + 1; + + # Check again $rc = xCAT::zvmUtils->isAddressUsed( $hcp, $lnkAddr ); } # Load VMCP module on HCP - $out = xCAT::zvmCPUtils->loadVmcp($hcp); + xCAT::zvmCPUtils->loadVmcp($hcp); # Link target disk $out = `ssh -o ConnectTimeout=5 $hcp "vmcp link $userId $addr $lnkAddr MW $multiPw"`; # Check for errors - $rc = xCAT::zvmUtils->isOutputGood( $callback, $out ); + $rc = xCAT::zvmUtils->checkOutput( $callback, $out ); if ( $rc == -1 ) { xCAT::zvmUtils->printLn( $callback, "Linking disk... Failed" ); xCAT::zvmUtils->printLn( $callback, "$out" ); @@ -658,14 +661,14 @@ sub changeVM { # Determine device node $out = `ssh $hcp "cat /proc/dasd/devices" | grep ".$lnkAddr("`; - my @parms = split( ' ', $out ); - my $devNode = $parms[6]; + my @vars = split( ' ', $out ); + my $devNode = $vars[6]; # Format target disk (only ECKD supported) $out = `ssh $hcp "dasdfmt -b 4096 -y -f /dev/$devNode"`; # Check for errors - $rc = xCAT::zvmUtils->isOutputGood( $callback, $out ); + $rc = xCAT::zvmUtils->checkOutput( $callback, $out ); if ( $rc == -1 ) { xCAT::zvmUtils->printLn( $callback, "Formating disk... Failed" ); xCAT::zvmUtils->printLn( $callback, "$out" ); @@ -677,7 +680,7 @@ sub changeVM { $out = `ssh -o ConnectTimeout=5 $hcp "vmcp det $lnkAddr"`; # Check for errors - $rc = xCAT::zvmUtils->isOutputGood( $callback, $out ); + $rc = xCAT::zvmUtils->checkOutput( $callback, $out ); if ( $rc == -1 ) { xCAT::zvmUtils->printLn( $callback, "Detaching disk... Failed" ); xCAT::zvmUtils->printLn( $callback, "$out" ); @@ -697,7 +700,7 @@ sub changeVM { $out = `ssh -o ConnectTimeout=5 $hcp "vmcp det $lnkAddr"`; # Check for errors - $rc = xCAT::zvmUtils->isOutputGood( $callback, $out ); + $rc = xCAT::zvmUtils->checkOutput( $callback, $out ); if ( $rc == -1 ) { xCAT::zvmUtils->printLn( $callback, "Detaching disk... Failed" ); xCAT::zvmUtils->printLn( $callback, "$out" ); @@ -753,7 +756,7 @@ sub changeVM { $out = `ssh $hcp "$::DIR/replacevs $userId $file"`; } else { - $out = "Error: No directory entry file specified"; + $out = "Error: No user entry file specified"; xCAT::zvmUtils->printLn( $callback, "$out" ); return; } @@ -786,7 +789,7 @@ sub changeVM { =head3 powerVM - Description : Powers on/off a virtual server + Description : Power on/off a virtual server Arguments : Node Option [on|off|reset|stat] Returns : Nothing @@ -818,6 +821,7 @@ sub powerVM { return; } + # Output string my $out; # Power on virtual server @@ -865,7 +869,7 @@ sub powerVM { =head3 scanVM - Description : Collects node information from one or more hardware control points + Description : Collects node information from HCP Arguments : HCP node Returns : Nothing Example : scanVM($callback, $node, $args); @@ -921,7 +925,7 @@ sub scanVM { # Get nodes managed by this HCP # Look in 'zvm' table my $tab = xCAT::Table->new( 'zvm', -create => 1, -autocommit => 0 ); - my @results = $tab->getAllAttribsWhere( "hcp like '%" . $hcp . "%'", 'node', 'userid' ); + my @entries = $tab->getAllAttribsWhere( "hcp like '%" . $hcp . "%'", 'node', 'userid' ); my $out; my $managedNode; @@ -932,7 +936,7 @@ sub scanVM { # Search for nodes managed by specified HCP # Get 'node' and 'userid' properties - foreach (@results) { + foreach (@entries) { $managedNode = $_->{'node'}; # Get groups @@ -941,7 +945,7 @@ sub scanVM { $groups = $propVals->{'groups'}; # Load VMCP module - $out = xCAT::zvmCPUtils->loadVmcp($managedNode); + xCAT::zvmCPUtils->loadVmcp($managedNode); # Get userID $id = xCAT::zvmCPUtils->getUserId($managedNode); @@ -972,7 +976,8 @@ sub scanVM { =head3 inventoryVM Description : Get virtual server hardware and software inventory - Arguments : Node and arguments (config|all) + Arguments : Node + Type of inventory (config|all) Returns : Nothing Example : inventoryVM($callback, $node, $args); @@ -1006,7 +1011,7 @@ sub inventoryVM { my $str = ""; # Load VMCP module - my $out = xCAT::zvmCPUtils->loadVmcp($node); + xCAT::zvmCPUtils->loadVmcp($node); # Get configuration if ( $args->[0] eq 'config' ) { @@ -1093,7 +1098,7 @@ sub inventoryVM { =head3 listVM - Description : Get user directory entry + Description : Get user entry Arguments : Node Returns : Nothing Example : listVM($callback, $node); @@ -1136,8 +1141,8 @@ sub listVM { =head3 makeVM Description : Create a virtual server - - Unique MAC address is assigned to the virtual server - Arguments : Node + - This assigns a unique MAC address to the virtual server + Arguments : Node User entry text file Returns : Nothing Example : makeVM($callback, $node, $args); @@ -1147,11 +1152,6 @@ sub listVM { #------------------------------------------------------- sub makeVM { - # Before a virtual server can be created - # You need to add the virtual server into the tables: - # mkdef -t node -o gpok123 userid=linux123 hcp=gpok456.endicott.ibm.com mgt=zvm groups=all - # This will add the node into the 'nodelist', 'nodehm', and 'zvm' tables - # Get inputs my ( $callback, $node, $args ) = @_; @@ -1186,34 +1186,35 @@ sub makeVM { my @vars = split( ' ', $lines[0] ); # Get LAN name - my $lanName = $vars[6]; + my $netName = $vars[6]; # Get MAC address in 'mac' table + my $macId; + my $generateNew = 0; @propNames = ('mac'); $propVals = xCAT::zvmUtils->getNodeProps( 'mac', $node, @propNames ); - my $generateNew = 0; - my $suffix; if ($propVals) { - $suffix = $propVals->{'mac'}; - $suffix = xCAT::zvmUtils->replaceStr( $suffix, ":", "" ); - # Get MAC suffix - $suffix = substr( $suffix, 6 ); + # Get MAC suffix -- This is the MACID value + $macId = $propVals->{'mac'}; + $macId = xCAT::zvmUtils->replaceStr( $macId, ":", "" ); + $macId = substr( $macId, 6 ); } else { - # If no MAC suffix is found in 'mac' table, get new MAC suffix - $suffix = xCAT::zvmUtils->getMacID($hcp); - if ( !$suffix ) { + # If no MACID is found, get one + $macId = xCAT::zvmUtils->getMacID($hcp); + if ( !$macId ) { xCAT::zvmUtils->printLn( $callback, "Error: Could not generate MACID" ); return; } + # Set flag to generate new MACID after virtual server is created $generateNew = 1; } # Append MACID at the end of the NICDEF statement in user entry text file - $out = `sed --in-place -e "s,$lanName,$lanName MACID $suffix,g" $userEntry`; + $out = `sed --in-place -e "s,$netName,$netName MACID $macId,g" $userEntry`; # SCP file over to HCP $out = `scp $userEntry $nodeStr:$userEntry`; @@ -1223,21 +1224,23 @@ sub makeVM { xCAT::zvmUtils->printLn( $callback, "$out" ); # Check output - my $rc = xCAT::zvmUtils->isOutputGood( $callback, $out ); + my $rc = xCAT::zvmUtils->checkOutput( $callback, $out ); if ( $rc == 0 ) { # Get HCP MAC address - $out = `ssh -o ConnectTimeout=5 $hcp "vmcp q nic" | grep $lanName`; - my @lines = split( "\n", $out ); - my @vars = split( " ", $lines[0] ); + $out = `ssh -o ConnectTimeout=5 $hcp "vmcp q nic" | grep $netName`; + @lines = split( "\n", $out ); + @vars = split( " ", $lines[0] ); + + # Extract MAC prefix my $prefix = $vars[1]; $prefix = xCAT::zvmUtils->replaceStr( $prefix, "-", "" ); $prefix = substr( $prefix, 0, 6 ); # Generate MAC address - my $mac = $prefix . $suffix; + my $mac = $prefix . $macId; - # Append a zero if length is less than 12 + # If length is less than 12, append a zero if ( length($mac) != 12 ) { $mac = "0" . $mac; } @@ -1253,9 +1256,9 @@ sub makeVM { # Save MAC address in 'mac' table xCAT::zvmUtils->setNodeProp( 'mac', $node, 'mac', $mac ); - # Generate new MAC suffix - if ( $generateNew == 1 ) { - $mac = xCAT::zvmUtils->generateMac($hcp); + # Generate new MACID + if ( $generateNew == 1 ) { + $mac = xCAT::zvmUtils->generateMacId($hcp); } } } @@ -1267,7 +1270,6 @@ sub makeVM { } return; - } #------------------------------------------------------- @@ -1275,7 +1277,9 @@ sub makeVM { =head3 cloneVM Description : Clone a virtual server - Arguments : Node and configuration + Arguments : Node + Disk pool + Multi password Returns : Nothing Example : cloneVM($callback, $targetNode, $args); @@ -1284,11 +1288,6 @@ sub makeVM { #------------------------------------------------------- sub cloneVM { - # Before a virtual server can be created - # You need to add the virtual server into the tables: - # mkdef -t node -o gpok123 userid=LINUX123 ip=9.60.18.123 hcp=gpok456.endicott.ibm.com mgt=zvm groups=all - # This will add the node into the 'nodelist', 'nodehm', 'zvm', and 'hosts' tables - # Get inputs my ( $callback, $targetNode, $args ) = @_; @@ -1349,25 +1348,25 @@ sub cloneVM { # Get target IP from /etc/hosts my $out = `cat /etc/hosts | grep $targetNode`; - my @parms = split( ' ', $out ); - my $targetIp = $parms[0]; + my @lines = split( '\n', $out ); + my @vars = split( ' ', $lines[0] ); + my $targetIp = $vars[0]; if ( !$targetIp ) { xCAT::zvmUtils->printLn( $callback, "Error: Missing IP for $targetNode in /etc/hosts" ); return; } - # Get other inputs (2 in total) - # Disk pool and multi password + # Get disk pool and multi password my $i; my %inputs; foreach $i ( 1 .. 2 ) { if ( $args->[$i] ) { # Split parameters by '=' - @parms = split( "=", $args->[$i] ); + @vars = split( "=", $args->[$i] ); # Create hash array - $inputs{ $parms[0] } = $parms[1]; + $inputs{ $vars[0] } = $vars[1]; } } @@ -1378,7 +1377,7 @@ sub cloneVM { return; } - # Get read, write, and multi password + # Get multi password my $trgtPw = $inputs{"pw"}; if ( !$trgtPw ) { xCAT::zvmUtils->printLn( $callback, "Error: Missing read/write/multi password" ); @@ -1388,49 +1387,149 @@ sub cloneVM { # Get MDisk statements of source node my @srcDisks = xCAT::zvmUtils->getMdisks( $callback, $sourceNode ); - # Get directory entry of source node - # Save user directory entry as /tmp/userEntry.txt - my $dirFile = "/tmp/dirEntry.txt"; - $out = xCAT::zvmUtils->saveDirEntryNoDisk( $callback, $sourceNode, $dirFile ); + # Get user entry of source node + # Save user directory entry as /tmp/node.txt + my $userEntry = "/tmp/$targetNode.txt"; + $out = `rm $userEntry`; # Remove existing user entry if any + $out = xCAT::zvmUtils->getUserEntryWODisk( $callback, $sourceNode, $userEntry ); + + # Replace source userID with target userID + $out = `sed --in-place -e "s,$sourceId,$targetUserId,g" $userEntry`; + + # Get MAC address in 'mac' table + my $targetMac; + my $macId; + my $generateNew = 0; # Flag to generate new MACID + @propNames = ('mac'); + $propVals = xCAT::zvmUtils->getNodeProps( 'mac', $targetNode, @propNames ); + if ($propVals) { + + # Get MACID + $targetMac = $propVals->{'mac'}; + $macId = $propVals->{'mac'}; + $macId = xCAT::zvmUtils->replaceStr( $macId, ":", "" ); + $macId = substr( $macId, 6 ); + } + else { + + # If no MACID is found, get one + $macId = xCAT::zvmUtils->getMacID($hcp); + if ( !$macId ) { + xCAT::zvmUtils->printLn( $callback, "Error: Could not generate MACID" ); + return; + } + + # Create MAC address for target node + $targetMac = xCAT::zvmUtils->createMacAddr( $targetNode, $macId ); + + # Set flag to generate new MACID after virtual server is created + $generateNew = 1; + } + + # Open user entry and find MACID + $out = `cat $userEntry | grep "NICDEF"`; + @lines = split( '\n', $out ); + if ( @lines < 1 ) { + xCAT::zvmUtils->printLn( $callback, "Error: No NICDEF statement found in user entry" ); + return; + } + + my $foundMacId = 0; + my $targetMacId; + my $netName; + + # Go through each NICDEF line + foreach (@lines) { + + # Go through every parameter + @vars = split( ' ', $_ ); + + # Get LAN name + $netName = $vars[6]; + foreach (@vars) { + + # If MACID declaration found, get MACID value + if ( $foundMacId == 1 ) { + $targetMacId = $_; + $foundMacId = 0; + } + + # Find MACID declaration + if ( $_ =~ m/MACID/i ) { + $foundMacId = 1; + } + } # End of foreach (@vars) + + # If MACID is found, generate a new MACID + if ($targetMacId) { + + $out = `sed --in-place -e "s,$targetMacId,$macId,g" $userEntry`; + last; + } # End of if ($targetMacId) + } # End of foreach (@lines) # SCP directory entry file over to HCP - $out = xCAT::zvmUtils->sendFile( $hcp, $dirFile ); + xCAT::zvmUtils->sendFile( $hcp, $userEntry, $userEntry ); # Create new virtual server + my $try = 0; + $rc = -1; xCAT::zvmUtils->printLn( $callback, "$targetNode: Creating user directory entry" ); - $out = `ssh $hcp "$::DIR/createvs $targetUserId $dirFile"`; + while ( ( $rc == -1 ) && ( $try < 5 ) ) { - # Check for errors - $rc = xCAT::zvmUtils->isOutputGood( $callback, $out ); + # Create new virtual server + $out = `ssh $hcp "$::DIR/createvs $targetUserId $userEntry"`; + $rc = xCAT::zvmUtils->checkOutput( $callback, $out ); + + # Exit loop on good return + if ( $rc == 0 ) { + last; + } + + # Try again to create virtual server + $try = $try + 1; + sleep(4); + } + + # Exit on bad output if ( $rc == -1 ) { - - # Exit on bad output xCAT::zvmUtils->printLn( $callback, "$out" ); return; } + # Save MAC address in 'mac' table + xCAT::zvmUtils->setNodeProp( 'mac', $targetNode, 'mac', $targetMac ); + + # Generate new MACID + if ( $generateNew == 1 ) { + $out = xCAT::zvmUtils->generateMacId($hcp); + } + # Load VMCP module on HCP and source node - $out = xCAT::zvmCPUtils->loadVmcp($hcp); - $out = xCAT::zvmCPUtils->loadVmcp($sourceNode); + xCAT::zvmCPUtils->loadVmcp($hcp); + xCAT::zvmCPUtils->loadVmcp($sourceNode); # Get VSwitch of master node my @vswitchId = xCAT::zvmCPUtils->getVswitchId($sourceNode); # Grant access to VSwitch for Linux user # GuestLan do not need permissions - xCAT::zvmUtils->printLn( $callback, "$targetNode: Granting VSwitch access" ); - foreach (@vswitchId) { - $out = xCAT::zvmCPUtils->grantVSwitch( $callback, $hcp, $targetUserId, $_ ); + my $netType = xCAT::zvmCPUtils->getNetworkType( $hcp, $netName ); + if ( $netType eq "VSWITCH" ) { + xCAT::zvmUtils->printLn( $callback, "$targetNode: Granting VSwitch access" ); + foreach (@vswitchId) { + $out = xCAT::zvmCPUtils->grantVSwitch( $callback, $hcp, $targetUserId, $_ ); - # Check for errors - $rc = xCAT::zvmUtils->isOutputGood( $callback, $out ); - if ( $rc == -1 ) { + # Check for errors + $rc = xCAT::zvmUtils->checkOutput( $callback, $out ); + if ( $rc == -1 ) { - # Exit on bad output - xCAT::zvmUtils->printLn( $callback, "$out" ); - return; - } - } + # Exit on bad output + xCAT::zvmUtils->printLn( $callback, "$out" ); + return; + } + } # End of foreach (@vswitchId) + } # End of if ( $netType eq "VSWITCH" ) # Add MDisk to target user directory entry my @trgtDisks; @@ -1441,32 +1540,44 @@ sub cloneVM { my $srcMultiPw; foreach (@srcDisks) { - # Get disk device address - @parms = split( ' ', $_ ); - $addr = $parms[1]; + # Get disk address + @vars = split( ' ', $_ ); + $addr = $vars[1]; push( @trgtDisks, $addr ); - $type = $parms[2]; - $mode = $parms[6]; - $srcMultiPw = $parms[9]; + $type = $vars[2]; + $mode = $vars[6]; + $srcMultiPw = $vars[9]; # Add ECKD disk if ( $type eq '3390' ) { # Get disk size (cylinders) - $out = `ssh -o ConnectTimeout=5 $sourceNode "vmcp q v dasd" | grep "DASD $addr"`; - @parms = split( ' ', $out ); - $cyl = xCAT::zvmUtils->trimStr( $parms[5] ); + $out = `ssh -o ConnectTimeout=5 $sourceNode "vmcp q v dasd" | grep "DASD $addr"`; + @vars = split( ' ', $out ); + $cyl = xCAT::zvmUtils->trimStr( $vars[5] ); - # Add disk xCAT::zvmUtils->printLn( $callback, "$targetNode: Adding minidisk" ); - $out = `ssh $hcp "$::DIR/add3390 $targetUserId $pool $addr $mode $cyl $trgtPw $trgtPw $trgtPw"`; + $try = 0; + $rc = -1; + while ( ( $rc == -1 ) && ( $try < 5 ) ) { - # Check for errors - $rc = xCAT::zvmUtils->isOutputGood( $callback, $out ); + # Add ECKD disk + $out = `ssh $hcp "$::DIR/add3390 $targetUserId $pool $addr $cyl $mode $trgtPw $trgtPw $trgtPw"`; + $rc = xCAT::zvmUtils->checkOutput( $callback, $out ); + + # Exit loop on good return + if ( $rc == 0 ) { + last; + } + + # Try again to add ECKD disk + $try = $try + 1; + sleep(4); + } + + # Exit on bad output if ( $rc == -1 ) { xCAT::zvmUtils->printLn( $callback, "$out" ); - - # Exit on bad output return; } } @@ -1487,29 +1598,31 @@ sub cloneVM { my $sourceDevNode; my $targetDevNode; foreach (@trgtDisks) { + + # New disk address $srcAddr = $_ + 1000; $targetAddr = $_ + 2000; - # Check if there is an existing address (source address) + # Check if new disk address is used (source) $rc = xCAT::zvmUtils->isAddressUsed( $hcp, $srcAddr ); - # If there is an existing address (source address) + # If disk address is used, generate a new one (source) while ( $rc == 0 ) { - # Generate a new address + # Generate a new disk address # Sleep 2 seconds to let existing disk appear sleep(2); $srcAddr = $srcAddr + 1; $rc = xCAT::zvmUtils->isAddressUsed( $hcp, $srcAddr ); } - # Check if there is an existing address (target address) + # Check if new disk address is used (target) $rc = xCAT::zvmUtils->isAddressUsed( $hcp, $targetAddr ); - # If there is an existing address + # If disk address is used, generate a new one (target) while ( $rc == 0 ) { - # Generate a new address + # Generate a new disk address # Sleep 2 seconds to let existing disk appear sleep(2); $targetAddr = $targetAddr + 1; @@ -1520,7 +1633,7 @@ sub cloneVM { $out = `ssh -o ConnectTimeout=5 $hcp "vmcp link $sourceId $_ $srcAddr MW $srcMultiPw"`; # Check for errors - $rc = xCAT::zvmUtils->isOutputGood( $callback, $out ); + $rc = xCAT::zvmUtils->checkOutput( $callback, $out ); if ( $rc == -1 ) { xCAT::zvmUtils->printLn( $callback, "$out" ); return; @@ -1530,7 +1643,7 @@ sub cloneVM { $out = `ssh -o ConnectTimeout=5 $hcp "vmcp link $targetUserId $_ $targetAddr MW $trgtPw"`; # Check for errors - $rc = xCAT::zvmUtils->isOutputGood( $callback, $out ); + $rc = xCAT::zvmUtils->checkOutput( $callback, $out ); if ( $rc == -1 ) { xCAT::zvmUtils->printLn( $callback, "$out" ); return; @@ -1541,10 +1654,10 @@ sub cloneVM { $out = xCAT::zvmCPUtils->flashCopy( $hcp, $srcAddr, $targetAddr ); # Check for errors - $rc = xCAT::zvmUtils->isOutputGood( $callback, $out ); + $rc = xCAT::zvmUtils->checkOutput( $callback, $out ); if ( $rc == -1 ) { - # FLASHCOPY is not supported + # FLASHCOPY is not supported -- use Linux DD xCAT::zvmUtils->printLn( $callback, "$targetNode: FLASHCOPY not supported. Using Linux DD" ); # Enable source disk @@ -1555,23 +1668,21 @@ sub cloneVM { # Determine source device node $out = `ssh $hcp "cat /proc/dasd/devices" | grep ".$srcAddr("`; - @parms = split( ' ', $out ); - $sourceDevNode = $parms[6]; + @vars = split( ' ', $out ); + $sourceDevNode = $vars[6]; # Determine target device node $out = `ssh $hcp "cat /proc/dasd/devices" | grep ".$targetAddr("`; - @parms = split( ' ', $out ); - $targetDevNode = $parms[6]; + @vars = split( ' ', $out ); + $targetDevNode = $vars[6]; # Format target disk xCAT::zvmUtils->printLn( $callback, "$targetNode: Formating disk" ); $out = `ssh $hcp "dasdfmt -b 4096 -y -f /dev/$targetDevNode"`; # Check for errors - $rc = xCAT::zvmUtils->isOutputGood( $callback, $out ); + $rc = xCAT::zvmUtils->checkOutput( $callback, $out ); if ( $rc == -1 ) { - - # Exit on bad output xCAT::zvmUtils->printLn( $callback, "$out" ); return; } @@ -1584,7 +1695,7 @@ sub cloneVM { $out = `ssh $hcp "dd if=/dev/$sourceDevNode of=/dev/$targetDevNode bs=4096"`; # Check for error - $rc = xCAT::zvmUtils->isOutputGood( $callback, $out ); + $rc = xCAT::zvmUtils->checkOutput( $callback, $out ); if ( $rc == -1 ) { xCAT::zvmUtils->printLn( $callback, "$out" ); return; @@ -1600,8 +1711,8 @@ sub cloneVM { # Determine target device node (it might have changed) $out = `ssh $hcp "cat /proc/dasd/devices" | grep ".$targetAddr("`; - @parms = split( ' ', $out ); - $targetDevNode = $parms[6]; + @vars = split( ' ', $out ); + $targetDevNode = $vars[6]; # Get disk address that is the root partition my $rootPartitionAddr = xCAT::zvmUtils->getRootDiskAddr($sourceNode); @@ -1620,18 +1731,14 @@ sub cloneVM { $out = `ssh $hcp sed --in-place -e "s/$sourceNode/$targetNode/g" $cloneMntPt/etc/HOSTNAME`; # If Red Hat -- Set hostname in /etc/sysconfig/network - $out = xCAT::zvmCPUtils->getOs($sourceNode); - if ( $out =~ m/Red Hat/i ) { + my $os = xCAT::zvmCPUtils->getOs($sourceNode); + if ( $os =~ m/Red Hat/i ) { $out = `ssh $hcp sed --in-place -e "s/$sourceNode/$targetNode/g" $cloneMntPt/etc/sysconfig/network`; } - # Set /etc/resolve.conf (If necessary) - # Set IP address my $sourceIp = xCAT::zvmUtils->getIp($sourceNode); - # Set MAC address for Layer 2 (If necessary) - # Get network configuration file # Location of this file depends on the OS my $ifcfg = xCAT::zvmUtils->getIfcfg($sourceNode); @@ -1641,6 +1748,61 @@ sub cloneVM { `ssh $hcp sed --in-place -e "s/$sourceNode/$targetNode/g" \ -e "s/$sourceIp/$targetIp/g" $cloneMntPt/etc/hosts`; $out = `ssh $hcp sed --in-place -e "s/$sourceIp/$targetIp/g" \ -e "s/$sourceNode/$targetNode/g" $ifcfgPath`; + # Set MAC address (If necessary) + # Remove LLADDR and UNIQUE parameters and append with correct values + $out = `ssh $hcp "cat $ifcfgPath" | grep -v "LLADDR" | grep -v "UNIQUE" > /tmp/network_config`; + $out = `echo "LLADDR='$targetMac'" >> /tmp/network_config`; + $out = `echo "UNIQUE=''" >> /tmp/network_config`; + xCAT::zvmUtils->sendFile( $hcp, "/tmp/network_config", $ifcfgPath ); + + # Set to hardware configuration -- Only for layer 2 + my $layer = xCAT::zvmCPUtils->getNetworkLayer($sourceNode); + if ( $layer == 2 ) { + if ( $os =~ m/Red Hat/i ) { + my $srcMac; + + # Get source MAC address in 'mac' table + @propNames = ('mac'); + $propVals = xCAT::zvmUtils->getNodeProps( 'mac', $sourceNode, @propNames ); + if ($propVals) { + + # Get MAC address + $srcMac = $propVals->{'mac'}; + } + else { + xCAT::zvmUtils->printLn( $callback, "$targetNode: Could not find MAC address of $sourceNode" ); + + # Unmount disk + $out = `ssh $hcp "umount $cloneMntPt"`; + + # Disable disks + $out = xCAT::zvmUtils->disableEnableDisk( $callback, $hcp, "-d", $srcAddr ); + $out = xCAT::zvmUtils->disableEnableDisk( $callback, $hcp, "-d", $targetAddr ); + + # Detatch disks from HCP + $out = `ssh $hcp "vmcp det $srcAddr"`; + $out = `ssh $hcp "vmcp det $targetAddr"`; + + return; + } + + # Set MAC address + $out = `ssh $hcp sed --in-place -e "s/$srcMac/$targetMac/g" $ifcfgPath`; + } + else { + + # Get hardware configuration + my $hwcfg = xCAT::zvmUtils->getHwcfg($sourceNode); + my $hwcfgPath = $cloneMntPt; + + # Set layer 2 support + $hwcfgPath .= $hwcfg; + $out = `ssh $hcp "cat $hwcfgPath" | grep -v "QETH_LAYER2_SUPPORT" > /tmp/hardware_config`; + $out = `echo "QETH_LAYER2_SUPPORT='1'" >> /tmp/hardware_config`; + xCAT::zvmUtils->sendFile( $hcp, "/tmp/hardware_config", $hwcfgPath ); + } + } # End of if ( $layer == 2 ) + # Flush disk $out = `ssh $hcp "sync"`; @@ -1657,21 +1819,21 @@ sub cloneVM { $out = `ssh $hcp "vmcp det $targetAddr"`; } + # Add node to DHCP + $out = `makedhcp -a`; + # Power on target virtual server xCAT::zvmUtils->printLn( $callback, "$targetNode: Powering on" ); $out = `ssh $hcp "$::DIR/startvs $targetUserId"`; # Check for error - $rc = xCAT::zvmUtils->isOutputGood( $callback, $out ); + $rc = xCAT::zvmUtils->checkOutput( $callback, $out ); if ( $rc == -1 ) { - - # Exit on bad output xCAT::zvmUtils->printLn( $callback, "$out" ); return; } xCAT::zvmUtils->printLn( $callback, "$targetNode: Done" ); - return; } @@ -1682,7 +1844,7 @@ sub cloneVM { Description : Set the boot state for a noderange - Installs zLinux - Layer 2 and 3 VSwitch/Lan supported - - The 1st NICDEF in the user entry will be used + - Uses 1st NICDEF in the user entry Arguments : Node Returns : Nothing Example : nodeSet($callback, $node, $args); @@ -1747,9 +1909,9 @@ sub nodeSet { # Get host IP and hostname from /etc/hosts my $out = `cat /etc/hosts | grep $node`; - my @parms = split( ' ', $out ); - my $hostIP = $parms[0]; - my $hostname = $parms[1]; + my @vars = split( ' ', $out ); + my $hostIP = $vars[0]; + my $hostname = $vars[1]; if ( !$hostIP || !$hostname ) { xCAT::zvmUtils->printLn( $callback, "Error: Missing IP for $node in /etc/hosts" ); return; @@ -1764,20 +1926,20 @@ sub nodeSet { # Grab first NICDEF address my @lines = split( '\n', $out ); - @parms = split( ' ', $lines[0] ); - my $readChannel = "0.0.0" . ( $parms[1] + 0 ); - my $writeChannel = "0.0.0" . ( $parms[1] + 1 ); - my $dataChannel = "0.0.0" . ( $parms[1] + 2 ); + @vars = split( ' ', $lines[0] ); + my $readChannel = "0.0.0" . ( $vars[1] + 0 ); + my $writeChannel = "0.0.0" . ( $vars[1] + 1 ); + my $dataChannel = "0.0.0" . ( $vars[1] + 2 ); # Get network type (Layer 2 or 3) - my $lanName = $parms[6]; - $out = `ssh $hcp "vmcp q lan $lanName"`; + my $netName = $vars[6]; + $out = `ssh $hcp "vmcp q lan $netName"`; if ( !$out ) { xCAT::zvmUtils->printLn( $callback, "Error: Missing NICDEF statement in user entry of node" ); return; } - # Go through each line and search for ETHERNET -- Which means layer 2 + # Go through each line my $layer = 3; # Default to layer 3 @lines = split( '\n', $out ); foreach (@lines) { @@ -1788,7 +1950,7 @@ sub nodeSet { } } - # Get MAC address -- Only for layer 2 LAN + # Get MAC address -- Only for layer 2 my $mac = ""; my @propNames; my $propVals; @@ -1799,9 +1961,11 @@ sub nodeSet { $propVals = xCAT::zvmUtils->getTabPropsByKey( 'mac', 'node', $node, @propNames ); $mac = $propVals->{'mac'}; - # If no MAC address is found, generate a new one + # If no MAC address is found, exit + # MAC address should have been assigned to the node upon creation if ( !$mac ) { - $mac = xCAT::zvmUtils->generateMac($hcp); + xCAT::zvmUtils->printLn( $callback, "Error: Missing MAC address of node" ); + return; } } @@ -1828,16 +1992,15 @@ sub nodeSet { # Get broadcast address of NIC my $ifcfg = xCAT::zvmUtils->getIfcfgByNic( $hcp, $readChannel ); $out = `cat $ifcfg | grep "BROADCAST"`; - @parms = split( '=', $out ); - my $broadcast = $parms[1]; + @vars = split( '=', $out ); + my $broadcast = $vars[1]; $broadcast = xCAT::zvmUtils->trimStr($broadcast); $broadcast = xCAT::zvmUtils->replaceStr( $broadcast, "'", "" ); # Load VMCP module on HCP - $out = xCAT::zvmCPUtils->loadVmcp($hcp); + xCAT::zvmCPUtils->loadVmcp($hcp); - # Sample paramter file exists in installation CD - # Use that as a guide + # Sample paramter file exists in installation CD -- Use that as a guide my $sampleParm; my $parmHeader; my $parms; @@ -1870,8 +2033,9 @@ sub nodeSet { # Edit template my $device = "qeth-bus-ccw-$readChannel"; my $chanIds = "$readChannel $writeChannel $dataChannel"; + $out = -`sed --in-place -e "s,replace_host_address,$hostIP,g" \ -e "s,replace_long_name,$hostname,g" \ -e "s,replace_short_name,$node,g" \ -e "s,replace_domain,$domain,g" \ -e "s,replace_hostname,$node,g" \ -e "s,replace_nameserver,$node,g" \ -e "s,replace_broadcast,$broadcast,g" \ -e "s,replace_device,$device,g" \ -e "s,replace_ipaddr,$hostIP,g" \ -e "s,replace_lladdr,$mac,g" \ -e "s,replace_netmask,$mask,g" \ -e "s,replace_network,$network,g" \ -e "s,replace_ccw_chan_ids,$chanIds,g" \ -e "s,replace_ccw_chan_mode,FOOBAR,g" \ -e "s,replace_gateway,$gateway,g" \ -e "s,replace_root_password,rootpw,g" $template`; +`sed --in-place -e "s,replace_host_address,$hostIP,g" \ -e "s,replace_long_name,$hostname,g" \ -e "s,replace_short_name,$node,g" \ -e "s,replace_domain,$domain,g" \ -e "s,replace_hostname,$node,g" \ -e "s,replace_nameserver,$nameserver,g" \ -e "s,replace_broadcast,$broadcast,g" \ -e "s,replace_device,$device,g" \ -e "s,replace_ipaddr,$hostIP,g" \ -e "s,replace_lladdr,$mac,g" \ -e "s,replace_netmask,$mask,g" \ -e "s,replace_network,$network,g" \ -e "s,replace_ccw_chan_ids,$chanIds,g" \ -e "s,replace_ccw_chan_mode,FOOBAR,g" \ -e "s,replace_gateway,$gateway,g" \ -e "s,replace_root_password,rootpw,g" $template`; # Read sample parmfile in /install/sles10.2/s390x/1/boot/s390x/ $sampleParm = "/install/$distr/s390x/1/boot/s390x/parmfile"; @@ -1895,7 +2059,7 @@ sub nodeSet { # ramdisk_size=65536 root=/dev/ram1 ro init=/linuxrc TERM=dumb # HostIP=10.0.0.5 Hostname=gpok5.endicott.ibm.com # Gateway=10.0.0.1 Netmask=255.255.255.0 - # Broadcast=10.0.0.0 Layer2=1 OSAHWaddr=02:00:01:00:00:05 + # Broadcast=10.0.0.0 Layer2=0 # ReadChannel=0.0.0800 WriteChannel=0.0.0801 DataChannel=0.0.0802 # Nameserver=9.0.2.11 Portname=OSAPORT # Install=ftp://10.0.0.1/sles10.2/s390x/1/ @@ -1931,9 +2095,9 @@ sub nodeSet { # Send kernel, parmfile, and initrd to reader to HCP $out = `cp /install/$distr/s390x/1/boot/s390x/vmrdr.ikr /tmp/kernel`; $out = `cp /install/$distr/s390x/1/boot/s390x/initrd /tmp/initrd`; - $out = xCAT::zvmUtils->sendFile( $hcp, "/tmp/kernel" ); - $out = xCAT::zvmUtils->sendFile( $hcp, "/tmp/parm" ); - $out = xCAT::zvmUtils->sendFile( $hcp, "/tmp/initrd" ); + xCAT::zvmUtils->sendFile( $hcp, "/tmp/kernel", "/tmp/kernel" ); + xCAT::zvmUtils->sendFile( $hcp, "/tmp/parm", "/tmp/parm" ); + xCAT::zvmUtils->sendFile( $hcp, "/tmp/initrd", "/tmp/initrd" ); # Set the virtual unit record devices online on HCP $out = xCAT::zvmUtils->disableEnableDisk( $callback, $hcp, "-e", "c" ); @@ -1945,33 +2109,24 @@ sub nodeSet { # Punch kernel to reader on HCP $out = xCAT::zvmCPUtils->punch2Reader( $hcp, $userId, "/tmp/kernel", "sles.kernel", "" ); - if ( !( $out =~ m/$searchStr/i ) ) { - xCAT::zvmUtils->printLn( $callback, "$node: Punching kernel to reader... Failed" ); + xCAT::zvmUtils->printLn( $callback, "$node: Punching kernel to reader... $out" ); + if ( $out =~ m/Failed/i ) { return; } - else { - xCAT::zvmUtils->printLn( $callback, "$node: Punching kernel to reader... Done" ); - } # Punch parm to reader on HCP $out = xCAT::zvmCPUtils->punch2Reader( $hcp, $userId, "/tmp/parm", "sles.parm", "-t" ); - if ( !( $out =~ m/$searchStr/i ) ) { - xCAT::zvmUtils->printLn( $callback, "$node: Punching parm to reader... Failed" ); + xCAT::zvmUtils->printLn( $callback, "$node: Punching parm to reader... $out" ); + if ( $out =~ m/Failed/i ) { return; } - else { - xCAT::zvmUtils->printLn( $callback, "$node: Punching parm to reader... Done" ); - } # Punch initrd to reader on HCP $out = xCAT::zvmCPUtils->punch2Reader( $hcp, $userId, "/tmp/initrd", "sles.initrd", "" ); - if ( !( $out =~ m/$searchStr/i ) ) { - xCAT::zvmUtils->printLn( $callback, "$node: Punching initrd to reader... Failed" ); + xCAT::zvmUtils->printLn( $callback, "$node: Punching initrd to reader... $out" ); + if ( $out =~ m/Failed/i ) { return; } - else { - xCAT::zvmUtils->printLn( $callback, "$node: Punching initrd to reader... Done" ); - } } # RHEL installation @@ -2010,15 +2165,15 @@ sub nodeSet { my $dasd = ""; my $i = 0; foreach (@mdisks) { - $i = $i + 1; - @parms = split( ' ', $_ ); + $i = $i + 1; + @vars = split( ' ', $_ ); # Do not put a comma at the end of the last disk address if ( $i == @mdisks ) { - $dasd = $dasd . "0.0.$parms[1]"; + $dasd = $dasd . "0.0.$vars[1]"; } else { - $dasd = $dasd . "0.0.$parms[1],"; + $dasd = $dasd . "0.0.$vars[1],"; } } @@ -2067,9 +2222,9 @@ sub nodeSet { # Send kernel, parmfile, conf, and initrd to reader to HCP $out = `cp /install/$distr/s390x/images/kernel.img /tmp/kernel`; $out = `cp /install/$distr/s390x/images/initrd.img /tmp/initrd`; - $out = xCAT::zvmUtils->sendFile( $hcp, "/tmp/kernel" ); - $out = xCAT::zvmUtils->sendFile( $hcp, "/tmp/parm" ); - $out = xCAT::zvmUtils->sendFile( $hcp, "/tmp/initrd" ); + xCAT::zvmUtils->sendFile( $hcp, "/tmp/kernel", "/tmp/kernel" ); + xCAT::zvmUtils->sendFile( $hcp, "/tmp/parm", "/tmp/parm" ); + xCAT::zvmUtils->sendFile( $hcp, "/tmp/initrd", "/tmp/initrd" ); # Set the virtual unit record devices online $out = xCAT::zvmUtils->disableEnableDisk( $callback, $hcp, "-e", "c" ); @@ -2081,38 +2236,29 @@ sub nodeSet { # Punch kernel to reader on HCP $out = xCAT::zvmCPUtils->punch2Reader( $hcp, $userId, "/tmp/kernel", "rhel.kernel", "" ); - if ( !( $out =~ m/$searchStr/i ) ) { - xCAT::zvmUtils->printLn( $callback, "$node: Punching kernel to reader... Failed" ); + xCAT::zvmUtils->printLn( $callback, "$node: Punching kernel to reader... $out" ); + if ( $out =~ m/Failed/i ) { return; } - else { - xCAT::zvmUtils->printLn( $callback, "$node: Punching kernel to reader... Done" ); - } # Punch parm to reader on HCP $out = xCAT::zvmCPUtils->punch2Reader( $hcp, $userId, "/tmp/parm", "rhel.parm", "-t" ); - if ( !( $out =~ m/$searchStr/i ) ) { - xCAT::zvmUtils->printLn( $callback, "$node: Punching parm to reader... Failed" ); + xCAT::zvmUtils->printLn( $callback, "$node: Punching parm to reader... $out" ); + if ( $out =~ m/Failed/i ) { return; } - else { - xCAT::zvmUtils->printLn( $callback, "$node: Punching parm to reader... Done" ); - } # Punch initrd to reader on HCP $out = xCAT::zvmCPUtils->punch2Reader( $hcp, $userId, "/tmp/initrd", "rhel.initrd", "" ); - if ( !( $out =~ m/$searchStr/i ) ) { - xCAT::zvmUtils->printLn( $callback, "$node: Punching initrd to reader... Failed" ); + xCAT::zvmUtils->printLn( $callback, "$node: Punching initrd to reader... $out" ); + if ( $out =~ m/Failed/i ) { return; } - else { - xCAT::zvmUtils->printLn( $callback, "$node: Punching initrd to reader... Done" ); - } } # Boot node $out = `ssh $hcp "$::DIR/startvs $userId"`; - my $rc = xCAT::zvmUtils->isOutputGood( $callback, $out ); + my $rc = xCAT::zvmUtils->checkOutput( $callback, $out ); if ( $rc == -1 ) { xCAT::zvmUtils->printLn( $callback, "Installation failed" ); return; @@ -2135,9 +2281,8 @@ sub nodeSet { =head3 getMacs - Description : Collects node MAC address - - This operation requires the node be online - - This operating gets the 1st MAC address found + Description : Collect node MAC address + - Requires the node be online Arguments : Node Returns : Nothing Example : getMacs($callback, $node, $args); @@ -2168,33 +2313,41 @@ sub getMacs { return; } - # Load VMCP module - my $out = xCAT::zvmCPUtils->loadVmcp($node); + # Get MAC address in 'mac' table + my @propNames = ('mac'); + my $propVals = xCAT::zvmUtils->getNodeProps( 'mac', $node, @propNames ); + my $mac; + if ($propVals) { + + # Get MAC address + $mac = $propVals->{'mac'}; + xCAT::zvmUtils->printLn( $callback, "$node: $mac" ); + return; + } + + # If MAC address is not in the 'mac' table, get it using VMCP + xCAT::zvmCPUtils->loadVmcp($node); # Get xCat MN Lan/VSwitch name - $out = `vmcp q v nic | egrep -i "VSWITCH|LAN"`; + my $out = `vmcp q v nic | egrep -i "VSWITCH|LAN"`; my @lines = split( '\n', $out ); my @vars; # Go through each line and extract VSwitch and Lan names # and create search string my $searchStr = ""; - my @vswitches; - my @lans; my $i; for ( $i = 0 ; $i < @lines ; $i++ ) { # Extract VSwitch name if ( $lines[$i] =~ m/VSWITCH/i ) { @vars = split( ' ', $lines[$i] ); - push( @vswitches, $vars[4] ); $searchStr = $searchStr . "$vars[4]"; } # Extract Lan name elsif ( $lines[$i] =~ m/LAN/i ) { @vars = split( ' ', $lines[$i] ); - push( @lans, $vars[4] ); $searchStr = $searchStr . "$vars[4]"; } @@ -2207,7 +2360,7 @@ sub getMacs { # This node should be on only 1 of the networks that the xCat MN is on $out = `ssh -o ConnectTimeout=5 $node "vmcp q v nic" | egrep -i "$searchStr"`; if ( !$out ) { - xCAT::zvmUtils->printLn( $callback, "Error: Could not find MAC address" ); + xCAT::zvmUtils->printLn( $callback, "$node: Failed to find MAC address" ); return; } @@ -2217,12 +2370,12 @@ sub getMacs { # Replace - with : $mac = xCAT::zvmUtils->replaceStr( $mac, "-", ":" ); - xCAT::zvmUtils->printLn( $callback, "$mac" ); + xCAT::zvmUtils->printLn( $callback, "$node: $mac" ); # Get network interface using MAC address $out = `ssh -o ConnectTimeout=5 $node "ifconfig" | grep "$mac"`; if ( !$out ) { - xCAT::zvmUtils->printLn( $callback, "Error: Could not find network interface" ); + xCAT::zvmUtils->printLn( $callback, "$node: Failed find network interface" ); return; } diff --git a/xCAT-server/share/xcat/install/rh/compute.rhel5.s390x.tmpl b/xCAT-server/share/xcat/install/rh/compute.rhel5.s390x.tmpl new file mode 100644 index 000000000..cd11d0e80 --- /dev/null +++ b/xCAT-server/share/xcat/install/rh/compute.rhel5.s390x.tmpl @@ -0,0 +1,34 @@ +# Kickstart file automatically generated by anaconda. + +install +url --url replace_url +key --skip +lang en_US.UTF-8 +network --device eth0 --mtu=1500 --bootproto static --ip replace_ip --netmask replace_netmask --gateway replace_gateway --nameserver replace_nameserver --hostname replace_hostname +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 diff --git a/xCAT-server/share/xcat/install/sles/compute.sles10.s390x.tmpl b/xCAT-server/share/xcat/install/sles/compute.sles10.s390x.tmpl new file mode 100644 index 000000000..443cb0e5c --- /dev/null +++ b/xCAT-server/share/xcat/install/sles/compute.sles10.s390x.tmpl @@ -0,0 +1,1083 @@ + + + + + + + None + none + 0.0.0100 + /dev/dasda + + /dev/dasda + /dev/disk/by-path/ccw-0.0.0100 + + DASD + io_subchannel + + + true + true + + + dasd_eckd_mod + + + + + + true + /dev/dasda1 (Linux native) + + + + 3338 + 15 + 12 + + + + 0.0.0100 + /org/freedesktop/Hal/devices/ccw_0_0_0100_storage + + + None + none + 0.0.0101 + /dev/dasdb + + /dev/dasdb + /dev/disk/by-path/ccw-0.0.0101 + + DASD + io_subchannel + + + true + true + + + dasd_eckd_mod + + + + + + true + /dev/dasdb1 (Linux native) + + + + 3338 + 15 + 12 + + + + 0.0.0101 + /org/freedesktop/Hal/devices/ccw_0_0_0101_storage + + + None + none + 0.0.0300 + /dev/dasdc + + /dev/dasdc + /dev/disk/by-path/ccw-0.0.0300 + + DASD + io_subchannel + + + true + true + + + dasd_fba_mod + + + + + + true + /dev/dasdc1 + + + + 256 + 16 + 128 + + + + 0.0.0300 + /org/freedesktop/Hal/devices/ccw_0_0_0300_storage + + + None + none + 0.0.0301 + /dev/dasdd + + /dev/dasdd + /dev/disk/by-path/ccw-0.0.0301 + + DASD + io_subchannel + + + true + true + + + dasd_fba_mod + + + + + + true + /dev/dasdd1 + + + + 512 + 16 + 128 + + + + 0.0.0301 + /org/freedesktop/Hal/devices/ccw_0_0_0301_storage + + + + + + false + + + none + + + true + true + true + true + false + true + + + + + x + users + + + + x + floppy + + + + x + bin + daemon + + + x + xok + + + + x + nobody + + + + x + modem + + + + x + lp + + + + x + tty + + + + ! + postfix + + + + ! + gdm + + + + x + nogroup + nobody + + + ! + maildrop + + + + ! + messagebus + + + + x + video + + + + x + sys + + + + x + shadow + + + + x + console + + + + x + cdrom + + + + ! + haldaemon + + + + x + trusted + + + + x + dialout + + + + x + wheel + + + + x + www + + + + x + games + + + + x + disk + + + + x + audio + + + + ! + suse-ncc + + + + x + ftp + + + + ! + at + + + + x + kmem + + + + x + public + + + + x + root + + + + x + mail + + + + x + daemon + + + + ! + ntp + + + + x + uucp + + + + ! + ntadmin + + + + x + man + + + + x + utmp + + + + x + news + + + + ! + sshd + + + + + + + 127.0.0.1 + + localhost + + + + replace_host_address + + replace_long_name replace_short_name + + + + ::1 + + localhost ipv6-localhost ipv6-loopback + + + + fe00::0 + + ipv6-localnet + + + + ff00::0 + + ipv6-mcastprefix + + + + ff02::1 + + ipv6-allnodes + + + + ff02::2 + + ipv6-allrouters + + + + ff02::3 + + ipv6-allhosts + + + + + + + + 1.0 + + + en_US + + + + + + + AUTO + + + true + true + replace_domain + replace_hostname + + replace_nameserver + + + + + dhcp + replace_device + replace_lladdr + auto + no + + + false + + + dasd-bus-ccw-0.0.0100 + dasd_eckd_mod + + + + dasd-bus-ccw-0.0.0101 + dasd_eckd_mod + + + + dasd-bus-ccw-0.0.0300 + dasd_fba_mod + + + + dasd-bus-ccw-0.0.0301 + dasd_fba_mod + + + + replace_ccw_chan_ids + replace_ccw_chan_mode + 3 + replace_device + qeth + + + + + false + + + + false + false + false + + false + + + + false + false + + + + /dev/dasda + + + true + ext3 + true + / + path + 131 + 1 + primary + max + + + all + + + /dev/dasdb + + + true + ext3 + true + /usr + path + 131 + 1 + primary + max + + + all + + + /dev/dasdc + + + true + swap + true + swap + device + 131 + 1 + primary + max + + + all + + + /dev/dasdd + + + true + swap + true + swap + device + 131 + 1 + primary + max + + + all + + + + false + + + + localhost, 127.0.0.1 + + + + + + true + true + 0 + + + true + true + 0 + + + true + true + 0 + + + true + true + 0 + + + + 5 + + + + libgsm + libssui + perl-Bootloader + samba-client + libiniparser + libnl + cifs-mount + OpenEXR + perl-XML-Parser + qt-qt3support + net-snmp + dbus-1-qt + perl-gettext + perl-Carp-Clan + dmapi + xorg-x11-Xnest + glibc-32bit + mDNSResponder-lib + perl-Config-Crontab + perl-X500-DN + libogg + perl-TermReadKey + pciutils-ids + perl-Config-IniFiles + perl-XML-Writer + update-alternatives + mono-winforms + yast2-trans-en_US + libvorbis + perl-Crypt-SmbHash + perl-TimeDate + zypper + taglib + libicu + perl-Digest-MD4 + perl-Parse-RecDescent + unrar + perl-Bit-Vector + perl-Date-Calc + boost + flac + python-cairo + aspell-en + libgimpprint + susehelp_en + iso-codes + libsvg-cairo + audiofile + esound + dbus-1-mono + limal-nfs-server + libzypp-zmd-backend + aalib + libsvg + perl-Compress-Zlib + perl-Digest-SHA1 + perl-URI + libgdiplus + limal-nfs-server-perl + + + x11 + gnome + base + + + xorg-x11-driver-video-radeon + 915resolution + xorg-x11-driver-video-nvidia + 3ddiag + sax2-libsax-perl + sax2-ident + sax2 + sax2-gui + sax2-libsax + xorg-x11-server-glx + xorg-x11-server + xorg-x11-driver-video + nautilus-cd-burner + yast2-sound + evolution + gnome2-SLES + mDNSResponder + cdrecord + cdrdao + dosbootdisk + gnome2-SuSE + suspend + acpid + bootcycle + fbset + libpfm + mcelog + mpt-status + linux32 + master-boot-code + pfmon + numactl + powersave + pdisk + smartmontools + salinfo + powerpc32 + syslinux + wol + yast2-irda + yast2-vm + yast2-power-management + + + + UTC + US/Eastern + + + + 100 + video,dialout + /home + -1 + /bin/bash + /etc/skel + + + + true + Games account + 100 + /var/games + + + + + + + + + /bin/bash + 12 + * + games + + + true + bin + 1 + /bin + + + + + + + + + /bin/bash + 1 + * + bin + + + true + nobody + 65533 + /var/lib/nobody + + + + + + + + + /bin/bash + 65534 + * + nobody + + + true + Printing daemon + 7 + /var/spool/lpd + + + + + + + + + /bin/bash + 4 + * + lp + + + true + Postfix Daemon + 51 + /var/spool/postfix + + + + + 99999 + 0 + 7 + + /bin/false + 51 + ! + postfix + + + true + Novell Customer Center User + 105 + /var/lib/YaST2/suse-ncc-fakehome + + + + + 99999 + 0 + 7 + + /bin/bash + 102 + ! + suse-ncc + + + true + FTP account + 49 + /srv/ftp + + + + + + + + + /bin/bash + 40 + * + ftp + + + true + Gnome Display Manager daemon + 104 + /var/lib/gdm + + + + + 99999 + 0 + 7 + + /bin/false + 50 + ! + gdm + + + true + Batch jobs daemon + 25 + /var/spool/atjobs + + + + + 99999 + 0 + 7 + + /bin/bash + 25 + ! + at + + + false + root + 0 + /root + + + + + + + + + /bin/bash + 0 + replace_root_password + root + + + true + Mailer daemon + 12 + /var/spool/clientmqueue + + + + + + + + + /bin/false + 8 + * + mail + + + true + Daemon + 2 + /sbin + + + + + + + + + /bin/bash + 2 + * + daemon + + + true + NTP daemon + 103 + /var/lib/ntp + + + + + 99999 + 0 + 7 + + /bin/false + 74 + ! + ntp + + + User for D-BUS + 101 + /var/run/dbus + /bin/false + 100 + + + true + Unix-to-Unix CoPy system + 14 + /etc/uucp + + + + + + + + + /bin/bash + 10 + * + uucp + + + User for haldaemon + 102 + /var/run/hal + /bin/false + 101 + + + true + WWW daemon apache + 8 + /var/lib/wwwrun + + + + + + + + + /bin/false + 30 + * + wwwrun + + + true + Manual pages viewer + 62 + /var/cache/man + + + + + + + + + /bin/bash + 13 + * + man + + + true + News system + 13 + /etc/news + + + + + + + + + /bin/bash + 9 + * + news + + + true + SSH daemon + 65 + /var/lib/sshd + + + + + 99999 + 0 + 7 + + /bin/false + 71 + ! + sshd + + + + + +