diff --git a/xCAT-server/lib/perl/xCAT/Template.pm b/xCAT-server/lib/perl/xCAT/Template.pm index 0f86bab18..510304cc4 100644 --- a/xCAT-server/lib/perl/xCAT/Template.pm +++ b/xCAT-server/lib/perl/xCAT/Template.pm @@ -14,6 +14,7 @@ use xCAT::ADUtils; #to allow setting of one-time machine passwords use xCAT::Utils; use xCAT::TableUtils; use xCAT::NetworkUtils; +use XML::Simple; BEGIN { $::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : '/opt/xcat'; @@ -103,6 +104,13 @@ sub subvars { $ENV{NODESTATUS}=$tmp; } + + my @managedaddressmode = xCAT::TableUtils->get_site_attribute("managedaddressmode"); + my $tmp=$managedaddressmode[0]; + if( defined($tmp) ){ + $ENV{MANAGEDADDRESSMODE}=$tmp; + } + #replace the env with the right value so that correct include files can be found $inc =~ s/#ENV:([^#]+)#/envvar($1)/eg; @@ -229,6 +237,7 @@ sub subvars { $inc =~ s/#CRYPT:([^:]+):([^:]+):([^#]+)#/crydb($1,$2,$3)/eg; $inc =~ s/#COMMAND:([^#]+)#/command($1)/eg; $inc =~ s/#KICKSTARTNET#/kickstartnetwork()/eg; + $inc =~ s/#YAST2NET#/yast2network()/eg; $inc =~ s/#ESXIPV6SETUP#/esxipv6setup()/eg; $inc =~ s/#WINTIMEZONE#/xCAT::TZUtils::get_wintimezone()/eg; $inc =~ s/#WINPRODKEY:([^#]+)#/get_win_prodkey($1)/eg; @@ -633,8 +642,8 @@ sub esxipv6setup { } sub kickstartnetwork { - my $line = "network --onboot=yes --bootproto="; - my $hoststab; + my $line = "network --onboot=yes --bootproto="; + my $hoststab; my $mactab = xCAT::Table->new('mac',-create=>0); unless ($mactab) { die "mac table should always exist prior to template processing when doing autoula"; } my $ent = $mactab->getNodeAttribs($node,['mac'],prefetchcache=>1); @@ -648,12 +657,241 @@ sub kickstartnetwork { $hoststab->setNodeAttribs($node,{ip=>$ulaaddr}); $line .= $ulaaddr; } elsif ($::XCATSITEVALS{managedaddressmode} =~ /static/) { - return "#KSNET static unsupported"; + my ($ipaddr,$hostname,$gateway,$netmask)=xCAT::NetworkUtils->getNodeNetworkCfg($node); + unless($ipaddr) { die "cannot resolve the network configuration of $node"; } + $line .="static --device=$suffix --ip=$ipaddr --netmask=$netmask --gateway=$gateway --hostname=$hostname "; + + my $nrtab = xCAT::Table->new('noderes',-create=>0); + unless ($nrtab) { die "noderes table should always exist prior to template processing"; } + my $ent = $nrtab->getNodeAttribs($node,['nameservers'],prefetchcache=>1); + unless ($ent and $ent->{nameservers}) { die "attribute nameservers not set for $node"; } + my @nameserverARR=split (",",$ent->{nameservers}); + my @nameserversIP; + foreach (@nameserverARR) + { + my ($host,$ip) = xCAT::NetworkUtils->gethostnameandip($_); + push @nameserversIP, $ip; + } + + if (scalar @nameserversIP) { + $line .=" --nameserver=". join(",",@nameserversIP); + } + + + #return "#KSNET static unsupported"; } else { $line .= "dhcp --device=$suffix"; } return $line; } + + +sub yast2network { + my $line; + my $hoststab; + my $mactab = xCAT::Table->new('mac',-create=>0); + unless ($mactab) { die "mac table should always exist prior to template processing when doing autoula"; } + my $ent = $mactab->getNodeAttribs($node,['mac'],prefetchcache=>1); + unless ($ent and $ent->{mac}) { die "missing mac data for $node"; } + my $suffix = $ent->{mac}; + $suffix = lc($suffix); + if ($::XCATSITEVALS{managedaddressmode} eq "autoula") { + #TODO + return "#YAST2NET autoula unsupported" + } elsif ($::XCATSITEVALS{managedaddressmode} =~ /static/) { + my ($ipaddr,$hostname,$gateway,$netmask)=xCAT::NetworkUtils->getNodeNetworkCfg($node); + unless($ipaddr) { die "cannot resolve the network configuration of $node"; } + + my $nrtab = xCAT::Table->new('noderes',-create=>0); + unless ($nrtab) { die "noderes table should always exist prior to template processing"; } + my $ent = $nrtab->getNodeAttribs($node,['nameservers'],prefetchcache=>1); + unless ($ent and $ent->{nameservers}) { die "attribute nameservers not set for $node"; } + my @nameserverARR=split (",",$ent->{nameservers}); + my @nameserversIP; + foreach (@nameserverARR) + { + my ($host,$ip) = xCAT::NetworkUtils->gethostnameandip($_); + push @nameserversIP, $ip; + } + + + # get the domains for each node - one call for all nodes in hosts file + my $nd = xCAT::NetworkUtils->getNodeDomains([$node]); + my %nodedomains = %$nd; + my $domain=$nodedomains{$node}; + my $networkhash={ + 'networking' => [ + { + 'dns' => [ + { + 'domain' => [ + "$domain" + ], + 'dhcp_hostname' => [ + { + 'content' => 'false', + 'config:type' => 'boolean' + } + ], + 'dhcp_resolv' => [ + { + 'content' => 'false', + 'config:type' => 'boolean' + } + ], + 'nameservers' => [ + { + 'config:type' => 'list', + 'nameserver' => @nameserversIP + } + ], + 'hostname' => [ + $hostname + ], + 'searchlist' => [ + { + 'search' => [ + $domain + ], + 'config:type' => 'list' + } + ] + } + ], + 'interfaces' => [ + { + 'interface' => [ + { + 'bootproto' => [ + 'static' + ], + 'startmode' => [ + 'onboot' + ], + 'netmask' => [ + $netmask + ], + 'device' => [ + 'eth0' + ], + 'ipaddr' => [ + $ipaddr + ] + } + ], + 'config:type' => 'list' + } + ], + 'routing' => [ + { + 'ip_forward' => [ + { + 'content' => 'false', + 'config:type' => 'boolean' + } + ], + 'routes' => [ + { + 'route' => [ + { + 'destination' => [ + 'default' + ], + 'gateway' => [ + $gateway + ], + 'netmask' => [ + '-' + ], + 'device' => [ + '-' + ] + } + ], + 'config:type' => 'list' + } + ] + } + ] + } + ] + }; + my $xml = new XML::Simple(KeepRoot => 1); + $line=$xml->XMLout($networkhash); + + #return "#KSNET static unsupported"; + } else { + + my $networkhash={ + 'networking' => [ + { + 'dns' => [ + { + 'domain' => [ + 'local' + ], + 'dhcp_hostname' => [ + { + 'content' => 'true', + 'config:type' => 'boolean' + } + ], + 'hostname' => [ + 'linux' + ], + 'dhcp_resolv' => [ + { + 'content' => 'true', + 'config:type' => 'boolean' + } + ] + } + ], + 'interfaces' => [ + { + 'interface' => [ + { + 'startmode' => [ + 'onboot' + ], + 'bootproto' => [ + 'dhcp' + ], + 'device' => [ + 'eth0' + ] + } + ], + 'config:type' => 'list' + } + ], + 'routing' => [ + { + 'ip_forward' => [ + { + 'content' => 'false', + 'config:type' => 'boolean' + } + ], + 'routes' => [ + { + 'config:type' => 'list' + } + ] + } + ] + } + ] + }; + + + my $xml = new XML::Simple(KeepRoot => 1); + $line=$xml->XMLout($networkhash); + + } + return $line; +} + sub autoulaaddress { my $suffix = shift; my $prefix = $::XCATSITEVALS{autoulaprefix}; diff --git a/xCAT-server/lib/xcat/plugins/anaconda.pm b/xCAT-server/lib/xcat/plugins/anaconda.pm index 278f36b1b..2f3ac450f 100644 --- a/xCAT-server/lib/xcat/plugins/anaconda.pm +++ b/xCAT-server/lib/xcat/plugins/anaconda.pm @@ -1377,12 +1377,17 @@ sub mkinstall $instserver=$ent->{nfsserver}; } + if ($::XCATSITEVALS{managedaddressmode} =~ /static/){ + my($host,$ip)=xCAT::NetworkUtils->gethostnameandip($instserver); + $instserver=$ip; + } my $httpprefix=$pkgdir; if ($installroot =~ /\/$/) { $httpprefix =~ s/^$installroot/\/install\//; } else { $httpprefix =~ s/^$installroot/\/install/; } + my $kcmdline = "quiet repo=$httpmethod://$instserver:$httpport$httpprefix ks=$httpmethod://" . $instserver . ":". $httpport @@ -1437,6 +1442,30 @@ sub mkinstall unless ($ksdev eq "bootif" and $os =~ /7/) { $kcmdline .= " ksdevice=" . $ksdev; } + + #if site.managedaddressmode=static, specify the network configuration as kernel options + #to avoid multicast dhcp + if($::XCATSITEVALS{managedaddressmode} =~ /static/){ + my ($ipaddr,$hostname,$gateway,$netmask)=xCAT::NetworkUtils->getNodeNetworkCfg($node); + unless($ipaddr) { die "cannot resolve the network configuration of $node"; } + + $kcmdline .=" ip=$ipaddr netmask=$netmask gateway=$gateway hostname=$hostname "; + my $nrtab = xCAT::Table->new('noderes',-create=>0); + unless ($nrtab) { die "noderes table should always exist prior to template processing"; } + my $ent = $nrtab->getNodeAttribs($node,['nameservers'],prefetchcache=>1); + unless ($ent and $ent->{nameservers}) { die "attribute nameservers not set for $node"; } + my @nameserverARR=split (",",$ent->{nameservers}); + my @nameserversIP; + foreach (@nameserverARR) + { + my ($host,$ip) = xCAT::NetworkUtils->gethostnameandip($_); + push @nameserversIP, $ip; + } + + if(scalar @nameserversIP){ + $kcmdline .=" dns=".join(",",@nameserversIP); + } + } #TODO: dd= for driver disks if (defined($sent->{serialport})) diff --git a/xCAT-server/lib/xcat/plugins/sles.pm b/xCAT-server/lib/xcat/plugins/sles.pm index d73f96c82..9549ae9b2 100755 --- a/xCAT-server/lib/xcat/plugins/sles.pm +++ b/xCAT-server/lib/xcat/plugins/sles.pm @@ -1075,6 +1075,13 @@ sub mkinstall { $netserver = $ent->{nfsserver}; } + + + if ($::XCATSITEVALS{managedaddressmode} =~ /static/){ + my($host,$ip)=xCAT::NetworkUtils->gethostnameandip($netserver); + $netserver=$ip; + } + my $httpprefix = $pkgdir; if ($installroot =~ /\/$/) { #must prepend /install/ $httpprefix =~ s/^$installroot/\/install\//; @@ -1139,6 +1146,32 @@ sub mkinstall $kcmdline .= " dud=file:/cus_driverdisk/$_"; } + #if site.managedaddressmode=static, specify the network configuration as kernel options + #to avoid multicast dhcp + if($::XCATSITEVALS{managedaddressmode} =~ /static/){ + my ($ipaddr,$hostname,$gateway,$netmask)=xCAT::NetworkUtils->getNodeNetworkCfg($node); + unless($ipaddr) { die "cannot resolve the network configuration of $node"; } + + $kcmdline .=" hostip=$ipaddr netmask=$netmask gateway=$gateway hostname=$hostname "; + my $nrtab = xCAT::Table->new('noderes',-create=>0); + unless ($nrtab) { die "noderes table should always exist prior to template processing"; } + my $ent = $nrtab->getNodeAttribs($node,['nameservers'],prefetchcache=>1); + unless ($ent and $ent->{nameservers}) { die "attribute nameservers not set for $node"; } + my @nameserverARR=split (",",$ent->{nameservers}); + my @nameserversIP; + foreach (@nameserverARR) + { + my ($host,$ip) = xCAT::NetworkUtils->gethostnameandip($_); + push @nameserversIP, $ip; + } + + if(scalar @nameserversIP){ + $kcmdline .=" dns=".join(",",@nameserversIP); + } + } + + + if (defined $sent->{serialport}) { unless ($sent->{serialspeed}) diff --git a/xCAT-server/share/xcat/install/rh/compute.rhels6.ppc64.tmpl b/xCAT-server/share/xcat/install/rh/compute.rhels6.ppc64.tmpl index 348677731..d05dec9f7 100644 --- a/xCAT-server/share/xcat/install/rh/compute.rhels6.ppc64.tmpl +++ b/xCAT-server/share/xcat/install/rh/compute.rhels6.ppc64.tmpl @@ -1,7 +1,8 @@ # lang en_US -network --bootproto dhcp +#network --bootproto dhcp +#KICKSTARTNET# # # Where's the source? diff --git a/xCAT-server/share/xcat/install/scripts/post.sles.common b/xCAT-server/share/xcat/install/scripts/post.sles.common index ec6e89437..cfe6f29cc 100644 --- a/xCAT-server/share/xcat/install/scripts/post.sles.common +++ b/xCAT-server/share/xcat/install/scripts/post.sles.common @@ -1,6 +1,10 @@ #!/bin/sh +export MANAGEDADDRESSMODE="#XCATVAR:MANAGEDADDRESSMODE#" cd /etc/sysconfig/network + +if [ "$MANAGEDADDRESSMODE" != "static" ] +then rm -f ifcfg-eth-id* rm -f ifcfg-myri* cat >ifcfg-eth0 <> ifcfg-$PRINIC fi fi + +if [ "$MANAGEDADDRESSMODE" != "static" ] +then echo "DHCLIENT_PRIMARY_DEVICE=yes" >> ifcfg-$PRINIC +fi + perl -pi -e 's/^FIREWALL="yes"/FIREWALL="no"/' /etc/sysconfig/network/config /etc/init.d/network restart diff --git a/xCAT-server/share/xcat/install/sles/compute.sles11.tmpl b/xCAT-server/share/xcat/install/sles/compute.sles11.tmpl index 64819cafa..b343a4fbe 100644 --- a/xCAT-server/share/xcat/install/sles/compute.sles11.tmpl +++ b/xCAT-server/share/xcat/install/sles/compute.sles11.tmpl @@ -63,25 +63,7 @@ - - - true - true - local - linux - - - - dhcp - eth0 - onboot - - - - false - - - + #YAST2NET# #INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/pre.sles# #INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/chroot.sles#