From 3bc4bfe0b6616a9cd86971af61bba1aedcd31c4e Mon Sep 17 00:00:00 2001 From: mellor Date: Mon, 6 Jul 2009 20:39:39 +0000 Subject: [PATCH] add makehosts support for otherinterfaces git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@3710 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- perl-xCAT/xCAT/Schema.pm | 7 ++++++- xCAT-server/lib/xcat/plugins/hosts.pm | 29 +++++++++++++++++++++++---- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/perl-xCAT/xCAT/Schema.pm b/perl-xCAT/xCAT/Schema.pm index 3487796d9..000f87f93 100644 --- a/perl-xCAT/xCAT/Schema.pm +++ b/perl-xCAT/xCAT/Schema.pm @@ -141,13 +141,14 @@ deps => { }, }, hosts => { - cols => [qw(node ip hostnames comments disable)], + cols => [qw(node ip hostnames otherinterfaces comments disable)], keys => [qw(node)], table_desc => 'IP address and hostnames of nodes. This info can be used to populate /etc/hosts or DNS.', descriptions => { node => 'The node name or group name.', ip => 'The IP address of the node.', hostnames => 'Hostname aliases added to /etc/hosts for this node.', + otherinterfaces => 'Other IP addresses to add for this node. Format: -:,:ip>,...', comments => 'Any user-written notes.', disable => "Set to 'yes' or '1' to comment out this row.", }, @@ -1243,6 +1244,10 @@ my @nodeattrs = ( tabentry => 'hosts.hostnames', access_tabentry => 'hosts.node=attr:node', }, + {attr_name => 'otherinterfaces', + tabentry => 'hosts.otherinterfaces', + access_tabentry => 'hosts.node=attr:node', + }, {attr_name => 'usercomment', tabentry => 'nodelist.comments', access_tabentry => 'nodelist.node=attr:node', diff --git a/xCAT-server/lib/xcat/plugins/hosts.pm b/xCAT-server/lib/xcat/plugins/hosts.pm index d04018923..3efaaf833 100644 --- a/xCAT-server/lib/xcat/plugins/hosts.pm +++ b/xCAT-server/lib/xcat/plugins/hosts.pm @@ -32,7 +32,7 @@ sub addnode { my $foundone=0; while ($idx <= $#hosts) { - if ($hosts[$idx] =~ /^${ip}\s/ or $hosts[$idx] =~ /^\d+\.\d+\.\d+\.\d+\s+${node}[\s\.]/) { + if ($hosts[$idx] =~ /^${ip}\s/ or $hosts[$idx] =~ /^\d+\.\d+\.\d+\.\d+\s+${node}[\s\.r]/) { if ($foundone) { $hosts[$idx]=""; } else { @@ -80,6 +80,21 @@ sub build_line { } +sub addotherinterfaces { + my $node = shift; + my $otherinterfaces = shift; + my $domain = shift; + + my @itf_pairs=split(/,/, $otherinterfaces); + foreach (@itf_pairs) { + my ($itf,$ip)=split(/:/, $_); + if ($itf =~ /^-/ ) { + $itf = $node.$itf }; + addnode $itf,$ip,'',$domain; + } +} + + sub process_request { Getopt::Long::Configure("bundling") ; $Getopt::Long::ignorecase=0; @@ -143,15 +158,21 @@ sub process_request { } if ($req->{node}) { - my $hostscache = $hoststab->getNodesAttribs($req->{node},[qw(ip node hostnames)]); + my $hostscache = $hoststab->getNodesAttribs($req->{node},[qw(ip node hostnames otherinterfaces)]); foreach(@{$req->{node}}) { - my $ref = $hostscache->{$_}->[0]; #$hoststab->getNodeAttribs($_,[qw(ip node hostnames)]); + my $ref = $hostscache->{$_}->[0]; #$hoststab->getNodeAttribs($_,[qw(ip node hostnames otherinterfaces)]); addnode $ref->{node},$ref->{ip},$ref->{hostnames},$domain; + if (defined($ref->{otherinterfaces})){ + addotherinterfaces $ref->{node},$ref->{otherinterfaces},$domain; + } } } else { - my @hostents = $hoststab->getAllNodeAttribs(['ip','node','hostnames']); + my @hostents = $hoststab->getAllNodeAttribs(['ip','node','hostnames','otherinterfaces']); foreach (@hostents) { addnode $_->{node},$_->{ip},$_->{hostnames},$domain; + if (defined($_->{otherinterfaces})){ + addotherinterfaces $_->{node},$_->{otherinterfaces},$domain; + } } } writeout();