Better host clash checking

This commit is contained in:
Jamie Cameron
2010-08-06 00:51:58 -07:00
parent 7ed56c7733
commit aea69f68f1
3 changed files with 30 additions and 3 deletions

View File

@@ -38,3 +38,4 @@ When applying the configuration fails with an error mentioning a line in the con
---- Changes since 1.510 ----
Added support for multi-value options, thanks to a patch from Luke Suchocki.
Also added support for multi-value options within a bracketed expression.
Hostname, IP address and MAC address clashes are now only checked for in the same shared network.

View File

@@ -593,6 +593,32 @@ local ($sr, $hr) = &get_subnets_and_hosts();
return @{$hr};
}
sub get_host_shared_network
{
local ($h) = @_;
local $shar;
while($h) {
if ($h->{'name'} eq 'shared-network') {
return $h;
}
$h = $h->{'parent'};
}
return undef;
}
sub get_my_shared_network_hosts
{
local ($h) = @_;
local $shar = &get_host_shared_network($h);
local @rv;
foreach my $oh (&get_hosts()) {
if (&get_host_shared_network($oh) eq $shar) {
push(@rv, $oh);
}
}
return @rv;
}
# hash that links objtypes shortcuts with object names
%obj_names2types = qw(host hst group grp subnet sub shared-network sha);

View File

@@ -55,7 +55,7 @@ else {
# Check for a hostname clash
if (($in{'new'} || $in{'name'} ne $host->{'values'}->[0]) &&
$access{'uniq_hst'}) {
foreach $h (&get_hosts()) {
foreach $h (&get_my_shared_network_hosts($npar)) {
&error("$text{'eacl_np'} $text{'eacl_uniq'}")
if (lc($h->{'values'}->[0]) eq lc($in{'name'}));
}
@@ -68,7 +68,7 @@ else {
: &find("hardware", $host->{'members'});
if ((!$oldhard || $in{'hardware'} ne $oldhard->{'values'}->[1])
&& $access{'uniq_hst'}) {
foreach $h (&get_hosts()) {
foreach $h (&get_my_shared_network_hosts($npar)) {
$chard = &find("hardware", $h->{'members'});
&error("$text{'eacl_np'} $text{'eacl_uniqh'}")
if ($chard && lc($chard->{'values'}->[1]) eq lc($in{'hardware'}));
@@ -96,7 +96,7 @@ else {
if ((!$oldfixed ||
$in{'fixed-address'} ne $oldfixed->{'values'}->[0])
&& $access{'uniq_hst'}) {
foreach $h (&get_hosts()) {
foreach $h (&get_my_shared_network_hosts($npar)) {
$cfixed = &find("fixed-address",
$h->{'members'});
&error("$text{'eacl_np'} $text{'eacl_uniqi'}")