[Fai-commit] r4122 - trunk/bin
fai-commit at lists.alioth.debian.org
fai-commit at lists.alioth.debian.org
Wed Nov 1 12:33:37 CET 2006
Author: lange
Date: 2006-11-01 12:33:36 +0100 (Wed, 01 Nov 2006)
New Revision: 4122
Modified:
trunk/bin/fai-chboot
Log:
apply patch from Thomas Poehnitzsch
- the option -p expected an argument
- when fai-chboot gets no ROOTFS it complained about missing host
- the default-file was treated special and not displayed with -ld
or -le
- some hex-files in the tftp-dir were (only in some cases)
classified as type Other
- subnets were not calculated/displayed correctly
- fai-chboot -L wrote the name for templates and default-files
twice instead of the type followed by name
- fai-chboot -Ld ignored default.disable but printed disabled
host that also were enabled (which should override it)
- when a new pxe config was created, existing disable-files were
left untouched (this is not really a bug, but IMO not what one
would expect)
- if a hostname was given to -c and only a template was found it
still used the host-file as source, resulting in an empty
destination
Modified: trunk/bin/fai-chboot
===================================================================
--- trunk/bin/fai-chboot 2006-11-01 10:51:50 UTC (rev 4121)
+++ trunk/bin/fai-chboot 2006-11-01 11:33:36 UTC (rev 4122)
@@ -79,63 +79,76 @@
opendir(DIR, $pxedir) || die "can't opendir $pxedir: $!";
foreach (readdir(DIR)) {
next if /^\./;
- if (/^default/) { push @default, $_ ; next};
- if (/^[0-9A-F]+$/) { push @enabled, $_ ; next};
- if (/\.disable$/) { push @disabled, $_ ; next};
- if (/\.tmpl$/) { push @templates, $_ ; next};
+ if (/^(default|[0-9A-F]+)$/) { push @enabled, $_ ; next};
+ if (/\.tmpl$/) { push @templates, $_ ; next};
+ if (/\.disable$/) {
+ if (-f (split /\./)[0]) {
+ warn "Skipping $_ as disabled host because also enabled.\n" if $verbose;
+ } else {
+ push @disabled, $_;
+ }
+ next;
+ };
push @other, $_;
}
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sub lsdir {
-# -lr list only disabled hosts
+# -ld list only disabled hosts
# -le list only enabled hosts
# -lt list only templates
# -lo list only "other", i.e that does not match templates or hosts
# -lg list by goups (enabled, disabled, templates, others)
-# -l[retog] <pattern> list matching pattern
+# -l[detog] <pattern> list matching pattern
- my (@n,$host,$ip,$iaddr,$hex,$type);
+ my ($n,$host,$iaddr,$hex,$type);
@patterns = @_; # a global variable
readpxedir();
# create list which entries we want to list
- @allfiles = (@default, at enabled, at disabled, at templates, at other);
+ @allfiles = (@enabled, at disabled, at templates, at other);
$opt_d and @allfiles = @disabled;
$opt_e and @allfiles = @enabled;
$opt_t and @allfiles = @templates;
$opt_o and @allfiles = @other;
- $opt_g and @allfiles = (@default, at enabled, at disabled, at templates, at other);
+ $opt_g and @allfiles = (@enabled, at disabled, at templates, at other);
# map all entries (in HEX) to hostname or IP
foreach $hex (@allfiles) {
- undef $type;
- # hex to ip address
- @n = $hex =~ m/[0-9A-F][0-9A-F]/g;
- $ip = join ('.', map {$_ = hex $_} @n);
+ undef $host,$type;
- if ($hex =~ /^default$/) {
+ if ($hex =~ /^default(.disable)?$/) {
$host = $hex;
$type = '[DEFAULT]';
} elsif ($hex =~ /\.tmpl$/) {
$host = "$hex";
$type = '[Template]';
- } elsif ($#n > 0 && $#n < 3) {
- # Don't fail if not a complete IP
- $host = "Subnet: $ip";
- } else {
- # ip to hostname
- $iaddr = inet_aton($ip);
- if ($h = gethostbyaddr($iaddr, AF_INET)) {
- $host = $h->name;
- $host =~ s/^([^.]+).*/$1/; # strip domain from FQDN so we have short hostnames
- } else {
+ } elsif ($hex =~ /[0-9A-F]+/) {
+ my $hexstrip = (split /\./,$hex)[0]; # remove .disable if necessary
+ $n = $hexstrip;
+ # hex to ip/subnet address
+ while ( length $n ) {
+ $host = sprintf( "%s%d" ,$host?"$host.":$host,
+ (hex substr $n,0,1,"" ) * 16 + (hex substr $n,0,1,""));
+ }
+ if ( $host and ( length($hexstrip) < 8) ) {
+ $host = "Subnet: $host/". length($hexstrip)*4
+ } else {
+ # ip to hostname
+ $iaddr = inet_aton($host);
+ if ($h = gethostbyaddr($iaddr, AF_INET)) {
+ $host = $h->name;
+ $host =~ s/^([^.]+).*/$1/; # strip domain from FQDN so we have short hostnames
+ }
+ }
+ }
+
+ if ( !$host ) {
$host = $hex;
$type = '[Other]';
- }
}
$hexname{$host} = $hex;
$hname{$hex}= $host;
@@ -143,7 +156,6 @@
}
if ($opt_g) { # print in group, sorted inside each group
- prtsorted(@default);
prtsorted(@enabled);
prtsorted(@disabled);
prtsorted(@templates);
@@ -190,9 +202,9 @@
$append =~ /FAI_ACTION=(\S+)/;
$append = $1;
# printf "%-16.16s $append $kernelname %-8s\n",$host,$hex;
- printf "%-16.16s %-20.20s $append $kernelname\n",$type?$type:$host,$hex;
+ printf "%-26.26s %-20.20s $append $kernelname\n",$type?$type:$host,$hex;
} else {
- printf "%s %s $kernelname $append\n",$host,$hex;
+ printf "%s %s $kernelname $append\n",$type?$type:$host,$hex;
}
undef $append;
@@ -225,11 +237,15 @@
my ($ipadr,$hex) = host2hex($host);
warn "$host has $ipadr in hex $hex\n" if $verbose;
+ if (-f "$pxedir/$hex.disable") {
+ unlink "$pxedir/$hex.disable";
+ print "removed old $pxedir/$hex.disable\n";
+ }
warn "Writing file $pxedir/$hex for $host\n" if $verbose;
return if $opt_n;
if ($opt_p && -e "$pxedir/$hex") {
- warn "WARNING: $pxedir/$hex already exists. Skipping file creation. ";
+ warn "WARNING: $pxedir/$hex already exists.\nSkipping file creation. ";
return;
}
open (FILE,"> $pxedir/$hex") or warn "$0 $@ $!";
@@ -305,7 +321,7 @@
} elsif (-e "$pxedir/$srchost" ) {
$srcfile = "$pxedir/$srchost";
} elsif (-e "$pxedir/$srchost.tmpl" ) {
- $srcfile = "$pxedir/$srchost";
+ $srcfile = "$pxedir/$srchost.tmpl";
} else {
warn "Source file for $srchost ($srchex) not available\n";
return;
@@ -313,7 +329,7 @@
} elsif ( -e "$pxedir/$srchost") {
$srcfile = "$pxedir/$srchost";
} elsif ( -e "$pxedir/$srchost.tmpl") {
- $srcfile = "$pxedir/$srchost";
+ $srcfile = "$pxedir/$srchost.tmpl";
} else {
warn "Source file for $srchost not available\n";
return;
@@ -336,7 +352,7 @@
}
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-getopts('gBc:D:edhnvlLiIp:f:Fk:Sto');
+getopts('gBc:D:edhnvlLiIpf:Fk:Sto');
$opt_h and usage;
defined @ARGV or usage;
@@ -406,7 +422,7 @@
} else {
$kernelname = shift;
$kernelname = "kernel $kernelname";
- $rootfs = shift;
+ $rootfs = shift or die "No rootfs specified.\n";
}
$opt_F and $opt_f="verbose,sshd,createvt";
More information about the Fai-commit
mailing list