2007-10-26 22:44:33 +00:00
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
#TODO: delete entries not being refreshed if no noderange
package xCAT_plugin::conserver ;
2008-07-18 22:24:06 +00:00
use strict ;
2007-10-26 22:44:33 +00:00
use xCAT::Table ;
2008-04-24 18:08:41 +00:00
use xCAT::Utils ;
use Getopt::Long ;
use Sys::Hostname ;
2007-10-26 22:44:33 +00:00
use strict ;
use Data::Dumper ;
my @ cservers = qw( mrv cyclades ) ;
my % termservers ; #list of noted termservers
2008-04-24 18:08:41 +00:00
my $ usage_string =
2009-01-23 04:16:03 +00:00
" makeconservercf [ - d | - - delete ] noderange
2008-04-24 18:08:41 +00:00
makeconservercf [ - l | - - local ]
2009-11-18 06:23:56 +00:00
makeconservercf [ - c | - - conserver ]
2009-04-06 14:58:10 +00:00
makeconservercf
2008-05-07 11:34:17 +00:00
makeconservercf - h | - - help
2008-04-24 18:08:41 +00:00
makeconservercf - v | - - version
2009-11-18 06:23:56 +00:00
- c | - - conserver The conserver gets set up only on the conserver host .
The default goes down to all the conservers on
the server nodes and set them up
- l | - - local The conserver gets set up only on the local host .
The default goes down to all the conservers on
the server nodes and set them up
- d | - - delete Conserver has the relevant entries for the given noderange removed immediately from configuration
- h | - - help Display this usage statement .
- V | - - verbose Verbose mode .
- v | - - version Display the version number . " ;
2008-04-24 18:08:41 +00:00
2008-07-07 18:29:55 +00:00
my $ version_string = xCAT::Utils - > Version ( ) ;
2008-04-24 18:08:41 +00:00
2007-10-26 22:44:33 +00:00
sub handled_commands {
return {
makeconservercf = > "conserver"
}
}
2008-05-07 11:34:17 +00:00
sub preprocess_request {
2008-04-24 18:08:41 +00:00
my $ request = shift ;
2009-07-15 19:12:07 +00:00
#if ($request->{_xcatdest}) { return [$request]; } #exit if preprocessed
if ( $ request - > { _xcatpreprocessed } - > [ 0 ] == 1 ) { return [ $ request ] ; }
2008-04-24 18:08:41 +00:00
my $ callback = shift ;
my @ requests ;
2008-05-13 01:15:53 +00:00
my $ noderange = $ request - > { node } ; #Should be arrayref
2008-04-24 18:08:41 +00:00
2008-05-07 11:34:17 +00:00
#display usage statement if -h
2008-04-24 18:08:41 +00:00
my $ extrargs = $ request - > { arg } ;
my @ exargs = ( $ request - > { arg } ) ;
if ( ref ( $ extrargs ) ) {
@ exargs = @$ extrargs ;
}
@ ARGV = @ exargs ;
my $ isSN = xCAT::Utils - > isServiceNode ( ) ;
my @ hostinfo = xCAT::Utils - > determinehostname ( ) ;
my % iphash = ( ) ;
foreach ( @ hostinfo ) { $ iphash { $ _ } = 1 ; }
$ Getopt:: Long:: ignorecase = 0 ;
#$Getopt::Long::pass_through=1;
if ( ! GetOptions (
2009-11-18 06:23:56 +00:00
'c|conserver' = > \ $ ::CONSERVER ,
2008-04-24 18:08:41 +00:00
'l|local' = > \ $ ::LOCAL ,
'h|help' = > \ $ ::HELP ,
2009-11-18 06:23:56 +00:00
'D|debug' = > \ $ ::DEBUG ,
'v|version' = > \ $ ::VERSION ,
'V|verbose' = > \ $ ::VERBOSE ) ) {
2008-04-24 18:08:41 +00:00
$ request = { } ;
return ;
}
2008-05-07 11:34:17 +00:00
if ( $ ::HELP ) {
2008-04-24 18:08:41 +00:00
$ callback - > ( { data = > $ usage_string } ) ;
$ request = { } ;
return ;
}
2008-05-07 11:34:17 +00:00
if ( $ ::VERSION ) {
2008-04-24 18:08:41 +00:00
$ callback - > ( { data = > $ version_string } ) ;
$ request = { } ;
return ;
}
if ( $ ::LOCAL ) {
if ( $ noderange && @$ noderange > 0 ) {
2009-04-06 15:05:18 +00:00
$ callback - > ( { data = > "Invalid option -l or --local when there are nodes specified." } ) ;
2008-04-24 18:08:41 +00:00
$ request = { } ;
return ;
}
}
2009-11-18 06:23:56 +00:00
if ( $ ::CONSERVER && $ ::LOCAL ) {
$ callback - > ( { data = > "Can not specify -l or --local together with -c or --conserver." } ) ;
$ request = { } ;
return ;
}
2009-04-03 07:10:55 +00:00
2008-04-24 18:08:41 +00:00
# get site master
my $ master = xCAT::Utils - > get_site_Master ( ) ;
if ( ! $ master ) { $ master = hostname ( ) ; }
# get conserver for each node
my % cons_hash = ( ) ;
my $ hmtab = xCAT::Table - > new ( 'nodehm' ) ;
my @ items ;
my $ allnodes = 1 ;
if ( $ noderange && @$ noderange > 0 ) {
$ allnodes = 0 ;
2008-09-12 15:12:03 +00:00
my $ hmcache = $ hmtab - > getNodesAttribs ( $ noderange , [ 'node' , 'serialport' , 'cons' , 'conserver' ] ) ;
2008-04-24 18:08:41 +00:00
foreach my $ node ( @$ noderange ) {
2008-07-07 22:47:38 +00:00
my $ ent = $ hmcache - > { $ node } - > [ 0 ] ; #$hmtab->getNodeAttribs($node,['node', 'serialport','cons', 'conserver']);
2008-05-07 11:34:17 +00:00
push @ items , $ ent ;
2008-04-24 18:08:41 +00:00
}
} else {
$ allnodes = 1 ;
2008-05-02 01:59:50 +00:00
@ items = $ hmtab - > getAllNodeAttribs ( [ 'node' , 'serialport' , 'cons' , 'conserver' ] ) ;
2008-04-24 18:08:41 +00:00
}
my @ nodes = ( ) ;
foreach ( @ items ) {
2008-05-07 11:34:17 +00:00
if ( ( ( ! defined ( $ _ - > { cons } ) ) || ( $ _ - > { cons } eq "" ) ) and ! defined ( $ _ - > { serialport } ) ) { next ; } #skip if 'cons' is not defined for this node, unless serialport suggests otherwise
2008-04-24 18:08:41 +00:00
if ( defined ( $ _ - > { conserver } ) ) { push @ { $ cons_hash { $ _ - > { conserver } } { nodes } } , $ _ - > { node } ; }
else { push @ { $ cons_hash { $ master } { nodes } } , $ _ - > { node } ; }
push @ nodes , $ _ - > { node } ;
}
#send all nodes to the MN
2009-11-18 06:23:56 +00:00
if ( ! $ isSN && ! $ ::CONSERVER ) { #If -c flag is set, do not add the all nodes to the management node
if ( $ ::VERBOSE ) {
my $ rsp ;
$ rsp - > { data } - > [ 0 ] = "Setting the nodes into /etc/conserver.cf on the management node" ;
xCAT::MsgUtils - > message ( "I" , $ rsp , $ callback ) ;
}
2008-04-24 18:08:41 +00:00
my $ reqcopy = { %$ request } ;
$ reqcopy - > { '_xcatdest' } = $ master ;
2009-07-15 19:12:07 +00:00
$ reqcopy - > { _xcatpreprocessed } - > [ 0 ] = 1 ;
2008-04-24 18:08:41 +00:00
$ reqcopy - > { '_allnodes' } = $ allnodes ; # the original command comes with nodes or not
if ( $ allnodes == 1 ) { @ nodes = ( ) ; }
2008-05-07 11:34:17 +00:00
$ reqcopy - > { node } = \ @ nodes ;
2008-04-24 18:08:41 +00:00
push @ requests , $ reqcopy ;
2008-05-07 11:34:17 +00:00
if ( $ ::LOCAL ) { return \ @ requests ; }
}
2009-11-18 06:23:56 +00:00
# send to conserver hosts
2008-04-24 18:08:41 +00:00
foreach my $ cons ( keys % cons_hash ) {
#print "cons=$cons\n";
2008-05-07 11:34:17 +00:00
my $ doit = 0 ;
2008-04-24 18:08:41 +00:00
if ( $ isSN ) {
if ( exists ( $ iphash { $ cons } ) ) { $ doit = 1 ; }
} else {
2009-11-18 06:23:56 +00:00
if ( ! exists ( $ iphash { $ cons } ) || $ ::CONSERVER ) { $ doit = 1 ; }
2008-04-24 18:08:41 +00:00
}
2008-05-07 11:34:17 +00:00
2008-04-24 18:08:41 +00:00
if ( $ doit ) {
my $ reqcopy = { %$ request } ;
$ reqcopy - > { '_xcatdest' } = $ cons ;
2009-07-15 19:12:07 +00:00
$ reqcopy - > { _xcatpreprocessed } - > [ 0 ] = 1 ;
2008-04-29 23:45:00 +00:00
$ reqcopy - > { '_allnodes' } = [ $ allnodes ] ; # the original command comes with nodes or not
2008-04-24 18:08:41 +00:00
$ reqcopy - > { node } = $ cons_hash { $ cons } { nodes } ;
my $ no = $ reqcopy - > { node } ;
#print "node=@$no\n";
push @ requests , $ reqcopy ;
2009-11-19 01:31:07 +00:00
} #end if
} #end foreach
2009-11-18 06:23:56 +00:00
if ( $ ::DEBUG ) {
my $ rsp ;
$ rsp - > { data } - > [ 0 ] = "In preprocess_request, request is " . Dumper ( @ requests ) ;
xCAT::MsgUtils - > message ( "I" , $ rsp , $ callback ) ;
2009-11-18 14:51:19 +00:00
}
2008-04-24 18:08:41 +00:00
return \ @ requests ;
}
2007-10-26 22:44:33 +00:00
sub process_request {
my $ req = shift ;
my $ cb = shift ;
if ( $ req - > { command } - > [ 0 ] eq "makeconservercf" ) {
makeconservercf ( $ req , $ cb ) ;
}
}
sub docfheaders {
# Put in standard headers common to all conserver.cf files
my $ content = shift ;
2009-03-16 23:45:45 +00:00
my @ newheaders = ( ) ;
2007-10-26 22:44:33 +00:00
my $ numlines = @$ content ;
2009-03-10 08:43:51 +00:00
my $ idx = 0 ;
my $ skip = 0 ;
2007-10-26 22:44:33 +00:00
my @ meat = grep ( ! /^#/ , @$ content ) ;
2008-01-10 01:14:14 +00:00
unless ( grep ( /^config \* {/ , @ meat ) ) {
2010-03-18 02:47:23 +00:00
# do not add the ssl configurations
# if conserver is not compiled with ssl support
my $ cmd = "console -h 2>&1" ;
my $ output = xCAT::Utils - > runcmd ( $ cmd , - 1 ) ;
if ( $ output !~ "encryption not compiled" )
{
push @ newheaders , "config * {\n" ;
push @ newheaders , " sslrequired yes;\n" ;
push @ newheaders , " sslauthority /etc/xcat/cert/ca.pem;\n" ;
push @ newheaders , " sslcredentials /etc/xcat/cert/server-cred.pem;\n" ;
push @ newheaders , "}\n" ;
}
2007-10-26 22:44:33 +00:00
}
unless ( grep ( /^default cyclades/ , @ meat ) ) {
2009-03-16 23:45:45 +00:00
push @ newheaders , "default cyclades { type host; portbase 7000; portinc 1; }\n"
2007-10-26 22:44:33 +00:00
}
unless ( grep ( /^default mrv/ , @ meat ) ) {
2009-03-16 23:45:45 +00:00
push @ newheaders , "default mrv { type host; portbase 2000; portinc 100; }\n"
2007-10-26 22:44:33 +00:00
}
2009-03-10 08:43:51 +00:00
#Go through and delete that which would match access and default
while ( $ idx < @$ content ) {
if ( ( $ content - > [ $ idx ] =~ /^access \*/ )
|| ( $ content - > [ $ idx ] =~ /^default \*/ ) ) {
$ skip = 1 ;
2008-04-24 18:08:41 +00:00
}
2009-03-10 08:43:51 +00:00
if ( $ skip == 1 ) {
splice ( @$ content , $ idx , 1 ) ;
} else {
$ idx + + ;
}
2009-03-12 11:21:29 +00:00
if ( $ skip and $ content - > [ $ idx ] =~ /\}/ ) {
2009-03-10 08:43:51 +00:00
splice ( @$ content , $ idx , 1 ) ;
$ skip = 0 ;
2008-09-10 15:07:26 +00:00
}
2007-10-26 22:44:33 +00:00
}
2009-03-10 08:43:51 +00:00
#push @$content,"#xCAT BEGIN ACCESS\n";
2009-03-16 23:45:45 +00:00
push @ newheaders , "access * {\n" ;
push @ newheaders , " trusted 127.0.0.1;\n" ;
2010-01-19 13:29:13 +00:00
my $ master = xCAT::Utils - > get_site_Master ( ) ;
push @ newheaders , " trusted $master;\n" ;
2009-03-16 23:45:45 +00:00
push @ newheaders , "}\n" ;
2009-03-10 08:43:51 +00:00
#push @$content,"#xCAT END ACCESS\n";
2009-03-16 23:45:45 +00:00
push @ newheaders , "default * {\n" ;
push @ newheaders , " logfile /var/log/consoles/&;\n" ;
push @ newheaders , " timestamp 1hab;\n" ;
push @ newheaders , " rw *;\n" ;
push @ newheaders , " master localhost;\n" ;
2009-03-10 08:43:51 +00:00
#-- if option "conserverondemand" in site table is set to yes
#-- then start all consoles on demand
#-- this helps eliminate many ssh connections to blade AMM
#-- which seems to kill AMMs occasionally
my $ sitetab = xCAT::Table - > new ( 'site' ) ;
my $ vcon = $ sitetab - > getAttribs ( { key = > "consoleondemand" } , 'value' ) ;
if ( $ vcon and $ vcon - > { "value" } and $ vcon - > { "value" } eq "yes" ) {
2009-03-16 23:45:45 +00:00
push @ newheaders , " options ondemand;\n" ;
2009-03-10 08:43:51 +00:00
}
2009-03-16 23:45:45 +00:00
push @ newheaders , "}\n" ;
unshift @$ content , @ newheaders ;
2007-10-26 22:44:33 +00:00
}
sub makeconservercf {
my $ req = shift ;
% termservers = ( ) ; #clear hash of existing entries
my $ cb = shift ;
2009-01-23 04:16:03 +00:00
my $ extrargs = $ req - > { arg } ;
my @ exargs = ( $ req - > { arg } ) ;
if ( ref ( $ extrargs ) ) {
@ exargs = @$ extrargs ;
}
@ ARGV = @ exargs ;
$ Getopt:: Long:: ignorecase = 0 ;
#$Getopt::Long::pass_through=1;
my $ delmode ;
GetOptions ( 'd|delete' = > \ $ delmode ) ;
2007-10-26 22:44:33 +00:00
my $ nodes = $ req - > { node } ;
2008-05-13 01:15:53 +00:00
my $ svboot = 0 ;
if ( exists ( $ req - > { svboot } ) ) { $ svboot = 1 ; }
2007-10-26 22:44:33 +00:00
my $ cfile ;
my @ filecontent ;
open $ cfile , '/etc/conserver.cf' ;
while ( <$cfile> ) {
push @ filecontent , $ _ ;
}
close $ cfile ;
docfheaders ( \ @ filecontent ) ;
2008-04-24 18:08:41 +00:00
my $ isSN = xCAT::Utils - > isServiceNode ( ) ;
my @ hostinfo = xCAT::Utils - > determinehostname ( ) ;
my % iphash = ( ) ;
foreach ( @ hostinfo ) { $ iphash { $ _ } = 1 ; }
#print "process_request nodes=@$nodes\n";
2007-10-26 22:44:33 +00:00
my $ hmtab = xCAT::Table - > new ( 'nodehm' ) ;
2008-07-07 22:47:38 +00:00
my @ cfgents1 ; # = $hmtab->getAllNodeAttribs(['cons','serialport','mgt','conserver','termserver','termport']);
if ( ( $ nodes and @$ nodes > 0 ) or $ req - > { noderange } - > [ 0 ] ) {
@ cfgents1 = $ hmtab - > getNodesAttribs ( $ nodes , [ 'cons' , 'serialport' , 'mgt' , 'conserver' , 'termserver' , 'termport' ] ) ;
2008-10-14 11:19:57 +00:00
#to make the result consistent to getAllNodeAttribs
my @ tmpcfgents1 ;
foreach my $ ent ( @ cfgents1 )
{
foreach my $ nodeent ( keys %$ ent )
{
push @ tmpcfgents1 , $ ent - > { $ nodeent } - > [ 0 ] ;
}
}
@ cfgents1 = @ tmpcfgents1
2008-07-07 22:47:38 +00:00
} else {
@ cfgents1 = $ hmtab - > getAllNodeAttribs ( [ 'cons' , 'serialport' , 'mgt' , 'conserver' , 'termserver' , 'termport' ] ) ;
}
2007-10-26 22:44:33 +00:00
#cfgents should now have all the nodes, so we can fill in our hashes one at a time.
2008-04-29 23:45:00 +00:00
2008-05-02 01:59:50 +00:00
# skip the one that does not have 'cons' defined, unless a serialport setting suggests otherwise
2008-04-29 23:45:00 +00:00
my @ cfgents = ( ) ;
2008-05-07 11:34:17 +00:00
foreach ( @ cfgents1 ) {
if ( $ _ - > { cons } or defined ( $ _ - > { 'serialport' } ) ) { push @ cfgents , $ _ ; }
2008-04-29 23:45:00 +00:00
}
2008-05-07 11:34:17 +00:00
2009-11-18 06:23:56 +00:00
if ( $ ::DEBUG ) {
my $ rsp ;
$ rsp - > { data } - > [ 0 ] = "In makeconservercf, cfgents is " . Dumper ( @ cfgents ) ;
xCAT::MsgUtils - > message ( "I" , $ rsp , $ cb ) ;
}
2008-04-29 23:45:00 +00:00
# get the teminal servers and terminal port when cons is mrv or cyclades
2007-10-26 22:44:33 +00:00
foreach ( @ cfgents ) {
2008-05-02 01:59:50 +00:00
unless ( $ _ - > { cons } ) { $ _ - > { cons } = $ _ - > { mgt } ; } #populate with fallback
2008-07-07 22:47:38 +00:00
#my $cmeth=$_->{cons};
#if (grep(/^$cmeth$/,@cservers)) { #terminal server, more attribs needed
# my $node = $_->{node};
# my $tent = $hmtab->getNodeAttribs($node,["termserver","termport"]);
# $_->{termserver} = $tent->{termserver};
# $termservers{$tent->{termserver}} = 1;
# $_->{termport}= $tent->{termport};
#}
2007-10-26 22:44:33 +00:00
}
2008-04-29 23:45:00 +00:00
# nodes defined, it is either on the service node or mkconserver is call with noderange on mn
2007-10-26 22:44:33 +00:00
if ( ( $ nodes and @$ nodes > 0 ) or $ req - > { noderange } - > [ 0 ] ) {
2008-04-24 18:08:41 +00:00
# strip all xCAT configured stuff from config if the original command was for all nodes
2008-04-29 23:45:00 +00:00
if ( ( $ req - > { _allnodes } ) && ( $ req - > { _allnodes } - > [ 0 ] == 1 ) ) { zapcfg ( \ @ filecontent ) ; }
2007-10-26 22:44:33 +00:00
foreach ( @$ nodes ) {
my $ node = $ _ ;
foreach ( @ cfgents ) {
if ( $ _ - > { node } eq $ node ) {
2008-09-06 21:49:25 +00:00
if ( $ _ - > { termserver } and not $ termservers { $ _ - > { termserver } } ) {
2007-10-26 22:44:33 +00:00
dotsent ( $ _ , \ @ filecontent ) ;
2008-09-06 21:49:25 +00:00
$ termservers { $ _ - > { termserver } } = 1 ; #prevent needless cycles being burned
2007-10-26 22:44:33 +00:00
}
2009-09-26 18:16:26 +00:00
if ( donodeent ( $ _ , \ @ filecontent , $ delmode ) eq "BADCFG" ) {
$ cb - > ( { node = > [ { name = > $ node , error = > "Bad configuration, check attributes under the nodehm category" , errorcode = > 1 } ] } ) ;
}
2007-10-26 22:44:33 +00:00
}
}
}
} else { #no nodes specified, do em all up
zapcfg ( \ @ filecontent ) ; # strip all xCAT configured stuff from config
2008-05-07 11:34:17 +00:00
2008-04-02 15:10:27 +00:00
# filter out node types without console support
my $ typetab = xCAT::Table - > new ( 'nodetype' ) ;
my % type ;
if ( defined ( $ typetab ) ) {
my @ ents = $ typetab - > getAllNodeAttribs ( [ qw( node nodetype ) ] ) ;
foreach ( @ ents ) {
$ type { $ _ - > { node } } = $ _ - > { nodetype } ;
}
}
2007-10-26 22:44:33 +00:00
foreach ( @ cfgents ) {
2008-04-24 18:08:41 +00:00
my $ keepdoing = 0 ;
2008-05-07 11:34:17 +00:00
if ( $ isSN && $ _ - > { conserver } && exists ( $ iphash { $ _ - > { conserver } } ) ) {
2008-04-24 18:08:41 +00:00
$ keepdoing = 1 ; #only hanlde the nodes that use this SN as the conserver
2007-10-26 22:44:33 +00:00
}
2008-04-24 18:08:41 +00:00
if ( ! $ isSN ) { $ keepdoing = 1 ; } #handle all for MN
if ( $ keepdoing ) {
2008-09-06 21:49:25 +00:00
if ( $ _ - > { termserver } and not $ termservers { $ _ - > { termserver } } ) {
2008-04-24 18:08:41 +00:00
dotsent ( $ _ , \ @ filecontent ) ;
2008-09-06 21:49:25 +00:00
$ termservers { $ _ - > { termserver } } = 1 ; #prevent needless cycles being burned
2008-04-24 18:08:41 +00:00
}
if ( $ type { $ _ - > { node } } !~ /fsp|bpa|hmc|ivm/ ) {
2009-09-26 18:16:26 +00:00
if ( donodeent ( $ _ , \ @ filecontent ) eq "BADCFG" ) {
2010-09-20 19:45:27 +00:00
$ cb - > ( { node = > [ { name = > $ _ - > { node } , error = > "Bad configuration, check attributes under the nodehm category" , errorcode = > 1 } ] } ) ;
2009-09-26 18:16:26 +00:00
}
2008-04-24 18:08:41 +00:00
}
2008-04-02 15:10:27 +00:00
}
2007-10-26 22:44:33 +00:00
}
}
open $ cfile , '>' , '/etc/conserver.cf' ;
2009-11-18 06:23:56 +00:00
if ( $ ::VERBOSE ) {
my $ rsp ;
$ rsp - > { data } - > [ 0 ] = "Setting the following lines into /etc/conserver.cf:\n @filecontent" ;
xCAT::MsgUtils - > message ( "I" , $ rsp , $ cb ) ;
}
2007-10-26 22:44:33 +00:00
foreach ( @ filecontent ) {
print $ cfile $ _ ;
}
close $ cfile ;
2008-04-24 18:08:41 +00:00
2008-05-13 01:15:53 +00:00
if ( ! $ svboot ) {
#restart conserver daemon
2008-05-29 18:30:48 +00:00
my $ cmd ;
2009-03-19 07:57:02 +00:00
if ( xCAT::Utils - > isAIX ( ) ) {
$ cmd = "stopsrc -s conserver" ;
xCAT::Utils - > runcmd ( $ cmd , 0 ) ;
$ cmd = "startsrc -s conserver" ;
xCAT::Utils - > runcmd ( $ cmd , 0 ) ;
2008-05-29 18:30:48 +00:00
} else {
2009-03-19 07:57:02 +00:00
$ cmd = "/etc/init.d/conserver stop" ;
xCAT::Utils - > runcmd ( $ cmd , 0 ) ;
$ cmd = "/etc/init.d/conserver start" ;
xCAT::Utils - > runcmd ( $ cmd , 0 ) ;
2008-05-29 18:30:48 +00:00
}
2008-05-13 01:15:53 +00:00
}
2007-10-26 22:44:33 +00:00
}
sub dotsent {
my $ cfgent = shift ;
my $ tserv = $ cfgent - > { termserver } ;
my $ content = shift ;
my $ idx = 0 ;
my $ toidx = - 1 ;
my $ skip = 0 ;
my $ skipnext = 0 ;
2008-04-24 18:08:41 +00:00
2007-10-26 22:44:33 +00:00
while ( $ idx < $#$ content ) { # Go through and delete that which would match my entry
if ( $ content - > [ $ idx ] =~ /^#xCAT BEGIN $tserv TS/ ) {
$ toidx = $ idx ; #TODO put it back right where I found it
$ skip = 1 ;
$ skipnext = 1 ;
} elsif ( $ content - > [ $ idx ] =~ /^#xCAT END $tserv TS/ ) {
$ skipnext = 0 ;
}
if ( $ skip ) {
splice ( @$ content , $ idx , 1 ) ;
} else {
$ idx + + ;
}
$ skip = $ skipnext ;
}
push @$ content , "#xCAT BEGIN $tserv TS\n" ;
push @$ content , "default $tserv {\n" ;
push @$ content , " include " . $ cfgent - > { cons } . ";\n" ;
push @$ content , " host $tserv;\n" ;
push @$ content , "}\n" ;
push @$ content , "#xCAT END $tserv TS\n" ;
2008-05-07 11:34:17 +00:00
2007-10-26 22:44:33 +00:00
}
2008-04-24 18:08:41 +00:00
2007-10-26 22:44:33 +00:00
sub donodeent {
my $ cfgent = shift ;
my $ node = $ cfgent - > { node } ;
my $ content = shift ;
2009-01-23 04:16:03 +00:00
my $ delmode = shift ;
2007-10-26 22:44:33 +00:00
my $ idx = 0 ;
my $ toidx = - 1 ;
my $ skip = 0 ;
my $ skipnext = 0 ;
2008-04-24 18:08:41 +00:00
my $ isSN = xCAT::Utils - > isServiceNode ( ) ;
2009-03-17 01:00:58 +00:00
while ( $ idx <= $#$ content ) { # Go through and delete that which would match my entry
2007-10-26 22:44:33 +00:00
if ( $ content - > [ $ idx ] =~ /^#xCAT BEGIN $node CONS/ ) {
$ toidx = $ idx ; #TODO put it back right where I found it
$ skip = 1 ;
$ skipnext = 1 ;
} elsif ( $ content - > [ $ idx ] =~ /^#xCAT END $node CONS/ ) {
$ skipnext = 0 ;
}
if ( $ skip ) {
splice ( @$ content , $ idx , 1 ) ;
} else {
$ idx + + ;
}
$ skip = $ skipnext ;
}
2009-01-23 04:16:03 +00:00
if ( $ delmode ) {
return ;
}
2009-09-26 18:16:26 +00:00
my $ cmeth = $ cfgent - > { cons } ;
if ( not $ cmeth or ( grep ( /^$cmeth$/ , @ cservers ) and ( not $ cfgent - > { termserver } or not $ cfgent - > { termport } ) ) ) {
return "BADCFG" ;
}
2007-10-26 22:44:33 +00:00
push @$ content , "#xCAT BEGIN $node CONS\n" ;
push @$ content , "console $node {\n" ;
2008-05-07 11:34:17 +00:00
#if ($cfgent->{cons}
2008-04-04 12:59:36 +00:00
#print $cmeth."\n";
2008-05-07 11:34:17 +00:00
if ( grep ( /^$cmeth$/ , @ cservers ) ) {
2007-10-26 22:44:33 +00:00
push @$ content , " include " . $ cfgent - > { termserver } . ";\n" ;
2008-05-07 11:34:17 +00:00
push @$ content , " port " . $ cfgent - > { termport } . ";\n" ;
2008-05-29 18:53:37 +00:00
if ( ( ! $ isSN ) && ( $ cfgent - > { conserver } ) && xCAT::Utils - > thishostisnot ( $ cfgent - > { conserver } ) ) { # let the master handle it
2008-04-24 18:08:41 +00:00
push @$ content , " master " . $ cfgent - > { conserver } . ";\n" ;
2008-05-07 11:34:17 +00:00
}
2007-10-26 22:44:33 +00:00
} else { #a script method...
push @$ content , " type exec;\n" ;
2008-05-29 18:53:37 +00:00
if ( ( ! $ isSN ) && ( $ cfgent - > { conserver } ) && xCAT::Utils - > thishostisnot ( $ cfgent - > { conserver } ) ) { # let the master handle it
2008-04-24 18:08:41 +00:00
push @$ content , " master " . $ cfgent - > { conserver } . ";\n" ;
} else { # handle it here
2008-05-07 11:34:17 +00:00
my $ locerror = $ isSN ? "PERL_BADLANG=0 " : '' ; # on service nodes, often LC_ALL is not set and perl complains
push @$ content , " exec $locerror" . $ ::XCATROOT . "/share/xcat/cons/" . $ cmeth . " " . $ node . ";\n"
2008-04-24 18:08:41 +00:00
}
2007-10-26 22:44:33 +00:00
}
push @$ content , "}\n" ;
push @$ content , "#xCAT END $node CONS\n" ;
}
sub zapcfg {
my $ content = shift ;
my $ idx = 0 ;
my $ toidx = - 1 ;
my $ skip = 0 ;
my $ skipnext = 0 ;
while ( $ idx <= $#$ content ) { # Go through and delete that which would match my entry
if ( $ content - > [ $ idx ] =~ /^#xCAT BEGIN/ ) {
$ toidx = $ idx ; #TODO put it back right where I found it
$ skip = 1 ;
$ skipnext = 1 ;
} elsif ( $ content - > [ $ idx ] =~ /^#xCAT END/ ) {
$ skipnext = 0 ;
}
if ( $ skip ) {
splice ( @$ content , $ idx , 1 ) ;
} else {
$ idx + + ;
}
$ skip = $ skipnext ;
}
}
2008-04-24 18:08:41 +00:00
2007-10-26 22:44:33 +00:00
1 ;
2008-04-24 18:08:41 +00:00