2012-09-07 08:19:36 +00:00
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
2012-10-08 08:40:30 +00:00
package xCAT_plugin :: 00 kitnodebase ;
2012-09-07 08:19:36 +00:00
use strict ;
use warnings ;
2012-11-05 15:00:12 +00:00
use Data::Dumper ;
2012-09-07 08:19:36 +00:00
require xCAT::Utils ;
require xCAT::Table ;
2012-10-08 08:40:30 +00:00
require xCAT::ProfiledNodeUtils ;
2012-09-07 08:19:36 +00:00
#-------------------------------------------------------
= head1
2012-10-08 08:40:30 +00:00
xCAT plugin , which is also the default kit plugin .
These commands are called by node management commands ,
2012-09-07 08:19:36 +00:00
should not be called directly by external .
2012-09-11 06:14:50 +00:00
The kit plugin framework is creating a common framework for kits ' extension. The major feature of this framework is to update kits' related configuration files /services automatically while add/ remove / update nodes .
2012-09-07 08:19:36 +00:00
2012-10-08 08:40:30 +00:00
According to design , if a kit wants have such a auto configure feature , it should create a xCAT plugin which implement commands "kitcmd_nodemgmt_add" , "kitcmd_nodemgmt_remove" ... , just like plugin "00kitnodebase" .
2012-09-11 06:14:50 +00:00
For example , we create a kit for LSF , and want to update LSF 's configuration file automatically updated while add/remove/update xCAT nodes, then we should create a xCAT plugin. This plugin will update LSF' s configuration file and may also reconfigure / restart LSF service while these change happens .
If we have multi kits , and all these kits have such a plugin , then all these plugins will be called while we add /remove/ update xCAT nodes . To configure these kits in one go by auto .
2012-10-08 08:40:30 +00:00
This plugin is a kit plugin , just for configure nodes ' related configurations automatically . So that we do not need to run these make * commands manually after creating them .
2012-09-11 06:14:50 +00:00
2012-10-08 08:40:30 +00:00
About kit plugin naming: naming this plugin starts with "00" is a way for specifying plugin calling orders , we want to call the default kit plugin in front of other kit plugins .
2012-09-11 06:14:50 +00:00
2012-09-07 08:19:36 +00:00
= cut
#-------------------------------------------------------
#-------------------------------------------------------
= head3 handled_commands
Return list of commands handled by this plugin
= cut
#-------------------------------------------------------
sub handled_commands {
return {
2012-10-08 08:40:30 +00:00
kitnodeadd = > '00kitnodebase' ,
kitnoderemove = > '00kitnodebase' ,
kitnodeupdate = > '00kitnodebase' ,
kitnoderefresh = > '00kitnodebase' ,
2012-09-07 08:19:36 +00:00
} ;
}
#-------------------------------------------------------
= head3 process_request
Process the command . This is the main call .
= cut
#-------------------------------------------------------
sub process_request {
my $ request = shift ;
my $ callback = shift ;
my $ request_command = shift ;
my $ command = $ request - > { command } - > [ 0 ] ;
my $ argsref = $ request - > { arg } ;
2013-04-17 07:06:57 +00:00
my $ macflag = 1 ;
if ( exists ( $ request - > { macflag } ) )
{
$ macflag = $ request - > { macflag } - > [ 0 ] ;
}
2012-09-07 08:19:36 +00:00
my $ nodelist = $ request - > { node } ;
2012-09-11 06:14:50 +00:00
my $ retref ;
2012-09-27 08:56:19 +00:00
my $ rsp ;
2012-09-07 08:19:36 +00:00
2012-10-08 08:40:30 +00:00
if ( $ command eq 'kitnodeadd' )
2012-09-07 08:19:36 +00:00
{
2012-10-08 08:40:30 +00:00
setrsp_progress ( "Updating hosts entries" ) ;
2012-11-05 15:00:12 +00:00
$ retref = xCAT::Utils - > runxcmd ( { command = > [ "makehosts" ] , node = > $ nodelist } , $ request_command , 0 , 2 ) ;
2012-10-22 09:37:09 +00:00
log_cmd_return ( $ retref ) ;
2012-10-08 08:40:30 +00:00
setrsp_progress ( "Updating DNS entries" ) ;
2012-11-05 15:00:12 +00:00
$ retref = xCAT::Utils - > runxcmd ( { command = > [ "makedns" ] , node = > $ nodelist } , $ request_command , 0 , 2 ) ;
2012-10-22 09:37:09 +00:00
log_cmd_return ( $ retref ) ;
2012-10-08 08:40:30 +00:00
2013-04-17 07:06:57 +00:00
if ( $ macflag )
{
setrsp_progress ( "Update DHCP entries" ) ;
$ retref = xCAT::Utils - > runxcmd ( { command = > [ "makedhcp" ] , node = > $ nodelist } , $ request_command , 0 , 2 ) ;
log_cmd_return ( $ retref ) ;
}
2012-10-08 08:40:30 +00:00
setrsp_progress ( "Update known hosts" ) ;
2012-11-05 15:00:12 +00:00
$ retref = xCAT::Utils - > runxcmd ( { command = > [ "makeknownhosts" ] , node = > $ nodelist } , $ request_command , 0 , 2 ) ;
2012-10-22 09:37:09 +00:00
log_cmd_return ( $ retref ) ;
2012-10-08 08:40:30 +00:00
2012-09-07 08:19:36 +00:00
my $ firstnode = ( @$ nodelist ) [ 0 ] ;
2012-12-24 03:49:00 +00:00
my $ chaintab = xCAT::Table - > new ( "chain" ) ;
my $ chainref = $ chaintab - > getNodeAttribs ( $ firstnode , [ 'chain' ] ) ;
my $ chainstr = $ chainref - > { 'chain' } ;
my @ chainarray = split ( "," , $ chainstr ) ;
2013-04-17 07:06:57 +00:00
if ( $ macflag )
{
if ( $ chainarray [ 0 ] ) {
setrsp_progress ( "Update nodes' boot settings" ) ;
$ retref = xCAT::Utils - > runxcmd ( { command = > [ "nodeset" ] , node = > $ nodelist , arg = > [ $ chainarray [ 0 ] ] } , $ request_command , 0 , 2 ) ;
log_cmd_return ( $ retref ) ;
}
2012-09-07 08:19:36 +00:00
}
2012-12-13 02:00:48 +00:00
my $ isfsp = xCAT::ProfiledNodeUtils - > is_fsp_node ( [ $ firstnode ] ) ;
if ( $ isfsp ) {
setrsp_progress ( "Updating FSP's IP address" ) ;
$ retref = xCAT::Utils - > runxcmd ( { command = > [ "rspconfig" ] , node = > $ nodelist , arg = > [ 'network=*' ] } , $ request_command , 0 , 2 ) ;
log_cmd_return ( $ retref ) ;
2013-04-17 07:06:57 +00:00
2012-12-13 02:00:48 +00:00
my $ cmmref = xCAT::ProfiledNodeUtils - > get_nodes_cmm ( $ nodelist ) ;
my @ cmmchassis = keys %$ cmmref ;
setrsp_progress ( "Update node's some attributes through 'rscan -u'" ) ;
$ retref = xCAT::Utils - > runxcmd ( { command = > [ "rscan" ] , node = > \ @ cmmchassis , arg = > [ '-u' ] } , $ request_command , 0 , 2 ) ;
log_cmd_return ( $ retref ) ;
2013-04-17 07:06:57 +00:00
2012-12-13 02:00:48 +00:00
setrsp_progress ( "Sets up connections for nodes to FSP" ) ;
$ retref = xCAT::Utils - > runxcmd ( { command = > [ "mkhwconn" ] , node = > $ nodelist , arg = > [ '-t' ] } , $ request_command , 0 , 2 ) ;
log_cmd_return ( $ retref ) ;
}
2012-11-05 15:00:12 +00:00
setrsp_progress ( "Updating conserver configuration files" ) ;
$ retref = xCAT::Utils - > runxcmd ( { command = > [ "makeconservercf" ] , node = > $ nodelist } , $ request_command , 0 , 2 ) ;
log_cmd_return ( $ retref ) ;
2012-09-07 08:19:36 +00:00
}
2012-10-08 08:40:30 +00:00
elsif ( $ command eq 'kitnoderemove' ) {
2012-11-05 15:00:12 +00:00
setrsp_progress ( "Updating conserver configuration files" ) ;
$ retref = xCAT::Utils - > runxcmd ( { command = > [ "makeconservercf" ] , node = > $ nodelist , arg = > [ '-d' ] } , $ request_command , 0 , 2 ) ;
log_cmd_return ( $ retref ) ;
2012-10-08 08:40:30 +00:00
setrsp_progress ( "Update nodes' boot settings" ) ;
2012-11-05 15:00:12 +00:00
$ retref = xCAT::Utils - > runxcmd ( { command = > [ "nodeset" ] , node = > $ nodelist , arg = > [ 'offline' ] } , $ request_command , 0 , 2 ) ;
2012-10-22 09:37:09 +00:00
log_cmd_return ( $ retref ) ;
2012-10-08 08:40:30 +00:00
setrsp_progress ( "Update known hosts" ) ;
2012-11-05 15:00:12 +00:00
$ retref = xCAT::Utils - > runxcmd ( { command = > [ "makeknownhosts" ] , node = > $ nodelist , arg = > [ '-r' ] } , $ request_command , 0 , 2 ) ;
2012-10-22 09:37:09 +00:00
log_cmd_return ( $ retref ) ;
2012-10-08 08:40:30 +00:00
setrsp_progress ( "Update DHCP entries" ) ;
2012-11-05 15:00:12 +00:00
$ retref = xCAT::Utils - > runxcmd ( { command = > [ "makedhcp" ] , node = > $ nodelist , arg = > [ '-d' ] } , $ request_command , 0 , 2 ) ;
2012-10-22 09:37:09 +00:00
log_cmd_return ( $ retref ) ;
2012-09-07 08:19:36 +00:00
}
2012-10-08 08:40:30 +00:00
elsif ( $ command eq 'kitnodeupdate' ) {
setrsp_progress ( "Updating hosts entries" ) ;
2012-11-05 15:00:12 +00:00
$ retref = xCAT::Utils - > runxcmd ( { command = > [ "makehosts" ] , node = > $ nodelist } , $ request_command , 0 , 2 ) ;
2012-10-22 09:37:09 +00:00
log_cmd_return ( $ retref ) ;
2012-10-08 08:40:30 +00:00
setrsp_progress ( "Updating DNS entries" ) ;
2012-11-05 15:00:12 +00:00
$ retref = xCAT::Utils - > runxcmd ( { command = > [ "makedns" ] , node = > $ nodelist } , $ request_command , 0 , 2 ) ;
2012-10-22 09:37:09 +00:00
log_cmd_return ( $ retref ) ;
2012-10-08 08:40:30 +00:00
setrsp_progress ( "Update DHCP entries" ) ;
2012-11-05 15:00:12 +00:00
$ retref = xCAT::Utils - > runxcmd ( { command = > [ "makedhcp" ] , node = > $ nodelist , arg = > [ '-d' ] } , $ request_command , 0 , 2 ) ;
2012-10-22 09:37:09 +00:00
log_cmd_return ( $ retref ) ;
2012-10-12 07:11:26 +00:00
# we should restart dhcp so that the node's records in /var/lib/dhcpd/dhcpd.lease can be clean up and re-generate.
system ( "/etc/init.d/dhcpd restart" ) ;
2012-11-05 15:00:12 +00:00
$ retref = xCAT::Utils - > runxcmd ( { command = > [ "makedhcp" ] , node = > $ nodelist } , $ request_command , 0 , 2 ) ;
2012-10-22 09:37:09 +00:00
log_cmd_return ( $ retref ) ;
2012-10-08 08:40:30 +00:00
setrsp_progress ( "Update known hosts" ) ;
2012-11-05 15:00:12 +00:00
$ retref = xCAT::Utils - > runxcmd ( { command = > [ "makeknownhosts" ] , node = > $ nodelist } , $ request_command , 0 , 2 ) ;
2012-10-22 09:37:09 +00:00
log_cmd_return ( $ retref ) ;
2012-09-07 08:19:36 +00:00
my $ firstnode = ( @$ nodelist ) [ 0 ] ;
2012-10-08 08:40:30 +00:00
my $ profileref = xCAT::ProfiledNodeUtils - > get_nodes_profiles ( [ $ firstnode ] ) ;
2012-09-07 08:19:36 +00:00
my % profilehash = %$ profileref ;
if ( exists $ profilehash { $ firstnode } { "ImageProfile" } ) {
2012-10-08 08:40:30 +00:00
setrsp_progress ( "Update nodes' boot settings" ) ;
2012-11-05 15:00:12 +00:00
$ retref = xCAT::Utils - > runxcmd ( { command = > [ "nodeset" ] , node = > $ nodelist , arg = > [ 'osimage=' . $ profilehash { $ firstnode } { "ImageProfile" } ] } , $ request_command , 0 , 2 ) ;
2012-10-22 09:37:09 +00:00
log_cmd_return ( $ retref ) ;
2012-09-07 08:19:36 +00:00
}
2012-11-05 15:00:12 +00:00
setrsp_progress ( "Updating conserver configuration files" ) ;
$ retref = xCAT::Utils - > runxcmd ( { command = > [ "makeconservercf" ] , node = > $ nodelist } , $ request_command , 0 , 2 ) ;
log_cmd_return ( $ retref ) ;
2012-09-07 08:19:36 +00:00
}
2012-10-08 08:40:30 +00:00
elsif ( $ command eq 'kitnoderefresh' ) {
2013-01-31 07:58:08 +00:00
# This is due to once update nicips table, we need remove node's records first and then re-create by run make* commands.
setrsp_progress ( "Remove nodes entries from system configuration files first." ) ;
$ retref = xCAT::Utils - > runxcmd ( { command = > [ "kitnoderemove" ] , node = > $ nodelist } , $ request_command , 0 , 2 ) ;
log_cmd_return ( $ retref ) ;
2012-10-08 08:40:30 +00:00
setrsp_progress ( "Updating hosts entries" ) ;
2012-11-05 15:00:12 +00:00
$ retref = xCAT::Utils - > runxcmd ( { command = > [ "makehosts" ] , node = > $ nodelist } , $ request_command , 0 , 2 ) ;
2012-10-22 09:37:09 +00:00
log_cmd_return ( $ retref ) ;
2012-10-08 08:40:30 +00:00
setrsp_progress ( "Updating DNS entries" ) ;
2012-11-05 15:00:12 +00:00
$ retref = xCAT::Utils - > runxcmd ( { command = > [ "makedns" ] , node = > $ nodelist } , $ request_command , 0 , 2 ) ;
2012-10-22 09:37:09 +00:00
log_cmd_return ( $ retref ) ;
2012-10-08 08:40:30 +00:00
setrsp_progress ( "Update DHCP entries" ) ;
2012-11-05 15:00:12 +00:00
$ retref = xCAT::Utils - > runxcmd ( { command = > [ "makedhcp" ] , node = > $ nodelist } , $ request_command , 0 , 2 ) ;
2012-10-22 09:37:09 +00:00
log_cmd_return ( $ retref ) ;
2012-10-08 08:40:30 +00:00
setrsp_progress ( "Update known hosts" ) ;
2012-11-05 15:00:12 +00:00
$ retref = xCAT::Utils - > runxcmd ( { command = > [ "makeknownhosts" ] , node = > $ nodelist } , $ request_command , 0 , 2 ) ;
2012-10-22 09:37:09 +00:00
log_cmd_return ( $ retref ) ;
2012-11-05 15:00:12 +00:00
2012-10-08 08:40:30 +00:00
setrsp_progress ( "Updating conserver configuration files" ) ;
2012-11-05 15:00:12 +00:00
$ retref = xCAT::Utils - > runxcmd ( { command = > [ "makeconservercf" ] , node = > $ nodelist } , $ request_command , 0 , 2 ) ;
2012-10-22 09:37:09 +00:00
log_cmd_return ( $ retref ) ;
2012-09-07 08:19:36 +00:00
}
else
{
}
}
2012-10-08 08:40:30 +00:00
#-------------------------------------------------------
= head3 setrsp_progress
Description: generate progresss info and return to client .
Args: $ msg - The progress message .
= cut
#-------------------------------------------------------
sub setrsp_progress
{
my $ msg = shift ;
2012-10-12 07:11:26 +00:00
xCAT::MsgUtils - > message ( 'S' , "$msg" ) ;
2012-10-08 08:40:30 +00:00
}
2012-10-22 09:37:09 +00:00
#-------------------------------------------------------
= head3 log_cmd_return
Description: Log commands return ref into log files .
Args: $ return - command return ref .
= cut
#-------------------------------------------------------
sub log_cmd_return
{
my $ return = shift ;
if ( $ return ) {
2012-11-05 15:00:12 +00:00
if ( $ return - > { error } ) {
my $ errarrayref = $ return - > { error } ;
xCAT::MsgUtils - > message ( 'S' , "Command error message:" . Dumper ( $ errarrayref ) ) ;
}
if ( $ return - > { data } ) {
my $ dataarrayref = $ return - > { data } ;
xCAT::MsgUtils - > message ( 'S' , "Command output message:" . Dumper ( $ dataarrayref ) ) ;
2012-10-22 09:37:09 +00:00
}
}
}
2012-09-07 08:19:36 +00:00
1 ;