Update codes after xCAT team review. comments: add more comments in codes, and also use runxcmd instead of call request commands directly
git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@13756 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
parent
a72e4b8fbe
commit
d89e6e1c7c
@ -15,7 +15,19 @@ require xCAT::PCMNodeMgmtUtils;
|
||||
xCAT plugin, which is also the default PCM kit plugin.
|
||||
These commands are called by PCM node management commands,
|
||||
should not be called directly by external.
|
||||
|
||||
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.
|
||||
|
||||
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 "00pcmkitbase".
|
||||
|
||||
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.
|
||||
|
||||
This plugin is a PCM kit plugin, just for configure nodes' related configurations automatically. So that we do not need to run these make* commands manually after creating them.
|
||||
|
||||
About PCM 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.
|
||||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------
|
||||
@ -57,57 +69,58 @@ sub process_request {
|
||||
my $argsref = $request->{arg};
|
||||
|
||||
my $nodelist = $request->{node};
|
||||
my $retref;
|
||||
|
||||
if($command eq 'kitcmd_nodemgmt_add')
|
||||
{
|
||||
$request_command->({command=>["makehosts"], node=>$nodelist});
|
||||
$request_command->({command=>["makedns"], node=>$nodelist}, arg=>['-n']);
|
||||
$retref = xCAT::Utils->runxcmd({command=>["makehosts"], node=>$nodelist}, $request_command, 0, 1);
|
||||
$retref = xCAT::Utils->runxcmd({command=>["makedns"], node=>$nodelist, arg=>['-n']}, $request_command, 0, 1);
|
||||
# Work around for makedns bug, it will set umask to 0007.
|
||||
umask(0022);
|
||||
$request_command->({command=>["makedhcp"], node=>$nodelist});
|
||||
$request_command->({command=>["makeknownhosts"], node=>$nodelist});
|
||||
$retref = xCAT::Utils->runxcmd({command=>["makekdhcp"], node=>$nodelist}, $request_command, 0, 1);
|
||||
$retref = xCAT::Utils->runxcmd({command=>["makeknownhosts"], node=>$nodelist}, $request_command, 0, 1);
|
||||
my $firstnode = (@$nodelist)[0];
|
||||
my $profileref = xCAT::PCMNodeMgmtUtils->get_nodes_profiles([$firstnode]);
|
||||
my %profilehash = %$profileref;
|
||||
if (exists $profilehash{$firstnode}{"ImageProfile"}){
|
||||
$request_command->({command=>["nodeset"], node=>$nodelist, arg=>['osimage='.$profilehash{$firstnode}{"ImageProfile"}]});
|
||||
$retref = xCAT::Utils->runxcmd({command=>["nodeset"], node=>$nodelist, arg=>['osimage='.$profilehash{$firstnode}{"ImageProfile"}]}, $request_command, 0, 1);
|
||||
}
|
||||
|
||||
}
|
||||
elsif ($command eq 'kitcmd_nodemgmt_remove'){
|
||||
$request_command->({command=>["nodeset"], node=>$nodelist, arg=>['offline']});
|
||||
$request_command->({command=>["makeknownhosts"], node=>$nodelist, arg=>['-r']});
|
||||
$request_command->({command=>["makedhcp"], node=>$nodelist, arg=>['-d']});
|
||||
$request_command->({command=>["makedns"], node=>$nodelist, arg=>['-d']});
|
||||
$retref = xCAT::Utils->runxcmd({command=>["nodeset"], node=>$nodelist, arg=>['offline']}, $request_command, 0, 1);
|
||||
$retref = xCAT::Utils->runxcmd({command=>["makeknownhosts"], node=>$nodelist, arg=>['-r']}, $request_command, 0, 1);
|
||||
$retref = xCAT::Utils->runxcmd({command=>["makekdhcp"], node=>$nodelist, arg=>['-d']}, $request_command, 0, 1);
|
||||
$retref = xCAT::Utils->runxcmd({command=>["makedns"], node=>$nodelist, arg=>['-d']}, $request_command, 0, 1);
|
||||
# Work around for makedns bug, it will set umask to 0007.
|
||||
umask(0022);
|
||||
$request_command->({command=>["makehosts"], node=>$nodelist, arg=>['-d']});
|
||||
$retref = xCAT::Utils->runxcmd({command=>["makehosts"], node=>$nodelist, arg=>['-d']}, $request_command, 0, 1);
|
||||
}
|
||||
elsif ($command eq 'kitcmd_nodemgmt_update'){
|
||||
$request_command->({command=>["makehosts"], node=>$nodelist});
|
||||
$request_command->({command=>["makedns"], node=>$nodelist}, arg=>['-n']);
|
||||
$retref = xCAT::Utils->runxcmd({command=>["makehosts"], node=>$nodelist}, $request_command, 0, 1);
|
||||
$retref = xCAT::Utils->runxcmd({command=>["makedns"], node=>$nodelist, arg=>['-n']}, $request_command, 0, 1);
|
||||
# Work around for makedns bug, it will set umask to 0007.
|
||||
umask(0022);
|
||||
$request_command->({command=>["makedhcp"], node=>$nodelist});
|
||||
$request_command->({command=>["makeknownhosts"], node=>$nodelist});
|
||||
$retref = xCAT::Utils->runxcmd({command=>["makekdhcp"], node=>$nodelist}, $request_command, 0, 1);
|
||||
$retref = xCAT::Utils->runxcmd({command=>["makeknownhosts"], node=>$nodelist}, $request_command, 0, 1);
|
||||
my $firstnode = (@$nodelist)[0];
|
||||
my $profileref = xCAT::PCMNodeMgmtUtils->get_nodes_profiles([$firstnode]);
|
||||
my %profilehash = %$profileref;
|
||||
if (exists $profilehash{$firstnode}{"ImageProfile"}){
|
||||
$request_command->({command=>["nodeset"], node=>$nodelist, arg=>['osimage='.$profilehash{$firstnode}{"ImageProfile"}]});
|
||||
$retref = xCAT::Utils->runxcmd({command=>["nodeset"], node=>$nodelist, arg=>['osimage='.$profilehash{$firstnode}{"ImageProfile"}]}, $request_command, 0, 1);
|
||||
}
|
||||
}
|
||||
elsif ($command eq 'kitcmd_nodemgmt_refresh'){
|
||||
$request_command->({command=>["makehosts"], node=>$nodelist});
|
||||
$request_command->({command=>["makedns"], node=>$nodelist}, arg=>['-n']);
|
||||
$retref = xCAT::Utils->runxcmd({command=>["makehosts"], node=>$nodelist}, $request_command, 0, 1);
|
||||
$retref = xCAT::Utils->runxcmd({command=>["makedns"], node=>$nodelist, arg=>['-n']}, $request_command, 0, 1);
|
||||
# Work around for makedns bug, it will set umask to 0007.
|
||||
umask(0022);
|
||||
$request_command->({command=>["makedhcp"], node=>$nodelist});
|
||||
$request_command->({command=>["makeknownhosts"], node=>$nodelist});
|
||||
$retref = xCAT::Utils->runxcmd({command=>["makekdhcp"], node=>$nodelist}, $request_command, 0, 1);
|
||||
$retref = xCAT::Utils->runxcmd({command=>["makeknownhosts"], node=>$nodelist}, $request_command, 0, 1);
|
||||
}
|
||||
elsif ($command eq 'kitcmd_nodemgmt_finished')
|
||||
{
|
||||
$request_command->({command=>["makeconservercf"]});
|
||||
$retref = xCAT::Utils->runxcmd({command=>["makeconservercf"]}, $request_command, 0, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -135,8 +135,21 @@ sub parse_args{
|
||||
|
||||
=head3 addhost_hostfile
|
||||
|
||||
Description : Create nodes by import hostinfo file.
|
||||
Arguments : N/A
|
||||
Description :
|
||||
Create PCM nodes by importing hostinfo file.
|
||||
This sub maps to request "addhost_hostfile", we need to call this command from CLI like following steps:
|
||||
# ln -s /opt/xcat/bin/xcatclientnnr /opt/xcat/bin/addhost_hostfile
|
||||
# addhost_hostfile file=/root/hostinfo.file networkprofile=network_cn imageprofile=rhel63_cn hardwareprofile=ipmi groups=group1,group2
|
||||
|
||||
The hostinfo file should be written like: (MAC address is mandatory attribute)
|
||||
# Auto generate hostname for this node entry.
|
||||
__hostname__:
|
||||
mac=11:11:11:11:11:11
|
||||
# Specified hostname node.
|
||||
node01:
|
||||
mac=22:22:22:22:22:22
|
||||
|
||||
After this call finished, the compute node's info will be updated automatically in /etc/hosts, dns config, dhcp config, TFTP config...
|
||||
|
||||
=cut
|
||||
|
||||
@ -221,12 +234,12 @@ sub addhost_hostfile {
|
||||
}
|
||||
# call mkdef to create hosts and then call nodemgmt for node management plugins.
|
||||
xCAT::MsgUtils->message('S', "[PCM nodes mgmt]call mkdef to create pcm nodes.\n");
|
||||
$request_command->({command=>["mkdef"], stdin=>[$retstr_gen], arg=>['-z']});
|
||||
my $retref = xCAT::Utils->runxcmd({command=>["mkdef"], stdin=>[$retstr_gen], arg=>['-z']}, $request_command, 0, 1);
|
||||
|
||||
my @nodelist = keys %hostinfo_dict;
|
||||
xCAT::MsgUtils->message('S', "[PCM nodes mgmt]call nodemgmt plugins.\n");
|
||||
$request_command->({command=>["kitcmd_nodemgmt_add"], node=>\@nodelist});
|
||||
$request_command->({command=>["kitcmd_nodemgmt_finished"], node=>\@nodelist});
|
||||
$retref = xCAT::Utils->runxcmd({command=>["kitcmd_nodemgmt_add"], node=>\@nodelist}, $request_command, 0, 1);
|
||||
$retref = xCAT::Utils->runxcmd({command=>["kitcmd_nodemgmt_finished"], node=>\@nodelist}, $request_command, 0, 1);
|
||||
setrsp_success(\@nodelist);
|
||||
}
|
||||
|
||||
@ -234,7 +247,7 @@ sub addhost_hostfile {
|
||||
|
||||
=head3 removehost
|
||||
|
||||
Description : Remove nodes.
|
||||
Description : Remove PCM nodes. After nodes removed, their info in /etc/hosts, dhcp, dns... will be removed automatically.
|
||||
Arguments : N/A
|
||||
|
||||
=cut
|
||||
@ -245,10 +258,10 @@ sub removehost{
|
||||
xCAT::MsgUtils->message('S', "[PCM nodes mgmt]Remove PCM nodes.\n");
|
||||
# For remove nodes, we should call 'nodemgmt' in front of 'noderm'
|
||||
xCAT::MsgUtils->message('S', "[PCM nodes mgmt]call nodemgmt plugins.\n");
|
||||
$request_command->({command=>["kitcmd_nodemgmt_remove"], node=>$nodes});
|
||||
$request_command->({command=>["kitcmd_nodemgmt_finished"], node=>$nodes});
|
||||
my $retref = xCAT::Utils->runxcmd({command=>["kitcmd_nodemgmt_remove"], node=>$nodes}, $request_command, 0, 1);
|
||||
$retref = xCAT::Utils->runxcmd({command=>["kitcmd_nodemgmt_finished"], node=>$nodes}, $request_command, 0, 1);
|
||||
xCAT::MsgUtils->message('S', "[PCM nodes mgmt]call noderm to remove nodes.\n");
|
||||
$request_command->({command=>["noderm"], node=>$nodes});
|
||||
$retref = xCAT::Utils->runxcmd({command=>["noderm"], node=>$nodes}, $request_command, 0, 1);
|
||||
setrsp_success($nodes);
|
||||
}
|
||||
|
||||
@ -256,7 +269,7 @@ sub removehost{
|
||||
|
||||
=head3 updatehost
|
||||
|
||||
Description : Update host profiles.
|
||||
Description : Update PCM node profiles: imageprofile, networkprofile and hardwareprofile.
|
||||
Arguments : N/A
|
||||
|
||||
=cut
|
||||
@ -320,8 +333,8 @@ sub updatehost{
|
||||
|
||||
# call plugins
|
||||
xCAT::MsgUtils->message('S', "[PCM nodes mgmt]call nodemgmt plugins.\n");
|
||||
$request_command->({command=>["kitcmd_nodemgmt_update"], node=>$nodes});
|
||||
$request_command->({command=>["kitcmd_nodemgmt_finished"], node=>$nodes});
|
||||
my $retref = xCAT::Utils->runxcmd({command=>["kitcmd_nodemgmt_update"], node=>$nodes}, $request_command, 0, 1);
|
||||
$retref = xCAT::Utils->runxcmd({command=>["kitcmd_nodemgmt_finished"], node=>$nodes}, $request_command, 0, 1);
|
||||
setrsp_success($nodes);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user