2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2025-05-21 19:22:05 +00:00

makedhcp check if mac format is valid

This commit is contained in:
bybai 2018-07-27 00:49:22 -04:00
parent ce42f6e03e
commit 880a84ce07
2 changed files with 24 additions and 0 deletions

View File

@ -587,6 +587,7 @@ sub addnode
);
return;
}
my @macs = split(/\|/, $ent->{mac});
my $mace;
my $deflstaments = $lstatements;
@ -603,6 +604,16 @@ sub addnode
$hname = $node;
} #Default to hostname equal to nodename
unless ($mac) { next; } #Skip corrupt format
if ($mac !~ /^[0-9a-fA-F]{2}(-[0-9a-fA-F]{2}){5}$|^[0-9a-fA-F]{2}(:[0-9a-fA-F]{2}){5}$/)
{
$callback->(
{
error => ["Invalid mac address $mac for $node"],
errorcode => [1]
}
);
next;
}
my $ip = getipaddr($hname, OnlyV4 => 1);
if ($hname eq '*NOIP*') {
$hname = $node . "-noip" . $mac;

View File

@ -66,6 +66,19 @@ cmd:rmdef testnode1
cmd:if [ -f "/etc/dhcp/dhcpd.conf" ];then mv -f /etc/dhcp/dhcpd.conf /etc/dhcp/dhcpd.conf.bak ; elif [ -f "/etc/dhcpd.conf" ]; then mv -f /etc/dhcpd.conf /etc/dhcpd.conf.bak; fi
end
start:makedhcp_a_linux_check_invalid_mac
description:Define all nodes to the DHCP server. If mac format is invalid, makedhcp -a print error and return 1
os:Linux
label:mn_only,dhcp
cmd:lsdef -l $$CN -z > /tmp/$$CN.stanza
cmd:chdef -t node -o $$CN mac=11:22:33
cmd:makedhcp $$CN
check:rc!=0
check:output!~ ^11:22:33$
cmd:chdef -t node -o $$CN mac=
cmd:cat /tmp/$$CN.stanza | chdef -z
end
start:makedhcp_a_d_linux
os:Linux
label:mn_only,dhcp