2009-10-01 18:28:00 +00:00
|
|
|
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
=head1
|
|
|
|
|
2009-11-09 21:12:41 +00:00
|
|
|
This is a CP utility plugin for z/VM.
|
2009-10-01 18:28:00 +00:00
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
package xCAT::zvmCPUtils;
|
|
|
|
use xCAT::zvmUtils;
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
1;
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 getUserId
|
|
|
|
|
|
|
|
Description : Get userID for specified node
|
|
|
|
Arguments : Node name
|
|
|
|
Returns : UserID
|
|
|
|
Example : my $userID = xCAT::zvmCPUtils->getUserId($node);
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
sub getUserId {
|
|
|
|
|
|
|
|
# Get inputs
|
|
|
|
my ( $class, $node ) = @_;
|
|
|
|
|
|
|
|
# Get userId using VMCP
|
2009-11-09 21:12:41 +00:00
|
|
|
my $out = `ssh -o ConnectTimeout=5 $node "vmcp q userid"`;
|
2009-10-01 18:28:00 +00:00
|
|
|
my @results = split( ' ', $out );
|
|
|
|
return ( $results[0] );
|
|
|
|
}
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 getSn
|
|
|
|
|
|
|
|
Description : Get serial number for specified node
|
|
|
|
Arguments : Node name
|
|
|
|
Returns : Serial number
|
|
|
|
Example : my $sn = xCAT::zvmCPUtils->getSn($node);
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
sub getSn {
|
|
|
|
|
|
|
|
# Get inputs
|
|
|
|
my ( $class, $node ) = @_;
|
|
|
|
|
2009-11-09 21:12:41 +00:00
|
|
|
# Get node properties from 'zvm' table
|
|
|
|
my @propNames = ('hcp');
|
|
|
|
my $propVals = xCAT::zvmUtils->getNodeProps( 'zvm', $node, @propNames );
|
|
|
|
|
2009-10-01 18:28:00 +00:00
|
|
|
# Get HCP
|
2009-11-09 21:12:41 +00:00
|
|
|
my $hcp = $propVals->{'hcp'};
|
2009-10-01 18:28:00 +00:00
|
|
|
|
|
|
|
# Look in /proc/sysinfo to get serial number
|
2009-11-09 21:12:41 +00:00
|
|
|
my $out = `ssh $hcp "cat /proc/sysinfo" | egrep -i "manufacturer|type|model|sequence code|plant"`;
|
2009-10-01 18:28:00 +00:00
|
|
|
my @props = split( '\n', $out );
|
|
|
|
my $man = $props[0];
|
|
|
|
my $type = $props[1];
|
|
|
|
my $model = $props[2];
|
|
|
|
my $sn = $props[3];
|
|
|
|
my $plant = $props[4];
|
|
|
|
|
|
|
|
# Trim and get property value
|
|
|
|
# Get manufacturer
|
|
|
|
@props = split( ':', $man );
|
2009-11-09 21:12:41 +00:00
|
|
|
$man = xCAT::zvmUtils->trimStr( $props[1] );
|
2009-10-01 18:28:00 +00:00
|
|
|
|
|
|
|
# Get machine type
|
|
|
|
@props = split( ':', $type );
|
2009-11-09 21:12:41 +00:00
|
|
|
$type = xCAT::zvmUtils->trimStr( $props[1] );
|
2009-10-01 18:28:00 +00:00
|
|
|
|
|
|
|
# Get model
|
|
|
|
@props = split( ': ', $model );
|
2009-11-09 21:12:41 +00:00
|
|
|
$model = xCAT::zvmUtils->trimStr( $props[1] );
|
2009-10-01 18:28:00 +00:00
|
|
|
@props = split( ' ', $model );
|
2009-11-09 21:12:41 +00:00
|
|
|
$model = xCAT::zvmUtils->trimStr( $props[0] );
|
2009-10-01 18:28:00 +00:00
|
|
|
|
|
|
|
# Get sequence number
|
|
|
|
@props = split( ':', $sn );
|
2009-11-09 21:12:41 +00:00
|
|
|
$sn = xCAT::zvmUtils->trimStr( $props[1] );
|
2009-10-01 18:28:00 +00:00
|
|
|
|
|
|
|
# Get plant
|
|
|
|
@props = split( ':', $plant );
|
2009-11-09 21:12:41 +00:00
|
|
|
$plant = xCAT::zvmUtils->trimStr( $props[1] );
|
2009-10-01 18:28:00 +00:00
|
|
|
|
|
|
|
return ("$man-$type-$model-$plant-$sn");
|
|
|
|
}
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 getHost
|
|
|
|
|
|
|
|
Description : Get z/VM host for specified node
|
|
|
|
Arguments : Node name
|
|
|
|
Returns : z/VM host
|
|
|
|
Example : my $host = xCAT::zvmCPUtils->getHost($node);
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
sub getHost {
|
|
|
|
|
|
|
|
# Get inputs
|
|
|
|
my ( $class, $node ) = @_;
|
|
|
|
|
|
|
|
# Get host using VMCP
|
2009-11-09 21:12:41 +00:00
|
|
|
my $out = `ssh -o ConnectTimeout=5 $node "vmcp q userid"`;
|
2009-10-01 18:28:00 +00:00
|
|
|
my @results = split( ' ', $out );
|
|
|
|
my $host = $results[2];
|
|
|
|
|
|
|
|
return ($host);
|
|
|
|
}
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 getOs
|
|
|
|
|
|
|
|
Description : Get operating system name of specified node
|
|
|
|
Arguments : Node name
|
|
|
|
Returns : Operating system name
|
|
|
|
Example : my $osName = xCAT::zvmCPUtils->getOs($node);
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
sub getOs {
|
|
|
|
|
|
|
|
# Get inputs
|
|
|
|
my ( $class, $node ) = @_;
|
|
|
|
|
|
|
|
# Get operating system
|
2009-11-09 21:12:41 +00:00
|
|
|
my $out = `ssh -o ConnectTimeout=10 $node "cat /etc/*release"`;
|
2009-10-01 18:28:00 +00:00
|
|
|
my @results = split( '\n', $out );
|
2009-11-09 21:12:41 +00:00
|
|
|
return ( xCAT::zvmUtils->trimStr( $results[0] ) );
|
2009-10-01 18:28:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 getArch
|
|
|
|
|
|
|
|
Description : Get architecture of specified node
|
|
|
|
Arguments : Node name
|
|
|
|
Returns : Architecture of node
|
|
|
|
Example : my $arch = xCAT::zvmCPUtils->getArch($node);
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
sub getArch {
|
|
|
|
|
|
|
|
# Get inputs
|
|
|
|
my ( $class, $node ) = @_;
|
|
|
|
|
|
|
|
# Get host using VMCP
|
2009-11-09 21:12:41 +00:00
|
|
|
my $arch = `ssh $node "uname -p"`;
|
2009-10-01 18:28:00 +00:00
|
|
|
|
2009-11-09 21:12:41 +00:00
|
|
|
return ( xCAT::zvmUtils->trimStr($arch) );
|
2009-10-01 18:28:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 getPrivileges
|
|
|
|
|
2009-11-09 21:12:41 +00:00
|
|
|
Description : Get privilege class of specified node
|
2009-10-01 18:28:00 +00:00
|
|
|
Arguments : Node name
|
2009-11-09 21:12:41 +00:00
|
|
|
Returns : Privilege class
|
2009-10-01 18:28:00 +00:00
|
|
|
Example : my $memory = xCAT::zvmCPUtils->getPrivileges($node);
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
sub getPrivileges {
|
|
|
|
|
|
|
|
# Get inputs
|
|
|
|
my ( $class, $node ) = @_;
|
|
|
|
|
2009-11-09 21:12:41 +00:00
|
|
|
# Get privilege class
|
|
|
|
my $out = `ssh -o ConnectTimeout=5 $node "vmcp q priv"`;
|
2009-10-01 18:28:00 +00:00
|
|
|
my @out = split( '\n', $out );
|
2009-11-09 21:12:41 +00:00
|
|
|
$out[1] = xCAT::zvmUtils->trimStr( $out[1] );
|
|
|
|
$out[2] = xCAT::zvmUtils->trimStr( $out[2] );
|
2009-10-01 18:28:00 +00:00
|
|
|
my $str = " $out[1]\n $out[2]\n";
|
|
|
|
return ($str);
|
|
|
|
}
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 getMemory
|
|
|
|
|
2009-11-09 21:12:41 +00:00
|
|
|
Description : Get memory of specified node
|
2009-10-01 18:28:00 +00:00
|
|
|
Arguments : Node name
|
2009-11-09 21:12:41 +00:00
|
|
|
Returns : Memory
|
2009-10-01 18:28:00 +00:00
|
|
|
Example : my $memory = xCAT::zvmCPUtils->getMemory($node);
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
sub getMemory {
|
|
|
|
|
|
|
|
# Get inputs
|
|
|
|
my ( $class, $node ) = @_;
|
|
|
|
|
2009-11-09 21:12:41 +00:00
|
|
|
# Get memory
|
|
|
|
my $out = `ssh -o ConnectTimeout=5 $node "vmcp q virtual storage"`;
|
2009-10-01 18:28:00 +00:00
|
|
|
my @out = split( '=', $out );
|
2009-11-09 21:12:41 +00:00
|
|
|
return ( xCAT::zvmUtils->trimStr( $out[1] ) );
|
2009-10-01 18:28:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 getCpu
|
|
|
|
|
2009-11-09 21:12:41 +00:00
|
|
|
Description : Get processor of specified node
|
2009-10-01 18:28:00 +00:00
|
|
|
Arguments : Node name
|
2009-11-09 21:12:41 +00:00
|
|
|
Returns : Processor
|
2009-10-01 18:28:00 +00:00
|
|
|
Example : my $proc = xCAT::zvmCPUtils->getCpu($node);
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
sub getCpu {
|
|
|
|
|
|
|
|
# Get inputs
|
|
|
|
my ( $class, $node ) = @_;
|
|
|
|
|
2009-11-09 21:12:41 +00:00
|
|
|
# Get processors
|
|
|
|
my $out = `ssh -o ConnectTimeout=5 $node "vmcp q virtual cpus"`;
|
2009-10-01 18:28:00 +00:00
|
|
|
my $str = xCAT::zvmUtils->tabStr($out);
|
|
|
|
|
|
|
|
return ($str);
|
|
|
|
}
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 getNic
|
|
|
|
|
2009-11-09 21:12:41 +00:00
|
|
|
Description : Get network interface card (NIC) of specified node
|
2009-10-01 18:28:00 +00:00
|
|
|
Arguments : Node name
|
2009-11-09 21:12:41 +00:00
|
|
|
Returns : NIC
|
2009-10-01 18:28:00 +00:00
|
|
|
Example : my $nic = xCAT::zvmCPUtils->getNic($node);
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
sub getNic {
|
|
|
|
|
|
|
|
# Get inputs
|
|
|
|
my ( $class, $node ) = @_;
|
|
|
|
|
2009-11-09 21:12:41 +00:00
|
|
|
# Get NIC
|
|
|
|
my $out = `ssh -o ConnectTimeout=5 $node "vmcp q virtual nic"`;
|
2009-10-01 18:28:00 +00:00
|
|
|
my $str = xCAT::zvmUtils->tabStr($out);
|
|
|
|
return ($str);
|
|
|
|
}
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 getDisks
|
|
|
|
|
2009-11-09 21:12:41 +00:00
|
|
|
Description : Get disk of specified node
|
2009-10-01 18:28:00 +00:00
|
|
|
Arguments : Node name
|
2009-11-09 21:12:41 +00:00
|
|
|
Returns : Disk
|
2009-10-01 18:28:00 +00:00
|
|
|
Example : my $storage = xCAT::zvmCPUtils->getDisks($node);
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
sub getDisks {
|
|
|
|
|
|
|
|
# Get inputs
|
|
|
|
my ( $class, $node ) = @_;
|
|
|
|
|
2009-11-09 21:12:41 +00:00
|
|
|
# Get disks
|
|
|
|
my $out = `ssh -o ConnectTimeout=5 $node "vmcp q virtual dasd"`;
|
2009-10-01 18:28:00 +00:00
|
|
|
my $str = xCAT::zvmUtils->tabStr($out);
|
|
|
|
return ($str);
|
|
|
|
}
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 loadVmcp
|
|
|
|
|
2009-11-09 21:12:41 +00:00
|
|
|
Description : Load VMCP module on specified node
|
2009-10-01 18:28:00 +00:00
|
|
|
Arguments : Node name
|
|
|
|
Returns : Nothing
|
|
|
|
Example : my $out = xCAT::zvmCPUtils->loadVmcp($node);
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
sub loadVmcp {
|
|
|
|
|
|
|
|
# Get inputs
|
|
|
|
my ( $class, $node ) = @_;
|
|
|
|
|
2009-11-09 21:12:41 +00:00
|
|
|
# Load Linux VMCP module
|
|
|
|
my $out = `ssh -o ConnectTimeout=5 $node "modprobe vmcp"`;
|
2009-10-01 18:28:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 getVswitchId
|
|
|
|
|
2009-11-09 21:12:41 +00:00
|
|
|
Description : Get VSwitch ID of specified node
|
2009-10-01 18:28:00 +00:00
|
|
|
Arguments : Node name
|
2009-11-09 21:12:41 +00:00
|
|
|
Returns : VSwitch IDs
|
2009-10-01 18:28:00 +00:00
|
|
|
Example : my @vswitch = xCAT::zvmCPUtils->getVswitchId($node);
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
sub getVswitchId {
|
|
|
|
|
|
|
|
# Get inputs
|
|
|
|
my ( $class, $node ) = @_;
|
|
|
|
|
2009-11-09 21:12:41 +00:00
|
|
|
# Get VSwitch
|
|
|
|
my $out = `ssh -o ConnectTimeout=5 $node "vmcp q nic" | grep "VSWITCH"`;
|
2009-10-01 18:28:00 +00:00
|
|
|
my @lines = split( '\n', $out );
|
|
|
|
my @parms;
|
|
|
|
my @vswitch;
|
|
|
|
foreach (@lines) {
|
|
|
|
@parms = split( ' ', $_ );
|
|
|
|
push( @vswitch, $parms[4] );
|
|
|
|
}
|
|
|
|
|
|
|
|
return @vswitch;
|
|
|
|
}
|
2009-10-21 18:03:40 +00:00
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 grantVSwitch
|
|
|
|
|
2009-11-09 21:12:41 +00:00
|
|
|
Description : Grant access to VSwitch for specified userID
|
2009-10-21 18:03:40 +00:00
|
|
|
Arguments : zHCP node
|
|
|
|
User ID
|
|
|
|
Vswitch ID
|
|
|
|
Returns : Output string
|
|
|
|
Example : my $out = xCAT::zvmCPUtils->grantVswitch($callback, $hcp, $userId, $vswitchId);
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
sub grantVSwitch {
|
|
|
|
|
|
|
|
# Get inputs
|
|
|
|
my ( $class, $callback, $hcp, $userId, $vswitchId ) = @_;
|
|
|
|
|
2009-11-09 21:12:41 +00:00
|
|
|
# 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'
|
2009-10-21 18:03:40 +00:00
|
|
|
my $retStr;
|
2009-11-09 21:12:41 +00:00
|
|
|
if ( $out =~ m/Command complete/i ) {
|
2009-10-21 18:03:40 +00:00
|
|
|
$retStr = "Done\n";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$retStr = "Failed\n";
|
|
|
|
return ($retStr);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ($retStr);
|
|
|
|
}
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 flashCopy
|
|
|
|
|
2009-11-09 21:12:41 +00:00
|
|
|
Description : Flash copy
|
2009-10-21 18:03:40 +00:00
|
|
|
Arguments : Node
|
|
|
|
Source address
|
|
|
|
Target address
|
|
|
|
Returns : Output string
|
|
|
|
Example : my $out = xCAT::zvmCPUtils->flashCopy($node, $srcAddr, $targetAddr);
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
sub flashCopy {
|
|
|
|
|
|
|
|
# Get inputs
|
|
|
|
my ( $class, $node, $srcAddr, $targetAddr ) = @_;
|
|
|
|
|
2009-11-09 21:12:41 +00:00
|
|
|
# Flash copy
|
|
|
|
my $out = `ssh $node "vmcp flashcopy $srcAddr 0 end to $targetAddr 0 end"`;
|
|
|
|
$out = xCAT::zvmUtils->trimStr($out);
|
2009-10-21 18:03:40 +00:00
|
|
|
|
|
|
|
# If return string contains 'Command complete'
|
2009-11-09 21:12:41 +00:00
|
|
|
my $retStr;
|
2009-10-21 18:03:40 +00:00
|
|
|
if ( $out =~ m/Command complete/i ) {
|
|
|
|
|
|
|
|
# Done
|
|
|
|
$retStr = "Done\n";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$retStr = "Failed\n";
|
|
|
|
return ($retStr);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ($retStr);
|
|
|
|
}
|
|
|
|
|
2009-11-09 21:12:41 +00:00
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 punch2Reader
|
|
|
|
|
|
|
|
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)
|
|
|
|
Options (e.g. -t -- Convert EBCDIC to ASCII)
|
|
|
|
Returns : Nothing
|
|
|
|
Example : my $rc = xCAT::zvmCPUtils->punch2Reader($hcp, $userId, $file, $fileName, $options);
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
sub punch2Reader {
|
|
|
|
my ( $class, $hcp, $userId, $file, $fileName, $options ) = @_;
|
|
|
|
|
|
|
|
# Punch to reader
|
|
|
|
my $out = `ssh -o ConnectTimeout=5 $hcp "vmur punch $options -u $userId -r $file -N $fileName"`;
|
|
|
|
|
|
|
|
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 ) = @_;
|
|
|
|
|
|
|
|
# Punch to reader
|
|
|
|
my $out = `ssh -o ConnectTimeout=5 $hcp "vmcp purge $userId rdr all"`;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 sendCPCmd
|
|
|
|
|
|
|
|
Description : Send CP command to given userID (Class C users only)
|
|
|
|
Arguments : HCP node
|
|
|
|
UserID to send CP command
|
|
|
|
Returns : Nothing
|
|
|
|
Example : my $rc = 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;
|
|
|
|
}
|