## Start post_install_network_config generated code #if $getVar('promisc_nics', '') != "" #set promisc_interfaces = [promisc.strip() for promisc in $promisc_nics.split(',') if promisc.strip()] #else #set promisc_interfaces = [] #end if #if $getVar("system_name","") != "" ## this is being provisioned by system records, not profile records ## so we can do the more complex stuff ## get the list of interface names #set ikeys = $interfaces.keys() #set osversion = $getVar("os_version","") #import re #set $vlanpattern = $re.compile("[a-zA-Z0-9]+[\.:][0-9]+") ## Determine if we should use the MAC address to configure the interfaces first ## Only physical interfaces are required to have a MAC address ## Also determine the number of bonding devices we have, so we can set the ## max-bonds option in modprobe.conf accordingly. -- jcapel #set $configbymac = True #set $bridge_slaves = {} #set $numbondingdevs = 0 #set $enableipv6 = False ## ============================================================================= #for $iname in $ikeys ## look at the interface hash data for the specific interface #set $idata = $interfaces[$iname] ## do not configure by mac address if we don't have one AND it's not for bonding/vlans ## as opposed to a "real" physical interface #if $idata.get("mac_address", "") == "" and not $vlanpattern.match($iname) and not $idata.get("interface_type", "").lower() in ("master","bond","bridge"): ## we have to globally turn off the config by mac feature as we can't ## use it now #set $configbymac = False #end if ## count the number of bonding devices we have. #if $idata.get("interface_type", "").lower() in ("master","bond","bonded_bridge_slave") #set $numbondingdevs += 1 #end if ## build a mapping of bridge slaves, since deb/ubuntu bridge slaves do not ## get interface entries of their own #if $idata.get("interface_type","").lower() == "bridge_slave" #set $this_master = $idata.get("interface_master", None) #if $this_master and not $bridge_slaves.has_key($this_master) #set $bridge_slaves[$this_master] = [] #end if <% bridge_slaves[this_master].append(iname) %> #end if ## enable IPv6 networking if we set an ipv6 address or turn on autoconfiguration #if $idata.get("ipv6_address", "") != "" or $ipv6_autoconfiguration == True #set $enableipv6 = True #end if #end for ## end looping through the interfaces to see which ones we need to configure. ## ============================================================================= ## Rewrite the interfaces file and make sure we preserve the loopback device echo "auto lo" > /target/etc/network/interfaces; \ echo " iface lo inet loopback" >> /target/etc/network/interfaces; \ echo "" >> /target/etc/network/interfaces; \ ## ============================================================================= ## now create the config file for each interface #for $iname in $ikeys ## create lots of variables to use later #set $idata = $interfaces[$iname] #set $mac = $idata.get("mac_address", "").upper() #set $mtu = $idata.get("mtu", "") #set $static = $idata.get("static", "") #set $management = $idata.get("management", "") #set $ip = $idata.get("ip_address", "") #set $netmask = $idata.get("netmask", "") #set $if_gateway = $idata.get("if_gateway", "") #set $static_routes = $idata.get("static_routes", "") #set $iface_type = $idata.get("interface_type", "").lower() #set $iface_master = $idata.get("interface_master", "") #set $bonding_opts = $idata.get("bonding_opts", "") #set $bridge_opts = $idata.get("bridge_opts", "").split(" ") #set $ipv6_address = $idata.get("ipv6_address", "") #set $ipv6_secondaries = $idata.get("ipv6_secondaries", "") #set $ipv6_mtu = $idata.get("ipv6_mtu", "") #set $ipv6_default_gateway = $idata.get("ipv6_default_gateway", "") #set $ipv6_static_routes = $idata.get("ipv6_static_routes", "") #set $devfile = "/target/etc/sysconfig/network-scripts/cobbler/ifcfg-" + $iname #set $routesfile = "/target/etc/sysconfig/network-scripts/cobbler/route-" + $iname #set $ipv6_routesfile = "/target/etc/sysconfig/network-scripts/cobbler/route6-" + $iname ## determine if this interface is for a VLAN #if $vlanpattern.match($iname) #set $is_vlan = "true" #else #set $is_vlan = "false" #end if ## slave interfaces are assumed to be static #if $iface_type in ("slave","bond_slave","bridge_slave","bonded_bridge_slave") #set $static = 1 #end if ## =================================================================== ## Things every interface get, no matter what ## =================================================================== echo "auto $iname" >> /target/etc/network/interfaces; \ ## =================================================================== ## Actions based on static configuration ## =================================================================== #if $static #if $iface_type not in ("slave","bond_slave","bridge_slave","bonded_bridge_slave") echo "iface $iname inet static" >> /target/etc/network/interfaces; \ #if $mac != "" echo " hwaddress $mac" >> /target/etc/network/interfaces; \ #end if #if $iname in $promisc_interfaces echo " address 0.0.0.0" >> /target/etc/network/interfaces; \ echo " up ifconfig $iname promisc up" >> /target/etc/network/interfaces; \ echo " down ifconfig $iname promisc down" >> /target/etc/network/interfaces; \ #else #if $ip != "" echo " address $ip" >> /target/etc/network/interfaces; \ #end if #if $if_gateway != "" echo " gateway $if_gateway" >> /target/etc/network/interfaces; \ #end if #if $netmask == "" ## Default to 255.255.255.0? #set $netmask = "255.255.255.0" #end if echo " netmask $netmask" >> /target/etc/network/interfaces; \ #end if #if $iface_type in ("master","bond") #set $bondslaves = "" #for $bondiname in $ikeys #set $bondidata = $interfaces[$bondiname] #set $bondiface_type = $bondidata.get("interface_type", "").lower() #set $bondiface_master = $bondidata.get("interface_master", "") #if $bondiface_master == $iname #set $bondslaves += $bondiname + " " #end if #end for echo " bond-slaves $bondslaves" >> /target/etc/network/interfaces; \ #for $bondopts in $bonding_opts.split(" ") #set [$bondkey, $bondvalue] = $bondopts.split("=") echo " bond-$bondkey $bondvalue" >> /target/etc/network/interfaces; \ #end for #end if #else echo "iface $iname inet manual" >> /target/etc/network/interfaces; \ #end if #if $iface_type in ("slave","bond_slave") and $iface_master != "" echo "bond-master $iface_master" >> /target/etc/network/interfaces; \ #end if #else echo "iface $iname inet dhcp" >> /target/etc/network/interfaces; \ #end if ## =================================================================== ## VLAN configuration ## =================================================================== #if $is_vlan == "true" #pass #end if ## =================================================================== ## Optional configuration stuff ## =================================================================== #if $mtu != "" echo " mtu $mtu" >> /target/etc/network/interfaces; \ #end if ## =================================================================== ## Interface route configuration ## =================================================================== #for $route in $static_routes #set routepattern = $re.compile("[0-9/.]+:[0-9.]+") #if $routepattern.match($route) #set [$network, $router] = $route.split(":") echo " up ip route add $network via $router dev $iname || true" >> /target/etc/network/interfaces; \ #else echo " # Warning: invalid route: $route" >> /target/etc/network/interfaces; \ #end if #end for #if $enableipv6 == True #for $route in $ipv6_static_routes #set routepattern = $re.compile("[0-9a-fA-F:/]+,[0-9a-fA-F:]+") #if $routepattern.match($route) #set [$network, $router] = $route.split(",") echo " up ip -6 route add $network via $router dev $iname || true" >> /target/etc/network/interfaces; \ #else echo " # Warning: invalid route: $route" >> /target/etc/network/interfaces; \ #end if #end for #end if #if $management #if $gateway != "" and $if_gateway == "" echo " gateway $gateway" >> /target/etc/network/interfaces; \ #end if ## ============================================================================= ## Configure name server search path in /target/etc/resolv.conf #set $nameservers = ' '.join($name_servers) #set $nameserver_search = ' '.join($name_servers_search) #if $nameservers != "" echo " dns-nameservers $nameservers" >> /target/etc/network/interfaces; \ #end if #if $nameserver_search != "" echo " dns-search $nameserver_search" >> /target/etc/network/interfaces; \ #end if #end if echo "" >> /target/etc/network/interfaces; \ ## =================================================================== ## Done with this interface ## =================================================================== #end for cp /target/etc/network/interfaces /etc/network/interfaces; \ ## ============================================================================= ## Configure the system's primary hostname. This is also passed to anaconda, but ## anaconda doesn't seem to honour it in DHCP-setups. #if $hostname != "" echo "$hostname" > /target/etc/hostname; \ #end if $SNIPPET('preseed_hosts') echo "processed preseed_hosts" >> /tmp/preseed.log; \ #end if ## End post_install_network_config generated code