support unicast dhcp during provisioning and 1st boot, including diskful for sles and rh

This commit is contained in:
immarvin 2014-04-11 02:40:34 -07:00
parent bbe9bc188c
commit 35d65f1a0b
6 changed files with 316 additions and 24 deletions

View File

@ -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};

View File

@ -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=<url> for driver disks
if (defined($sent->{serialport}))

View File

@ -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})

View File

@ -1,7 +1,8 @@
#
lang en_US
network --bootproto dhcp
#network --bootproto dhcp
#KICKSTARTNET#
#
# Where's the source?

View File

@ -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 <<EOF
@ -8,7 +12,7 @@ DEVICE=eth0
BOOTPROTO=dhcp
STARTMODE=onboot
EOF
fi
. /tmp/prinicsetting
rm /tmp/prinicsetting
if [ "$PRINIC" != "eth0" ]
@ -22,7 +26,12 @@ then
# echo "DHCLIENT_PRIMARY_DEVICE=yes" >> 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

View File

@ -63,25 +63,7 @@
<surname/>
</user>
</users>
<networking>
<dns>
<dhcp_hostname config:type="boolean">true</dhcp_hostname>
<dhcp_resolv config:type="boolean">true</dhcp_resolv>
<domain>local</domain>
<hostname>linux</hostname>
</dns>
<interfaces config:type="list">
<interface>
<bootproto>dhcp</bootproto>
<device>eth0</device>
<startmode>onboot</startmode>
</interface>
</interfaces>
<routing>
<ip_forward config:type="boolean">false</ip_forward>
<routes config:type="list"/>
</routing>
</networking>
#YAST2NET#
<scripts>
#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/pre.sles#
#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/chroot.sles#