2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2025-08-21 18:50:28 +00:00

xCAT probe discovery dhcp dynamic check

This commit is contained in:
XuWei
2016-06-30 21:47:32 -04:00
parent 0fafd7fab6
commit de8bc849ac

View File

@@ -273,8 +273,8 @@ sub check_genesis_file {
1. check if there are dynamic range for specific networks defineded in dhcp conf file
2. check if these specific networks have corresponding genesis configuration
Arguments:
networks: A Comma separated list of networks. Every network is combined by network address and mask(i.e. network/mask).
For example: 10.0.0.0/255.0.0.0,50.1.0.0/255.255.0.0
networks: Array of networks. Every network is combined by network address and mask(i.e. network/mask).
For example: (10.0.0.0/255.0.0.0, 50.1.0.0/255.255.0.0)
Returns:
0 : pass
1 : failed
@@ -285,71 +285,77 @@ sub dhcp_dynamic_range_check {
my $nets = shift;
my $rst = 0;
my $dhcpconfig = "/etc/dhcp/dhcpd.conf";
my $os = probe_utils->get_os();
my $dhcpconfig;
if (-e "/etc/dhcp/dhcpd.conf"){
$dhcpconfig = "/etc/dhcp/dhcpd.conf";
} elsif (-e "/etc/dhcp3/dhcpd.conf"){
$dhcpconfig = "/etc/dhcp3/dhcpd.conf";
}
if ($os =~ "unknown") {
probe_utils->send_msg("$output", "d", "The OS is not supported.") if ($verbose);
unless ($dhcpconfig) {
probe_utils->send_msg("$output", "d", "Cannot find the dhcpd.conf file.") if ($verbose);
return 1;
} elsif ($os =~ "ubuntu") {
if (! -e "/etc/dhcp") {
$dhcpconfig = "/etc/dhcp3/dhcpd.conf";
}
}
my $config_line;
my $net_ip;
my $net_mask;
my $is_match;
my $subnet;
my $dynamic_range;
my $net_file;
my %subnet_hash;
unless (open (FILE, $dhcpconfig)) {
probe_utils->send_msg("$output", "d", "Cannot open file $dhcpconfig.") if ($verbose);
($net_ip, $net_mask) = split ('/', $net);
return 1;
}
while ($config_line = <FILE>) {
chomp($config_line);
$config_line =~ s/^\s+|\s+$//g;
if ($config_line =~ /^subnet\s+(\d+\.\d+\.\d+\.\d+)\s+netmask\s+(\d+\.\d+\.\d+\.\d+)\s+/) {
$subnet = "$1/$2";
$subnet_hash{$subnet} = "unknown";
}
if ($config_line =~ /subnet_end/) {
$subnet_hash{$subnet} = $dynamic_range if ($dynamic_range);
$subnet = "";
$dynamic_range = "";
}
if ($config_line =~ /^range dynamic-bootp (\d+.\d+.\d+.\d+) (\d+.\d+.\d+.\d+)/) {
$dynamic_range = "$1-$2";
}
}
my $net_ip;
my $netmask;
my $netfile;
my $net_cdir;
my $arch = `uname -i`;
chomp($arch);
my $tftpdir = `tabdump site | grep "tftpdir" | awk -F "," '{print \$2}'`;
my $tftpdir = `lsdef -t site -i tftpdir -c | awk -F "=" '{print \$2}'`;
chomp($tftpdir);
$tftpdir =~ s/"//g;
unless ($tftpdir) {
$tftpdir = "/tftpboot";
}
foreach my $net (@$nets){
if ( !exists($subnet_hash{$net})) {
probe_utils->send_msg("$output", "d", "The net $net is not matched.") if ($verbose);
$rst = 1;
next;
}
if ($subnet_hash{$net} ne "unknown") {
probe_utils->send_msg("$output", "d", "Dynamic range for net $net is $subnet_hash{$net}.") if ($verbose);
} else {
probe_utils->send_msg("$output", "d", "Dynamic range for net $net did not be configured.") if ($verbose);
$rst = 1;
next;
}
foreach $net (@$nets){
($net_ip, $net_mask) = split ('/', $net);
$net_str = "subnet $net_ip netmask $net_mask";
$is_match = 0;
$dynamic_range = "";
unless (open (FILE, $dhcpconfig)) {
probe_utils->send_msg("$output", "d", "Cannot open file $dhcpconfig.") if ($verbose);
return 1;
}
while ($config_line = <FILE>) {
chomp($config_line);
$config_line =~ s/^\s+|\s+$//g;
if ($config_line =~ /^$net_str/) {
$is_match = 1;
probe_utils->send_msg("$output", "d", "The net $net is matched.") if ($verbose);
}
if ($config_line =~ /subnet_end/) {
if ($is_match eq 0) {
probe_utils->send_msg("$output", "d", "There is no subnet match net $net.") if ($verbose);
$rst = 1;
next;
}
unless ($dynamic_range) {
probe_utils->send_msg("$output", "d", "Dynamic range for net $net did not be configured.") if ($verbose);
$rst = 1;
}
}
if (($config_line =~ /^range dynamic-bootp/) and ($is_match eq 1)) {
my @range_tmp = split(' ', $config_line);
$dynamic_range = "$range_tmp[2]-$range_tmp[3]";
probe_utils->send_msg("$output", "d", "Dynamic range for net $net is $dynamic_range.") if ($verbose);
}
}
my $net_cdir = xCAT::NetworkUtils::formatNetmask($net_mask, 0, 1);
$net_cdir = xCAT::NetworkUtils::formatNetmask($net_mask, 0, 1);
if ($arch =~ /ppc64/i) {
$net_file = "$tftpdir/pxelinux.cfg/p/$net_ip"."_$net_cdir";
} else {
@@ -1081,7 +1087,7 @@ if (!$no_pre_check) {
$rst = do_pre_check();
exit 1 if ($rst);
}
exit;
$rst = do_monitor();
exit $rst;