2008-02-25 13:05:21 +00:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
#-------------------------------------------------------
|
|
|
|
package xCAT_plugin::DHCPsn;
|
|
|
|
use xCAT::Table;
|
|
|
|
|
|
|
|
use xCAT::Utils;
|
2008-03-07 18:30:27 +00:00
|
|
|
use xCAT_plugin::dhcp;
|
2008-02-25 13:05:21 +00:00
|
|
|
use xCAT::MsgUtils;
|
2008-03-07 18:30:27 +00:00
|
|
|
|
|
|
|
use xCAT::Client;
|
2008-02-25 13:05:21 +00:00
|
|
|
use Getopt::Long;
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
=head1
|
|
|
|
xCAT plugin package to setup of DHCP
|
|
|
|
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 handled_commands
|
|
|
|
|
2008-09-09 12:31:27 +00:00
|
|
|
Check to see if on a Linux Service Node
|
2008-02-25 13:05:21 +00:00
|
|
|
Check database to see if this node is a DHCP server
|
|
|
|
Call setup_DHCP
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
sub handled_commands
|
|
|
|
{
|
2008-05-19 18:15:48 +00:00
|
|
|
# If called in XCATBYPASS mode, don't do any setup
|
|
|
|
if ($ENV{'XCATBYPASS'}) {
|
|
|
|
return 0;
|
|
|
|
}
|
2008-09-09 12:31:27 +00:00
|
|
|
if (xCAT::Utils->isAIX()) { # do not run on AIX
|
|
|
|
return 0;
|
|
|
|
}
|
2008-05-19 18:15:48 +00:00
|
|
|
|
2008-02-25 13:05:21 +00:00
|
|
|
my $rc = 0;
|
|
|
|
if (xCAT::Utils->isServiceNode())
|
|
|
|
{
|
|
|
|
my @nodeinfo = xCAT::Utils->determinehostname;
|
2008-03-07 18:30:27 +00:00
|
|
|
my $nodename = pop @nodeinfo; # get hostname
|
|
|
|
my @nodeipaddr = @nodeinfo; # get ip addresses
|
2008-02-25 13:05:21 +00:00
|
|
|
my $service = "dhcpserver";
|
|
|
|
|
2008-03-06 18:42:32 +00:00
|
|
|
$rc = xCAT::Utils->isServiceReq($nodename, $service, \@nodeipaddr);
|
2008-02-25 13:05:21 +00:00
|
|
|
if ($rc == 1)
|
|
|
|
{
|
|
|
|
|
|
|
|
# service needed on this Service Node
|
2008-03-07 18:30:27 +00:00
|
|
|
$rc = &setup_DHCP($nodename); # setup DHCP
|
2008-02-26 13:50:39 +00:00
|
|
|
if ($rc == 0)
|
|
|
|
{
|
|
|
|
xCAT::Utils->update_xCATSN($service);
|
|
|
|
}
|
2008-02-25 13:05:21 +00:00
|
|
|
}
|
2008-03-16 13:40:12 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
|
|
|
|
if ($rc == 2)
|
|
|
|
{ # setup, just start the daemon
|
2008-05-13 14:49:54 +00:00
|
|
|
$cmd = " service dhcpd restart";
|
|
|
|
system $cmd;
|
|
|
|
if ($? > 0)
|
|
|
|
{ # error
|
|
|
|
xCAT::MsgUtils->message("S", "Error on command: $cmd");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-16 13:40:12 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2008-02-25 13:05:21 +00:00
|
|
|
}
|
|
|
|
return $rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 process_request
|
|
|
|
|
|
|
|
Process the command
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
sub process_request
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 setup_DHCP
|
|
|
|
|
|
|
|
Sets up DHCP services
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
sub setup_DHCP
|
|
|
|
{
|
|
|
|
my ($nodename) = @_;
|
|
|
|
my $rc = 0;
|
|
|
|
my $cmd;
|
|
|
|
|
|
|
|
|
2008-05-13 14:49:54 +00:00
|
|
|
# run makedhcp
|
|
|
|
$XCATROOT = "/opt/xcat"; # default
|
2008-02-25 13:05:21 +00:00
|
|
|
|
2008-05-13 14:49:54 +00:00
|
|
|
if ($ENV{'XCATROOT'})
|
|
|
|
{
|
|
|
|
$XCATROOT = $ENV{'XCATROOT'};
|
|
|
|
}
|
|
|
|
my $cmdref;
|
|
|
|
$cmdref->{command}->[0] = "makedhcp";
|
|
|
|
$cmdref->{cwd}->[0] = "/opt/xcat/sbin";
|
|
|
|
$cmdref->{arg}->[0] = "-n";
|
2008-03-07 18:30:27 +00:00
|
|
|
|
2008-05-13 14:49:54 +00:00
|
|
|
my $modname = "dhcp";
|
|
|
|
${"xCAT_plugin::" . $modname . "::"}{process_request}
|
2008-03-16 13:40:12 +00:00
|
|
|
->($cmdref, \&xCAT::Client::handle_response);
|
2008-03-07 18:30:27 +00:00
|
|
|
|
2008-03-26 12:43:43 +00:00
|
|
|
|
2008-05-13 14:49:54 +00:00
|
|
|
$cmd = "chkconfig dhcpd on";
|
|
|
|
system $cmd;
|
|
|
|
if ($? > 0)
|
|
|
|
{ # error
|
2008-02-27 14:00:26 +00:00
|
|
|
xCAT::MsgUtils->message("S", "Error from $cmd");
|
|
|
|
return 1;
|
2008-05-13 14:49:54 +00:00
|
|
|
}
|
|
|
|
$cmd = "service dhcpd restart";
|
|
|
|
system $cmd;
|
|
|
|
if ($? > 0)
|
|
|
|
{
|
2008-02-25 13:05:21 +00:00
|
|
|
xCAT::MsgUtils->message("S", "Error from $cmd");
|
|
|
|
return 1;
|
2008-05-13 14:49:54 +00:00
|
|
|
}
|
|
|
|
$cmdref;
|
|
|
|
$cmdref->{command}->[0] = "makedhcp";
|
|
|
|
$cmdref->{cwd}->[0] = "/opt/xcat/sbin";
|
|
|
|
$cmdref->{arg}->[0] = "-a";
|
2008-03-26 12:43:43 +00:00
|
|
|
|
2008-05-13 14:49:54 +00:00
|
|
|
my $modname = "dhcp";
|
2008-03-26 12:43:43 +00:00
|
|
|
${"xCAT_plugin::" . $modname . "::"}{process_request}
|
|
|
|
->($cmdref, \&xCAT::Client::handle_response);
|
2008-02-25 13:05:21 +00:00
|
|
|
|
|
|
|
return $rc;
|
|
|
|
}
|
2008-03-07 18:30:27 +00:00
|
|
|
|
2008-02-25 13:05:21 +00:00
|
|
|
1;
|