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:13:27 +00:00
|
|
|
This is a utility plugin for z/VM.
|
2009-10-01 18:28:00 +00:00
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
package xCAT::zvmUtils;
|
|
|
|
use xCAT::MsgUtils;
|
|
|
|
use xCAT::Utils;
|
|
|
|
use xCAT::Table;
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
1;
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
2009-11-09 21:13:27 +00:00
|
|
|
=head3 getNodeProps
|
|
|
|
Description : Get node properties
|
2009-10-01 18:28:00 +00:00
|
|
|
Arguments : Table
|
|
|
|
Node
|
2009-11-09 21:13:27 +00:00
|
|
|
Properties
|
2009-12-08 19:39:00 +00:00
|
|
|
Returns : Node properties from given table
|
2009-11-09 21:13:27 +00:00
|
|
|
Example : my $propVals = xCAT::zvmUtils->getNodeProps($tabName, $node, $propNames);
|
2009-10-01 18:28:00 +00:00
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
2009-11-09 21:13:27 +00:00
|
|
|
sub getNodeProps {
|
2009-10-01 18:28:00 +00:00
|
|
|
|
|
|
|
# Get inputs
|
2009-11-09 21:13:27 +00:00
|
|
|
my ( $class, $tabName, $node, @propNames ) = @_;
|
2009-10-01 18:28:00 +00:00
|
|
|
|
2009-12-08 19:39:00 +00:00
|
|
|
# Get table
|
2009-10-01 18:28:00 +00:00
|
|
|
my $tab = xCAT::Table->new($tabName);
|
|
|
|
|
2009-12-08 19:39:00 +00:00
|
|
|
# Get property values
|
2009-11-09 21:13:27 +00:00
|
|
|
my $propVals = $tab->getNodeAttribs( $node, [@propNames] );
|
2009-12-08 19:39:00 +00:00
|
|
|
|
2009-11-09 21:13:27 +00:00
|
|
|
return ($propVals);
|
|
|
|
}
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 getTabPropsByKey
|
2009-12-08 19:39:00 +00:00
|
|
|
Description : Get table entry properties by key
|
2009-11-09 21:13:27 +00:00
|
|
|
Arguments : Table
|
2009-12-08 19:39:00 +00:00
|
|
|
Key name
|
2009-11-09 21:13:27 +00:00
|
|
|
Key value
|
|
|
|
Requested properties
|
2009-12-08 19:39:00 +00:00
|
|
|
Returns : Table entry properties
|
2009-11-12 14:44:55 +00:00
|
|
|
Example : my $propVals = xCAT::zvmUtils->getTabPropsByKey($tabName, $key, $keyValue, @reqProps);
|
2009-11-09 21:13:27 +00:00
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
sub getTabPropsByKey {
|
|
|
|
|
|
|
|
# Get inputs
|
|
|
|
my ( $class, $tabName, $key, $keyVal, @propNames ) = @_;
|
|
|
|
|
2009-12-08 19:39:00 +00:00
|
|
|
# Get table
|
2009-11-09 21:13:27 +00:00
|
|
|
my $tab = xCAT::Table->new($tabName);
|
|
|
|
my $propVals;
|
|
|
|
|
2009-12-08 19:39:00 +00:00
|
|
|
# Get table attributes matching given key
|
2009-11-09 21:13:27 +00:00
|
|
|
$propVals = $tab->getAttribs( { $key => $keyVal }, @propNames );
|
|
|
|
return ($propVals);
|
2009-10-01 18:28:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
2010-01-08 20:59:28 +00:00
|
|
|
=head3 getAllTabEntries
|
|
|
|
Description : Get all entries within given table
|
|
|
|
Arguments : Table
|
|
|
|
Returns : All table entries
|
|
|
|
Example : my $entries = xCAT::zvmUtils->getAllTabEntries($tabName);
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
sub getAllTabEntries {
|
|
|
|
|
|
|
|
# Get inputs
|
|
|
|
my ( $class, $tabName ) = @_;
|
|
|
|
|
|
|
|
# Get table
|
|
|
|
my $tab = xCAT::Table->new($tabName);
|
|
|
|
my $entries;
|
|
|
|
|
|
|
|
# Get all entries within given table
|
|
|
|
$entries = $tab->getAllEntries();
|
|
|
|
return ($entries);
|
|
|
|
}
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
2009-11-09 21:13:27 +00:00
|
|
|
=head3 setNodeProp
|
2009-10-01 18:28:00 +00:00
|
|
|
|
2009-12-08 19:39:00 +00:00
|
|
|
Description : Set node property in a given table
|
2009-10-01 18:28:00 +00:00
|
|
|
Arguments : Table
|
2009-12-08 19:39:00 +00:00
|
|
|
Node
|
2009-10-01 18:28:00 +00:00
|
|
|
Property
|
|
|
|
Returns : Nothing
|
2009-11-09 21:13:27 +00:00
|
|
|
Example : xCAT::zvmUtils->setNodeProp($tabName, $node, $propName, $propVal);
|
2009-10-01 18:28:00 +00:00
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
2009-11-09 21:13:27 +00:00
|
|
|
sub setNodeProp {
|
2009-10-01 18:28:00 +00:00
|
|
|
|
|
|
|
# Get inputs
|
|
|
|
my ( $class, $tabName, $node, $propName, $propVal ) = @_;
|
|
|
|
|
2009-12-08 19:39:00 +00:00
|
|
|
# Get table
|
2009-10-01 18:28:00 +00:00
|
|
|
my $tab = xCAT::Table->new( $tabName, -create => 1, -autocommit => 0 );
|
|
|
|
|
|
|
|
# Set property
|
|
|
|
$tab->setAttribs( { 'node' => $node }, { $propName => $propVal } );
|
|
|
|
|
|
|
|
# Save table
|
|
|
|
$tab->commit;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
2009-11-12 14:44:55 +00:00
|
|
|
=head3 delTabEntry
|
2009-10-01 18:28:00 +00:00
|
|
|
|
2009-12-08 19:39:00 +00:00
|
|
|
Description : Delete a table entry
|
2009-10-01 18:28:00 +00:00
|
|
|
Arguments : Table
|
2009-12-08 19:39:00 +00:00
|
|
|
Key name
|
|
|
|
Key value
|
2009-10-01 18:28:00 +00:00
|
|
|
Returns : Nothing
|
2009-12-08 19:39:00 +00:00
|
|
|
Example : xCAT::zvmUtils->delTabEntry($tabName, $keyName, $keyVal);
|
2009-10-01 18:28:00 +00:00
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
2009-11-12 14:44:55 +00:00
|
|
|
sub delTabEntry {
|
2009-10-01 18:28:00 +00:00
|
|
|
|
|
|
|
# Get inputs
|
2009-12-08 19:39:00 +00:00
|
|
|
my ( $class, $tabName, $keyName, $keyVal ) = @_;
|
2009-10-01 18:28:00 +00:00
|
|
|
|
2009-12-08 19:39:00 +00:00
|
|
|
# Get table
|
2009-10-01 18:28:00 +00:00
|
|
|
my $tab = xCAT::Table->new( $tabName, -create => 1, -autocommit => 0 );
|
|
|
|
|
2009-12-08 19:39:00 +00:00
|
|
|
# Delete entry from table
|
|
|
|
my %key = ( $keyName => $keyVal );
|
2009-10-01 18:28:00 +00:00
|
|
|
$tab->delEntries( \%key );
|
|
|
|
|
|
|
|
# Save table
|
|
|
|
$tab->commit;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 tabStr
|
|
|
|
|
2009-11-09 21:13:27 +00:00
|
|
|
Description : Tab string (4 spaces)
|
2009-10-01 18:28:00 +00:00
|
|
|
Arguments : String
|
|
|
|
Returns : Tabbed string
|
|
|
|
Example : my $str = xCAT::zvmUtils->tabStr($str);
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
sub tabStr {
|
|
|
|
|
|
|
|
# Get inputs
|
|
|
|
my ( $class, $inStr ) = @_;
|
|
|
|
my @lines = split( "\n", $inStr );
|
|
|
|
|
|
|
|
# Tab output
|
|
|
|
my $outStr;
|
|
|
|
foreach (@lines) {
|
|
|
|
$outStr .= " $_\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
return ($outStr);
|
|
|
|
}
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
2009-11-09 21:13:27 +00:00
|
|
|
=head3 trimStr
|
2009-10-01 18:28:00 +00:00
|
|
|
|
2009-12-08 19:39:00 +00:00
|
|
|
Description : Trim whitespaces within a string
|
2009-10-01 18:28:00 +00:00
|
|
|
Arguments : String
|
|
|
|
Returns : Trimmed string
|
2009-11-09 21:13:27 +00:00
|
|
|
Example : my $str = xCAT::zvmUtils->trimStr($str);
|
2009-10-01 18:28:00 +00:00
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
2009-11-09 21:13:27 +00:00
|
|
|
sub trimStr {
|
2009-10-01 18:28:00 +00:00
|
|
|
|
|
|
|
# Get string
|
|
|
|
my ( $class, $str ) = @_;
|
|
|
|
|
|
|
|
# Trim right
|
|
|
|
$str =~ s/\s*$//;
|
|
|
|
|
|
|
|
# Trim left
|
|
|
|
$str =~ s/^\s*//;
|
|
|
|
|
|
|
|
return ($str);
|
|
|
|
}
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
2009-11-09 21:13:27 +00:00
|
|
|
=head3 replaceStr
|
|
|
|
|
2009-12-08 19:39:00 +00:00
|
|
|
Description : Replace a given pattern within a string
|
2009-11-09 21:13:27 +00:00
|
|
|
Arguments : String
|
2009-12-08 19:39:00 +00:00
|
|
|
Returns : String with given pattern replaced
|
2009-11-09 21:13:27 +00:00
|
|
|
Example : my $str = xCAT::zvmUtils->replaceStr($str, $pattern, $replacement);
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
sub replaceStr {
|
|
|
|
|
|
|
|
# Get string
|
|
|
|
my ( $class, $str, $pattern, $replacement ) = @_;
|
|
|
|
|
|
|
|
# Replace string
|
|
|
|
$str =~ s/$pattern/$replacement/g;
|
|
|
|
|
|
|
|
return ($str);
|
|
|
|
}
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
2009-10-01 18:28:00 +00:00
|
|
|
=head3 printLn
|
|
|
|
|
|
|
|
Description : Print string
|
|
|
|
Arguments : String
|
|
|
|
Returns : Nothing
|
|
|
|
Example : xCAT::zvmUtils->printLn($callback, $str);
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
sub printLn {
|
|
|
|
|
|
|
|
# Get inputs
|
|
|
|
my ( $class, $callback, $str ) = @_;
|
|
|
|
|
|
|
|
# Print string
|
|
|
|
my $rsp;
|
|
|
|
$rsp->{data}->[0] = "$str";
|
|
|
|
xCAT::MsgUtils->message( "I", $rsp, $callback );
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 isZvmNode
|
|
|
|
|
2009-12-08 19:39:00 +00:00
|
|
|
Description : Checks if a given node is in the 'zvm' table
|
2009-10-01 18:28:00 +00:00
|
|
|
Arguments : Node
|
|
|
|
Returns : TRUE Node exists
|
|
|
|
FALSE Node does not exists
|
|
|
|
Example : my $out = xCAT::zvmUtils->isZvmNode($node);
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
sub isZvmNode {
|
|
|
|
|
|
|
|
# Get inputs
|
|
|
|
my ( $class, $node ) = @_;
|
|
|
|
|
|
|
|
# zVM guest ID
|
|
|
|
my $id;
|
|
|
|
|
|
|
|
# Look in 'zvm' table
|
|
|
|
my $tab = xCAT::Table->new( 'zvm', -create => 1, -autocommit => 0 );
|
|
|
|
|
|
|
|
my @results = $tab->getAllAttribsWhere( "node like '%" . $node . "%'", 'userid' );
|
|
|
|
foreach (@results) {
|
2009-12-08 19:39:00 +00:00
|
|
|
|
|
|
|
# Get userID
|
2009-10-01 18:28:00 +00:00
|
|
|
$id = $_->{'userid'};
|
|
|
|
|
2009-12-08 19:39:00 +00:00
|
|
|
# Return 'TRUE' if given node is in the table
|
2009-10-01 18:28:00 +00:00
|
|
|
if ($id) {
|
|
|
|
return ('TRUE');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ('FALSE');
|
|
|
|
}
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 getIp
|
|
|
|
|
2009-12-08 19:39:00 +00:00
|
|
|
Description : Get the IP address of a given node
|
2009-10-01 18:28:00 +00:00
|
|
|
Arguments : Node
|
2009-12-08 19:39:00 +00:00
|
|
|
Returns : IP address of given node
|
2009-10-01 18:28:00 +00:00
|
|
|
Example : my $ip = xCAT::zvmUtils->getIp($node);
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
sub getIp {
|
|
|
|
|
|
|
|
# Get inputs
|
|
|
|
my ( $class, $node ) = @_;
|
|
|
|
|
|
|
|
# Get IP address
|
2009-11-09 21:13:27 +00:00
|
|
|
my $out = `ssh -o ConnectTimeout=10 $node "ifconfig" | grep "inet addr:" | grep -v "127.0.0.1"`;
|
|
|
|
my @lines = split( '\n', $out );
|
2009-10-01 18:28:00 +00:00
|
|
|
|
2009-11-09 21:13:27 +00:00
|
|
|
# Get the first IP that comes back
|
|
|
|
my @parms = split( ' ', $lines[0] );
|
|
|
|
foreach (@parms) {
|
|
|
|
|
|
|
|
# Get inet addr parameter
|
|
|
|
if ( $_ =~ m/addr:/i ) {
|
|
|
|
my @ip = split( ':', $_ );
|
|
|
|
return ( $ip[1] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
2009-10-01 18:28:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
2009-12-08 19:39:00 +00:00
|
|
|
=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
|
2010-01-08 20:59:28 +00:00
|
|
|
my $os = xCAT::zvmUtils->getOs($node);
|
2009-12-08 19:39:00 +00:00
|
|
|
|
|
|
|
# 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
2009-10-01 18:28:00 +00:00
|
|
|
=head3 getIfcfg
|
|
|
|
|
2009-12-08 19:39:00 +00:00
|
|
|
Description : Get network configuration file path of given node
|
2009-11-09 21:13:27 +00:00
|
|
|
Red Hat -- /etc/sysconfig/network-scripts/ifcfg-eth
|
|
|
|
SUSE -- /etc/sysconfig/network/ifcfg-qeth
|
2009-10-01 18:28:00 +00:00
|
|
|
Arguments : Node
|
2009-11-09 21:13:27 +00:00
|
|
|
Returns : Network configuration file path
|
2009-10-01 18:28:00 +00:00
|
|
|
Example : my $ifcfg = xCAT::zvmUtils->getIfcfg($node);
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
sub getIfcfg {
|
|
|
|
|
|
|
|
# Get inputs
|
|
|
|
my ( $class, $node ) = @_;
|
|
|
|
|
2009-11-09 21:13:27 +00:00
|
|
|
# Get OS
|
2010-01-08 20:59:28 +00:00
|
|
|
my $os = xCAT::zvmUtils->getOs($node);
|
2009-10-01 18:28:00 +00:00
|
|
|
|
2009-11-09 21:13:27 +00:00
|
|
|
# Get network configuration file path
|
|
|
|
my $out;
|
|
|
|
my @parms;
|
|
|
|
|
|
|
|
# If it is Red Hat -- ifcfg-qeth file is in /etc/sysconfig/network-scripts
|
|
|
|
if ( $os =~ m/Red Hat/i ) {
|
|
|
|
$out = `ssh -o ConnectTimeout=5 $node "ls /etc/sysconfig/network-scripts/ifcfg-eth*"`;
|
|
|
|
@parms = split( '\n', $out );
|
|
|
|
return ( $parms[0] );
|
|
|
|
}
|
|
|
|
|
|
|
|
# If it is SUSE -- ifcfg-qeth file is in /etc/sysconfig/network
|
|
|
|
elsif ( $os =~ m/SUSE/i ) {
|
|
|
|
$out = `ssh -o ConnectTimeout=5 $node "ls /etc/sysconfig/network/ifcfg-qeth*"`;
|
|
|
|
@parms = split( '\n', $out );
|
|
|
|
return ( $parms[0] );
|
|
|
|
}
|
|
|
|
|
|
|
|
# If no file is found -- Return nothing
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 getIfcfgByNic
|
|
|
|
|
2009-12-08 19:39:00 +00:00
|
|
|
Description : Get /etc/sysconfig/network/ifcfg-qeth file name of given NIC
|
2009-11-09 21:13:27 +00:00
|
|
|
Arguments : Node
|
|
|
|
NIC address
|
|
|
|
Returns : /etc/sysconfig/network/ifcfg-qeth file name
|
|
|
|
Example : my $ifcfg = xCAT::zvmUtils->getIfcfgByNic($node, $nic);
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
sub getIfcfgByNic {
|
|
|
|
|
|
|
|
# Get inputs
|
|
|
|
my ( $class, $node, $nic ) = @_;
|
|
|
|
|
|
|
|
# Get OS
|
2010-01-08 20:59:28 +00:00
|
|
|
my $os = xCAT::zvmUtils->getOs($node);
|
2009-11-09 21:13:27 +00:00
|
|
|
|
|
|
|
# Get network configuration file path
|
|
|
|
my $out;
|
|
|
|
my @parms;
|
|
|
|
|
|
|
|
# If it is Red Hat -- ifcfg-qeth file is in /etc/sysconfig/network-scripts
|
|
|
|
if ( $os =~ m/Red Hat/i ) {
|
|
|
|
$out = `ssh -o ConnectTimeout=5 $node "ls /etc/sysconfig/network-scripts/ifcfg-eth*" | grep "$nic"`;
|
|
|
|
@parms = split( '\n', $out );
|
|
|
|
return ( $parms[0] );
|
|
|
|
}
|
|
|
|
|
|
|
|
# If it is SUSE -- ifcfg-qeth file is in /etc/sysconfig/network
|
|
|
|
elsif ( $os =~ m/SUSE/i ) {
|
|
|
|
$out = `ssh -o ConnectTimeout=5 $node "ls /etc/sysconfig/network/ifcfg-qeth*" | grep "$nic"`;
|
|
|
|
@parms = split( '\n', $out );
|
|
|
|
return ( $parms[0] );
|
|
|
|
}
|
|
|
|
|
|
|
|
# If no file is found -- Return nothing
|
|
|
|
return;
|
2009-10-01 18:28:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
2009-10-21 18:03:40 +00:00
|
|
|
=head3 getBroadcastIP
|
2009-10-01 18:28:00 +00:00
|
|
|
|
2009-11-09 21:13:27 +00:00
|
|
|
Description : Get IP broadcast of given node
|
2009-10-01 18:28:00 +00:00
|
|
|
Arguments : Node
|
|
|
|
Returns : IP broadcast
|
2009-10-21 18:03:40 +00:00
|
|
|
Example : my $broadcast = xCAT::zvmUtils->getBroadcastIP($node);
|
2009-10-01 18:28:00 +00:00
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
2009-10-21 18:03:40 +00:00
|
|
|
sub getBroadcastIP {
|
2009-10-01 18:28:00 +00:00
|
|
|
|
|
|
|
# Get inputs
|
|
|
|
my ( $class, $node ) = @_;
|
|
|
|
|
|
|
|
# Get IP address
|
2009-11-09 21:13:27 +00:00
|
|
|
my $out = `ssh -o ConnectTimeout=5 $node "ifconfig" | grep "Bcast:" | cut -d: -f3`;
|
2009-10-01 18:28:00 +00:00
|
|
|
my @parms = split( ' ', $out );
|
|
|
|
|
|
|
|
return ( $parms[0] );
|
|
|
|
}
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 getDns
|
|
|
|
|
2009-11-09 21:13:27 +00:00
|
|
|
Description : Get DNS server of given node
|
2009-10-01 18:28:00 +00:00
|
|
|
Arguments : Node
|
|
|
|
Returns : DNS server
|
|
|
|
Example : my $dns = xCAT::zvmUtils->getDns($node);
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
sub getDns {
|
|
|
|
|
|
|
|
# Get inputs
|
|
|
|
my ( $class, $node ) = @_;
|
|
|
|
|
|
|
|
# Get IP address
|
2009-11-09 21:13:27 +00:00
|
|
|
my $out = `ssh -o ConnectTimeout=5 $node "cat /etc/resolv.conf" | grep "nameserver"`;
|
2009-10-01 18:28:00 +00:00
|
|
|
my @parms = split( ' ', $out );
|
|
|
|
|
|
|
|
return ( $parms[1] );
|
|
|
|
}
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 getGateway
|
|
|
|
|
2009-11-09 21:13:27 +00:00
|
|
|
Description : Get default gateway of given node
|
2009-10-01 18:28:00 +00:00
|
|
|
Arguments : Node
|
|
|
|
Returns : Default gateway
|
|
|
|
Example : my $gw = xCAT::zvmUtils->getGateway($node);
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
sub getGateway {
|
|
|
|
|
|
|
|
# Get inputs
|
|
|
|
my ( $class, $node ) = @_;
|
|
|
|
|
|
|
|
# Get IP address
|
2009-11-09 21:13:27 +00:00
|
|
|
my $out = `ssh -o ConnectTimeout=5 $node "cat /etc/sysconfig/network/routes"`;
|
2009-10-01 18:28:00 +00:00
|
|
|
my @parms = split( ' ', $out );
|
|
|
|
return ( $parms[1] );
|
|
|
|
}
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 sendFile
|
|
|
|
|
2009-12-08 19:39:00 +00:00
|
|
|
Description : Send a file to a given node using SCP
|
2009-10-01 18:28:00 +00:00
|
|
|
Arguments : Node
|
2009-12-08 19:39:00 +00:00
|
|
|
Source file
|
|
|
|
Target file
|
2009-10-01 18:28:00 +00:00
|
|
|
Returns : Nothing
|
2009-12-08 19:39:00 +00:00
|
|
|
Example : xCAT::zvmUtils->sendFile($node, $srcFile, $trgtFile);
|
2009-10-01 18:28:00 +00:00
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
sub sendFile {
|
|
|
|
|
|
|
|
# Get inputs
|
2009-12-08 19:39:00 +00:00
|
|
|
my ( $class, $node, $srcFile, $trgtFile ) = @_;
|
2009-10-01 18:28:00 +00:00
|
|
|
|
|
|
|
# Create destination string
|
2009-12-08 19:39:00 +00:00
|
|
|
my $dest = "root@" . $node;
|
2009-10-01 18:28:00 +00:00
|
|
|
|
|
|
|
# SCP directory entry file over to HCP
|
2009-12-08 19:39:00 +00:00
|
|
|
my $out = `scp $srcFile $dest:$trgtFile`;
|
2009-10-01 18:28:00 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
2009-10-21 18:03:40 +00:00
|
|
|
=head3 getRootDiskAddr
|
2009-10-01 18:28:00 +00:00
|
|
|
|
2009-11-09 21:13:27 +00:00
|
|
|
Description : Get root disk address of given node
|
2009-12-08 19:39:00 +00:00
|
|
|
Arguments : Node name
|
|
|
|
Returns : Root disk address
|
2009-10-21 18:03:40 +00:00
|
|
|
Example : my $deviceNode = xCAT::zvmUtils->getRootDiskAddr($node);
|
2009-10-01 18:28:00 +00:00
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
2009-10-21 18:03:40 +00:00
|
|
|
sub getRootDiskAddr {
|
2009-10-01 18:28:00 +00:00
|
|
|
|
|
|
|
# Get inputs
|
|
|
|
my ( $class, $node ) = @_;
|
|
|
|
|
|
|
|
# Get device node mounted on (/)
|
2009-11-09 21:13:27 +00:00
|
|
|
my $out = `ssh $node "mount" | grep "/ type" | sed 's/1//'`;
|
2009-10-21 18:03:40 +00:00
|
|
|
my @parms = split( " ", $out );
|
2009-11-09 21:13:27 +00:00
|
|
|
@parms = split( "/", xCAT::zvmUtils->trimStr( $parms[0] ) );
|
2009-10-21 18:03:40 +00:00
|
|
|
my $devNode = $parms[0];
|
|
|
|
|
2009-11-09 21:13:27 +00:00
|
|
|
# Get disk address
|
|
|
|
$out =
|
|
|
|
`ssh $node "cat /proc/dasd/devices" | grep "$devNode" | sed 's/(ECKD)//' | sed 's/(FBA )//' | sed 's/0.0.//'`;
|
2009-10-21 18:03:40 +00:00
|
|
|
@parms = split( " ", $out );
|
2009-10-01 18:28:00 +00:00
|
|
|
return ( $parms[0] );
|
|
|
|
}
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 disableEnableDisk
|
|
|
|
|
2009-12-08 19:39:00 +00:00
|
|
|
Description : Disable/enable a disk for given node
|
2009-10-21 18:03:40 +00:00
|
|
|
Arguments : Device address
|
2009-12-08 19:39:00 +00:00
|
|
|
Option (-d|-e)
|
2009-10-01 18:28:00 +00:00
|
|
|
Returns : Nothing
|
|
|
|
Example : my $out = xCAT::zvmUtils->disableEnableDisk($callback, $node, $option, $devAddr);
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
sub disableEnableDisk {
|
|
|
|
|
|
|
|
# Get inputs
|
|
|
|
my ( $class, $callback, $node, $option, $devAddr ) = @_;
|
|
|
|
|
2009-12-08 19:39:00 +00:00
|
|
|
# Disable/enable disk
|
2009-10-01 18:28:00 +00:00
|
|
|
if ( $option eq "-d" || $option eq "-e" ) {
|
2009-11-09 21:13:27 +00:00
|
|
|
my $out = `ssh $node "chccwdev $option $devAddr"`;
|
2009-10-01 18:28:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 getMdisks
|
|
|
|
|
|
|
|
Description : Get MDisk statements in user directory entry
|
|
|
|
Arguments : Node
|
|
|
|
Returns : MDisk statements
|
|
|
|
Example : my @mdisks = xCAT::zvmUtils->getMdisks($callback, $node);
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
sub getMdisks {
|
|
|
|
|
|
|
|
# Get inputs
|
|
|
|
my ( $class, $callback, $node ) = @_;
|
|
|
|
|
|
|
|
# Directory where executables are
|
|
|
|
my $dir = '/opt/zhcp/bin';
|
|
|
|
|
|
|
|
# Get HCP
|
2009-11-09 21:13:27 +00:00
|
|
|
my @propNames = ( 'hcp', 'userid' );
|
|
|
|
my $propVals = xCAT::zvmUtils->getNodeProps( 'zvm', $node, @propNames );
|
|
|
|
my $hcp = $propVals->{'hcp'};
|
2009-10-01 18:28:00 +00:00
|
|
|
|
|
|
|
# Get node userID
|
2009-11-09 21:13:27 +00:00
|
|
|
my $userId = $propVals->{'userid'};
|
2009-10-01 18:28:00 +00:00
|
|
|
|
2009-11-09 21:13:27 +00:00
|
|
|
my $out = `ssh $hcp "$dir/getuserentry $userId" | grep "MDISK"`;
|
2009-10-01 18:28:00 +00:00
|
|
|
|
|
|
|
# Get MDISK statements
|
|
|
|
my @lines = split( '\n', $out );
|
|
|
|
my @disks;
|
|
|
|
foreach (@lines) {
|
2009-11-09 21:13:27 +00:00
|
|
|
$_ = xCAT::zvmUtils->trimStr($_);
|
2009-10-01 18:28:00 +00:00
|
|
|
|
2009-11-09 21:13:27 +00:00
|
|
|
# Save MDISK statements
|
|
|
|
push( @disks, $_ );
|
2009-10-01 18:28:00 +00:00
|
|
|
}
|
2009-12-08 19:39:00 +00:00
|
|
|
|
2009-10-01 18:28:00 +00:00
|
|
|
return (@disks);
|
|
|
|
}
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
2009-12-08 19:39:00 +00:00
|
|
|
=head3 getUserEntryWODisk
|
2009-10-01 18:28:00 +00:00
|
|
|
|
2009-12-08 19:39:00 +00:00
|
|
|
Description : Get user directory entry for given node
|
|
|
|
without MDISK statments, and save it to a file
|
2009-10-01 18:28:00 +00:00
|
|
|
Arguments : Node
|
2009-12-08 19:39:00 +00:00
|
|
|
File name to save user entry under
|
2009-10-01 18:28:00 +00:00
|
|
|
Returns : Nothing
|
2009-12-08 19:39:00 +00:00
|
|
|
Example : my $out = xCAT::zvmUtils->getUserEntryWODisk($callback, $node, $file);
|
2009-10-01 18:28:00 +00:00
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
2009-12-08 19:39:00 +00:00
|
|
|
sub getUserEntryWODisk {
|
2009-10-01 18:28:00 +00:00
|
|
|
|
|
|
|
# Get inputs
|
|
|
|
my ( $class, $callback, $node, $file ) = @_;
|
|
|
|
|
|
|
|
# Directory where executables are
|
|
|
|
my $dir = '/opt/zhcp/bin';
|
|
|
|
|
2009-11-09 21:13:27 +00:00
|
|
|
# Get node properties from 'zvm' table
|
|
|
|
my @propNames = ( 'hcp', 'userid' );
|
|
|
|
my $propVals = xCAT::zvmUtils->getNodeProps( 'zvm', $node, @propNames );
|
|
|
|
|
2009-10-01 18:28:00 +00:00
|
|
|
# Get HCP
|
2009-11-09 21:13:27 +00:00
|
|
|
my $hcp = $propVals->{'hcp'};
|
2009-10-01 18:28:00 +00:00
|
|
|
if ( !$hcp ) {
|
2009-11-09 21:13:27 +00:00
|
|
|
xCAT::zvmUtils->printLn( $callback, "Error: Missing node HCP" );
|
2009-10-01 18:28:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Get node userID
|
2009-11-09 21:13:27 +00:00
|
|
|
my $userId = $propVals->{'userid'};
|
2009-10-01 18:28:00 +00:00
|
|
|
if ( !$userId ) {
|
|
|
|
xCAT::zvmUtils->printLn( $callback, "Error: Missing node ID" );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-11-09 21:13:27 +00:00
|
|
|
my $out = `ssh $hcp "$dir/getuserentry $userId" | grep -v "MDISK"`;
|
2009-10-01 18:28:00 +00:00
|
|
|
|
|
|
|
# Create a file to save output
|
|
|
|
open( DIRENTRY, ">$file" );
|
|
|
|
|
2009-11-09 21:13:27 +00:00
|
|
|
# Save output
|
2009-10-01 18:28:00 +00:00
|
|
|
my @lines = split( '\n', $out );
|
|
|
|
foreach (@lines) {
|
|
|
|
|
|
|
|
# Trim line
|
2009-11-09 21:13:27 +00:00
|
|
|
$_ = xCAT::zvmUtils->trimStr($_);
|
2009-10-01 18:28:00 +00:00
|
|
|
|
2009-11-09 21:13:27 +00:00
|
|
|
# Write directory entry into file
|
|
|
|
print DIRENTRY "$_\n";
|
2009-10-01 18:28:00 +00:00
|
|
|
}
|
|
|
|
close(DIRENTRY);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 appendHostname
|
|
|
|
|
2009-12-08 19:39:00 +00:00
|
|
|
Description : Append specified hostname in front of a given string
|
2009-10-01 18:28:00 +00:00
|
|
|
Arguments : Hostname
|
|
|
|
String
|
|
|
|
Returns : String with hostname in front
|
|
|
|
Example : my $str = xCAT::zvmUtils->appendHostname($hostname, $str);
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
sub appendHostname {
|
|
|
|
my ( $class, $hostname, $str ) = @_;
|
|
|
|
|
|
|
|
# Append hostname to every line
|
|
|
|
my @outLn = split( "\n", $str );
|
|
|
|
$str = "";
|
|
|
|
foreach (@outLn) {
|
|
|
|
$str .= "$hostname: " . $_ . "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
return $str;
|
|
|
|
}
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
2009-12-08 19:39:00 +00:00
|
|
|
=head3 checkOutput
|
2009-10-01 18:28:00 +00:00
|
|
|
|
2009-11-09 21:13:27 +00:00
|
|
|
Description : Check return of given output
|
2009-10-01 18:28:00 +00:00
|
|
|
Arguments : Output string
|
2009-12-08 19:39:00 +00:00
|
|
|
Returns : 0 Good output
|
2009-10-01 18:28:00 +00:00
|
|
|
-1 Bad output
|
2009-12-08 19:39:00 +00:00
|
|
|
Example : my $ans = xCAT::zvmUtils->checkOutput($callback, $out);
|
2009-10-01 18:28:00 +00:00
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
2009-12-08 19:39:00 +00:00
|
|
|
sub checkOutput {
|
2009-10-01 18:28:00 +00:00
|
|
|
my ( $class, $callback, $out ) = @_;
|
|
|
|
|
|
|
|
# Check output string
|
|
|
|
my @outLn = split( "\n", $out );
|
|
|
|
foreach (@outLn) {
|
|
|
|
|
2009-10-21 18:03:40 +00:00
|
|
|
# If output contains 'Failed' return -1
|
|
|
|
if ( $_ =~ m/Failed/i ) {
|
2009-10-01 18:28:00 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 isAddressUsed
|
|
|
|
|
2009-11-09 21:13:27 +00:00
|
|
|
Description : Check if given address is used
|
2009-10-21 18:03:40 +00:00
|
|
|
Arguments : Node
|
|
|
|
Disk address
|
2009-12-08 19:39:00 +00:00
|
|
|
Returns : 0 Address used
|
2009-10-01 18:28:00 +00:00
|
|
|
-1 Address not used
|
|
|
|
Example : my $ans = xCAT::zvmUtils->isAddressUsed($node, $address);
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
sub isAddressUsed {
|
|
|
|
my ( $class, $node, $address ) = @_;
|
|
|
|
|
|
|
|
# Search for disk address
|
2009-11-09 21:13:27 +00:00
|
|
|
my $out = `ssh -o ConnectTimeout=5 $node "vmcp q v dasd" | grep "DASD $address"`;
|
2009-10-01 18:28:00 +00:00
|
|
|
if ($out) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
2009-11-09 21:13:27 +00:00
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
2009-11-12 14:44:55 +00:00
|
|
|
=head3 getMacID
|
2009-11-09 21:13:27 +00:00
|
|
|
|
2009-12-08 19:39:00 +00:00
|
|
|
Description : Get MACID from /opt/zhcp/conf/next_macid on HCP
|
2009-11-12 14:44:55 +00:00
|
|
|
Arguments : HCP node
|
|
|
|
Returns : MACID
|
2009-12-08 19:39:00 +00:00
|
|
|
Example : my $macId = xCAT::zvmUtils->getMacID($hcp);
|
2009-11-09 21:13:27 +00:00
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
2009-11-12 14:44:55 +00:00
|
|
|
sub getMacID {
|
|
|
|
my ( $class, $hcp ) = @_;
|
2009-11-09 21:13:27 +00:00
|
|
|
|
2009-11-12 14:44:55 +00:00
|
|
|
# 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 ) {
|
2009-11-09 21:13:27 +00:00
|
|
|
|
2009-12-08 19:39:00 +00:00
|
|
|
# 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"`;
|
|
|
|
}
|
2009-11-12 14:44:55 +00:00
|
|
|
}
|
|
|
|
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"`;
|
2009-12-08 19:39:00 +00:00
|
|
|
$out = `ssh -o ConnectTimeout=5 $hcp "echo 'FFFFFF' > /opt/zhcp/conf/next_macid"`;
|
2009-11-12 14:44:55 +00:00
|
|
|
}
|
|
|
|
|
2009-12-08 19:39:00 +00:00
|
|
|
# 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);
|
2009-11-12 14:44:55 +00:00
|
|
|
|
2009-12-08 19:39:00 +00:00
|
|
|
return $macId;
|
2009-11-12 14:44:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
2009-12-08 19:39:00 +00:00
|
|
|
=head3 generateMacId
|
2009-11-12 14:44:55 +00:00
|
|
|
|
2009-12-08 19:39:00 +00:00
|
|
|
Description : Generate a MACID
|
|
|
|
Arguments : HCP node
|
|
|
|
Returns : MACID
|
|
|
|
Example : my $macId = xCAT::zvmUtils->generateMacId($hcp);
|
2009-11-12 14:44:55 +00:00
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
2009-12-08 19:39:00 +00:00
|
|
|
sub generateMacId {
|
2009-11-12 14:44:55 +00:00
|
|
|
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 ) {
|
|
|
|
|
2009-12-08 19:39:00 +00:00
|
|
|
# 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"`;
|
|
|
|
}
|
2009-11-12 14:44:55 +00:00
|
|
|
}
|
|
|
|
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"`;
|
2009-12-08 19:39:00 +00:00
|
|
|
$out = `ssh -o ConnectTimeout=5 $hcp "echo 'FFFFFF' > /opt/zhcp/conf/next_macid"`;
|
2009-11-12 14:44:55 +00:00
|
|
|
}
|
|
|
|
|
2009-12-08 19:39:00 +00:00
|
|
|
# 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);
|
2009-11-12 14:44:55 +00:00
|
|
|
my $int;
|
|
|
|
|
2009-12-08 19:39:00 +00:00
|
|
|
if ($macId) {
|
2009-11-12 14:44:55 +00:00
|
|
|
|
2009-12-08 19:39:00 +00:00
|
|
|
# Convert hexadecimal -- decimal
|
|
|
|
$int = hex($macId);
|
|
|
|
$macId = sprintf( "%d", $int );
|
2009-11-12 14:44:55 +00:00
|
|
|
|
|
|
|
# Generate new MAC suffix
|
2009-12-08 19:39:00 +00:00
|
|
|
$macId = $macId - 1;
|
2009-11-12 14:44:55 +00:00
|
|
|
|
2009-12-08 19:39:00 +00:00
|
|
|
# Convert decimal -- hexadecimal
|
|
|
|
$macId = sprintf( "%X", $macId );
|
2010-01-08 20:59:28 +00:00
|
|
|
|
2009-12-08 19:39:00 +00:00
|
|
|
# Save new MACID
|
|
|
|
$out = `ssh -o ConnectTimeout=5 $hcp "echo $macId > /opt/zhcp/conf/next_macid"`;
|
2009-11-12 14:44:55 +00:00
|
|
|
}
|
|
|
|
|
2009-12-08 19:39:00 +00:00
|
|
|
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 );
|
2009-11-12 14:44:55 +00:00
|
|
|
|
2009-12-08 19:39:00 +00:00
|
|
|
# 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;
|
2009-11-09 21:13:27 +00:00
|
|
|
}
|
2010-01-08 20:59:28 +00:00
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 getSn
|
|
|
|
|
|
|
|
Description : Get serial number for given node
|
|
|
|
Arguments : Node
|
|
|
|
Returns : Serial number
|
|
|
|
Example : my $sn = xCAT::zvmUtils->getSn($node);
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
sub getSn {
|
|
|
|
|
|
|
|
# Get inputs
|
|
|
|
my ( $class, $node ) = @_;
|
|
|
|
|
|
|
|
# Get node properties from 'zvm' table
|
|
|
|
my @propNames = ('hcp');
|
|
|
|
my $propVals = xCAT::zvmUtils->getNodeProps( 'zvm', $node, @propNames );
|
|
|
|
|
|
|
|
# Get HCP
|
|
|
|
my $hcp = $propVals->{'hcp'};
|
|
|
|
|
|
|
|
# Look in /proc/sysinfo to get serial number
|
|
|
|
my $out = `ssh $hcp "cat /proc/sysinfo" | egrep -i "manufacturer|type|model|sequence code|plant"`;
|
|
|
|
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 );
|
|
|
|
$man = xCAT::zvmUtils->trimStr( $props[1] );
|
|
|
|
|
|
|
|
# Get machine type
|
|
|
|
@props = split( ':', $type );
|
|
|
|
$type = xCAT::zvmUtils->trimStr( $props[1] );
|
|
|
|
|
|
|
|
# Get model
|
|
|
|
@props = split( ': ', $model );
|
|
|
|
$model = xCAT::zvmUtils->trimStr( $props[1] );
|
|
|
|
@props = split( ' ', $model );
|
|
|
|
$model = xCAT::zvmUtils->trimStr( $props[0] );
|
|
|
|
|
|
|
|
# Get sequence number
|
|
|
|
@props = split( ':', $sn );
|
|
|
|
$sn = xCAT::zvmUtils->trimStr( $props[1] );
|
|
|
|
|
|
|
|
# Get plant
|
|
|
|
@props = split( ':', $plant );
|
|
|
|
$plant = xCAT::zvmUtils->trimStr( $props[1] );
|
|
|
|
|
|
|
|
return ("$man-$type-$model-$plant-$sn");
|
|
|
|
}
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 getOs
|
|
|
|
|
|
|
|
Description : Get operating system name of given node
|
|
|
|
Arguments : Node
|
|
|
|
Returns : Operating system name
|
|
|
|
Example : my $osName = xCAT::zvmUtils->getOs($node);
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
sub getOs {
|
|
|
|
|
|
|
|
# Get inputs
|
|
|
|
my ( $class, $node ) = @_;
|
|
|
|
|
|
|
|
# Get operating system
|
|
|
|
my $out = `ssh -o ConnectTimeout=10 $node "cat /etc/*release"`;
|
|
|
|
my @results = split( '\n', $out );
|
|
|
|
return ( xCAT::zvmUtils->trimStr( $results[0] ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 getArch
|
|
|
|
|
|
|
|
Description : Get architecture of given node
|
|
|
|
Arguments : Node
|
|
|
|
Returns : Architecture of node
|
|
|
|
Example : my $arch = xCAT::zvmUtils->getArch($node);
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
sub getArch {
|
|
|
|
|
|
|
|
# Get inputs
|
|
|
|
my ( $class, $node ) = @_;
|
|
|
|
|
|
|
|
# Get host using VMCP
|
|
|
|
my $arch = `ssh $node "uname -p"`;
|
|
|
|
|
|
|
|
return ( xCAT::zvmUtils->trimStr($arch) );
|
|
|
|
}
|