using fai-chboot with mac-address
Torge Gipp
post at torge-gipp.de
Sun May 30 11:30:21 CEST 2010
On Sat, 29 May 2010 18:06:02 +0200, Michael Tautschnig <mt at debian.org>
wrote:
>
>I think it's just that nobody requested it before. But it should be
>pretty
>straight forward to come up with a patch: Just check for ":" in the
>hostname and
>handle this accordingly in the host2hex function of fai-chboot.
>
>Best,
>Michael
>
Yes, I think so ;-) Here is a small patch I have written yesterday;
#-------------------
sub host2hex {
my $host = shift;
if ($host =~ /^\d+\.\d+\.\d+\.\d+$/) {
# hostname is already an IP address
return ip2hex($host);
}
return ('no IP','default') if ($host =~ /^default/);
# - - - Mac-Adresse als Host
if ($host =~ /^([0-9a-fA-F]{2}([:-]|$)){6}$/i) { # Pattern-Matching
Mac-Address with Seperators "-" or ":"
$host = lc $host; # Lowercase for pxe-file
my @nums = split /[:-]/, $host;
$mac = "01-$nums[0]-$nums[1]-$nums[2]-$nums[3]-$nums[4]-$nums[5]"; #
build pxe-filename
return $mac;
};
if ($host =~ /^[0-9a-fA-F]{12}$/i) { # Pattern-Matching Mac-Address w/o
Seperators
$host = lc $host;
my @nums = split /(.{2})/, $host;
$mac = "01-$nums[1]-$nums[3]-$nums[5]-$nums[7]-$nums[9]-$nums[11]"; #
build pxe-filename
return $mac;
};
my $h = gethost($host);
die "$0: unknown host: $host\n" unless $h;
if ( @{$h->addr_list} > 1 ) {
my $i;
for my $addr ( @{$h->addr_list} ) {
$ipadr = inet_ntoa($addr);
printf "$host \taddr #%d is [%s]\n", $i++, $ipadr if $debug;
}
} else {
$ipadr = inet_ntoa($h->addr);
printf "$host \taddress is [%s]\n", $ipadr if $debug;
}
ip2hex($ipadr);
}
#--------------------
Perhaps it is useful for one or the other, in the future.
Regards, Torge
More information about the linux-fai-devel
mailing list