2007-10-26 22:44:33 +00:00
|
|
|
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
package xCAT_plugin::networks;
|
|
|
|
use xCAT::Table;
|
|
|
|
use Data::Dumper;
|
|
|
|
use Sys::Syslog;
|
2008-01-26 19:06:21 +00:00
|
|
|
use Socket;
|
2008-05-06 18:27:45 +00:00
|
|
|
use xCAT::Utils;
|
2010-06-09 09:22:14 +00:00
|
|
|
use xCAT::NetworkUtils;
|
2009-08-11 17:18:27 +00:00
|
|
|
use Getopt::Long;
|
2007-10-26 22:44:33 +00:00
|
|
|
|
2008-05-06 18:27:45 +00:00
|
|
|
sub handled_commands
|
|
|
|
{
|
|
|
|
return {makenetworks => "networks",};
|
2008-01-26 19:06:21 +00:00
|
|
|
}
|
2007-10-26 22:44:33 +00:00
|
|
|
|
2008-05-06 18:27:45 +00:00
|
|
|
sub preprocess_request
|
|
|
|
{
|
|
|
|
my $req = shift;
|
2009-08-11 17:18:27 +00:00
|
|
|
my $callback = shift;
|
2010-01-15 20:39:11 +00:00
|
|
|
|
|
|
|
# exit if preprocessed
|
2009-08-11 17:18:27 +00:00
|
|
|
if ($req->{_xcatpreprocessed}->[0] == 1) { return [$req]; }
|
2010-01-15 20:39:11 +00:00
|
|
|
|
|
|
|
my @requests = ({%$req}); #first element is local instance
|
|
|
|
|
|
|
|
$::args = $req->{arg};
|
2009-08-11 17:18:27 +00:00
|
|
|
|
|
|
|
if (defined(@{$::args})) {
|
|
|
|
@ARGV = @{$::args};
|
|
|
|
}
|
|
|
|
|
|
|
|
Getopt::Long::Configure("no_pass_through");
|
|
|
|
if (
|
|
|
|
!GetOptions(
|
|
|
|
'help|h|?' => \$::HELP,
|
|
|
|
'display|d' => \$::DISPLAY,
|
|
|
|
'verbose|V' => \$::VERBOSE,
|
|
|
|
'version|v' => \$::VERSION,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
{
|
|
|
|
# return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Option -h for Help
|
|
|
|
if ($::HELP )
|
|
|
|
{
|
|
|
|
&makenetworks_usage($callback);
|
|
|
|
return undef;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Option -v for version - do we need this???
|
|
|
|
if ($::VERSION)
|
|
|
|
{
|
|
|
|
my $rsp;
|
|
|
|
my $version=xCAT::Utils->Version();
|
|
|
|
$rsp->{data}->[0] = "makenetworks - $version";
|
|
|
|
xCAT::MsgUtils->message("I", $rsp, $callback);
|
|
|
|
return undef;
|
|
|
|
}
|
|
|
|
|
2010-01-15 20:39:11 +00:00
|
|
|
# process the network interfaces on this system
|
|
|
|
if (&donets($callback) != 0) {
|
|
|
|
my $rsp;
|
|
|
|
push @{$rsp->{data}}, "Could not get network information.\n";
|
|
|
|
xCAT::MsgUtils->message("E", $rsp, $callback);
|
|
|
|
return undef;
|
|
|
|
}
|
|
|
|
|
2008-05-06 18:27:45 +00:00
|
|
|
my @sn = xCAT::Utils->getSNList();
|
|
|
|
foreach my $s (@sn)
|
|
|
|
{
|
|
|
|
my $reqcopy = {%$req};
|
|
|
|
$reqcopy->{'_xcatdest'} = $s;
|
2010-01-15 20:39:11 +00:00
|
|
|
$reqcopy->{_xcatpreprocessed}->[0] = 1;
|
2008-05-06 18:27:45 +00:00
|
|
|
push @requests, $reqcopy;
|
2008-01-26 19:06:21 +00:00
|
|
|
}
|
2010-01-15 20:39:11 +00:00
|
|
|
|
2008-05-06 18:27:45 +00:00
|
|
|
return \@requests;
|
2008-01-26 19:06:21 +00:00
|
|
|
}
|
2008-05-06 18:27:45 +00:00
|
|
|
|
|
|
|
sub process_request
|
|
|
|
{
|
2009-08-11 17:18:27 +00:00
|
|
|
my $request = shift;
|
|
|
|
my $callback = shift;
|
|
|
|
|
|
|
|
$::args = $request->{arg};
|
|
|
|
|
|
|
|
if (defined(@{$::args})) {
|
|
|
|
@ARGV = @{$::args};
|
2008-04-08 18:30:47 +00:00
|
|
|
}
|
2009-08-11 17:18:27 +00:00
|
|
|
|
|
|
|
Getopt::Long::Configure("no_pass_through");
|
|
|
|
if (
|
|
|
|
!GetOptions(
|
|
|
|
'help|h|?' => \$::HELP,
|
|
|
|
'display|d' => \$::DISPLAY,
|
|
|
|
'verbose|V' => \$::VERBOSE,
|
|
|
|
'version|v' => \$::VERSION,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
{
|
|
|
|
# return 1;
|
2007-10-26 22:44:33 +00:00
|
|
|
}
|
2009-08-11 17:18:27 +00:00
|
|
|
|
2010-01-15 20:39:11 +00:00
|
|
|
# process the network interfaces on this system
|
|
|
|
# - management node was already done
|
|
|
|
if (!xCAT::Utils->isMN()) {
|
|
|
|
if (&donets($callback) != 0) {
|
|
|
|
my $rsp;
|
|
|
|
push @{$rsp->{data}}, "Could not get network information.\n";
|
|
|
|
xCAT::MsgUtils->message("E", $rsp, $callback);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 donets
|
|
|
|
Get network information and display or create xCAT network defs
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
0 - OK
|
|
|
|
1 - error
|
|
|
|
|
|
|
|
Usage:
|
|
|
|
my $rc = &donets($callback);
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
sub donets
|
|
|
|
{
|
|
|
|
my $callback = shift;
|
|
|
|
|
|
|
|
my $host = `hostname`;
|
|
|
|
chomp $host;
|
|
|
|
|
|
|
|
# get all the existing xCAT network defs
|
|
|
|
my @netlist;
|
|
|
|
@netlist = xCAT::DBobjUtils->getObjectsOfType('network');
|
|
|
|
|
|
|
|
my %nethash;
|
|
|
|
if (scalar(@netlist)) {
|
|
|
|
my %objtype;
|
|
|
|
foreach my $netn (@netlist) {
|
|
|
|
$objtype{$netn} = 'network';
|
|
|
|
}
|
|
|
|
|
|
|
|
%nethash = xCAT::DBobjUtils->getobjdefs(\%objtype, $callback);
|
|
|
|
if (!defined(%nethash)) {
|
|
|
|
my $rsp;
|
|
|
|
$rsp->{data}->[0] = "Could not get xCAT network definitions.\n";
|
|
|
|
xCAT::MsgUtils->message("E", $rsp, $::callback);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-11 17:18:27 +00:00
|
|
|
my $nettab = xCAT::Table->new('networks', -create => 1, -autocommit => 0);
|
|
|
|
|
|
|
|
if (xCAT::Utils->isAIX()) {
|
|
|
|
|
|
|
|
# get list of interfaces "ifconfig -l"
|
|
|
|
my $ifgcmd = "ifconfig -l";
|
|
|
|
my @interfaces = split(/\s+/, xCAT::Utils->runcmd($ifgcmd, 0));
|
|
|
|
if ($::RUNCMD_RC != 0) {
|
|
|
|
my $rsp;
|
|
|
|
push @{$rsp->{data}}, "Could not run \'$ifgcmd\'.\n";
|
|
|
|
xCAT::MsgUtils->message("E", $rsp, $callback);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2010-06-09 09:22:14 +00:00
|
|
|
my $master=xCAT::Utils->get_site_Master();
|
|
|
|
my $masterip = xCAT::NetworkUtils->getipaddr($master);
|
|
|
|
if ($masterip =~ /:/) {
|
|
|
|
# do each ethernet interface for ipv6
|
|
|
|
foreach my $i (@interfaces) {
|
|
|
|
|
|
|
|
if ($i =~ /^en/) {
|
|
|
|
|
|
|
|
# "ifconfig en0 |grep fe80" to get net and prefix length
|
|
|
|
my $cmd = "ifconfig $i |grep -i inet6";
|
|
|
|
my @netinfo = xCAT::Utils->runcmd($cmd, -1);
|
|
|
|
if ($::RUNCMD_RC != 0) {
|
|
|
|
# no ipv6 address configured
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
# only handle the ipv6 addr without %
|
|
|
|
foreach my $line (@netinfo)
|
|
|
|
{
|
|
|
|
next if ($line =~ /\%/);
|
|
|
|
|
|
|
|
my $gateway;
|
|
|
|
my $netmask;
|
|
|
|
my @fields;
|
|
|
|
|
|
|
|
@fields = split(/ /, $line);
|
|
|
|
($gateway, $netmask) = split(/\//, $fields[1]);
|
|
|
|
|
|
|
|
my $eip = Net::IP::ip_expand_address ($gateway,6);
|
|
|
|
my $bip = Net::IP::ip_iptobin($eip,6);
|
|
|
|
my $bmask = Net::IP::ip_get_mask($netmask,6);
|
|
|
|
my $bnet = $bip & $bmask;
|
|
|
|
my $ipnet = Net::IP::ip_bintoip($bnet,6);
|
|
|
|
my $net = Net::IP::ip_compress_address($ipnet,6);
|
|
|
|
|
|
|
|
my $netname = $net . "-" . $netmask;
|
|
|
|
|
|
|
|
# see if this network (or equivalent) is already defined
|
|
|
|
# - compare net and prefix_len values
|
|
|
|
my $foundmatch = 0;
|
|
|
|
foreach my $netn (@netlist) {
|
|
|
|
# get net and prefix_len
|
|
|
|
my $dnet = $nethash{$netn}{'net'};
|
|
|
|
my $dprefix_len = $nethash{$netn}{'mask'};
|
|
|
|
|
|
|
|
if (($net == $dnet) && ($netmask == $dprefix_len))
|
|
|
|
{
|
|
|
|
$foundmatch = 1;
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($::DISPLAY) {
|
|
|
|
my $rsp;
|
|
|
|
push @{$rsp->{data}}, "\n#From $host.";
|
|
|
|
pus h @{$rsp->{data}}, "$netname:";
|
|
|
|
push @{$rsp->{data}}, " objtype=network";
|
|
|
|
push @{$rsp->{data}}, " net=$net";
|
|
|
|
push @{$rsp->{data}}, " mask=$netmask";
|
|
|
|
push @{$rsp->{data}}, " mgtifname=$i";
|
|
|
|
push @{$rsp->{data}}, " gateway=$gateway\n";
|
|
|
|
if ($foundmatch) {
|
|
|
|
pus h @{$rsp->{data}}, "# Note: An equivalent xCAT network definition already exists.\n";
|
|
|
|
}
|
|
|
|
xCA T::MsgUtils->message("I", $rsp, $callback);
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if ($foundmatch) {
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
# add new network def
|
|
|
|
$nettab->setAttribs({'net' => $net, 'mask' => $netmask}, {'netname' => $netname, 'gateway' => $gateway, 'mgtifname' => $i});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
# do each ethernet interface for ipv4
|
|
|
|
foreach my $i (@interfaces) {
|
|
|
|
|
|
|
|
if ($i =~ /^en/) {
|
|
|
|
|
|
|
|
# "mktcpip -S en0" to get nm & gw
|
|
|
|
my $mkcmd = "mktcpip -S $i";
|
|
|
|
my @netinfo = xCAT::Utils->runcmd($mkcmd, 0);
|
|
|
|
if ($::RUNCMD_RC != 0) {
|
|
|
|
my $rsp;
|
|
|
|
push @{$rsp->{data}}, "Could not run \'$mkcmd\'.\n";
|
|
|
|
xCAT::MsgUtils->message("E", $rsp, $callback);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
my $netmask;
|
|
|
|
my $ipaddr;
|
|
|
|
my @fields;
|
|
|
|
my $gateway;
|
|
|
|
foreach my $line (@netinfo) {
|
|
|
|
next if ($line =~ /^\s*#/);
|
|
|
|
|
|
|
|
@fields = split(/:/, $line);
|
|
|
|
}
|
|
|
|
$ipaddr = $fields[1];
|
|
|
|
$netmask = $fields[2];
|
|
|
|
$gateway = $fields[6];
|
|
|
|
|
|
|
|
# split interface IP
|
|
|
|
my ($ip1, $ip2, $ip3, $ip4) = split('\.', $ipaddr);
|
|
|
|
|
|
|
|
# split mask
|
|
|
|
my ($m1, $m2, $m3, $m4) = split('\.', $netmask);
|
|
|
|
|
|
|
|
# AND nm and ip to get net attribute
|
|
|
|
my $n1 = ((int $ip1) & (int $m1));
|
|
|
|
my $n2 = ((int $ip2) & (int $m2));
|
|
|
|
my $n3 = ((int $ip3) & (int $m3));
|
|
|
|
my $n4 = ((int $ip4) & (int $m4));
|
|
|
|
|
|
|
|
my $net = "$n1.$n2.$n3.$n4";
|
|
|
|
|
|
|
|
# use convention for netname attr
|
|
|
|
my $netn;
|
|
|
|
my $maskn;
|
|
|
|
($netn = $net) =~ s/\./\_/g;
|
|
|
|
($maskn = $netmask) =~ s/\./\_/g;
|
|
|
|
# ( 1_2_3_4-255_255_255_192 - ugh!)
|
|
|
|
my $netname = $netn . "-" . $maskn;
|
|
|
|
|
|
|
|
# see if this network (or equivalent) is already defined
|
|
|
|
# - compare net and mask values
|
|
|
|
my $foundmatch = 0;
|
|
|
|
foreach my $netn (@netlist) {
|
|
|
|
# split definition mask
|
|
|
|
my ($dm1, $dm2, $dm3, $dm4) = split('\.', $nethash{$netn}{'mask'});
|
|
|
|
|
|
|
|
# split definition net addr
|
|
|
|
my ($dn1, $dn2, $dn3, $dn4) = split('\.', $nethash{$netn}{'net'});
|
|
|
|
|
|
|
|
# check for the same netmask and network address
|
|
|
|
if ( ($n1 == $dn1) && ($n2 ==$dn2) && ($n3 == $dn3) && ($n4 == $dn4) ) {
|
|
|
|
if ( ($m1 == $dm1) && ($m2 ==$dm2) && ($m3 == $dm3) && ($m4== $dm4) ) {
|
|
|
|
$foundmatch=1;
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($::DISPLAY) {
|
|
|
|
my $rsp;
|
|
|
|
push @{$rsp->{data}}, "\n#From $host.";
|
|
|
|
push @{$rsp->{data}}, "$netname:";
|
|
|
|
push @{$rsp->{data}}, " objtype=network";
|
|
|
|
push @{$rsp->{data}}, " net=$net";
|
|
|
|
push @{$rsp->{data}}, " mask=$netmask";
|
|
|
|
push @{$rsp->{data}}, " mgtifname=$i";
|
|
|
|
push @{$rsp->{data}}, " gateway=$gateway\n";
|
|
|
|
if ($foundmatch) {
|
|
|
|
push @{$rsp->{data}}, "# Note: An equivalent xCAT network definition already exists.\n";
|
|
|
|
}
|
|
|
|
xCAT::MsgUtils->message("I", $rsp, $callback);
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if ($foundmatch) {
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
# add new network def
|
|
|
|
$nettab->setAttribs({'net' => $net, 'mask' => $netmask}, {'netname' => $netname, 'gateway' => $gateway, 'mgtifname' => $i});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} # end foreach
|
|
|
|
} #end if ipv4
|
|
|
|
|
|
|
|
} else {
|
2009-08-11 17:18:27 +00:00
|
|
|
|
|
|
|
# For Linux systems
|
|
|
|
my @rtable = split /\n/, `/bin/netstat -rn`;
|
|
|
|
open($rconf, "/etc/resolv.conf");
|
|
|
|
my @nameservers;
|
|
|
|
if ($rconf)
|
|
|
|
{
|
|
|
|
my @rcont;
|
|
|
|
while (<$rconf>)
|
|
|
|
{
|
|
|
|
push @rcont, $_;
|
|
|
|
}
|
|
|
|
close($rconf);
|
|
|
|
foreach (grep /nameserver/, @rcont)
|
|
|
|
{
|
2010-01-20 13:45:18 +00:00
|
|
|
my $line = $_;
|
|
|
|
my @pair;
|
|
|
|
$line =~ s/#.*//;
|
|
|
|
$line =~ s/^\s*//;
|
|
|
|
@pair = split(/\s+/, $line);
|
|
|
|
if ($pair[0] eq 'nameserver' && $pair[1] ne '') {
|
|
|
|
push @nameservers, $pair[1];
|
|
|
|
}
|
2009-08-11 17:18:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
splice @rtable, 0, 2;
|
2010-11-15 12:26:20 +00:00
|
|
|
|
|
|
|
my %netgw = ();
|
|
|
|
foreach my $rtent (@rtable)
|
|
|
|
{
|
|
|
|
my @entarr = split /\s+/, $rtent;
|
|
|
|
if ($entarr[3] eq 'UG')
|
|
|
|
{
|
|
|
|
$netgw{$entarr[0]}{$entarr[2]} = $entarr[1];
|
|
|
|
}
|
|
|
|
}
|
2009-08-11 17:18:27 +00:00
|
|
|
foreach (@rtable)
|
|
|
|
{ #should be the lines to think about, do something with U, and something else with UG
|
|
|
|
|
2010-01-15 20:39:11 +00:00
|
|
|
my $foundmatch=0;
|
2009-08-11 17:18:27 +00:00
|
|
|
my $rsp;
|
|
|
|
my $net;
|
|
|
|
my $mask;
|
|
|
|
my $mgtifname;
|
|
|
|
my $gw;
|
|
|
|
my @ent = split /\s+/, $_;
|
|
|
|
my $firstoctet = $ent[0];
|
|
|
|
$firstoctet =~ s/^(\d+)\..*/$1/;
|
|
|
|
|
|
|
|
if ($ent[0] eq "169.254.0.0" or ($firstoctet >= 224 and $firstoctet <= 239) or $ent[0] eq "127.0.0.0")
|
|
|
|
{
|
|
|
|
next;
|
|
|
|
}
|
2010-01-15 20:39:11 +00:00
|
|
|
|
2009-08-11 17:18:27 +00:00
|
|
|
if ($ent[3] eq 'U')
|
|
|
|
{
|
|
|
|
$net = $ent[0];
|
|
|
|
$mask = $ent[2];
|
|
|
|
$mgtifname = $ent[7];
|
2010-11-15 12:26:20 +00:00
|
|
|
if (defined($netgw{$net}{$mask}))
|
|
|
|
{
|
|
|
|
$gw = $netgw{$net}{$mask}; #gateway for this network
|
|
|
|
} else {
|
|
|
|
$gw = $netgw{'0.0.0.0'}{'0.0.0.0'}; #default gatetway
|
|
|
|
}
|
2009-08-11 17:18:27 +00:00
|
|
|
|
|
|
|
# use convention for netname attr
|
|
|
|
my $netn;
|
|
|
|
my $maskn;
|
|
|
|
($netn = $net) =~ s/\./\_/g;
|
|
|
|
($maskn = $mask) =~ s/\./\_/g;
|
|
|
|
# ( 1_2_3_4-255_255_255_192 - ugh!)
|
|
|
|
my $netname = $netn . "-" . $maskn;
|
|
|
|
|
2010-01-15 20:39:11 +00:00
|
|
|
# see if this network (or equivalent) is already defined
|
|
|
|
# - compare net and mask values
|
|
|
|
|
|
|
|
# split mask
|
|
|
|
my ($m1, $m2, $m3, $m4) = split('\.', $mask);
|
|
|
|
|
|
|
|
# split net addr
|
|
|
|
my ($n1, $n2, $n3, $n4) = split('\.', $net);
|
|
|
|
|
|
|
|
foreach my $netn (@netlist) {
|
|
|
|
|
|
|
|
# split definition mask
|
|
|
|
my ($dm1, $dm2, $dm3, $dm4) = split('\.', $nethash{$netn}{'mask'});
|
|
|
|
|
|
|
|
# split definition net addr
|
|
|
|
my ($dn1, $dn2, $dn3, $dn4) = split('\.', $nethash{$netn}{'net'});
|
|
|
|
|
|
|
|
# check for the same netmask and network address
|
|
|
|
if ( ($n1 == $dn1) && ($n2 ==$dn2) && ($n3 == $dn3) && ($n4 == $dn4) ) {
|
|
|
|
if ( ($m1 == $dm1) && ($m2 ==$dm2) && ($m3 == $dm3) && ($m4== $dm4) ) {
|
|
|
|
$foundmatch=1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-11 17:18:27 +00:00
|
|
|
if ($::DISPLAY) {
|
|
|
|
push @{$rsp->{data}}, "\n#From $host.";
|
|
|
|
push @{$rsp->{data}}, "$netname:";
|
|
|
|
push @{$rsp->{data}}, " objtype=network";
|
|
|
|
push @{$rsp->{data}}, " net=$net";
|
|
|
|
push @{$rsp->{data}}, " mask=$mask";
|
2010-11-15 12:26:20 +00:00
|
|
|
if ($gw)
|
|
|
|
{
|
|
|
|
push @{$rsp->{data}}, " gateway=$gw";
|
|
|
|
}
|
2009-08-11 17:18:27 +00:00
|
|
|
push @{$rsp->{data}}, " mgtifname=$mgtifname";
|
|
|
|
} else {
|
2010-01-15 20:39:11 +00:00
|
|
|
if (!$foundmatch) {
|
2010-11-15 12:26:20 +00:00
|
|
|
$nettab->setAttribs({'net' => $net, 'mask' => $mask}, {'netname' => $netname, 'mgtifname' => $mgtifname, 'gateway' => $gw});
|
2010-01-15 20:39:11 +00:00
|
|
|
}
|
2009-08-11 17:18:27 +00:00
|
|
|
}
|
|
|
|
|
2010-01-15 20:39:11 +00:00
|
|
|
my $tent = $nettab->getAttribs({'net' => $net, 'mask' => $mask}, 'nameservers');
|
2009-08-11 17:18:27 +00:00
|
|
|
unless ($tent and $tent->{nameservers})
|
|
|
|
{
|
|
|
|
my $text = join ',', @nameservers;
|
|
|
|
if ($::DISPLAY) {
|
|
|
|
push @{$rsp->{data}}, " nameservers=$text";
|
|
|
|
} else {
|
2010-01-15 20:39:11 +00:00
|
|
|
if (!$foundmatch) {
|
|
|
|
$nettab->setAttribs({'net' => $net, 'mask' => $mask}, {nameservers => $text});
|
|
|
|
}
|
2009-08-11 17:18:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
unless ($tent and $tent->{tftpserver})
|
|
|
|
{
|
|
|
|
my $netdev = $ent[7];
|
|
|
|
my @netlines = split /\n/, `/sbin/ip addr show dev $netdev`;
|
|
|
|
foreach (grep /\s*inet\b/, @netlines)
|
|
|
|
{
|
|
|
|
my @row = split(/\s+/, $_);
|
|
|
|
my $ipaddr = $row[2];
|
|
|
|
$ipaddr =~ s/\/.*//;
|
|
|
|
my @maska = split(/\./, $mask);
|
|
|
|
my @ipa = split(/\./, $ipaddr);
|
|
|
|
my @neta = split(/\./, $net);
|
|
|
|
my $isme = 1;
|
|
|
|
foreach (0 .. 3)
|
|
|
|
{
|
|
|
|
my $oct = (0 + $maska[$_]) & ($ipa[$_] + 0);
|
|
|
|
unless ($oct == $neta[$_])
|
|
|
|
{
|
|
|
|
$isme = 0;
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($isme)
|
|
|
|
{
|
|
|
|
if ($::DISPLAY) {
|
|
|
|
push @{$rsp->{data}}, " tftpserver=$ipaddr";
|
|
|
|
} else {
|
2010-01-15 20:39:11 +00:00
|
|
|
if (!$foundmatch) {
|
|
|
|
$nettab->setAttribs({'net' => $net, 'mask' => $mask}, {tftpserver => $ipaddr});
|
|
|
|
}
|
2009-08-11 17:18:27 +00:00
|
|
|
}
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-12-06 16:42:01 +00:00
|
|
|
|
2009-08-11 17:18:27 +00:00
|
|
|
#Nothing much sane to do for the other fields at the moment?
|
|
|
|
}
|
|
|
|
elsif ($ent[3] eq 'UG')
|
|
|
|
{
|
|
|
|
|
|
|
|
#TODO: networks through gateway. and how we might care..
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
|
|
|
|
#TODO: anything to do with such entries?
|
|
|
|
}
|
2010-01-15 20:39:11 +00:00
|
|
|
|
2009-08-11 17:18:27 +00:00
|
|
|
if ($::DISPLAY) {
|
2010-01-15 20:39:11 +00:00
|
|
|
|
|
|
|
if ($foundmatch) {
|
|
|
|
push @{$rsp->{data}}, "# Note: An equivalent xCAT network definition already exists.\n";
|
|
|
|
}
|
2009-08-11 17:18:27 +00:00
|
|
|
xCAT::MsgUtils->message("I", $rsp, $callback);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$nettab->commit;
|
2010-01-15 20:39:11 +00:00
|
|
|
|
|
|
|
return 0;
|
2009-08-11 17:18:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 makenetworks_usage
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
sub makenetworks_usage
|
|
|
|
{
|
|
|
|
my $callback = shift;
|
|
|
|
|
|
|
|
my $rsp;
|
|
|
|
push @{$rsp->{data}}, "\nUsage: makenetworks - Gather cluster network information and add it to the xCAT database.\n";
|
|
|
|
push @{$rsp->{data}}, " makenetworks [-h|--help ]\n";
|
|
|
|
push @{$rsp->{data}}, " makenetworks [-v|--version]\n";
|
|
|
|
push @{$rsp->{data}}, " makenetworks [-V|--verbose] [-d|--display]\n";
|
|
|
|
xCAT::MsgUtils->message("I", $rsp, $callback);
|
|
|
|
return 0;
|
2007-10-26 22:44:33 +00:00
|
|
|
}
|
2009-08-11 17:18:27 +00:00
|
|
|
|
2007-10-26 22:44:33 +00:00
|
|
|
1;
|