2010-09-16 02:05:28 +00:00
#!/usr/bin/env perl -w
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
#####################################################
#
# Reads the cluster configuration file and primes the database in prep
# for HW discovery and node deployment.
#
# Preconditions before running the xcatsetup cmd:
# -
#
2010-10-14 16:00:20 +00:00
# Todo: Limitations on the values in the config file:
2010-09-23 12:52:29 +00:00
# - do not yet support redundant bpcs or fsps
2010-12-17 19:14:32 +00:00
# - also support verbose mode
2010-09-16 02:05:28 +00:00
#
#####################################################
package xCAT_plugin::setup ;
use strict ;
#use warnings;
2011-04-09 13:19:45 +00:00
use Socket ; #todo: also support ipv6 for routes
2010-09-16 02:05:28 +00:00
use xCAT::NodeRange ;
2011-04-09 13:19:45 +00:00
require xCAT::Schema ;
require xCAT::Table ;
require xCAT::Utils ;
require xCAT::MsgUtils ;
require xCAT::NetworkUtils ;
#use Data::Dumper;
2010-09-16 02:05:28 +00:00
use xCAT::DBobjUtils ;
2011-04-09 13:19:45 +00:00
require xCAT_plugin::networks ;
2010-09-16 02:05:28 +00:00
my $ CALLBACK ;
my % STANZAS ;
2010-12-08 17:32:46 +00:00
my $ SUB_REQ ;
my $ DELETENODES ;
2010-12-17 19:14:32 +00:00
my % NUMCECSINFRAME ;
2011-04-01 21:30:08 +00:00
#my $DHCPINTERFACES;
2011-05-17 06:08:01 +00:00
my $ PANUMBER = 0 ;
my $ CECNUMBER = 0 ;
2011-06-20 08:51:17 +00:00
#my @CECS;
my @ PARENTS ;
my % FRAMESFP ;
2010-09-16 02:05:28 +00:00
sub handled_commands {
return ( { xcatsetup = > "setup" } ) ;
}
sub process_request
{
use Getopt::Long ;
Getopt::Long:: Configure ( "bundling" ) ;
#Getopt::Long::Configure("pass_through");
Getopt::Long:: Configure ( "no_pass_through" ) ;
my $ request = shift ;
$ CALLBACK = shift ;
2010-12-08 17:32:46 +00:00
$ SUB_REQ = shift ;
2010-09-16 02:05:28 +00:00
#my $nodes = $request->{node};
#my $command = $request->{command}->[0];
my $ args = $ request - > { arg } ;
my $ VERSION ;
my $ HELP ;
2010-10-14 16:00:20 +00:00
my % SECTIONS ; # which stanzas should be processed
my $ SECT ;
2010-09-16 02:05:28 +00:00
my $ setup_usage = sub {
my $ exitcode = shift @ _ ;
my % rsp ;
2010-12-08 17:32:46 +00:00
push @ { $ rsp { data } } , "Usage: xcatsetup [-v|--version] [-?|-h|--help] [-s|--stanzas stanza-list] [--yesreallydeletenodes] <cluster-config-file>" ;
2010-09-16 02:05:28 +00:00
if ( $ exitcode ) { $ rsp { errorcode } = $ exitcode ; }
$ CALLBACK - > ( \ % rsp ) ;
} ;
# Process the cmd line args
if ( $ args ) { @ ARGV = @ { $ args } ; }
else { @ ARGV = ( ) ; }
2010-12-08 17:32:46 +00:00
if ( ! GetOptions ( 'h|?|help' = > \ $ HELP , 'v|version' = > \ $ VERSION , 's|stanzas=s' = > \ $ SECT , 'yesreallydeletenodes' = > \ $ DELETENODES ) ) { $ setup_usage - > ( 1 ) ; return ; }
2010-09-16 02:05:28 +00:00
2010-12-08 17:32:46 +00:00
if ( $ HELP || ( scalar ( @ ARGV ) == 0 && ! $ VERSION ) ) { $ setup_usage - > ( 0 ) ; return ; }
2010-09-16 02:05:28 +00:00
if ( $ VERSION ) {
my % rsp ;
my $ version = xCAT::Utils - > Version ( ) ;
$ rsp { data } - > [ 0 ] = $ version ;
$ CALLBACK - > ( \ % rsp ) ;
return ;
}
2010-10-14 16:00:20 +00:00
if ( $ SECT ) {
foreach my $ s ( split ( /[\s,]+/ , $ SECT ) ) { $ SECTIONS { $ s } = 1 ; }
}
2011-03-03 18:41:59 +00:00
#todo: support reading the config file from stdin
2010-09-16 02:05:28 +00:00
my $ input ;
my $ filename = fullpath ( $ ARGV [ 0 ] , $ request - > { cwd } - > [ 0 ] ) ;
if ( ! open ( $ input , $ filename ) ) {
errormsg ( "Can not open file $filename." , 2 ) ;
return ;
}
# Parse the config file
my $ success = readFileInput ( $ input ) ;
close ( $ input ) ;
if ( ! $ success ) { return ; }
# Write the db entries
2010-10-14 16:00:20 +00:00
writedb ( $ request - > { cwd } - > [ 0 ] , \ % SECTIONS ) ;
2010-09-16 02:05:28 +00:00
}
sub readFileInput {
my $ input = shift ;
my $ l ;
my $ stanza ;
my $ linenum = 0 ;
while ( $ l = <$input> ) {
$ linenum + + ;
# skip blank and comment lines
next if ( $ l =~ /^\s*$/ || $ l =~ /^\s*#/ ) ;
# process a real line
if ( $ l =~ /^\s*(\S+)\s*=\s*(.*)\s*$/ ) {
my $ attr = $ 1 ;
my $ val = $ 2 ;
#$attr =~ s/^\s*//; # Remove any leading whitespace - already did that
#$attr =~ s/\s*$//; # Remove any trailing whitespace - already did that
2011-03-11 07:42:57 +00:00
$ attr =~ tr /A-Z/ a - z / ; # Convert to lowercase
2010-09-16 02:05:28 +00:00
#$val =~ s/^\s*//;
2011-06-20 08:51:17 +00:00
$ val =~ s/\s*$// ;
2010-09-16 02:05:28 +00:00
# set the value in the hash for this stanza
if ( ! defined ( $ stanza ) ) { errormsg ( "expected stanza header at line $linenum." , 3 ) ; return ; }
$ STANZAS { $ stanza } - > { $ attr } = $ val ;
}
elsif ( $ l =~ /^\s*(\S+)\s*:\s*$/ ) {
$ stanza = $ 1 ;
}
else {
errormsg ( "syntax error on line $linenum." , 3 ) ;
return 0 ;
}
} # end while - go to next line
return 1 ;
}
2011-04-01 21:30:08 +00:00
# A few common tables that a lot of functions need. The value is whether or not it should autocommit.
2010-12-17 19:14:32 +00:00
my % tables = ( 'site' = > 1 ,
'nodelist' = > 1 ,
'hosts' = > 1 ,
'ppc' = > 1 ,
'nodetype' = > 1 ,
'nodehm' = > 1 ,
'noderes' = > 1 ,
'postscripts' = > 1 ,
'nodepos' = > 1 ,
'servicenode' = > 1 ,
'nodegroup' = > 0 ,
2011-03-11 07:42:57 +00:00
'networks' = > 1 ,
2011-04-09 13:19:45 +00:00
'routes' = > 0 ,
2011-05-25 10:35:28 +00:00
'vpd' = > 1 ,
2010-09-16 02:05:28 +00:00
) ;
2010-10-29 19:09:18 +00:00
my $ CECPOSITIONS ; # a hash of the cec values in the nodepos table
2010-09-16 02:05:28 +00:00
sub writedb {
2010-10-14 16:00:20 +00:00
my ( $ cwd , $ sections ) = @ _ ; # the current dir from the request and the stanzas that should be processed
2010-09-16 02:05:28 +00:00
# Open some common tables that several of the stanzas need
foreach my $ tab ( keys % tables ) {
2010-12-17 19:14:32 +00:00
$ tables { $ tab } = xCAT::Table - > new ( $ tab , - create = > 1 , - autocommit = > $ tables { $ tab } ) ;
2010-09-16 02:05:28 +00:00
if ( ! $ tables { $ tab } ) { errormsg ( "Can not open $tab table in database. Exiting config file processing." , 3 ) ; return ; }
}
2011-04-01 21:30:08 +00:00
# Write site table attrs (hash key=xcat-site)
my $ domain = $ STANZAS { 'xcat-site' } - > { domain } ;
if ( $ domain && ( ! scalar ( keys ( %$ sections ) ) || $$ sections { 'xcat-site' } ) ) { writesite ( $ domain ) ; }
2011-03-11 07:42:57 +00:00
2010-09-16 02:05:28 +00:00
# Write service LAN info (hash key=xcat-service-lan)
2011-03-11 07:42:57 +00:00
my $ iprange = $ STANZAS { 'xcat-service-lan' } - > { 'dhcp-dynamic-range' } ;
if ( $ iprange && ( ! scalar ( keys ( %$ sections ) ) || $$ sections { 'xcat-service-lan' } ) ) {
2011-04-01 21:30:08 +00:00
#my $mkresult = xCAT_plugin::networks->donets();
2011-03-11 07:42:57 +00:00
unless ( writenetworks ( $ iprange ) ) { closetables ( ) ; return ; }
}
2010-09-16 02:05:28 +00:00
# Write HMC info (hash key=xcat-hmcs)
my $ hmcrange = $ STANZAS { 'xcat-hmcs' } - > { 'hostname-range' } ;
2010-10-29 19:09:18 +00:00
if ( $ hmcrange && ( ! scalar ( keys ( %$ sections ) ) || $$ sections { 'xcat-hmcs' } ) ) {
unless ( writehmc ( $ hmcrange ) ) { closetables ( ) ; return ; }
}
2010-09-16 02:05:28 +00:00
# Write frame info (hash key=xcat-frames)
my $ framerange = $ STANZAS { 'xcat-frames' } - > { 'hostname-range' } ;
2010-10-29 19:09:18 +00:00
if ( $ framerange && ( ! scalar ( keys ( %$ sections ) ) || $$ sections { 'xcat-frames' } ) ) {
unless ( writeframe ( $ framerange , $ cwd ) ) { closetables ( ) ; return ; }
}
2010-09-16 02:05:28 +00:00
2011-05-17 06:08:01 +00:00
# Write bpa info (hash key=xcat-bpas)
my $ bpaa0 = $ STANZAS { 'xcat-frames' } - > { 'bpa-a-0-starting-ip' } ;
my $ bpab0 = $ STANZAS { 'xcat-frames' } - > { 'bpa-b-0-starting-ip' } ;
my $ bpaa1 = $ STANZAS { 'xcat-frames' } - > { 'bpa-a-1-starting-ip' } ;
my $ bpab1 = $ STANZAS { 'xcat-frames' } - > { 'bpa-b-1-starting-ip' } ;
2011-06-20 08:51:17 +00:00
if ( ( $ bpaa0 or $ bpaa1 or $ bpab0 or $ bpab1 ) and ( ! scalar ( keys ( %$ sections ) ) || $$ sections { 'xcat-frames' } ) ) {
2011-05-17 06:08:01 +00:00
unless ( writechildren ( $ bpaa0 , $ bpaa1 , $ bpab0 , $ bpab1 , "bpa" ) ) { closetables ( ) ; return ; }
}
2011-06-20 08:51:17 +00:00
#if ( !($bpaa0 and $bpaa1 and $bpab0 and $bpab1) and
# ($bpaa0 or $bpaa1 or $bpab0 or $bpab1)) {
# # need to do something here?
#}
2010-09-16 02:05:28 +00:00
# Write CEC info (hash key=xcat-cecs)
my $ cecrange = $ STANZAS { 'xcat-cecs' } - > { 'hostname-range' } ;
2010-10-29 19:09:18 +00:00
if ( $ cecrange && ( ! scalar ( keys ( %$ sections ) ) || $$ sections { 'xcat-cecs' } ) ) {
unless ( writecec ( $ cecrange , $ cwd ) ) { closetables ( ) ; return ; }
}
2011-05-17 06:08:01 +00:00
# Write fsp info (hash key=xcat-fsps)
my $ fspa0 = $ STANZAS { 'xcat-cecs' } - > { 'fsp-a-0-starting-ip' } ;
my $ fspb0 = $ STANZAS { 'xcat-cecs' } - > { 'fsp-b-0-starting-ip' } ;
my $ fspa1 = $ STANZAS { 'xcat-cecs' } - > { 'fsp-a-1-starting-ip' } ;
my $ fspb1 = $ STANZAS { 'xcat-cecs' } - > { 'fsp-b-1-starting-ip' } ;
2011-06-20 08:51:17 +00:00
if ( ( $ fspa0 or $ fspa1 or $ fspb0 or $ fspb1 ) and ( ! scalar ( keys ( %$ sections ) ) || $$ sections { 'xcat-cecs' } ) ) {
2011-05-17 06:08:01 +00:00
unless ( writechildren ( $ fspa0 , $ fspa1 , $ fspb0 , $ fspb1 , "fsp" ) ) { closetables ( ) ; return ; }
}
2011-06-20 08:51:17 +00:00
#if ( !($fspa0 and $fspa1 and $fspb0 and $fspb1) and
# ($fspa0 or $fspa1 or $fspb0 or $fspb1)) {
# # need to do something here?
#}
2010-10-29 19:09:18 +00:00
# Save the CEC positions for all the node definitions later
if ( $ cecrange ) {
$ CECPOSITIONS = $ tables { 'nodepos' } - > getNodesAttribs ( [ noderange ( $ cecrange ) ] , [ 'rack' , 'u' ] ) ;
#print Dumper($CECPOSITIONS);
}
2010-09-16 02:05:28 +00:00
# Write BB info (hash key=xcat-building-blocks)
my $ framesperbb = $ STANZAS { 'xcat-building-blocks' } - > { 'num-frames-per-bb' } ;
2010-10-29 19:09:18 +00:00
if ( $ framesperbb && ( ! scalar ( keys ( %$ sections ) ) || $$ sections { 'xcat-building-blocks' } ) ) {
unless ( writebb ( $ framesperbb ) ) { closetables ( ) ; return ; }
}
2010-09-16 02:05:28 +00:00
2010-12-17 19:14:32 +00:00
# Write lpar info in ppc, noderes, servicenode, etc.
my $ lparrange = $ STANZAS { 'xcat-lpars' } - > { 'hostname-range' } ;
if ( $ lparrange && ( ! scalar ( keys ( %$ sections ) ) || $$ sections { 'xcat-lpars' } ) ) {
unless ( writelpar ( $ lparrange ) ) { closetables ( ) ; return ; }
#unless (writelpar-service($lparrange)) { closetables(); return; }
#unless (writelpar-storage($lparrange)) { closetables(); return; }
}
2010-10-14 16:00:20 +00:00
my $ snrange = $ STANZAS { 'xcat-service-nodes' } - > { 'hostname-range' } ;
2010-10-29 19:09:18 +00:00
if ( $ snrange && ( ! scalar ( keys ( %$ sections ) ) || $$ sections { 'xcat-service-nodes' } ) ) {
unless ( writesn ( $ snrange ) ) { closetables ( ) ; return ; }
}
2010-10-14 16:00:20 +00:00
my $ storagerange = $ STANZAS { 'xcat-storage-nodes' } - > { 'hostname-range' } ;
2010-10-29 19:09:18 +00:00
if ( $ storagerange && ( ! scalar ( keys ( %$ sections ) ) || $$ sections { 'xcat-storage-nodes' } ) ) {
unless ( writestorage ( $ storagerange ) ) { closetables ( ) ; return ; }
}
2010-10-14 16:00:20 +00:00
my $ computerange = $ STANZAS { 'xcat-compute-nodes' } - > { 'hostname-range' } ;
2010-10-29 19:09:18 +00:00
if ( $ computerange && ( ! scalar ( keys ( %$ sections ) ) || $$ sections { 'xcat-compute-nodes' } ) ) {
unless ( writecompute ( $ computerange ) ) { closetables ( ) ; return ; }
}
closetables ( ) ;
}
sub closetables {
2010-09-16 02:05:28 +00:00
# Close all the open common tables to finish up
foreach my $ tab ( keys % tables ) {
if ( $ tables { $ tab } ) { $ tables { $ tab } - > close ( ) ; }
}
}
2011-04-01 21:30:08 +00:00
sub writesite {
if ( $ DELETENODES ) { return 1 ; }
#write: domain, nameservers=<MN>
my $ domain = shift ;
infomsg ( 'Defining site attributes...' ) ;
# set the domain specified in the config file
#print "domain=$domain\n";
$ tables { 'site' } - > setAttribs ( { key = > 'domain' } , { value = > $ domain } ) ;
# set the site.nameservers value to the site.master value
my $ ref = $ tables { 'site' } - > getAttribs ( { key = > 'master' } , 'value' ) ;
if ( $ ref ) {
$ tables { 'site' } - > setAttribs ( { key = > 'nameservers' } , { value = > $ ref - > { value } } ) ;
}
# set the HFI switch topology
if ( $ STANZAS { 'xcat-site' } - > { topology } ) {
$ tables { 'site' } - > setAttribs ( { key = > 'topology' } , { value = > $ STANZAS { 'xcat-site' } - > { topology } } ) ;
}
return 1 ;
}
2011-03-11 07:42:57 +00:00
sub writenetworks {
if ( $ DELETENODES ) { return 1 ; }
my $ range = shift ;
2011-04-01 21:30:08 +00:00
infomsg ( 'Defining service LAN attributes...' ) ;
#using dhcp-dynamic-range, write: networks.dynamicrange for the service network.
# Note: for AIX the permanent IPs for HMCs/FSPs/BPAs (specified in later stanzas) should be within this dynamic range, at the high end. For linux the permanent IPs should be outside this dynamic range.
# Use the first IP in the specified dynamic range to locate the service network in the networks table
#todo: create the service and cluster networks in the networks table based on the ip ranges they give us
# for the hw and the nodes
2011-03-11 07:42:57 +00:00
# set the IP range specified in the config file
#print "range=$range\n";
2011-04-01 21:30:08 +00:00
my $ dhcpinterfaces ;
2011-03-11 07:42:57 +00:00
# find the network the range existed
$ range =~ /(\d+\.\d+\.\d+\.\d+)\-(\d+\.\d+\.\d+\.\d+)/ ;
my ( $ ip1 , $ ip2 , $ ip3 , $ ip4 ) = split ( '\.' , $ 1 ) ;
my @ entries = @ { $ tables { 'networks' } - > getAllEntries ( ) } ;
2011-04-01 21:30:08 +00:00
#todo: give an error msg if you do not find a network that corresponds to the range they gave
2011-03-11 07:42:57 +00:00
if ( @ entries ) {
for my $ net ( @ entries ) {
my % netref = %$ net ;
my ( $ m1 , $ m2 , $ m3 , $ m4 ) = split ( '\.' , $ netref { 'mask' } ) ;
my $ n1 = ( ( int $ ip1 ) & ( int $ m1 ) ) ;
my $ n2 = ( ( int $ ip2 ) & ( int $ m2 ) ) ;
my $ n3 = ( ( int $ ip3 ) & ( int $ m3 ) ) ;
my $ n4 = ( ( int $ ip4 ) & ( int $ m4 ) ) ;
my $ ornet = "$n1.$n2.$n3.$n4" ;
if ( $ ornet eq $ netref { 'net' } ) {
$ tables { 'networks' } - > setAttribs ( { 'net' = > $ netref { 'net' } , 'mask' = > $ netref { 'mask' } } , { 'dynamicrange' = > $ range } ) ;
2011-04-01 21:30:08 +00:00
$ dhcpinterfaces = $ netref { 'mgtifname' } ;
2011-03-11 07:42:57 +00:00
last ;
}
}
}
2011-04-01 21:30:08 +00:00
# set site.dhcpinterfaces
#todo: we also need to include the cluster mgmt network
if ( $ dhcpinterfaces ) {
$ tables { 'site' } - > setAttribs ( { key = > 'dhcpinterfaces' } , { value = > $ dhcpinterfaces } ) ;
2010-10-28 11:59:22 +00:00
}
2010-09-23 17:57:35 +00:00
2011-04-01 21:30:08 +00:00
return 1 ;
}
2010-09-16 02:05:28 +00:00
sub writehmc {
2010-10-28 11:59:22 +00:00
# using hostname-range, write: nodelist.node, nodelist.groups
2010-09-16 02:05:28 +00:00
my $ hmcrange = shift ;
2010-12-17 19:14:32 +00:00
my $ nodes = [ noderange ( $ hmcrange , 0 ) ] ;
if ( ! scalar ( @$ nodes ) ) { return 1 ; }
if ( $ DELETENODES ) {
deletenodes ( 'HMCs' , $ hmcrange ) ;
deletegroup ( 'hmc' ) ;
return 1 ;
}
2010-10-29 19:09:18 +00:00
my $ hmchash ;
unless ( $ hmchash = parsenoderange ( $ hmcrange ) ) { return 0 ; }
2010-12-08 17:32:46 +00:00
infomsg ( 'Defining HMCs...' ) ;
2011-06-20 13:49:52 +00:00
$ tables { 'nodelist' } - > setNodesAttribs ( $ nodes , { groups = > 'hmc,all' , hidden = > 0 } ) ;
2010-12-17 19:14:32 +00:00
staticGroup ( 'hmc' ) ;
2010-09-16 02:05:28 +00:00
2010-10-28 11:59:22 +00:00
# using hostname-range and starting-ip, write regex for: hosts.node, hosts.ip
2010-09-16 02:05:28 +00:00
my $ hmcstartip = $ STANZAS { 'xcat-hmcs' } - > { 'starting-ip' } ;
2010-10-29 19:09:18 +00:00
if ( $ hmcstartip && isIP ( $ hmcstartip ) ) {
2011-04-02 07:48:09 +00:00
my $ hmcstartnum = int $$ hmchash { 'primary-start' } ;
2010-09-16 02:05:28 +00:00
my ( $ ipbase , $ ipstart ) = $ hmcstartip =~ /^(\d+\.\d+\.\d+)\.(\d+)$/ ;
# take the number from the nodename, and as it increases, increase the ip addr
2011-03-11 07:42:57 +00:00
my $ regex = '|\S+?(\d+)\D*$|' . "$ipbase.($ipstart+" . '$1' . "-$hmcstartnum)|" ;
2010-09-16 02:05:28 +00:00
$ tables { 'hosts' } - > setNodeAttribs ( 'hmc' , { ip = > $ regex } ) ;
}
2010-10-28 11:59:22 +00:00
# using hostname-range, write regex for: ppc.node, nodetype.nodetype
2010-12-17 19:14:32 +00:00
$ tables { 'ppc' } - > setNodeAttribs ( 'hmc' , { nodetype = > 'hmc' } ) ;
2011-06-27 13:05:02 +00:00
$ tables { 'nodetype' } - > setNodeAttribs ( 'hmc' , { nodetype = > 'ppc' } ) ;
2010-10-28 11:59:22 +00:00
# Set the 1st two hmcs as the ones CNM should send service events to
$ nodes = [ noderange ( $ hmcrange , 0 ) ] ;
$ tables { 'site' } - > setAttribs ( { key = > 'ea_primary_hmc' } , { value = > $$ nodes [ 0 ] } ) ;
if ( scalar ( @$ nodes ) >= 2 ) { $ tables { 'site' } - > setAttribs ( { key = > 'ea_backup_hmc' } , { value = > $$ nodes [ 1 ] } ) ; }
2010-10-29 19:09:18 +00:00
return 1 ;
2010-09-16 02:05:28 +00:00
}
sub writeframe {
# write hostname-range in nodelist table
my ( $ framerange , $ cwd ) = @ _ ;
my $ nodes = [ noderange ( $ framerange , 0 ) ] ;
2011-06-20 08:51:17 +00:00
foreach ( @$ nodes ) { push @ PARENTS , $ _ ; }
2010-12-17 19:14:32 +00:00
if ( ! scalar ( @$ nodes ) ) { return 1 ; }
2011-05-17 06:08:01 +00:00
$ PANUMBER = scalar ( @$ nodes ) ;
2010-12-17 19:14:32 +00:00
if ( $ DELETENODES ) {
deletenodes ( 'frames' , $ framerange ) ;
deletegroup ( 'frame' ) ;
return 1 ;
2010-09-16 02:05:28 +00:00
}
2010-12-17 19:14:32 +00:00
infomsg ( 'Defining frames...' ) ;
2011-06-20 08:51:17 +00:00
my @ fnodes = @$ nodes ;
2011-06-20 13:49:52 +00:00
$ tables { 'nodelist' } - > setNodesAttribs ( $ nodes , { groups = > 'frame,all' , hidden = > 0 } ) ;
2010-12-17 19:14:32 +00:00
staticGroup ( 'frame' ) ;
2010-09-16 02:05:28 +00:00
# Using the frame group, write starting-ip in hosts table
2011-04-01 21:30:08 +00:00
my $ framehash = parsenoderange ( $ framerange ) ;
2011-05-17 06:08:01 +00:00
#my $framestartip = $STANZAS{'xcat-frames'}->{'starting-ip'};
#if ($framestartip && isIP($framestartip)) {
#my $framestartnum = int $$framehash{'primary-start'};
#my ($ipbase, $ipstart) = $framestartip =~/^(\d+\.\d+\.\d+)\.(\d+)$/;
## take the number from the nodename, and as it increases, increase the ip addr
#my $regex = '|\S+?(\d+)\D*$|' . "$ipbase.($ipstart+" . '$1' . "-$framestartnum)|";
# $tables{'hosts'}->setNodeAttribs('frame', {ip => $regex});
#}
2010-09-16 02:05:28 +00:00
# Using the frame group, write: nodetype.nodetype, nodehm.mgt
2011-03-11 07:42:57 +00:00
$ tables { 'ppc' } - > setNodeAttribs ( 'frame' , { nodetype = > 'frame' } ) ;
2011-06-20 08:51:17 +00:00
$ tables { 'nodetype' } - > setNodeAttribs ( 'frame' , { nodetype = > 'ppc' } ) ;
2010-09-16 02:05:28 +00:00
# Using the frame group, num-frames-per-hmc, hmc hostname-range, write regex for: ppc.node, ppc.hcp, ppc.id
# The frame # should come from the nodename
2011-03-11 07:42:57 +00:00
my $ idregex = '|\S+?(\d+)\D*$|(0+$1)|' ;
2010-09-16 22:26:39 +00:00
my % hash = ( id = > $ idregex ) ;
if ( $ STANZAS { 'xcat-site' } - > { 'use-direct-fsp-control' } ) {
2010-10-21 20:32:14 +00:00
$ tables { 'nodehm' } - > setNodeAttribs ( 'frame' , { mgt = > 'bpa' } ) ;
2010-09-16 22:26:39 +00:00
my $ hcpregex = '|(.+)|($1)|' ; # its managed by itself
$ hash { hcp } = $ hcpregex ;
}
else {
$ tables { 'nodehm' } - > setNodeAttribs ( 'frame' , { mgt = > 'hmc' } ) ;
# let lsslp fill in the hcp
}
2010-09-16 02:05:28 +00:00
# Calculate which hmc manages this frame by dividing by num-frames-per-hmc
2011-03-11 07:42:57 +00:00
my $ framesperhmc = $ STANZAS { 'xcat-frames' } - > { 'num-frames-per-hmc' } ;
if ( $ framesperhmc and $ STANZAS { 'xcat-hmcs' } - > { 'hostname-range' } ) {
my $ hmchash ;
unless ( $ hmchash = parsenoderange ( $ STANZAS { 'xcat-hmcs' } - > { 'hostname-range' } ) ) { return 0 ; }
my $ hmcbase = $$ hmchash { 'primary-base' } ;
2011-04-02 07:48:09 +00:00
my $ fnum = int $$ framehash { 'primary-start' } ;
2011-03-11 07:42:57 +00:00
my $ hmcattch = $$ hmchash { 'attach' } ;
2011-04-02 07:48:09 +00:00
my $ umb = int $$ hmchash { 'primary-start' } ;
2011-03-11 07:42:57 +00:00
my $ sfpregex ;
2011-06-20 08:51:17 +00:00
#unless ($hmcattch) { $sfpregex = '|\S+?(\d+)\D*$|'.$hmcbase.'(($1-'.$fnum.')/'.$framesperhmc.'+'.$umb.')|'; }
#else { $sfpregex = '|\S+?(\d+)\D*$|'.$hmcbase.'(($1-'.$fnum.')/'.$framesperhmc.'+'.$umb.')'.$hmcattch.'|'; }
#my $tlength = length($$hmchash{'primary-start'});
#$sfpregex = '|\S+?(\d+)\D*$|'.$hmcbase.'(\'0\'*('.$tlength.'-length$1))'.'(($1-'.$fnum.')/'.$framesperhmc.'+'.$umb.')'.$hmcattch.'|';
#$hash{sfp} = $sfpregex;
# keep the sfp attribute for the CEC belongs to it.
# won't use regular express because the cec number in a frame is not fixed.
foreach my $ nn ( @ fnodes ) {
$ nn =~ /\S+?(\d+)\D*$/ ;
my $ num = int ( $ 1 ) ;
my $ num1 = int ( ( int ( $ num ) - $ fnum ) / $ framesperhmc ) + $ umb ;
my $ num2 = length ( $$ hmchash { 'primary-start' } ) - length ( $ num1 ) ;
$ FRAMESFP { $ nn } { sfp } = $ hmcbase . $ num1 . $ hmcattch if ( $ num2 <= 0 ) ;
$ FRAMESFP { $ nn } { sfp } = $ hmcbase . '0' . $ num1 . $ hmcattch if ( $ num2 eq 1 ) ;
$ FRAMESFP { $ nn } { sfp } = $ hmcbase . '00' . $ num1 . $ hmcattch if ( $ num2 eq 2 ) ;
}
$ tables { 'ppc' } - > setNodesAttribs ( \ % FRAMESFP ) ;
2011-03-11 07:42:57 +00:00
}
2010-09-16 22:26:39 +00:00
$ tables { 'ppc' } - > setNodeAttribs ( 'frame' , \ % hash ) ;
2010-09-16 02:05:28 +00:00
# Write vpd-file to vpd table
2010-10-29 19:09:18 +00:00
if ( $ STANZAS { 'xcat-frames' } - > { 'vpd-file' } ) {
my $ filename = fullpath ( $ STANZAS { 'xcat-frames' } - > { 'vpd-file' } , $ cwd ) ;
readwritevpd ( $ filename ) ;
}
return 1 ;
2010-09-16 02:05:28 +00:00
}
2011-05-17 06:08:01 +00:00
sub writechildren {
my $ a0startingip = shift ;
my $ a1startingip = shift ;
my $ b0startingip = shift ;
my $ b1startingip = shift ;
my $ ntype = shift ;
my @ startingips ;
push @ startingips , $ a0startingip ;
push @ startingips , $ a1startingip ;
push @ startingips , $ b0startingip ;
push @ startingips , $ b1startingip ;
my @ all ;
2011-06-20 08:51:17 +00:00
my $ tt = 0 ;
my % ranges ;
2011-05-17 06:08:01 +00:00
for my $ cip ( @ startingips ) {
2011-06-20 08:51:17 +00:00
my $ trange ;
if ( $ cip ) {
my ( $ ipbase , $ ipstart ) = $ cip =~ /^(\d+\.\d+\.\d+)\.(\d+)$/ ;
my $ endip = $ ipstart + $ PANUMBER - 1 ;
$ trange = $ cip . '-' . $ ipbase . '.' . $ endip ;
my $ nodes = [ noderange ( $ trange , 0 ) ] ;
foreach ( @$ nodes ) { push @ all , $ _ ; }
} else {
$ trange = 1 ;
}
$ ranges { 'A-0' } = $ trange if ( $ tt eq 0 ) ;
$ ranges { 'A-1' } = $ trange if ( $ tt eq 1 ) ;
$ ranges { 'B-0' } = $ trange if ( $ tt eq 2 ) ;
$ ranges { 'B-1' } = $ trange if ( $ tt eq 3 ) ;
$ tt + + ;
2011-05-17 06:08:01 +00:00
}
if ( $ DELETENODES ) {
2011-06-20 08:51:17 +00:00
for my $ rr ( keys % ranges ) {
deletenodes ( $ ntype , $ ranges { $ rr } ) ;
}
deletegroup ( $ ntype ) ;
2011-05-17 06:08:01 +00:00
return 1 ;
}
# write bpa/fsp nodes to database with nodelist.node, nodelist.groups
infomsg ( "Defining $ntype" . "s..." ) ;
2011-06-20 13:49:52 +00:00
$ tables { 'nodelist' } - > setNodesAttribs ( \ @ all , { groups = > "$ntype,all" , hidden = > 1 } ) ;
2011-05-17 06:08:01 +00:00
staticGroup ( $ ntype ) ;
# Using the bpa group, write: ppc.nodetype, nodetype.nodetype,
$ tables { 'ppc' } - > setNodeAttribs ( $ ntype , { nodetype = > $ ntype } ) ;
2011-06-20 08:51:17 +00:00
$ tables { 'nodetype' } - > setNodeAttribs ( $ ntype , { nodetype = > 'ppc' } ) ;
2011-05-17 06:08:01 +00:00
# Using the bpa group, write regex for: nodehm.mgt, ppc.node, ppc.hcp
my % hash ;
if ( $ STANZAS { 'xcat-site' } - > { 'use-direct-fsp-control' } ) {
$ tables { 'nodehm' } - > setNodeAttribs ( $ ntype , { mgt = > $ ntype } ) ;
my $ hcpregex = '|(.+)|($1)|' ; # its managed by itself
$ hash { hcp } = $ hcpregex ;
}
else {
$ tables { 'nodehm' } - > setNodeAttribs ( $ ntype , { mgt = > 'hmc' } ) ;
}
$ tables { 'ppc' } - > setNodeAttribs ( $ ntype , \ % hash ) ;
# Using the bpa group, write regex for:ppc.parent
2011-06-20 08:51:17 +00:00
# we should not assume the user define four fsp/bpas with the same starting ip the last bit
my % sidehash ;
my % parenthash ;
for my $ tside ( keys % ranges ) {
next if ( $ ranges { $ tside } eq 1 ) ;
my ( $ ipbase , $ ipstart ) = $ ranges { $ tside } =~ /^(\d+\.\d+\.\d+\.)(\d+)\-\d+\.\d+\.\d+\.\d+$/ ;
my $ i = 0 ;
my @ parents = sort ( @ PARENTS ) ;
foreach my $ ch ( @ parents ) { $ parenthash { $ ipbase . ( $ i + $ ipstart ) } - > { parent } = $ ch ; $ i + + ; }
# my $nodetmp = [noderange($$tside, 0)];
# foreach my $ch (@$nodetmp) {$sidehash{$ch}->{side} = $tside;}
my $ nodetmp = [ noderange ( $ ranges { $ tside } , 0 ) ] ;
foreach my $ ch ( @$ nodetmp ) { $ sidehash { $ ch } - > { side } = $ tside ; }
2011-05-25 10:33:26 +00:00
}
2011-06-20 08:51:17 +00:00
$ tables { 'vpd' } - > setNodesAttribs ( \ % sidehash ) ;
$ tables { 'ppc' } - > setNodesAttribs ( \ % parenthash ) ;
#my ($ipbase, $ipstart) = $a0startingip =~ /^(\d+\.\d+\.\d+)\.(\d+)$/;
#my $phash;
#if ($ntype eq "bpa") {
# $phash = parsenoderange($STANZAS{'xcat-frames'}->{'hostname-range'});
#} else {
# $phash = parsenoderange($STANZAS{'xcat-cecs'}->{'hostname-range'});
#}
#my $fs = $$phash{'primary-start'};
#my $nb = $$phash{'primary-base'};
#my $nameend = $$phash{'attach'};
#my $namesecond = $$phash{'secondary-base'};
#my $pregex;
#my $tlength = length($fs);
#if ($ntype eq "bpa") {
# $pregex = '|^(\d+\.\d+\.\d+)\.(\d+)$|'.$nb.'(\'0\'*('.$tlength.'-length($2)))('.int($fs).'+$2-'.$ipstart.')'.$nameend.'|';
# $tables{'ppc'}->setNodeAttribs($ntype, {parent => $pregex});
#} elsif (!($STANZAS{'xcat-cecs'}->{'supernode-list'})) {
# # no supernode-list specified, which means every frame contians same number cecs
# my $ss = $$phash{'secondary-start'};
# my $se = $$phash{'secondary-end'};
# my $cm;
# my $clength;
# if($ss and $se) {
# $cm = int($se) - int($ss);
# $clength = length($ss);
# }
# my $fn = '('.int($fs).'-1+($2-'.$ipstart.'+1)/'.$cm.')';
# my $cn = '('.int($ss).'-1+($2-'.$ipstart.'+1)%'.$cm.')';
# $pregex = '|^(\d+\.\d+\.\d+)\.(\d+)$|'.$nb.'(\'0\'*('.$tlength.'-length'.$fn.'))'.$fn.$namesecond.'(\'0\'*('.$clength.'-length'.$cn.'))'.$cn.$nameend.'|';
# $tables{'ppc'}->setNodeAttribs($ntype, {parent => $pregex});
#}
#
## the cec numbers for each frame are different
## so we need to find the fsp parent one by one
#if ($ntype eq "fsp" and $STANZAS{'xcat-cecs'}->{'supernode-list'} and @CECS) {
# my @cecparent = sort(@CECS);
# my %parenthash;
# for my $cip (@startingips) {
# my ($ipbase, $ipstart) = $cip =~/^(\d+\.\d+\.\d+\.)(\d+)$/;
# my $i = 0;
# foreach my $ch (@cecparent) {$parenthash{$ipbase.($i+$ipstart)}->{parent} = $ch; $i++;}
# }
# $tables{'ppc'}->setNodesAttribs(\%parenthash);
#}
#
## write: vpd.side
#my $time = 0;
#for my $cip (@startingips) {
# my ($ipbase, $ipstart) = $cip =~/^(\d+\.\d+\.\d+)\.(\d+)$/;
# my $endip = $ipstart + $PANUMBER;
# my $endnode = $ipbase . '.' . $endip;
# my $range = $cip . '-' . $endnode;
# my $nodetmp = [noderange($range, 0)];
# $time ++;
# my %sidehash;
# foreach my $ch (@$nodetmp) {
# $sidehash{$ch}->{side} = "A-0" if ($time eq 1);
# $sidehash{$ch}->{side} = "A-1" if ($time eq 2);
# $sidehash{$ch}->{side} = "B-0" if ($time eq 3);
# $sidehash{$ch}->{side} = "B-1" if ($time eq 4);
# }
# $tables{'vpd'}->setNodesAttribs(\%sidehash);
2011-05-17 06:08:01 +00:00
#}
return 1 ;
}
2010-09-16 02:05:28 +00:00
sub readwritevpd {
my $ filename = shift ;
if ( ! defined ( $ filename ) ) { return ; }
my $ content ;
if ( ! open ( STANZAF , $ filename ) ) { errormsg ( "Can not open file $filename." , 2 ) ; return ; }
while ( my $ line = <STANZAF> ) { $ content . = $ line ; }
close STANZAF ;
#print "content=$content";
my $ rc = xCAT::DBobjUtils - > readFileInput ( $ content ) ;
if ( $ rc ) { errormsg ( "Error in processing stanza file $filename, rc=$rc." , 2 ) ; return ; }
$ rc = xCAT::DBobjUtils - > setobjdefs ( \ % ::FILEATTRS ) ;
if ( $ rc ) { errormsg ( "Error setting database attributes from stanza file $filename, rc=$rc." , 2 ) ; return ; }
}
sub writecec {
# write hostname-range in nodelist table
my ( $ cecrange , $ cwd ) = @ _ ;
my $ nodes = [ noderange ( $ cecrange , 0 ) ] ;
2010-10-14 16:00:20 +00:00
if ( $$ nodes [ 0 ] =~ /\[/ ) {
errormsg ( "hostname ranges with 2 sets of '[]' are not supported in xCAT 2.5 and below." , 21 ) ;
2010-10-29 19:09:18 +00:00
return 0 ;
2010-10-14 16:00:20 +00:00
}
2010-12-17 19:14:32 +00:00
if ( ! scalar ( @$ nodes ) ) { return 1 ; }
2011-05-17 06:08:01 +00:00
$ PANUMBER = scalar ( @$ nodes ) ;
2010-12-17 19:14:32 +00:00
if ( $ DELETENODES ) {
deletenodes ( 'CECs' , $ cecrange ) ;
deletegroup ( 'cec' ) ;
dynamicGroups ( 'delete' , $ nodes ) ;
return 1 ;
2010-09-16 02:05:28 +00:00
}
2010-12-17 19:14:32 +00:00
infomsg ( 'Defining CECs...' ) ;
2011-06-20 13:49:52 +00:00
$ tables { 'nodelist' } - > setNodesAttribs ( $ nodes , { groups = > 'cec,all' , hidden = > 0 } ) ;
2010-12-17 19:14:32 +00:00
staticGroup ( 'cec' ) ;
2010-09-16 02:05:28 +00:00
# Using the cec group, write starting-ip in hosts table
my $ cecstartip = $ STANZAS { 'xcat-cecs' } - > { 'starting-ip' } ;
2010-12-08 17:32:46 +00:00
my $ cechash = parsenoderange ( $ cecrange ) ;
2010-10-29 19:09:18 +00:00
if ( $ cecstartip && isIP ( $ cecstartip ) ) {
2010-09-25 15:14:10 +00:00
my ( $ ipbase , $ ip3rd , $ ip4th ) = $ cecstartip =~ /^(\d+\.\d+)\.(\d+)\.(\d+)$/ ;
2010-09-16 02:05:28 +00:00
# take the number from the nodename, and as it increases, increase the ip addr
2010-10-14 16:00:20 +00:00
#print Dumper($cechash);
my $ regex ;
if ( defined ( $$ cechash { 'secondary-start' } ) ) {
# using name like f1c1
2011-04-02 07:48:09 +00:00
my $ primstartnum = int $$ cechash { 'primary-start' } ;
my $ secstartnum = int $$ cechash { 'secondary-start' } ;
2010-10-14 16:00:20 +00:00
# Math for 3rd field: ip3rd+primnum-primstartnum
# Math for 4th field: ip4th+secnum-secstartnum
2011-03-11 07:42:57 +00:00
$ regex = '|\D+(\d+)\D+(\d+)\D*$|' . "$ipbase.($ip3rd+" . '$1' . "-$primstartnum).($ip4th+" . '$2' . "-$secstartnum)|" ;
2011-06-20 08:51:17 +00:00
} else {
2010-10-14 16:00:20 +00:00
# using name like cec01
2011-04-02 07:48:09 +00:00
my $ cecstartnum = int $$ cechash { 'primary-start' } ;
2010-10-14 16:00:20 +00:00
# Math for 4th field: (ip4th-1+cecnum-cecstartnum)%254 + 1
# Math for 3rd field: (ip4th-1+cecnum-cecstartnum)/254 + ip3rd
2011-03-11 07:42:57 +00:00
$ regex = '|\S+?(\d+)$\D*|' . "$ipbase.((${ip4th}-1+" . '$1' . "-$cecstartnum)/254+$ip3rd).((${ip4th}-1+" . '$1' . "-$cecstartnum)%254+1)|" ;
2010-10-14 16:00:20 +00:00
}
2011-05-17 06:08:01 +00:00
#$tables{'hosts'}->setNodeAttribs('cec', {ip => $regex});
2010-09-16 02:05:28 +00:00
}
2010-10-14 16:00:20 +00:00
# Using the cec group, write: nodetype.nodetype
2011-03-11 07:42:57 +00:00
$ tables { 'ppc' } - > setNodeAttribs ( 'cec' , { nodetype = > 'cec' } ) ;
2011-06-20 13:49:52 +00:00
$ tables { 'nodetype' } - > setNodeAttribs ( 'cec' , { nodetype = > 'ppc' } ) ;
2010-09-16 02:05:28 +00:00
2010-10-15 20:08:12 +00:00
# Write regex for ppc.hcp, nodehm.mgt
2010-09-16 22:26:39 +00:00
if ( $ STANZAS { 'xcat-site' } - > { 'use-direct-fsp-control' } ) {
$ tables { 'nodehm' } - > setNodeAttribs ( 'cec' , { mgt = > 'fsp' } ) ;
my $ hcpregex = '|(.+)|($1)|' ; # its managed by itself
$ tables { 'ppc' } - > setNodeAttribs ( 'cec' , { hcp = > $ hcpregex } ) ;
}
else {
$ tables { 'nodehm' } - > setNodeAttribs ( 'cec' , { mgt = > 'hmc' } ) ;
# let lsslp fill in the hcp
}
2010-09-16 02:05:28 +00:00
2010-10-29 19:09:18 +00:00
# Create dynamic groups for the nodes in each cec
2010-12-17 19:14:32 +00:00
$ nodes = [ noderange ( $ cecrange , 0 ) ] ; # the setNodesAttribs() function blanks out the nodes array
dynamicGroups ( 'add' , $ nodes , 'parent==' ) ;
2011-03-03 18:41:59 +00:00
2010-09-16 02:05:28 +00:00
$ nodes = [ noderange ( $ cecrange , 0 ) ] ; # the setNodesAttribs() function blanks out the nodes array
2011-03-03 18:41:59 +00:00
# If they are taking the simple approach for now of not assigning supernode #s, but just told
# us how many cecs should be in each frame, write: ppc.id, ppc.parent, nodelist.groups, nodepos.rack, nodepos.u
if ( ! ( $ STANZAS { 'xcat-cecs' } - > { 'supernode-list' } ) && $ STANZAS { 'xcat-cecs' } - > { 'num-cecs-per-frame' } ) {
# Loop thru all cecs, incrementing the cageid and frameindex appropriately, and put the cec attrs in the hashes.
my $ cecsperframe = $ STANZAS { 'xcat-cecs' } - > { 'num-cecs-per-frame' } ;
my % ppchash ;
my % nodehash ;
my % nodeposhash ;
my $ numcecs = 1 ; # the # of cecs we have assigned to the current frame
my $ cageid = 5 ; #todo: p7 ih starts at 5, but what about other models?
my $ frames = [ noderange ( $ STANZAS { 'xcat-frames' } - > { 'hostname-range' } , 0 ) ] ;
my $ frameindex = 0 ;
foreach my $ cec ( @$ nodes ) {
my $ framename = $$ frames [ $ frameindex ] ;
2011-06-20 08:51:17 +00:00
my $ sfp = $ FRAMESFP { $ framename } { sfp } ;
$ ppchash { $ cec } = { id = > $ cageid , parent = > $ framename , sfp = > $ sfp } ;
2011-03-03 18:41:59 +00:00
$ nodehash { $ cec } = { groups = > "${framename}cecs,cec,all" } ;
2011-03-11 07:42:57 +00:00
my ( $ framenum ) = $ framename =~ /\S+?(\d+)\D*$/ ;
2011-03-03 18:41:59 +00:00
$ nodeposhash { $ cec } = { rack = > $ framenum + 0 , u = > $ cageid } ;
# increment indexes for the next iteration of the loop
$ cageid += 2 ;
$ numcecs + + ;
if ( $ numcecs > $ cecsperframe ) { $ frameindex + + ; $ numcecs = 1 ; $ cageid = 5 ; } #todo: p7 ih starts at 5
}
$ tables { 'ppc' } - > setNodesAttribs ( \ % ppchash ) ;
$ tables { 'nodelist' } - > setNodesAttribs ( \ % nodehash ) ;
$ tables { 'nodepos' } - > setNodesAttribs ( \ % nodeposhash ) ;
}
# If they specified supernode-list, write ppc.supernode. While we are at it, also assign the cage id and parent.
2010-09-16 02:05:28 +00:00
my % framesupers ;
2010-10-29 19:09:18 +00:00
if ( ! ( $ STANZAS { 'xcat-cecs' } - > { 'supernode-list' } ) ) { return 1 ; }
2010-09-16 02:05:28 +00:00
my $ filename = fullpath ( $ STANZAS { 'xcat-cecs' } - > { 'supernode-list' } , $ cwd ) ;
2010-10-29 19:09:18 +00:00
unless ( readsupers ( $ filename , \ % framesupers ) ) { return ; }
2010-09-16 02:05:28 +00:00
my $ i = 0 ; # the index into the array of cecs
2010-12-08 17:32:46 +00:00
#my $maxcageid=0; # check to see if all frames have same # of cecs if they are using f1c1 type name
#my $alreadywarned=0;
my $ numcecs ; # how many cecs in a frame we have assigned supernode nums to
2010-10-14 16:00:20 +00:00
my % ppchash ;
2010-09-16 02:05:28 +00:00
my % nodehash ;
2010-10-29 19:09:18 +00:00
my % nodeposhash ;
2010-12-08 17:32:46 +00:00
my @ nonexistant ; # if there are less cecs in some frames, we may need to delete them
2010-09-16 02:05:28 +00:00
# Collect each nodes supernode num into a hash
foreach my $ k ( sort keys % framesupers ) {
my $ f = $ framesupers { $ k } ; # $f is a ptr to an array of super node numbers
if ( ! $ f ) { next ; } # in case some frame nums did not get filled in by user
2011-03-03 18:41:59 +00:00
my $ cageid = 5 ; #todo: p7 ih starts at 5, but what about other models?
2010-12-08 17:32:46 +00:00
my $ numcecs = 0 ;
2010-09-16 02:05:28 +00:00
foreach my $ s ( @$ f ) { # loop thru the supernode nums in this frame
my $ supernum = $ s ;
my $ numnodes = 4 ;
if ( $ s =~ /\(\d+\)/ ) { ( $ supernum , $ numnodes ) = $ s =~ /^(\d+)\((\d+)\)/ ; }
for ( my $ j = 0 ; $ j < $ numnodes ; $ j + + ) { # assign the next few nodes to this supernode num
my $ nodename = $$ nodes [ $ i + + ] ;
2010-12-08 17:32:46 +00:00
$ numcecs + + ;
2010-09-16 02:05:28 +00:00
#print "Setting $nodename supernode attribute to $supernum,$j\n";
2011-06-20 08:51:17 +00:00
my $ sfp = $ FRAMESFP { $ k } { sfp } ;
$ ppchash { $ nodename } = { supernode = > "$supernum,$j" , id = > $ cageid , parent = > $ k , sfp = > $ sfp } ;
$ nodehash { $ nodename } = { groups = > "${k}cecs,cec,all" } ;
2011-03-11 07:42:57 +00:00
my ( $ framenum ) = $ k =~ /\S+?(\d+)\D*$/ ;
2010-10-29 19:09:18 +00:00
$ nodeposhash { $ nodename } = { rack = > $ framenum + 0 , u = > $ cageid } ;
2010-09-23 17:57:35 +00:00
$ cageid += 2 ;
2010-09-16 02:05:28 +00:00
}
}
2010-12-17 19:14:32 +00:00
$ NUMCECSINFRAME { $ k } = $ numcecs ; # save this for later
my ( $ knum ) = $ k =~ /(\d+)$/ ;
$ NUMCECSINFRAME { $ knum + 0 } = $ numcecs ; # also save it by the frame num
2010-12-08 17:32:46 +00:00
if ( defined ( $$ cechash { 'secondary-start' } ) && $ numcecs != ( $$ cechash { 'secondary-end' } - $$ cechash { 'secondary-start' } + 1 ) ) {
# There are some cecs in this frame that did not get assigned supernode nums - maybe they do not exist
#infomsg("Warning: the xcat-cecs:hostname-range of $cecrange appears to be using frame and CEC numbers in the CEC hostnames, but there is not the same number of CECs in each frame (according to the supernodelist). This causes the supernode numbers to be assigned to the wrong CECs.");
my $ totalcecs = $$ cechash { 'secondary-end' } - $$ cechash { 'secondary-start' } + 1 ;
#print "skipping cecs ", $numcecs+1, "-$totalcecs\n";
if ( $ STANZAS { 'xcat-cecs' } - > { 'delete-unused-cecs' } ) {
# mark to be delete the unused cecs that do not have supernode nums specified
for ( my $ l = 1 ; $ l <= ( $ totalcecs - $ numcecs ) ; $ l + + ) { push @ nonexistant , $$ nodes [ $ i + + ] ; }
}
else {
$ i += ( $ totalcecs - $ numcecs ) ; # fast-forward over the cecs in this frame that do not have supernode nums
}
}
2010-09-16 02:05:28 +00:00
}
2010-12-08 17:32:46 +00:00
# Now write all of the attribute values to the tables
2010-10-14 16:00:20 +00:00
if ( scalar ( keys % framesupers ) ) {
2010-12-08 17:32:46 +00:00
if ( scalar ( @ nonexistant ) ) {
my $ nr = join ( ',' , @ nonexistant ) ;
2010-12-17 19:14:32 +00:00
#print "deleting $nr\n";
noderm ( $ nr ) ;
2010-12-08 17:32:46 +00:00
}
2010-12-17 19:14:32 +00:00
$ tables { 'ppc' } - > setNodesAttribs ( \ % ppchash ) ;
$ tables { 'nodelist' } - > setNodesAttribs ( \ % nodehash ) ;
$ tables { 'nodepos' } - > setNodesAttribs ( \ % nodeposhash ) ;
2010-10-14 16:00:20 +00:00
}
2011-06-20 08:51:17 +00:00
@ PARENTS = ( ) ;
foreach ( keys % nodehash ) { push @ PARENTS , $ _ ; }
return 1 ;
2010-09-16 02:05:28 +00:00
}
# Read/parse the supernode-list file and return the values in a hash of arrays
sub readsupers {
my $ filename = shift ;
my $ framesup = shift ;
if ( ! defined ( $ filename ) ) { return ; }
my $ input ;
if ( ! open ( $ input , $ filename ) ) {
errormsg ( "Can not open file $filename." , 2 ) ;
2010-10-29 19:09:18 +00:00
return 0 ;
2010-09-16 02:05:28 +00:00
}
my $ l ;
my $ linenum = 0 ;
while ( $ l = <$input> ) {
$ linenum + + ;
# skip blank and comment lines
next if ( $ l =~ /^\s*$/ || $ l =~ /^\s*#/ ) ;
#print "l=$l\n";
# process a real line - name, then colon, then only whitespace, numbers, and parens
my ( $ frame , $ supernums ) ;
if ( ( $ frame , $ supernums ) = $ l =~ /^\s*(\S+)\s*:\s*([\s,\(\)\d]+)$/ ) {
#print "frame=$frame, supernums=$supernums\n";
2010-10-29 19:09:18 +00:00
my $ supers = [ split ( /[\s,]+/ , $ supernums ) ] ;
# check the format of the super number entries
foreach my $ s ( @$ supers ) {
unless ( $ s =~ /^\d+$/ || $ s =~ /^\d+\(\d+\)$/ ) { errormsg ( "invalid supernode specification $s in supernode-list file line $linenum." , 8 ) ; return 0 ; }
}
# store the entries
$$ framesup { $ frame } = $ supers ;
2010-09-16 02:05:28 +00:00
}
else {
2010-10-29 19:09:18 +00:00
errormsg ( "syntax error on supernode-list file line $linenum." , 3 ) ;
return 0 ;
2010-09-16 02:05:28 +00:00
}
} # end while - go to next line
close ( $ input ) ;
2010-10-29 19:09:18 +00:00
return 1 ;
2010-09-16 02:05:28 +00:00
}
sub writebb {
my $ framesperbb = shift ;
2010-12-17 19:14:32 +00:00
if ( $ DELETENODES ) { return 1 ; }
2010-09-16 02:05:28 +00:00
infomsg ( 'Defining building blocks...' ) ;
# Set site.sharedtftp=1 since we have bldg blocks
$ tables { 'site' } - > setAttribs ( { key = > 'sharedtftp' } , { value = > 1 } ) ;
2010-12-17 19:14:32 +00:00
$ tables { 'site' } - > setAttribs ( { key = > 'sshbetweennodes' } , { value = > 'service' } ) ;
2010-09-16 02:05:28 +00:00
2011-04-01 21:30:08 +00:00
# Using num-frames-per-bb write ppc.parent (bb #) for the frames
2010-10-29 19:09:18 +00:00
if ( $ framesperbb !~ /^\d+$/ ) { errormsg ( "invalid non-integer value for num-frames-per-bb: $framesperbb" , 7 ) ; return 0 ; }
2011-04-01 21:30:08 +00:00
my $ framehash = parsenoderange ( $ STANZAS { 'xcat-frames' } - > { 'hostname-range' } ) ;
my $ framestartnum = $$ framehash { 'primary-start' } ;
my $ bbregex = '|\S+?(\d+)\D*$|((($1-' . $ framestartnum . ')/' . $ framesperbb . ')+1)|' ;
2010-09-16 02:05:28 +00:00
$ tables { 'ppc' } - > setNodeAttribs ( 'frame' , { parent = > $ bbregex } ) ;
2010-10-29 19:09:18 +00:00
return 1 ;
2010-09-16 02:05:28 +00:00
}
2010-12-17 19:14:32 +00:00
# Create lpar node definitions. This stanza is used only if they are using hostnames like f1c1p1
sub writelpar {
my $ range = shift ;
my $ nodes = [ noderange ( $ range , 0 ) ] ;
if ( ! scalar ( @$ nodes ) ) { return 1 ; }
if ( $ DELETENODES ) {
deletenodes ( 'LPAR nodes' , $ range ) ;
deletegroup ( 'lpar' ) ;
deletegroup ( 'service' ) ;
deletegroup ( 'compute' ) ;
#todo: also delete dynamic groups: dynamicGroups('delete', [keys(%servicenodes)]);
return 1 ;
}
infomsg ( 'Defining LPAR nodes...' ) ;
my $ rangeparts = parsenoderange ( $ range ) ;
if ( ! defined ( $$ rangeparts { 'tertiary-start' } ) ) { errormsg ( "Currently only support xcat-lpars:hostname-range format like f[1-2]c[1-2]p[1-2]." , 5 ) ; return 0 ; }
my ( $ startnum ) = $$ rangeparts { 'primary-start' } ; # save this value for later
2011-06-20 13:49:52 +00:00
$ tables { 'nodelist' } - > setNodesAttribs ( $ nodes , { groups = > 'compute,lpar,all' , hidden = > 0 } ) ;
2010-12-17 19:14:32 +00:00
staticGroup ( 'lpar' ) ;
staticGroup ( 'service' ) ;
staticGroup ( 'compute' ) ;
# Write regex for hosts.node, hosts.ip, etc, for all lpars. Also write a special entry
# for service nodes, since they also have an ethernet adapter.
my $ startip = $ STANZAS { 'xcat-lpars' } - > { 'starting-ip' } ;
2011-04-09 13:19:45 +00:00
if ( ! isIP ( $ startip ) ) { errormsg ( "$startip is not a valid IP address for xcat-lpars:starting-ip." , 5 ) ; }
else {
2010-12-17 19:14:32 +00:00
my ( $ ipbase , $ ip2nd , $ ip3rd , $ ip4th ) = $ startip =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/ ;
# take the number from the nodename, and as it increases, increase the ip addr
# using name like f1c1p1
2011-04-02 07:48:09 +00:00
my $ primstartnum = int $$ rangeparts { 'primary-start' } ;
my $ secstartnum = int $$ rangeparts { 'secondary-start' } ;
my $ thirdstartnum = int $$ rangeparts { 'tertiary-start' } ;
2010-12-17 19:14:32 +00:00
# Math for 2nd field: ip2nd+primnum-primstartnum
# Math for 3rd field: ip3rd+secnum-secstartnum
# Math for 4th field: ip4th+thirdnum-thirdstartnum
2011-03-11 07:42:57 +00:00
my $ regex = '|\D+(\d+)\D+(\d+)\D+(\d+)\D*$|' . "$ipbase.($ip2nd+" . '$1' . "-$primstartnum).($ip3rd+" . '$2' . "-$secstartnum).($ip4th+" . '$3' . "-$thirdstartnum)|" ;
2010-12-17 19:14:32 +00:00
my % hash = ( ip = > $ regex ) ;
# for service nodes, use the starting ip from that stanza
my $ serviceip = $ STANZAS { 'xcat-service-nodes' } - > { 'starting-ip' } ;
my ( $ servbase , $ serv2nd , $ serv3rd , $ serv4th ) = $ serviceip =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/ ;
my % servicehash ;
2011-04-09 13:19:45 +00:00
if ( ! isIP ( $ serviceip ) ) { errormsg ( "$serviceip is not a valid IP address for xcat-service-nodes:starting-ip." , 5 ) ; }
else {
2011-03-11 07:42:57 +00:00
my $ serviceregex = '|\D+(\d+)\D+(\d+)\D+(\d+)\D*$|' . "$servbase.($serv2nd+" . '$1' . "-$primstartnum).($serv3rd+" . '$2' . "-$secstartnum).($serv4th+" . '$3' . "-$thirdstartnum)|" ;
2010-12-17 19:14:32 +00:00
$ servicehash { ip } = $ serviceregex ;
}
my $ otherint = $ STANZAS { 'xcat-lpars' } - > { 'otherinterfaces' } ;
if ( $ otherint ) {
# need to replace each ip addr in otherinterfaces with a regex
my @ ifs = split ( /[\s,]+/ , $ otherint ) ;
foreach my $ if ( @ ifs ) {
my ( $ nic , $ nicip ) = split ( /:/ , $ if ) ;
if ( ! isIP ( $ nicip ) ) { next ; }
my ( $ nicbase , $ nic2nd , $ nic3rd , $ nic4th ) = $ nicip =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/ ;
$ if = "$nic:$nicbase.($nic2nd+" . '$1' . "-$primstartnum).($nic3rd+" . '$2' . "-$secstartnum).($nic4th+" . '$3' . "-$thirdstartnum)" ;
}
2011-03-11 07:42:57 +00:00
$ regex = '|\D+(\d+)\D+(\d+)\D+(\d+)\D*$|' . join ( ',' , @ ifs ) . '|' ;
2010-12-17 19:14:32 +00:00
#print "regex=$regex\n";
$ hash { otherinterfaces } = $ regex ;
if ( $ serviceip && isIP ( $ serviceip ) ) {
# same as regular lpar value, except prepend the lpar ip as -hf0
my $ hf0 = "-hf0:$ipbase.($ip2nd+" . '$1' . "-$primstartnum).($ip3rd+" . '$2' . "-$secstartnum).($ip4th+" . '$3' . "-$thirdstartnum)" ;
2011-03-11 07:42:57 +00:00
my $ serviceregex = '|\D+(\d+)\D+(\d+)\D+(\d+)\D*$|' . "$hf0," . join ( ',' , @ ifs ) . '|' ;
2010-12-17 19:14:32 +00:00
$ servicehash { otherinterfaces } = $ serviceregex ;
}
}
my $ aliases = $ STANZAS { 'xcat-lpars' } - > { 'aliases' } ;
if ( $ aliases ) {
# support more than 1 alias
my @ alist = split ( /[\s,]+/ , $ aliases ) ;
foreach my $ a ( @ alist ) { if ( $ a =~ /^-/ ) { $ a = '($1)' . $ a ; } } # prepend the hostname
$ regex = '|(.+)|' . join ( ',' , @ alist ) . '|' ;
$ hash { hostnames } = $ regex ;
# For services nodes, we do not really need any aliases, but we have to override the above
$ servicehash { hostnames } = '|(.+)|($1)-eth0|' ;
}
$ tables { 'hosts' } - > setNodeAttribs ( 'lpar' , \ % hash ) ;
if ( $ serviceip && isIP ( $ serviceip ) ) { $ tables { 'hosts' } - > setNodeAttribs ( 'service' , \ % servicehash ) ; }
}
# If there are an inconsistent # of cecs in each frame, delete the lpars that are not really there
2011-03-31 00:57:15 +00:00
if ( $ STANZAS { 'xcat-cecs' } - > { 'delete-unused-cecs' } and $ STANZAS { 'xcat-cecs' } - > { 'supernode-list' } and ! $ STANZAS { 'xcat-cecs' } - > { 'num-cecs-per-frame' } ) {
2010-12-17 19:14:32 +00:00
my @ nodestodelete ; # the lpars to delete
my $ maxcecs = $$ rangeparts { 'secondary-end' } - $$ rangeparts { 'secondary-start' } + 1 ;
foreach my $ k ( sort keys % NUMCECSINFRAME ) {
if ( $ NUMCECSINFRAME { $ k } >= $ maxcecs ) { next ; } # this frame is completely populated
# create the noderange of the lpars that need to be deleted
my ( $ framenum ) = $ k =~ /(\d+)$/ ;
my $ len = length ( $$ rangeparts { 'secondary-start' } ) ;
my $ index1 = $ NUMCECSINFRAME { $ k } + $$ rangeparts { 'secondary-start' } ;
$ index1 = sprintf ( "%0${len}d" , $ index1 ) ;
my $ index2 = $$ rangeparts { 'secondary-end' } ;
$ index2 = sprintf ( "%0${len}d" , $ index2 ) ;
$ len = length ( $$ rangeparts { 'primary-start' } ) ;
$ framenum = sprintf ( "%0${len}d" , $ framenum ) ;
my $ nr = $$ rangeparts { 'primary-base' } . $ framenum . $$ rangeparts { 'secondary-base' } . "[$index1-$index2]" . $$ rangeparts { 'tertiary-base' } . '[' . $$ rangeparts { 'tertiary-start' } . '-' . $$ rangeparts { 'tertiary-end' } . ']' ;
2011-03-11 07:42:57 +00:00
if ( $$ rangeparts { 'attach' } ) { $ nr . = $$ rangeparts { 'attach' } ; }
2010-12-17 19:14:32 +00:00
push @ nodestodelete , $ nr ;
}
my $ delnodes = join ( ',' , @ nodestodelete ) ;
#print "should delete: $delnodes\n";
#rmdef('f5c12p[1-8]');
noderm ( $ delnodes ) ;
}
# Set some attrs common to all lpars
2011-07-05 06:45:24 +00:00
$ tables { 'nodetype' } - > setNodeAttribs ( 'lpar' , { nodetype = > 'ppc,osi' , arch = > 'ppc64' } ) ;
2010-12-17 19:14:32 +00:00
$ tables { 'nodehm' } - > setNodeAttribs ( 'lpar' , { mgt = > 'fsp' , cons = > 'fsp' } ) ;
$ tables { 'noderes' } - > setNodeAttribs ( 'lpar' , { netboot = > 'yaboot' } ) ;
# Write regexs for some of the ppc attrs
# Note: we assume here that if they used f1c1p1 for nodes they should use f1c1 for cecs
my $ cechash = parsenoderange ( $ STANZAS { 'xcat-cecs' } - > { 'hostname-range' } ) ;
my $ cecprimbase = $$ cechash { 'primary-base' } ;
#my $cecprimlen = length($$cechash{'primary-start'});
my $ cecsecbase = $$ cechash { 'secondary-base' } ;
if ( ! $ cecsecbase ) { errormsg ( "when using LPAR names like f1c1p1, you must also use CEC names like f1c1" , 7 ) ; return 0 ; }
2011-04-01 21:30:08 +00:00
#my $framehash = parsenoderange($STANZAS{'xcat-frames'}->{'hostname-range'});
2010-12-17 19:14:32 +00:00
#my $framebase = $$framehash{'primary-base'};
#my $framestart = $$framehash{'primary-start'};
#my $framelen = length($$framehash{'primary-start'});
my % ppchash ;
my % nodeposhash ;
2011-03-11 07:42:57 +00:00
$ ppchash { id } = '|^\D+\d+\D+\d+\D+(\d+)\D*$|(($1-1)*4+1)|' ; #todo: this is p7 ih specific
2010-12-17 19:14:32 +00:00
# convert between the lpar name and the cec name. Assume that numbers are the same, but the base can be different
2011-03-11 07:42:57 +00:00
my $ regex = '|^\D+(\d+)\D+(\d+)\D+\d+\D*$|' . "$cecprimbase" . '($1)' . "$cecsecbase" . '($2)|' ;
2010-12-17 19:14:32 +00:00
$ ppchash { hcp } = $ regex ;
$ ppchash { parent } = $ regex ;
$ ppchash { nodetype } = 'lpar' ;
#print Dumper($CECPOSITIONS);
$ tables { 'ppc' } - > setNodeAttribs ( 'lpar' , \ % ppchash ) ;
#todo: for now, let the nodepos attrs for the cec be good enough
#$nodeposhash{rack} = {rack => $CECPOSITIONS->{$cecname}->[0]->{rack}, u => $CECPOSITIONS->{$cecname}->[0]->{u}};
#$nodeposhash{u} = {rack => $CECPOSITIONS->{$cecname}->[0]->{rack}, u => $CECPOSITIONS->{$cecname}->[0]->{u}};
#$tables{'nodepos'}->setNodeAttribs('lpar', \%nodeposhash);
# Figure out which lpars are service nodes and storage nodes and put them in groups
my $ framesperbb = $ STANZAS { 'xcat-building-blocks' } - > { 'num-frames-per-bb' } ;
my $ numframes = $$ rangeparts { 'primary-end' } - $$ rangeparts { 'primary-start' } + 1 ;
my $ numbbs = int ( $ numframes / $ framesperbb ) + ( $ numframes %$ framesperbb > 0 ) ;
my % servicenodes ;
my % storagenodes ;
my % lpars ;
#my $cecsperbb = $STANZAS{'xcat-building-blocks'}->{'num-cecs-per-bb'};
#if ($cecsperbb !~ /^\d+$/) { errormsg("invalid non-integer value for num-cecs-per-bb: $cecsperbb", 7); return 0; }
for ( my $ b = 1 ; $ b <= $ numbbs ; $ b + + ) {
my $ framebase = ( $ b - 1 ) * $ framesperbb + 1 ;
2011-04-09 13:19:45 +00:00
findSNsinBB ( 'service' , $ b , $ framebase , $ rangeparts , \ % servicenodes , \ % lpars ) or return 0 ;
2010-12-17 19:14:32 +00:00
findSNsinBB ( 'storage' , $ b , $ framebase , $ rangeparts , \ % storagenodes ) or return 0 ;
}
2011-04-09 13:19:45 +00:00
if ( scalar ( keys ( % servicenodes ) ) ) {
$ tables { 'nodelist' } - > setNodesAttribs ( \ % servicenodes ) ;
writeMnRouteNames ( [ keys ( % servicenodes ) ] ) ;
}
2010-12-17 19:14:32 +00:00
if ( scalar ( keys ( % storagenodes ) ) ) { $ tables { 'nodelist' } - > setNodesAttribs ( \ % storagenodes ) ; }
if ( scalar ( keys ( % lpars ) ) ) { $ tables { 'noderes' } - > setNodesAttribs ( \ % lpars ) ; }
# Set some more service node specific attributes
2011-04-09 13:19:45 +00:00
$ tables { 'servicenode' } - > setNodeAttribs ( 'service' , { nameserver = > 1 , dhcpserver = > 1 , tftpserver = > 1 , nfsserver = > 1 , conserver = > 1 , monserver = > 1 , ftpserver = > 1 , nimserver = > 1 , ipforward = > defined ( $ STANZAS { 'xcat-service-nodes' } - > { 'route-masks' } ) } ) ;
2010-12-17 19:14:32 +00:00
if ( $ STANZAS { 'll-config' } - > { 'central_manager_list' } ) { # write the LL postscript for service nodes
addPostscript ( 'service' , 'llserver.sh' ) ;
addPostscript ( 'compute' , 'llcompute.sh' ) ;
}
dynamicGroups ( 'add' , [ keys ( % servicenodes ) ] , 'xcatmaster==' ) ;
}
# Find either service nodes or storage nodes in a BB. Adds the nodenames of the lpars to the snodes hash,
# and defines the groups in the hash, and assigns the other lpars to the correct service node.
sub findSNsinBB {
2011-04-09 13:19:45 +00:00
my ( $ sntext , $ bb , $ framebase , $ rangeparts , $ snodes , $ lpars ) = @ _ ;
2010-12-17 19:14:32 +00:00
my $ primbase = $$ rangeparts { 'primary-base' } ;
my $ primlen = length ( $$ rangeparts { 'primary-start' } ) ;
my $ secbase = $$ rangeparts { 'secondary-base' } ;
my $ seclen = length ( $$ rangeparts { 'secondary-start' } ) ;
my $ tertbase = $$ rangeparts { 'tertiary-base' } ;
my $ tertlen = length ( $$ rangeparts { 'tertiary-start' } ) ;
my $ framesperbb = $ STANZAS { 'xcat-building-blocks' } - > { 'num-frames-per-bb' } ;
# Determine the lpar node name for each service/storage node
my $ snsperbb = $ STANZAS { "xcat-$sntext-nodes" } - > { "num-$sntext-nodes-per-bb" } ;
if ( $ snsperbb !~ /^\d+$/ ) { errormsg ( "invalid non-integer value for num-$sntext-nodes-per-bb: $snsperbb" , 7 ) ; return 0 ; }
my @ snpositions = split ( /[\s,]+/ , $ STANZAS { "xcat-$sntext-nodes" } - > { 'cec-positions-in-bb' } ) ;
if ( scalar ( @ snpositions ) != $ snsperbb ) { errormsg ( "invalid number of positions specified for xcat-$sntext-nodes:cec-positions-in-bb." , 3 ) ; return 0 ; }
2011-04-01 21:30:08 +00:00
my $ cecsperframe = $ STANZAS { 'xcat-cecs' } - > { 'num-cecs-per-frame' } ; # they may have specified this instead of a supernode-list, which would fill in NUMCECSINFRAME
2010-12-17 19:14:32 +00:00
my @ snsinbb ;
foreach my $ p ( @ snpositions ) {
my $ cecbase = 0 ;
my $ frame = $ framebase ;
2011-04-01 21:30:08 +00:00
while ( $ p > ( $ cecbase + ( $ NUMCECSINFRAME { $ frame } || $ cecsperframe ) ) ) {
2010-12-17 19:14:32 +00:00
# p is not in this frame, go on to the next
2011-04-01 21:30:08 +00:00
$ cecbase += $ NUMCECSINFRAME { $ frame } || $ cecsperframe ;
2010-12-17 19:14:32 +00:00
$ frame + + ;
#print "cecbase=$cecbase, frame=$frame\n";
if ( $ frame >= ( $ framebase + $ framesperbb ) ) { errormsg ( "Can not find $sntext node position $p in building block $bb." , 9 ) ; return 0 ; }
}
my $ cecinframe = $ p - $ cecbase ;
#my $nodename = $primbase . sprintf("%0${primlen}d", $frame) . $secbase . sprintf("%0${seclen}d", $cecinframe) . $tertbase . sprintf("%0${tertlen}d", 1);
my $ nodename = buildNodename ( $ frame , $ cecinframe , 1 , $ primbase , $ primlen , $ secbase , $ seclen , $ tertbase , $ tertlen ) ;
#print "nodename=$nodename\n";
$$ snodes { $ nodename } = { groups = > "bb$bb$sntext,$sntext,lpar,all" } ;
push @ snsinbb , "$frame,$cecinframe" ; # save for later
}
if ( $ lpars ) {
# Set xcatmaster/servicenode attrs for lpars
my $ cecsperbb = $ STANZAS { 'xcat-building-blocks' } - > { 'num-cecs-per-bb' } ;
if ( $ cecsperbb !~ /^\d+$/ ) { errormsg ( "invalid non-integer value for num-cecs-per-bb: $cecsperbb" , 7 ) ; return 0 ; }
my $ servsperbb = $ STANZAS { 'xcat-service-nodes' } - > { 'num-service-nodes-per-bb' } ;
my $ cecspersn = int ( $ cecsperbb / $ snsperbb ) ;
my $ pmax = $ STANZAS { 'xcat-lpars' } - > { 'num-lpars-per-cec' } ;
# Loop thru all lpars in this BB, assigning it to a service node
my $ snindex = 0 ;
my $ cecinthisbb = 1 ;
for ( my $ f = $ framebase ; $ f < ( $ framebase + $ framesperbb ) ; $ f + + ) {
2011-04-01 21:30:08 +00:00
for ( my $ c = 1 ; $ c <= ( $ NUMCECSINFRAME { $ f } || $ cecsperframe ) ; $ c + + ) {
2010-12-17 19:14:32 +00:00
# form the current service node name
my ( $ snframe , $ sncec ) = split ( /,/ , $ snsinbb [ $ snindex ] ) ;
my $ snname = buildNodename ( $ snframe , $ sncec , 1 , $ primbase , $ primlen , $ secbase , $ seclen , $ tertbase , $ tertlen ) ;
my $ othersns ;
# build the list of other service node names
for ( my $ s = 0 ; $ s < scalar ( @ snsinbb ) ; $ s + + ) {
if ( $ s != $ snindex ) {
my ( $ snf , $ snc ) = split ( /,/ , $ snsinbb [ $ s ] ) ;
2011-04-01 21:30:08 +00:00
$ othersns . = ',' . buildNodename ( $ snf , $ snc , 1 , $ primbase , $ primlen , $ secbase , $ seclen , $ tertbase , $ tertlen ) ;
2010-12-17 19:14:32 +00:00
}
}
# assign all partitions in this cec to this service node
for ( my $ p = 1 ; $ p <= $ pmax ; $ p + + ) {
my $ lparname = buildNodename ( $ f , $ c , $ p , $ primbase , $ primlen , $ secbase , $ seclen , $ tertbase , $ tertlen ) ;
2011-04-01 21:30:08 +00:00
my $ routes = "cnto$snname" ;
if ( $ othersns ) { $ routes . = join ( ',cnto' , split ( ',' , $ othersns ) ) ; } # othersns has a leading comma
$$ lpars { $ lparname } = { xcatmaster = > $ snname , servicenode = > "$snname$othersns" , routenames = > $ routes } ;
2010-12-17 19:14:32 +00:00
}
# move to the next cec and possibly the next sn
$ cecinthisbb + + ;
if ( $ cecinthisbb > $ cecspersn && $ snindex < ( scalar ( @ snsinbb ) - 1 ) ) { $ snindex + + ; }
}
}
# delete the service nodes themselves from this list
foreach my $ serv ( @ snsinbb ) {
my ( $ snframe , $ sncec ) = split ( /,/ , $ serv ) ;
my $ snname = buildNodename ( $ snframe , $ sncec , 1 , $ primbase , $ primlen , $ secbase , $ seclen , $ tertbase , $ tertlen ) ;
delete $$ lpars { $ snname } ;
}
}
return 1 ;
}
sub buildNodename {
my ( $ frame , $ cec , $ partition , $ primbase , $ primlen , $ secbase , $ seclen , $ tertbase , $ tertlen ) = @ _ ;
my $ lparname = $ primbase . sprintf ( "%0${primlen}d" , $ frame ) . $ secbase . sprintf ( "%0${seclen}d" , $ cec ) . $ tertbase . sprintf ( "%0${tertlen}d" , $ partition ) ;
return $ lparname ;
}
2010-09-16 02:05:28 +00:00
2011-04-09 13:19:45 +00:00
# For the list of route names (basically the list of SNs), create entries in the routes table
sub writeMnRouteNames {
my $ sns = shift ;
my $ serviceip = $ STANZAS { 'xcat-service-nodes' } - > { 'starting-ip' } ;
my $ routemasks = $ STANZAS { 'xcat-service-nodes' } - > { 'route-masks' } ;
if ( ! $ serviceip || ! isIP ( $ serviceip ) || ! $ routemasks ) { return ; }
#todo: delete the routes if in delete mode
# Parse the route masks
my @ parts = split ( /[\s,]+/ , $ routemasks ) ;
my % nicmasks ;
foreach my $ p ( @ parts ) {
my ( $ nic , $ nicmask ) = split ( /:/ , $ p ) ;
$ nicmasks { $ nic } = $ nicmask ;
}
# Go thru the route names and create entries in the routes table
my @ mnroutes ;
my $ rtab = $ tables { 'routes' } ;
foreach my $ sn ( @$ sns ) {
#my ($sn) = $r =~ /^mnto(.+)$/;
my $ ref = $ tables { 'hosts' } - > getNodeAttribs ( $ sn , [ 'ip' , 'otherinterfaces' ] ) ;
if ( ! $ ref || $ ref - > { ip } !~ /\S/ || $ ref - > { otherinterfaces } !~ /\S/ ) { next ; }
my % routehash = ( gateway = > $ ref - > { ip } ) ;
# go thru each nic to create a route for it
my @ ifs = split ( /[\s,]+/ , $ ref - > { otherinterfaces } ) ;
foreach my $ i ( @ ifs ) {
my ( $ nic , $ nicip ) = split ( /:/ , $ i ) ;
my $ routename = "mnto$sn$nic" ;
$ routehash { mask } = $ nicmasks { $ nic } ;
# and together $nicip with $nicmasks{$nic} to get the $routehash{net}
2011-05-17 06:08:01 +00:00
my $ mask = xCAT::NetworkUtils:: getipaddr ( $ nicmasks { $ nic } ) ; #, GetNumber=>1);
my $ ip = xCAT::NetworkUtils:: getipaddr ( $ nicip ) ; #, GetNumber=>1);
2011-04-09 13:19:45 +00:00
my $ subnet = $ ip & $ mask ;
$ subnet = inet_ntoa ( pack ( 'N' , $ subnet ) ) ;
$ routehash { net } = $ subnet ;
$ rtab - > setAttribs ( { routename = > $ routename } , \ % routehash ) ;
push @ mnroutes , $ routename ; # gather all the routenames for site.mnroutenames
}
}
$ rtab - > commit ( ) ;
$ tables { 'site' } - > setAttribs ( { key = > 'mnroutenames' } , { value = > join ( ',' , @ mnroutes ) } ) ;
}
2010-09-16 02:05:28 +00:00
# Create service node definitions
sub writesn {
my $ range = shift ;
2010-12-17 19:14:32 +00:00
if ( defined ( $ STANZAS { 'xcat-lpars' } - > { 'hostname-range' } ) ) { errormsg ( "Can not define hostname-range in both the xcat-lpars and xcat-service-nodes stanzas." , 8 ) ; return 0 ; }
my $ nodes = [ noderange ( $ range , 0 ) ] ;
if ( ! scalar ( @$ nodes ) ) { return 1 ; }
if ( $ DELETENODES ) {
deletenodes ( 'service nodes' , $ range ) ;
deletegroup ( 'service' ) ;
dynamicGroups ( 'delete' , $ nodes ) ;
return 1 ;
}
2010-09-16 02:05:28 +00:00
infomsg ( 'Defining service nodes...' ) ;
2010-10-14 16:00:20 +00:00
# We support name formats: sn01 or (todo:) b1s1
my $ rangeparts = parsenoderange ( $ range ) ;
2011-04-02 07:48:09 +00:00
my ( $ startnum ) = int $$ rangeparts { 'primary-start' } ; # save this value for later
2011-06-20 13:49:52 +00:00
$ tables { 'nodelist' } - > setNodesAttribs ( $ nodes , { groups = > 'service,lpar,all' , hidden = > 0 } ) ;
2010-12-17 19:14:32 +00:00
staticGroup ( 'service' ) ;
2010-09-16 02:05:28 +00:00
# Write regex for: hosts.node, hosts.ip
2010-10-14 16:00:20 +00:00
my $ startip = $ STANZAS { 'xcat-service-nodes' } - > { 'starting-ip' } ;
2010-10-29 19:09:18 +00:00
if ( $ startip && isIP ( $ startip ) ) {
2010-09-16 02:05:28 +00:00
my ( $ ipbase , $ ipstart ) = $ startip =~ /^(\d+\.\d+\.\d+)\.(\d+)$/ ;
# take the number from the nodename, and as it increases, increase the ip addr
2010-10-21 20:05:11 +00:00
my $ regex = '|\S+?(\d+)$|' . "$ipbase.($ipstart+" . '$1' . "-$startnum)|" ;
2010-09-16 02:05:28 +00:00
my % hash = ( ip = > $ regex ) ;
2010-10-14 16:00:20 +00:00
my $ otherint = $ STANZAS { 'xcat-service-nodes' } - > { 'otherinterfaces' } ;
2010-09-16 02:05:28 +00:00
if ( $ otherint ) {
# need to replace each ip addr in otherinterfaces with a regex
my @ ifs = split ( /[\s,]+/ , $ otherint ) ;
foreach my $ if ( @ ifs ) {
my ( $ nic , $ startip ) = split ( /:/ , $ if ) ;
2010-10-29 19:09:18 +00:00
if ( ! isIP ( $ startip ) ) { next ; }
2010-09-16 02:05:28 +00:00
( $ ipbase , $ ipstart ) = $ startip =~ /^(\d+\.\d+\.\d+)\.(\d+)$/ ;
$ if = "$nic:$ipbase.($ipstart+" . '$1' . "-$startnum)" ;
}
2010-10-21 20:05:11 +00:00
$ regex = '|\S+?(\d+)$|' . join ( ',' , @ ifs ) . '|' ;
2010-09-16 02:05:28 +00:00
#print "regex=$regex\n";
$ hash { otherinterfaces } = $ regex ;
}
$ tables { 'hosts' } - > setNodeAttribs ( 'service' , \ % hash ) ;
}
2010-10-14 16:00:20 +00:00
# Write regex for: ppc.id, nodetype.nodetype, etc.
2010-12-17 19:14:32 +00:00
$ tables { 'ppc' } - > setNodeAttribs ( 'service' , { id = > '1' , nodetype = > 'lpar' } ) ;
2011-07-05 06:45:24 +00:00
$ tables { 'nodetype' } - > setNodeAttribs ( 'service' , { nodetype = > 'ppc,osi' , arch = > 'ppc64' } ) ;
2010-09-16 02:05:28 +00:00
$ tables { 'nodehm' } - > setNodeAttribs ( 'service' , { mgt = > 'fsp' , cons = > 'fsp' } ) ;
$ tables { 'noderes' } - > setNodeAttribs ( 'service' , { netboot = > 'yaboot' } ) ;
2011-04-09 13:19:45 +00:00
$ tables { 'servicenode' } - > setNodeAttribs ( 'service' , { nameserver = > 1 , dhcpserver = > 1 , tftpserver = > 1 , nfsserver = > 1 , conserver = > 1 , monserver = > 1 , ftpserver = > 1 , nimserver = > 1 , ipforward = > defined ( $ STANZAS { 'xcat-service-nodes' } - > { 'route-masks' } ) } ) ;
2010-10-28 11:59:22 +00:00
if ( $ STANZAS { 'll-config' } - > { 'central_manager_list' } ) { # write the LL postscript for service nodes
2010-12-17 19:14:32 +00:00
addPostscript ( 'service' , 'llserver.sh' )
2010-10-28 11:59:22 +00:00
}
2010-09-16 02:05:28 +00:00
2010-10-14 16:00:20 +00:00
# Figure out what cec each sn is in and write ppc.hcp and ppc.parent
# Math for SN in BB: cecnum = ( ( (snnum-1) / snsperbb) * cecsperbb) + cecstart-1 + snpositioninbb
2010-09-25 15:14:10 +00:00
my $ cecsperbb = $ STANZAS { 'xcat-building-blocks' } - > { 'num-cecs-per-bb' } ;
2010-10-29 19:09:18 +00:00
if ( $ cecsperbb !~ /^\d+$/ ) { errormsg ( "invalid non-integer value for num-cecs-per-bb: $cecsperbb" , 7 ) ; return 0 ; }
2010-10-14 16:00:20 +00:00
my $ snsperbb = $ STANZAS { 'xcat-service-nodes' } - > { 'num-service-nodes-per-bb' } ;
2010-10-29 19:09:18 +00:00
if ( $ snsperbb !~ /^\d+$/ ) { errormsg ( "invalid non-integer value for num-service-nodes-per-bb: $snsperbb" , 7 ) ; return 0 ; }
2010-10-14 16:00:20 +00:00
my @ positions = split ( /[\s,]+/ , $ STANZAS { 'xcat-service-nodes' } - > { 'cec-positions-in-bb' } ) ;
2010-10-29 19:09:18 +00:00
if ( scalar ( @ positions ) != $ snsperbb ) { errormsg ( "invalid number of positions specified for xcat-service-nodes:cec-positions-in-bb." , 3 ) ; return 0 ; }
2010-09-25 15:14:10 +00:00
my $ cechash = parsenoderange ( $ STANZAS { 'xcat-cecs' } - > { 'hostname-range' } ) ;
2010-10-14 16:00:20 +00:00
my $ cecbase = $$ cechash { 'primary-base' } ;
my $ cecstart = $$ cechash { 'primary-start' } ;
my $ ceclen = length ( $$ cechash { 'primary-start' } ) ;
# these are only needed for names like f2c3
my $ secbase = $$ cechash { 'secondary-base' } ;
my $ secstart = $$ cechash { 'secondary-start' } ;
my $ secend = $$ cechash { 'secondary-end' } ;
my $ seclen = length ( $$ cechash { 'secondary-start' } ) ;
$ nodes = [ noderange ( $ range , 0 ) ] ;
my % nodehash ;
2010-10-29 19:09:18 +00:00
my % nodeposhash ;
2010-10-14 16:00:20 +00:00
my % grouphash ;
# Go thru each service node and calculate which cec it is in
for ( my $ i = 0 ; $ i < scalar ( @$ nodes ) ; $ i + + ) {
# figure out the BB num to add this node to that group
my $ bbnum = int ( $ i / $ snsperbb ) + 1 ;
2010-10-15 20:08:12 +00:00
my $ bbname = "bb$bbnum" ;
2010-12-17 19:14:32 +00:00
$ grouphash { $$ nodes [ $ i ] } = { groups = > "${bbname}service,service,lpar,all" } ;
2010-10-14 16:00:20 +00:00
# figure out the CEC num
my $ snpositioninbb = $ positions [ $ i % $ snsperbb ] ; # the offset within the BB
2011-04-01 21:30:08 +00:00
my $ cecnum = ( int ( $ i / $ snsperbb ) * $ cecsperbb ) + $ snpositioninbb + $ cecstart - 1 ; # which cec num, counting from the beginning
2010-10-14 16:00:20 +00:00
my $ cecname ;
if ( ! $ secbase ) {
$ cecname = $ cecbase . sprintf ( "%0${ceclen}d" , $ cecnum ) ;
}
else { # calculate the 2 indexes for a name like f2c3
2011-05-05 17:11:22 +00:00
#----------------------------------\
# count the cecs in frames until we get to the correct frame
my $ cecbasenum = 0 ;
my $ cecsperframe = $ STANZAS { 'xcat-cecs' } - > { 'num-cecs-per-frame' } ; # they may have specified this instead of a supernode-list, which would fill in NUMCECSINFRAME
my $ framesperbb = $ STANZAS { 'xcat-building-blocks' } - > { 'num-frames-per-bb' } ;
my $ framebase = ( $ bbnum - 1 ) * $ framesperbb + $ cecstart ; # the frame num of the 1st frame in this bb
my $ frame = $ framebase ;
while ( $ snpositioninbb > ( $ cecbasenum + ( $ NUMCECSINFRAME { $ frame } || $ cecsperframe ) ) ) {
# snpositioninbb is not in this frame, go on to the next
$ cecbasenum += $ NUMCECSINFRAME { $ frame } || $ cecsperframe ;
$ frame + + ;
#print "cecbase=$cecbase, frame=$frame\n";
if ( $ frame >= ( $ framebase + $ framesperbb ) ) { errormsg ( "Can not find service node position $snpositioninbb in building block $bbnum." , 9 ) ; return 0 ; }
}
my $ cecinframe = $ snpositioninbb - $ cecbasenum ;
#----------------------------------/
# Old way: we essentially have to do base n math, where n is the size of the second range
#my $n = $secend - $secstart + 1;
#my $primary = int(($cecnum-1) / $n) + 1;
#my $secondary = ($cecnum-1) % $n + 1;
#$cecname = $cecbase . sprintf("%0${ceclen}d", $primary) . $secbase . sprintf("%0${seclen}d", $secondary);
$ cecname = $ cecbase . sprintf ( "%0${ceclen}d" , $ frame ) . $ secbase . sprintf ( "%0${seclen}d" , $ cecinframe ) ;
2010-10-14 16:00:20 +00:00
}
#print "sn=$$nodes[$i], cec=$cecname\n";
$ nodehash { $$ nodes [ $ i ] } = { hcp = > $ cecname , parent = > $ cecname } ;
2010-10-29 19:09:18 +00:00
#print Dumper($CECPOSITIONS);
#print "cecname=$cecname\n";
$ nodeposhash { $$ nodes [ $ i ] } = { rack = > $ CECPOSITIONS - > { $ cecname } - > [ 0 ] - > { rack } , u = > $ CECPOSITIONS - > { $ cecname } - > [ 0 ] - > { u } } ;
2010-10-14 16:00:20 +00:00
}
2011-04-09 13:19:45 +00:00
# Form the list of route for MN to CN
#my $routes = 'mnto' . join(',mnto', @$nodes);
#$tables{'site'}->setAttribs({key => 'mnroutenames'}, {value => $routes});
writeMnRouteNames ( $ nodes ) ;
2011-04-01 21:30:08 +00:00
2010-10-14 16:00:20 +00:00
$ tables { 'ppc' } - > setNodesAttribs ( \ % nodehash ) ;
$ tables { 'nodelist' } - > setNodesAttribs ( \ % grouphash ) ;
2010-10-29 19:09:18 +00:00
$ tables { 'nodepos' } - > setNodesAttribs ( \ % nodeposhash ) ;
2010-10-28 11:59:22 +00:00
2010-12-08 17:32:46 +00:00
# Create dynamic groups for the nodes in each service node
2010-12-17 19:14:32 +00:00
$ nodes = [ noderange ( $ range , 0 ) ] ; # the setNodesAttribs() function blanks out the nodes array
dynamicGroups ( 'add' , $ nodes , 'xcatmaster==' ) ;
2010-10-29 19:09:18 +00:00
return 1 ;
2010-09-16 02:05:28 +00:00
}
# Create storage node definitions
sub writestorage {
my $ range = shift ;
2010-12-17 19:14:32 +00:00
if ( defined ( $ STANZAS { 'xcat-lpars' } - > { 'hostname-range' } ) ) { errormsg ( "Can not define hostname-range in both the xcat-lpars and xcat-storage-nodes stanzas." , 8 ) ; return 0 ; }
2010-09-16 02:05:28 +00:00
my $ nodes = [ noderange ( $ range , 0 ) ] ;
2010-12-17 19:14:32 +00:00
if ( ! scalar ( @$ nodes ) ) { return 1 ; }
if ( $ DELETENODES ) {
deletenodes ( 'storage nodes' , $ range ) ;
deletegroup ( 'storage' ) ;
return 1 ;
}
infomsg ( 'Defining storage nodes...' ) ;
2010-10-14 16:00:20 +00:00
my $ rangeparts = parsenoderange ( $ range ) ;
2011-04-02 07:48:09 +00:00
my ( $ startnum ) = int $$ rangeparts { 'primary-start' } ; # save this value for later
2011-06-20 13:49:52 +00:00
$ tables { 'nodelist' } - > setNodesAttribs ( $ nodes , { groups = > 'storage,lpar,all' , hidden = > 0 } ) ;
2010-12-17 19:14:32 +00:00
staticGroup ( 'storage' ) ;
2010-09-16 02:05:28 +00:00
# Write regex for: hosts.node, hosts.ip
2010-10-14 16:00:20 +00:00
my $ startip = $ STANZAS { 'xcat-storage-nodes' } - > { 'starting-ip' } ;
2010-10-29 19:09:18 +00:00
if ( $ startip && isIP ( $ startip ) ) {
2010-09-16 02:05:28 +00:00
my ( $ ipbase , $ ipstart ) = $ startip =~ /^(\d+\.\d+\.\d+)\.(\d+)$/ ;
# take the number from the nodename, and as it increases, increase the ip addr
2010-10-21 20:05:11 +00:00
my $ regex = '|\S+?(\d+)$|' . "$ipbase.($ipstart+" . '$1' . "-$startnum)|" ;
2010-09-16 02:05:28 +00:00
my % hash = ( ip = > $ regex ) ;
2010-10-14 16:00:20 +00:00
my $ otherint = $ STANZAS { 'xcat-storage-nodes' } - > { 'otherinterfaces' } ;
2010-09-16 02:05:28 +00:00
if ( $ otherint ) {
# need to replace each ip addr in otherinterfaces with a regex
my @ ifs = split ( /[\s,]+/ , $ otherint ) ;
foreach my $ if ( @ ifs ) {
my ( $ nic , $ startip ) = split ( /:/ , $ if ) ;
2010-10-29 19:09:18 +00:00
if ( ! isIP ( $ startip ) ) { next ; }
2010-09-16 02:05:28 +00:00
( $ ipbase , $ ipstart ) = $ startip =~ /^(\d+\.\d+\.\d+)\.(\d+)$/ ;
$ if = "$nic:$ipbase.($ipstart+" . '$1' . "-$startnum)" ;
}
2010-10-21 20:05:11 +00:00
$ regex = '|\S+?(\d+)$|' . join ( ',' , @ ifs ) . '|' ;
2010-09-16 02:05:28 +00:00
#print "regex=$regex\n";
$ hash { otherinterfaces } = $ regex ;
}
2010-10-14 16:00:20 +00:00
my $ aliases = $ STANZAS { 'xcat-storage-nodes' } - > { 'aliases' } ;
2010-09-16 02:05:28 +00:00
if ( $ aliases ) {
2010-10-29 19:09:18 +00:00
# support more than 1 alias
my @ alist = split ( /[\s,]+/ , $ aliases ) ;
2010-12-17 19:14:32 +00:00
foreach my $ a ( @ alist ) { if ( $ a =~ /^-/ ) { $ a = '($1)' . $ a ; } } # prepend the hostname
2010-10-29 19:09:18 +00:00
$ regex = '|(.+)|' . join ( ',' , @ alist ) . '|' ;
2010-09-16 02:05:28 +00:00
$ hash { hostnames } = $ regex ;
}
$ tables { 'hosts' } - > setNodeAttribs ( 'storage' , \ % hash ) ;
}
2010-10-14 16:00:20 +00:00
# Write ppc.id, nodetype.nodetype, etc.
2010-12-17 19:14:32 +00:00
$ tables { 'ppc' } - > setNodeAttribs ( 'storage' , { id = > '1' , nodetype = > 'lpar' } ) ;
2011-07-05 06:45:24 +00:00
$ tables { 'nodetype' } - > setNodeAttribs ( 'storage' , { nodetype = > 'ppc,osi' , arch = > 'ppc64' } ) ;
2010-09-16 02:05:28 +00:00
$ tables { 'nodehm' } - > setNodeAttribs ( 'storage' , { mgt = > 'fsp' , cons = > 'fsp' } ) ;
$ tables { 'noderes' } - > setNodeAttribs ( 'storage' , { netboot = > 'yaboot' } ) ;
2010-10-14 16:00:20 +00:00
# Figure out what cec each storage node is in and write ppc.hcp, ppc.parent, noderes.xcatmaster, noderes.servicenode
# Math for SN in BB: cecnum = ( ( (snnum-1) / snsperbb) * cecsperbb) + cecstart-1 + snpositioninbb
my $ cecsperbb = $ STANZAS { 'xcat-building-blocks' } - > { 'num-cecs-per-bb' } ;
2010-10-29 19:09:18 +00:00
if ( $ cecsperbb !~ /^\d+$/ ) { errormsg ( "invalid non-integer value for num-cecs-per-bb: $cecsperbb" , 7 ) ; return 0 ; }
2010-10-14 16:00:20 +00:00
my $ snsperbb = $ STANZAS { 'xcat-storage-nodes' } - > { 'num-storage-nodes-per-bb' } ;
2010-10-29 19:09:18 +00:00
if ( $ snsperbb !~ /^\d+$/ ) { errormsg ( "invalid non-integer value for num-storage-nodes-per-bb: $snsperbb" , 7 ) ; return 0 ; }
2010-10-14 16:00:20 +00:00
my @ positions = split ( /[\s,]+/ , $ STANZAS { 'xcat-storage-nodes' } - > { 'cec-positions-in-bb' } ) ;
2010-10-29 19:09:18 +00:00
if ( scalar ( @ positions ) != $ snsperbb ) { errormsg ( "invalid number of positions specified for xcat-storage-nodes:cec-positions-in-bb." , 3 ) ; return 0 ; }
2010-10-14 16:00:20 +00:00
my $ cechash = parsenoderange ( $ STANZAS { 'xcat-cecs' } - > { 'hostname-range' } ) ;
my $ cecbase = $$ cechash { 'primary-base' } ;
my $ cecstart = $$ cechash { 'primary-start' } ;
my $ ceclen = length ( $$ cechash { 'primary-start' } ) ;
# these are only needed for names like f2c3
my $ secbase = $$ cechash { 'secondary-base' } ;
my $ secstart = $$ cechash { 'secondary-start' } ;
my $ secend = $$ cechash { 'secondary-end' } ;
my $ seclen = length ( $$ cechash { 'secondary-start' } ) ;
my $ sns = [ noderange ( $ STANZAS { 'xcat-service-nodes' } - > { 'hostname-range' } , 0 ) ] ;
$ nodes = [ noderange ( $ range , 0 ) ] ;
my % nodehash ;
2010-10-29 19:09:18 +00:00
my % nodeposhash ;
2010-10-14 16:00:20 +00:00
my % grouphash ;
my % nodereshash ;
2011-04-01 21:30:08 +00:00
# Go thru each storage node and calculate which cec it is in and its service node
2010-10-14 16:00:20 +00:00
for ( my $ i = 0 ; $ i < scalar ( @$ nodes ) ; $ i + + ) {
# figure out the BB num to add this node to that group
my $ bbnum = int ( $ i / $ snsperbb ) + 1 ;
2010-10-15 20:08:12 +00:00
my $ bbname = "bb$bbnum" ;
2011-04-01 21:30:08 +00:00
$ grouphash { $$ nodes [ $ i ] } = { groups = > "${bbname}storage,storage,lpar,all" } ;
2010-10-14 16:00:20 +00:00
# figure out the CEC num
my $ snpositioninbb = $ positions [ $ i % $ snsperbb ] ; # the offset within the BB
my $ cecnum = ( int ( $ i / $ snsperbb ) * $ cecsperbb ) + $ snpositioninbb ; # which cec num, counting from the beginning
my $ cecname ;
if ( ! $ secbase ) {
$ cecname = $ cecbase . sprintf ( "%0${ceclen}d" , $ cecnum ) ;
}
else { # calculate the 2 indexes for a name like f2c3
2011-05-05 17:11:22 +00:00
#----------------------------------\
# count the cecs in frames until we get to the correct frame
my $ cecbasenum = 0 ;
my $ cecsperframe = $ STANZAS { 'xcat-cecs' } - > { 'num-cecs-per-frame' } ; # they may have specified this instead of a supernode-list, which would fill in NUMCECSINFRAME
my $ framesperbb = $ STANZAS { 'xcat-building-blocks' } - > { 'num-frames-per-bb' } ;
my $ framebase = ( $ bbnum - 1 ) * $ framesperbb + $ cecstart ; # the frame num of the 1st frame in this bb
my $ frame = $ framebase ;
while ( $ snpositioninbb > ( $ cecbasenum + ( $ NUMCECSINFRAME { $ frame } || $ cecsperframe ) ) ) {
# snpositioninbb is not in this frame, go on to the next
$ cecbasenum += $ NUMCECSINFRAME { $ frame } || $ cecsperframe ;
$ frame + + ;
#print "cecbase=$cecbase, frame=$frame\n";
if ( $ frame >= ( $ framebase + $ framesperbb ) ) { errormsg ( "Can not find service node position $snpositioninbb in building block $bbnum." , 9 ) ; return 0 ; }
}
my $ cecinframe = $ snpositioninbb - $ cecbasenum ;
#----------------------------------/
# Old way: we essentially have to do base n math, where n is the size of the second range
#my $n = $secend - $secstart + 1;
#my $primary = int(($cecnum-1) / $n) + 1;
#my $secondary = ($cecnum-1) % $n + 1;
#$cecname = $cecbase . sprintf("%0${ceclen}d", $primary) . $secbase . sprintf("%0${seclen}d", $secondary);
$ cecname = $ cecbase . sprintf ( "%0${ceclen}d" , $ frame ) . $ secbase . sprintf ( "%0${seclen}d" , $ cecinframe ) ;
2010-10-14 16:00:20 +00:00
}
#print "sn=$$nodes[$i], cec=$cecname\n";
$ nodehash { $$ nodes [ $ i ] } = { hcp = > $ cecname , parent = > $ cecname } ;
2010-10-29 19:09:18 +00:00
$ nodeposhash { $$ nodes [ $ i ] } = { rack = > $ CECPOSITIONS - > { $ cecname } - > [ 0 ] - > { rack } , u = > $ CECPOSITIONS - > { $ cecname } - > [ 0 ] - > { u } } ;
2010-10-14 16:00:20 +00:00
2010-12-17 19:14:32 +00:00
# Now determine the service node this storage node is under
2010-10-14 16:00:20 +00:00
#my $bbnum = int(($cecnum-1) / $cecsperbb) + 1;
my $ cecinthisbb = ( $ cecnum - 1 ) % $ cecsperbb + 1 ;
my $ servsperbb = $ STANZAS { 'xcat-service-nodes' } - > { 'num-service-nodes-per-bb' } ;
2010-12-17 19:14:32 +00:00
#todo: handle case where this does not divide evenly
2010-10-14 16:00:20 +00:00
my $ cecspersn = int ( $ cecsperbb / $ servsperbb ) ;
my $ snoffset = int ( ( $ cecinthisbb - 1 ) / $ cecspersn ) + 1 ;
my $ snsbeforethisbb = ( $ bbnum - 1 ) * $ servsperbb ;
my $ snnum = $ snsbeforethisbb + $ snoffset ;
my $ snname = $$ sns [ $ snnum - 1 ] ;
# generate a list of the other SNs in this BB
my $ othersns ;
for ( my $ s = $ snsbeforethisbb + 1 ; $ s <= $ snsbeforethisbb + $ servsperbb ; $ s + + ) {
if ( $ s != $ snnum ) { $ othersns . = ',' . $$ sns [ $ s - 1 ] ; }
}
2011-04-01 21:30:08 +00:00
my $ routes = "cnto$snname" ;
if ( $ othersns ) { $ routes . = join ( ',cnto' , split ( ',' , $ othersns ) ) ; } # othersns has a leading comma
$ nodereshash { $$ nodes [ $ i ] } = { xcatmaster = > $ snname , servicenode = > "$snname$othersns" , routenames = > $ routes } ;
2010-10-14 16:00:20 +00:00
}
$ tables { 'ppc' } - > setNodesAttribs ( \ % nodehash ) ;
$ tables { 'nodelist' } - > setNodesAttribs ( \ % grouphash ) ;
$ tables { 'noderes' } - > setNodesAttribs ( \ % nodereshash ) ;
2010-10-29 19:09:18 +00:00
$ tables { 'nodepos' } - > setNodesAttribs ( \ % nodeposhash ) ;
return 1 ;
2010-09-16 02:05:28 +00:00
}
2010-10-14 16:00:20 +00:00
# Create compute node definitions
2010-09-16 02:05:28 +00:00
sub writecompute {
my $ range = shift ;
2010-12-17 19:14:32 +00:00
if ( defined ( $ STANZAS { 'xcat-lpars' } - > { 'hostname-range' } ) ) { errormsg ( "Can not define hostname-range in both the xcat-lpars and xcat-storage-nodes stanzas." , 8 ) ; return 0 ; }
2010-09-16 02:05:28 +00:00
my $ nodes = [ noderange ( $ range , 0 ) ] ;
2010-12-17 19:14:32 +00:00
if ( ! scalar ( @$ nodes ) ) { return 1 ; }
if ( $ DELETENODES ) {
deletenodes ( 'compute nodes' , $ range ) ;
deletegroup ( 'compute' ) ;
return 1 ;
2010-09-16 02:05:28 +00:00
}
2010-12-17 19:14:32 +00:00
infomsg ( 'Defining compute nodes...' ) ;
2011-06-20 13:49:52 +00:00
$ tables { 'nodelist' } - > setNodesAttribs ( $ nodes , { groups = > 'compute,lpar,all' , hidden = > 0 } ) ;
2010-12-17 19:14:32 +00:00
staticGroup ( 'compute' ) ;
2010-09-16 02:05:28 +00:00
# Write regex for: hosts.node, hosts.ip
2010-10-14 16:00:20 +00:00
my $ nodehash = parsenoderange ( $ range ) ;
my $ startip = $ STANZAS { 'xcat-compute-nodes' } - > { 'starting-ip' } ;
2010-10-29 19:09:18 +00:00
if ( $ startip && isIP ( $ startip ) ) {
2010-09-26 10:24:49 +00:00
my ( $ ipbase , $ ip3rd , $ ip4th ) = $ startip =~ /^(\d+\.\d+)\.(\d+)\.(\d+)$/ ;
2010-09-16 02:05:28 +00:00
# take the number from the nodename, and as it increases, increase the ip addr
2011-04-02 07:48:09 +00:00
my $ startnum = int $$ nodehash { 'primary-start' } ;
2010-09-26 10:24:49 +00:00
# Math for 4th field: (ip4th-1+nodenum-startnum)%254 + 1
# Math for 3rd field: (ip4th-1+nodenum-startnum)/254 + ip3rd
2010-10-21 20:05:11 +00:00
my $ regex = '|\S+?(\d+)$|' . "$ipbase.((${ip4th}-1+" . '$1' . "-$startnum)/254+$ip3rd).((${ip4th}-1+" . '$1' . "-$startnum)%254+1)|" ;
2010-09-26 10:24:49 +00:00
#my $regex = '|\D+(\d+)|' . "$ipbase.($ipstart+" . '$1' . "-$startnum)|";
2010-09-16 02:05:28 +00:00
my % hash = ( ip = > $ regex ) ;
2010-10-14 16:00:20 +00:00
my $ otherint = $ STANZAS { 'xcat-compute-nodes' } - > { 'otherinterfaces' } ;
2010-09-16 02:05:28 +00:00
if ( $ otherint ) {
# need to replace each ip addr in otherinterfaces with a regex
my @ ifs = split ( /[\s,]+/ , $ otherint ) ;
foreach my $ if ( @ ifs ) {
my ( $ nic , $ startip ) = split ( /:/ , $ if ) ;
2010-10-29 19:09:18 +00:00
if ( ! isIP ( $ startip ) ) { next ; }
2010-09-26 10:24:49 +00:00
( $ ipbase , $ ip3rd , $ ip4th ) = $ startip =~ /^(\d+\.\d+)\.(\d+)\.(\d+)$/ ;
#$if = "$nic:$ipbase.($ipstart+" . '$1' . "-$startnum)";
2010-10-15 20:08:12 +00:00
$ if = "$nic:$ipbase.((${ip4th}-1+" . '$1' . "-$startnum)/254+$ip3rd).((${ip4th}-1+" . '$1' . "-$startnum)%254+1)" ;
2010-09-16 02:05:28 +00:00
}
2010-10-21 20:05:11 +00:00
$ regex = '|\S+?(\d+)$|' . join ( ',' , @ ifs ) . '|' ;
2010-09-16 02:05:28 +00:00
#print "regex=$regex\n";
$ hash { otherinterfaces } = $ regex ;
}
2010-10-14 16:00:20 +00:00
my $ aliases = $ STANZAS { 'xcat-compute-nodes' } - > { 'aliases' } ;
2010-09-16 02:05:28 +00:00
if ( $ aliases ) {
2010-10-29 19:09:18 +00:00
# support more than 1 alias
my @ alist = split ( /[\s,]+/ , $ aliases ) ;
2010-12-17 19:14:32 +00:00
foreach my $ a ( @ alist ) { if ( $ a =~ /^-/ ) { $ a = '($1)' . $ a ; } } # prepend the hostname
2010-10-29 19:09:18 +00:00
$ regex = '|(.+)|' . join ( ',' , @ alist ) . '|' ;
2010-09-16 02:05:28 +00:00
$ hash { hostnames } = $ regex ;
}
$ tables { 'hosts' } - > setNodeAttribs ( 'compute' , \ % hash ) ;
}
# Write regex for: nodetype.nodetype, etc.
2010-12-17 19:14:32 +00:00
$ tables { 'ppc' } - > setNodeAttribs ( 'compute' , { nodetype = > 'lpar' } ) ;
2011-07-05 06:45:24 +00:00
$ tables { 'nodetype' } - > setNodeAttribs ( 'compute' , { nodetype = > 'ppc,osi' , arch = > 'ppc64' } ) ;
2010-09-16 02:05:28 +00:00
$ tables { 'nodehm' } - > setNodeAttribs ( 'compute' , { mgt = > 'fsp' , cons = > 'fsp' } ) ;
$ tables { 'noderes' } - > setNodeAttribs ( 'compute' , { netboot = > 'yaboot' } ) ;
2010-10-28 11:59:22 +00:00
if ( $ STANZAS { 'll-config' } - > { 'central_manager_list' } ) { # write the LL postscript for compute nodes
2010-12-17 19:14:32 +00:00
addPostscript ( 'compute' , 'llcompute.sh' ) ;
2010-10-28 11:59:22 +00:00
}
2010-09-16 02:05:28 +00:00
2010-10-14 16:00:20 +00:00
# Figure out what cec each compute node is in and write ppc.hcp, ppc.parent, ppc.id, noderes.xcatmaster, noderes.servicenode
my $ cecsperbb = $ STANZAS { 'xcat-building-blocks' } - > { 'num-cecs-per-bb' } ;
2010-10-29 19:09:18 +00:00
if ( $ cecsperbb !~ /^\d+$/ ) { errormsg ( "invalid non-integer value for num-cecs-per-bb: $cecsperbb" , 7 ) ; return 0 ; }
2010-09-25 15:14:10 +00:00
my $ lparspercec = $ STANZAS { 'xcat-lpars' } - > { 'num-lpars-per-cec' } ;
2010-10-29 19:09:18 +00:00
if ( $ lparspercec !~ /^\d+$/ ) { errormsg ( "invalid non-integer value for num-lpars-per-cec: $lparspercec" , 7 ) ; return 0 ; }
2010-10-14 16:00:20 +00:00
my $ snsperbb = $ STANZAS { 'xcat-service-nodes' } - > { 'num-service-nodes-per-bb' } ;
# store the positions of service and storage nodes, so we can avoid those
my % snpositions ;
my @ positions = split ( /[\s,]+/ , $ STANZAS { 'xcat-service-nodes' } - > { 'cec-positions-in-bb' } ) ;
foreach ( @ positions ) { $ snpositions { $ _ } = 1 ; }
@ positions = split ( /[\s,]+/ , $ STANZAS { 'xcat-storage-nodes' } - > { 'cec-positions-in-bb' } ) ;
foreach ( @ positions ) { $ snpositions { $ _ } = 1 ; }
2011-05-05 17:11:22 +00:00
# this next line is only valid for cec names like cec01, because names like f1c1 can have gaps due to unequal number of cecs in each frame
2010-10-14 16:00:20 +00:00
my $ cecs = [ noderange ( $ STANZAS { 'xcat-cecs' } - > { 'hostname-range' } , 0 ) ] ;
2011-05-05 17:11:22 +00:00
#-------------------------\
# in case they are using names like f1c1, we need to collect this info
my $ cecsperframe = $ STANZAS { 'xcat-cecs' } - > { 'num-cecs-per-frame' } ;
my $ cechash = parsenoderange ( $ STANZAS { 'xcat-cecs' } - > { 'hostname-range' } ) ;
my $ cecbase = $$ cechash { 'primary-base' } ;
my $ cecstart = $$ cechash { 'primary-start' } ;
my $ ceclen = length ( $$ cechash { 'primary-start' } ) ;
my $ secbase = $$ cechash { 'secondary-base' } ;
my $ secstart = $$ cechash { 'secondary-start' } ;
my $ secend = $$ cechash { 'secondary-end' } ;
my $ seclen = length ( $$ cechash { 'secondary-start' } ) ;
#--------------------------/
2010-10-14 16:00:20 +00:00
my $ sns = [ noderange ( $ STANZAS { 'xcat-service-nodes' } - > { 'hostname-range' } , 0 ) ] ;
$ nodes = [ noderange ( $ range , 0 ) ] ;
my % nodehash ;
2010-10-29 19:09:18 +00:00
my % nodeposhash ;
2010-10-14 16:00:20 +00:00
my % nodereshash ;
2011-05-05 17:11:22 +00:00
# set these two incrementers to the imaginary position just before the 1st position
my $ cecnum = 0 ; # for cec names like cec01
2010-10-14 16:00:20 +00:00
my $ lparid = $ lparspercec ;
2011-05-05 17:11:22 +00:00
my $ framenum = $ cecstart ; # for cec names like f1c1
my $ cecnuminframe = 0 ; # $secstart -1;
2011-04-01 21:30:08 +00:00
# Go thru each compute node and calculate which cec it is in and its service node
2010-10-14 16:00:20 +00:00
for ( my $ i = 0 ; $ i < scalar ( @$ nodes ) ; $ i + + ) {
2011-05-05 17:11:22 +00:00
if ( $ lparid >= $ lparspercec ) { # at the end of the cec
$ lparid = 1 ;
$ cecnum + + ; # name like cec01 and also for counting the cecs
if ( $ secbase ) { # name like f1c1
$ cecnuminframe + + ;
if ( $ cecnuminframe > ( $ NUMCECSINFRAME { $ framenum } || $ cecsperframe ) ) { $ framenum + + ; $ cecnuminframe = 1 ; } # go on to the next frame
}
}
2010-10-14 16:00:20 +00:00
else { $ lparid + + }
if ( $ lparid == 1 ) { # check if this is a service or storage node position
my $ pos = ( $ cecnum - 1 ) % $ cecsperbb + 1 ;
if ( $ snpositions { $ pos } ) {
2011-05-05 17:11:22 +00:00
#if ($lparid >= $lparspercec) { $cecnum++; $lparid=1; } # at the end of the cec
if ( $ lparid >= $ lparspercec ) { # at the end of the cec
$ lparid = 1 ;
$ cecnum + + ; # name like cec01 and also for counting the cecs
if ( $ secbase ) { # name like f1c1
$ cecnuminframe + + ;
if ( $ cecnuminframe > ( $ NUMCECSINFRAME { $ framenum } || $ cecsperframe ) ) { $ framenum + + ; $ cecnuminframe = 1 ; } # go on to the next frame
}
}
2010-10-14 16:00:20 +00:00
else { $ lparid + + }
}
}
2011-05-05 17:11:22 +00:00
my $ cecname ;
if ( ! $ secbase ) { $ cecname = $$ cecs [ $ cecnum - 1 ] ; } # name like cec01
else { # name like f1c1
$ cecname = $ cecbase . sprintf ( "%0${ceclen}d" , $ framenum ) . $ secbase . sprintf ( "%0${seclen}d" , $ cecnuminframe ) ;
}
2010-10-14 16:00:20 +00:00
my $ id = $ lparid ;
if ( $ lparspercec == 8 ) {
#todo: for now assume 8 means a p7 IH. Make a different way to determine this is a p7 IH
$ id = ( ( $ lparid - 1 ) * 4 ) + 1 ;
}
#print "sn=$$nodes[$i], cec=$cecname\n";
$ nodehash { $$ nodes [ $ i ] } = { hcp = > $ cecname , parent = > $ cecname , id = > $ id } ;
2010-10-29 19:09:18 +00:00
$ nodeposhash { $$ nodes [ $ i ] } = { rack = > $ CECPOSITIONS - > { $ cecname } - > [ 0 ] - > { rack } , u = > $ CECPOSITIONS - > { $ cecname } - > [ 0 ] - > { u } } ;
2010-10-14 16:00:20 +00:00
# Now determine the service node this compute node is under
my $ bbnum = int ( ( $ cecnum - 1 ) / $ cecsperbb ) + 1 ;
my $ cecinthisbb = ( $ cecnum - 1 ) % $ cecsperbb + 1 ;
2010-12-17 19:14:32 +00:00
#todo: handle case where this does not divide evenly
2010-10-14 16:00:20 +00:00
my $ cecspersn = int ( $ cecsperbb / $ snsperbb ) ;
my $ snoffset = int ( ( $ cecinthisbb - 1 ) / $ cecspersn ) + 1 ;
my $ snsbeforethisbb = ( $ bbnum - 1 ) * $ snsperbb ;
my $ snnum = $ snsbeforethisbb + $ snoffset ;
my $ snname = $$ sns [ $ snnum - 1 ] ;
# generate a list of the other SNs in this BB
my $ othersns ;
for ( my $ s = $ snsbeforethisbb + 1 ; $ s <= $ snsbeforethisbb + $ snsperbb ; $ s + + ) {
if ( $ s != $ snnum ) { $ othersns . = ',' . $$ sns [ $ s - 1 ] ; }
}
2011-04-01 21:30:08 +00:00
my $ routes = "cnto$snname" ;
if ( $ othersns ) { $ routes . = join ( ',cnto' , split ( ',' , $ othersns ) ) ; } # othersns has a leading comma
$ nodereshash { $$ nodes [ $ i ] } = { xcatmaster = > $ snname , servicenode = > "$snname$othersns" , routenames = > $ routes } ;
2010-09-25 15:14:10 +00:00
}
2010-10-14 16:00:20 +00:00
$ tables { 'ppc' } - > setNodesAttribs ( \ % nodehash ) ;
$ tables { 'noderes' } - > setNodesAttribs ( \ % nodereshash ) ;
2010-10-29 19:09:18 +00:00
$ tables { 'nodepos' } - > setNodesAttribs ( \ % nodeposhash ) ;
return 1 ;
2010-09-25 15:14:10 +00:00
}
# Parse a noderange like n01-n20, n[01-20], or f[1-2]c[01-10].
# Returns a hash that contains: primary-base, primary-start, primary-end, primary-pad, secondary-base, secondary-start, secondary-end, secondary-pad
sub parsenoderange {
my $ nr = shift ;
my $ ret = { } ;
2011-04-02 07:48:09 +00:00
# Check for a 3 square bracket range, e.g. f[1-2]c[01-10]p[1-8] or f[1-2]c[01-10]p[1-8]a
if ( $ nr =~ /^\s*(\S+?)\[(\d+)[\-\:](\d+)\](\S+?)\[(\d+)[\-\:](\d+)\](\S+?)\[(\d+)[\-\:](\d+)\](\S*?)\s*$/ ) {
2011-03-11 07:42:57 +00:00
( $$ ret { 'primary-base' } , $$ ret { 'primary-start' } , $$ ret { 'primary-end' } , $$ ret { 'secondary-base' } , $$ ret { 'secondary-start' } , $$ ret { 'secondary-end' } , $$ ret { 'tertiary-base' } , $$ ret { 'tertiary-start' } , $$ ret { 'tertiary-end' } , $$ ret { 'attach' } ) = ( $ 1 , $ 2 , $ 3 , $ 4 , $ 5 , $ 6 , $ 7 , $ 8 , $ 9 , $ 10 ) ;
if ( ( length ( $$ ret { 'primary-start' } ) != length ( $$ ret { 'primary-end' } ) ) || ( length ( $$ ret { 'secondary-start' } ) != length ( $$ ret { 'secondary-end' } ) ) || ( length ( $$ ret { 'tertiary-start' } ) != length ( $$ ret { 'tertiary-end' } ) ) ) { errormsg ( "invalid noderange format: $nr. The beginning and ending numbers of the range must have the same number of digits." , 5 ) ; return undef ; }
2011-03-31 00:57:15 +00:00
#if ( ($$ret{'primary-start'} != 1) || ($$ret{'secondary-start'} != 1) || ($$ret{'tertiary-start'} != 1) ) { errormsg("invalid noderange format: $nr. Currently noderanges must start at 1.", 5); return undef; }
2011-03-11 07:42:57 +00:00
return $ ret ;
}
2011-04-02 07:48:09 +00:00
# Check for a 2 square bracket range, e.g. f[1-2]c[01-10] or f[1-2]c[01-10]a
if ( $ nr =~ /^\s*(\S+?)\[(\d+)[\-\:](\d+)\](\S+?)\[(\d+)[\-\:](\d+)\](\S*?)\s*$/ ) {
2011-03-11 07:42:57 +00:00
( $$ ret { 'primary-base' } , $$ ret { 'primary-start' } , $$ ret { 'primary-end' } , $$ ret { 'secondary-base' } , $$ ret { 'secondary-start' } , $$ ret { 'secondary-end' } , $$ ret { 'attach' } ) = ( $ 1 , $ 2 , $ 3 , $ 4 , $ 5 , $ 6 , $ 7 ) ;
if ( ( length ( $$ ret { 'primary-start' } ) != length ( $$ ret { 'primary-end' } ) ) || ( length ( $$ ret { 'secondary-start' } ) != length ( $$ ret { 'secondary-end' } ) ) ) { errormsg ( "invalid noderange format: $nr. The beginning and ending numbers of the range must have the same number of digits." , 5 ) ; return undef ; }
2011-03-31 00:57:15 +00:00
#if ( ($$ret{'primary-start'} != 1) || ($$ret{'secondary-start'} != 1) ) { errormsg("invalid noderange format: $nr. Currently noderanges must start at 1.", 5); return undef; }
2011-03-11 07:42:57 +00:00
return $ ret ;
}
2011-04-02 07:48:09 +00:00
# Check for a square bracket range, e.g. n[01-20] or n[01-20]a
if ( $ nr =~ /^\s*(\S+?)\[(\d+)[\-\:](\d+)\](\S*?)\s*$/ ) {
2011-03-11 07:42:57 +00:00
( $$ ret { 'primary-base' } , $$ ret { 'primary-start' } , $$ ret { 'primary-end' } , $$ ret { 'attach' } ) = ( $ 1 , $ 2 , $ 3 , $ 4 ) ;
if ( length ( $$ ret { 'primary-start' } ) != length ( $$ ret { 'primary-end' } ) ) { errormsg ( "invalid noderange format: $nr. The beginning and ending numbers of the range must have the same number of digits." , 5 ) ; return undef ; }
2011-03-31 00:57:15 +00:00
#if ($$ret{'primary-start'} != 1) { errormsg("invalid noderange format: $nr. Currently noderanges must start at 1.", 5); return undef; }
2011-03-11 07:42:57 +00:00
return $ ret ;
}
2010-09-25 15:14:10 +00:00
2011-04-02 07:48:09 +00:00
# Check for normal range, e.g. n01-n20 or n01a-n20a
2011-03-11 07:42:57 +00:00
my $ base2 ;
2011-04-02 07:48:09 +00:00
if ( $ nr =~ /^\s*(\S+?)(\d+)(\S*?)\-(\S+?)(\d+)(\S*?)\s*$/ ) {
2011-03-11 07:42:57 +00:00
( $$ ret { 'primary-base' } , $$ ret { 'primary-start' } , $$ ret { 'attach' } , $ base2 , $$ ret { 'primary-end' } , $$ ret { 'attach2' } ) = ( $ 1 , $ 2 , $ 3 , $ 4 , $ 5 , $ 6 ) ;
if ( $$ ret { 'primary-base' } ne $ base2 ) { errormsg ( "invalid noderange format: $nr" , 5 ) ; return undef ; }
if ( length ( $$ ret { 'primary-start' } ) != length ( $$ ret { 'primary-end' } ) ) { errormsg ( "invalid noderange format: $nr. The beginning and ending numbers of the range must have the same number of digits." , 5 ) ; return undef ; }
2011-03-31 00:57:15 +00:00
#if ($$ret{'primary-start'} != 1) { errormsg("invalid noderange format: $nr. Currently noderanges must start at 1.", 5); return undef; }
2011-03-11 07:42:57 +00:00
return $ ret ;
}
2010-09-25 15:14:10 +00:00
2010-10-21 20:05:11 +00:00
# It may be a simple single nodename
if ( $ nr =~ /^\s*([^\[\]\-\:\s]+?)(\d+)\s*$/ ) {
( $$ ret { 'primary-base' } , $$ ret { 'primary-start' } , $$ ret { 'primary-end' } ) = ( $ 1 , $ 2 , $ 2 ) ;
return $ ret ;
}
errormsg ( "invalid noderange format: $nr" , 5 ) ;
2010-09-25 15:14:10 +00:00
return undef ; # range did not match any of the cases above
2010-09-16 02:05:28 +00:00
}
2010-10-29 19:09:18 +00:00
# Verify this is valid IP address format (ipv4 only for right now).
# If not, print error msg and return 0.
sub isIP {
my $ ip = shift ;
2010-12-08 17:32:46 +00:00
if ( $ ip =~ /^\s*\d+\.\d+\.\d+\.\d+\s*$/ ) { return 1 ; }
2010-10-29 19:09:18 +00:00
errormsg ( "invalid IP address format: $ip" , 6 ) ;
return 0 ;
}
2010-09-16 02:05:28 +00:00
sub errormsg {
my $ msg = shift ;
my $ exitcode = shift ;
my % rsp ;
push @ { $ rsp { error } } , $ msg ;
xCAT::MsgUtils - > message ( 'E' , \ % rsp , $ CALLBACK , $ exitcode ) ;
return ;
}
sub infomsg {
my $ msg = shift ;
my % rsp ;
push @ { $ rsp { info } } , $ msg ;
xCAT::MsgUtils - > message ( 'I' , \ % rsp , $ CALLBACK ) ;
return ;
}
sub fullpath {
my ( $ filename , $ cwd ) = @ _ ;
if ( $ filename =~ /^\s*\// ) { return $ filename ; } # it was already a full path
return xCAT::Utils - > full_path ( $ filename , $ cwd ) ;
}
2010-12-08 17:32:46 +00:00
sub deletenodes {
my ( $ name , $ range ) = @ _ ;
if ( $ range !~ /\S/ ) { return ; }
infomsg ( "Deleting $name..." ) ;
2010-12-17 19:14:32 +00:00
rmdef ( $ range ) ;
2010-12-08 17:32:46 +00:00
return ;
}
2010-12-17 19:14:32 +00:00
sub deletegroup {
my $ group = shift ;
if ( $ group !~ /\S/ ) { return ; }
#print "group=$group\n";
my $ ret = xCAT::Utils - > runxcmd ( { command = > [ 'rmdef' ] , arg = > [ '-t' , 'group' , '--nocache' , '-o' , $ group ] } , $ SUB_REQ , 0 , 1 ) ;
if ( $$ ret [ 0 ] !~ /^Object definitions have been removed\.$/ ) { xCAT::MsgUtils - > message ( 'D' , { data = > $ ret } , $ CALLBACK ) ; }
}
sub rmdef {
my $ range = shift ;
if ( $ range !~ /\S/ ) { return ; }
#print "deleting $range\n";
my $ ret = xCAT::Utils - > runxcmd ( { command = > [ 'rmdef' ] , arg = > [ '-t' , 'node' , '--nocache' , '-o' , $ range ] } , $ SUB_REQ , 0 , 1 ) ;
#print Dumper($ret);
if ( $$ ret [ 0 ] !~ /^Object definitions have been removed\.$/ && $$ ret [ 0 ] !~ /^Could not find an object named/ ) { xCAT::MsgUtils - > message ( 'D' , { data = > $ ret } , $ CALLBACK ) ; }
#$CALLBACK->({data=>$ret});
}
sub noderm {
my $ range = shift ;
if ( $ range !~ /\S/ ) { return ; }
#print "noderm $range\n";
my $ ret = xCAT::Utils - > runxcmd ( { command = > [ 'noderm' ] , noderange = > [ $ range ] } , $ SUB_REQ , 0 , 1 ) ;
xCAT::MsgUtils - > message ( 'D' , { data = > $ ret } , $ CALLBACK ) ;
}
# Create or delete dynamic groups for the given node list
sub dynamicGroups {
my ( $ action , $ nodes , $ where ) = @ _ ;
#my $ntab = xCAT::Table->new('nodegroup', -create=>1,-autocommit=>0);
#if (!$ntab) { errormsg("Can not open nodegroup table in database.", 3); return; }
my $ ntab = $ tables { 'nodegroup' } ;
foreach my $ n ( @$ nodes ) {
if ( $ action ne 'delete' ) {
#print "adding group ${n}nodes with $where$n\n";
$ ntab - > setAttribs ( { groupname = > "${n}nodes" } , { grouptype = > 'dynamic' , members = > 'dynamic' , wherevals = > "$where$n" } ) ;
} else {
$ ntab - > delEntries ( { groupname = > "${n}nodes" } ) ;
}
}
$ ntab - > commit ( ) ;
#$ntab->close();
}
sub staticGroup {
my $ group = shift ;
$ tables { 'nodegroup' } - > setAttribs ( { groupname = > $ group } , { grouptype = > 'static' , members = > 'static' } ) ; # this makes rmdef happier
$ tables { 'nodegroup' } - > commit ( ) ;
}
sub addPostscript {
my ( $ group , $ postscript ) = @ _ ;
my $ ref = $ tables { 'postscripts' } - > getNodeAttribs ( $ group , 'postscripts' ) ;
#print Dumper($ref);
my $ posts ;
if ( $ ref && $ ref - > { postscripts } =~ /\S/ ) {
$ posts = $ ref - > { postscripts } ;
if ( $ posts !~ /(^|,)llserver\.sh(,|$)/ ) { $ posts . = ",$postscript" ; }
}
else { $ posts = "$postscript" ; }
$ tables { 'postscripts' } - > setNodeAttribs ( $ group , { postscripts = > $ posts } ) ;
}
2010-09-16 02:05:28 +00:00
1 ;