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;
|
|
|
|
|
|
|
|
use xCAT::MsgUtils;
|
|
|
|
use Getopt::Long;
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
=head1
|
|
|
|
xCAT plugin package to setup of DHCP
|
|
|
|
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 handled_commands
|
|
|
|
|
|
|
|
Check to see if on a Service Node
|
|
|
|
Check database to see if this node is a DHCP server
|
|
|
|
Call setup_DHCP
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
sub handled_commands
|
|
|
|
{
|
|
|
|
my $rc = 0;
|
|
|
|
if (xCAT::Utils->isServiceNode())
|
|
|
|
{
|
|
|
|
my @nodeinfo = xCAT::Utils->determinehostname;
|
2008-03-06 18:42:32 +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
|
|
|
|
$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
|
|
|
}
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
my @output;
|
|
|
|
|
|
|
|
# read DB for nodeinfo
|
|
|
|
my $retdata = xCAT::Utils->readSNInfo($nodename);
|
|
|
|
if ($retdata->{'arch'})
|
|
|
|
{ # no error
|
|
|
|
my $master = $retdata->{'master'};
|
|
|
|
my $os = $retdata->{'os'};
|
|
|
|
my $arch = $retdata->{'arch'};
|
|
|
|
|
|
|
|
# run makedhcp
|
|
|
|
$XCATROOT = "/opt/xcat"; # default
|
|
|
|
|
|
|
|
if ($ENV{'XCATROOT'})
|
|
|
|
{
|
|
|
|
$XCATROOT = $ENV{'XCATROOT'};
|
|
|
|
}
|
|
|
|
$cmd = "$XCATROOT/sbin/makedhcp -n";
|
|
|
|
@output = xCAT::Utils->runcmd($cmd, -1);
|
|
|
|
if ($::RUNCMD_RC != 0)
|
|
|
|
{
|
|
|
|
xCAT::MsgUtils->message("S", "Error from $cmd, output=@output");
|
|
|
|
return 1;
|
|
|
|
}
|
2008-02-27 14:00:26 +00:00
|
|
|
$cmd = "chkconfig dhcpd on";
|
|
|
|
xCAT::Utils->runcmd($cmd, -1);
|
|
|
|
if ($::RUNCMD_RC != 0)
|
|
|
|
{
|
|
|
|
xCAT::MsgUtils->message("S", "Error from $cmd");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
$cmd = "/etc/rc.d/init.d/dhcpd start";
|
2008-02-25 13:05:21 +00:00
|
|
|
xCAT::Utils->runcmd($cmd, -1);
|
|
|
|
if ($::RUNCMD_RC != 0)
|
|
|
|
{
|
|
|
|
xCAT::MsgUtils->message("S", "Error from $cmd");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ # error reading Db
|
|
|
|
$rc = 1;
|
|
|
|
}
|
|
|
|
return $rc;
|
|
|
|
}
|
|
|
|
1;
|