# 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 $gateway != "" # set the gateway in the network configuration file grep -v GATEWAY /etc/sysconfig/network > /etc/sysconfig/network.cobbler echo "GATEWAY=$gateway" >> /etc/sysconfig/network.cobbler rm -f /etc/sysconfig/network mv /etc/sysconfig/network.cobbler /etc/sysconfig/network #end if #if $hostname != "" # set the hostname in the network configuration file grep -v HOSTNAME /etc/sysconfig/network > /etc/sysconfig/network.cobbler echo "HOSTNAME=$hostname" >> /etc/sysconfig/network.cobbler rm -f /etc/sysconfig/network mv /etc/sysconfig/network.cobbler /etc/sysconfig/network /bin/hostname $hostname #end if $SNIPPET('kickstart_hosts') #set $num_ns_search = $len($name_servers_search) #if $num_ns_search > 0 sed -i -e "/^search /d" /etc/resolv.conf echo -n "search " >>/etc/resolv.conf #for $nameserversearch in $name_servers_search echo -n "$nameserversearch " >>/etc/resolv.conf #end for echo "" >>/etc/resolv.conf #end if #set $num_ns = $len($name_servers) #if $num_ns > 0 sed -i -e "/^nameserver /d" /etc/resolv.conf #for $nameserver in $name_servers echo "nameserver $nameserver" >>/etc/resolv.conf #end for #end if declare -A physical_interfaces set \$(ip -o link | grep -v lo | awk '{print \$2}' | sed 's/://') let physical_interface_num=\$#; let physical_interface_offset=0 echo "network interface numbers: \$physical_interface_num" > /tmp/network_log while [ \$physical_interface_offset -lt \$physical_interface_num ]; do physical_interfaces[\$1]=\$1 let physical_interface_offset=\$physical_interface_offset+1 shift 1 done echo "interfaces: \${physical_interfaces[@]}" >> /tmp/network_log declare -A physical_interface_mac declare -A physical_mac_interface for physical_interface in \${physical_interfaces[@]}; do mac=\$(cat /sys/class/net/\${physical_interface}/address) mac=\${mac^^} physical_interface_mac[\${physical_interface}]=\$mac physical_mac_interface[\$mac]=\${physical_interface} done for key in \${!physical_interface_mac[@]}; do echo "interface to mac: $key => \${physical_interface_mac[\$key]}" >> /tmp/network_log done for key in \${!physical_mac_interface[@]}; do echo "mac to interface: $key => \${physical_mac_interface[\$key]}" >> /tmp/network_log done declare -A logical_interface_mapping declare -A unset_logical_interfaces declare -A used_physical_interfaces #set ikeys = $interfaces.keys() #set osversion = $getVar("os_version","") #import re #set $vlanpattern = $re.compile("([a-zA-Z0-9]+)[\.][0-9]+") #set $subinterfacepattern = $re.compile("([a-zA-Z0-9]+)[:][0-9]+") #set $numbondingdevs = 0 #for $iname in $ikeys #set $idata = $interfaces[$iname] #set $mac = $idata.get("mac_address", "").upper() #set $interface_type = $idata.get("interface_type", "").lower() #if $interface_type in ("master","bond","bonded_bridge_slave") #set $numbondingdevs += 1 #end if #if $mac != "" physical_interface=\${physical_mac_interface[$mac]} logical_interface_mapping[$iname]=\$physical_interface if [ -n "\$physical_interface" ]; then unset physical_interfaces[\$physical_interface] if [ "\$physical_interface" != "$iname" ]; then used_physical_interfaces[\$physical_interface]=\$physical_interface fi fi #else logical_interface_mapping[$iname]="" unset_logical_interfaces[$iname]=$iname #end if #end for echo "unset logical interfaces: \${unset_logical_interfaces[@]}" >> /tmp/network_log for logical_interface in \${unset_logical_interfaces[@]}; do if [ -n "\${physical_interfaces[\$logical_interface]}" ]; then logical_interface_mapping[\$logical_interface]=\$logical_interface unset unset_logical_interfaces[\$logical_interface] unset physical_interfaces[\$logical_interface] fi done sorted_physical_interfaces=(\$(printf '%s\n' \${physical_interfaces[@]} | sort)) echo "sorted physical interfaces: \${sorted_physical_interfaces[@]}" >> /tmp/network_log sorted_unset_logical_interfaces=(\$(printf '%s\n' \${unset_logical_interfaces[@]} | sort)) echo "sorted logical interfaces: \${sorted_unset_logical_interfaces[@]}" >> /tmp/network_log while [ \${#sorted_physical_interfaces[@]} -gt 0 -a \${#sorted_unset_logical_interfaces[@]} -gt 0 ]; do physical_interface=\${sorted_physical_interfaces[0]} logical_interface=\${sorted_unset_logical_interfaces[0]} unset sorted_physical_interfaces[0] unset sorted_unset_logical_interfaces[0] unset physical_interfaces[\$physical_interface] unset unset_logical_interfaces[\$logical_interface] logical_interface_mapping[\$logical_interface]=\$physical_interface done sorted_used_physical_interfaces=(\$(printf '%s\n' \${used_physical_interfaces[@]} | sort)) while [ \${#sorted_physical_interfaces[@]} -gt 0 -a \${#sorted_used_physical_interfaces[@]} -gt 0 ]; do physical_interface=\${sorted_physical_interfaces[0]} logical_interface=\${sorted_used_physical_interfaces[0]} unset sorted_physical_interfaces[0] unset sorted_used_physical_interfaces[0] unset physical_interfaces[\$physical_interface] unset used_physical_interfaces[\$logical_interface] logical_interface_mapping[\$logical_interface]=\$physical_interface done for key in \${!logical_interface_mapping[@]}; do echo "map logical interface to physical interface: \$key => \${logical_interface_mapping[\$key]}" >> /tmp/network_log done #if $numbondingdevs > 0 # we have bonded interfaces, so set max_bonds if [ -f "/etc/modprobe.conf" ]; then echo "options bonding max_bonds=$numbondingdevs" >> /etc/modprobe.conf fi #end if # create a working directory for interface scripts mkdir /etc/sysconfig/network-scripts/cobbler cp /etc/sysconfig/network-scripts/ifcfg-lo /etc/sysconfig/network-scripts/cobbler/ #for $iname in $ikeys # Start configuration for $iname ## 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 $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 $devfile = "/etc/sysconfig/network-scripts/cobbler/ifcfg-" + $iname #set $routesfile = "/etc/sysconfig/network-scripts/cobbler/route-" + $iname #if $iface_type in ("slave","bond_slave","bridge_slave","bonded_bridge_slave") #set $static = 1 #end if echo "DEVICE=$iname" > $devfile echo "ONBOOT=yes" >> $devfile #if $iface_type not in ("master","bond","bridge","bonded_bridge_slave") #if $vlanpattern.match(iname) pass #else #set $interface_matched = $subinterfacepattern.match($iname) #if $interface_matched #set $interface_name = $interface_matched.group(1) logical_interface=$interface_name #else logical_interface=$iname #end if physical_interface=\${logical_interface_mapping[\$logical_interface]} if [ -n "\$physical_interface" ]; then physical_mac=\${physical_interface_mac[\$physical_interface]} fi if [ -n "\$physical_mac" ]; then echo "HWADDR=\$physical_mac" >> $devfile fi #if not $subinterfacepattern.match($iname) if [ -f "/etc/modprobe.conf" ] && [ -n "\$physical_interface" ]; then grep \$physical_interface /etc/modprobe.conf | sed "s/\$physical_interface/$iname/" >> /etc/modprobe.conf.cobbler grep -v \$physical_interface /etc/modprobe.conf >> /etc/modprobe.conf.new rm -f /etc/modprobe.conf mv /etc/modprobe.conf.new /etc/modprobe.conf fi #end if #end if #end if #if $iface_type in ("master","bond","bonded_bridge_slave") ## if this is a bonded interface, configure it in modprobe.conf if [ -f "/etc/modprobe.conf" ]; then #if $osversion == "rhel4" echo "install $iname /sbin/modprobe bonding -o $iname $bonding_opts" >> /etc/modprobe.conf.cobbler #else echo "alias $iname bonding" >> /etc/modprobe.conf.cobbler #end if fi #if $bonding_opts != "" cat >> $devfile << EOF BONDING_OPTS="$bonding_opts" EOF #end if #elif $iface_type in ("slave","bond_slave") and $iface_master != "" echo "SLAVE=yes" >> $devfile echo "MASTER=$iface_master" >> $devfile echo "HOTPLUG=no" >> $devfile #end if #if $iface_type == "bridge" echo "TYPE=Bridge" >> $devfile #for $bridge_opt in $bridge_opts #if $bridge_opt.strip() != "" echo "$bridge_opt" >> $devfile #end if #end for #elif $iface_type in ["bridge_slave", "bonded_bridge_slave"] and $iface_master != "" echo "BRIDGE=$iface_master" >> $devfile echo "HOTPLUG=no" >> $devfile #end if #if $iface_type != "bridge" echo "TYPE=Ethernet" >> $devfile #end if #if $iname in $promisc_interfaces echo "PROMISC=yes" >> $devfile #end if #if $static echo "BOOTPROTO=static" >> $devfile #if $ip != "" and $iname not in $promisc_interfaces echo "IPADDR=$ip" >> $devfile #end if #if $if_gateway != "" echo "GATEWAY=$if_gateway" >> $devfile #end if #if $netmask == "" #set $netmask = "255.255.255.0" #end if echo "NETMASK=$netmask" >> $devfile #else echo "BOOTPROTO=dhcp" >> $devfile #if $len($name_servers) > 0 echo "PEERDNS=no" >> $devfile #end if #end if #if $vlanpattern.match($iname) echo "VLAN=yes" >> $devfile echo "ONPARENT=yes" >> $devfile #elif $subinterfacepattern.match($iname) echo "ONPARENT=yes" >> $devfile #end if #if $mtu != "" echo "MTU=$mtu" >> $devfile #end if #if $iface_type not in ("slave","bond_slave","bridge_slave","bonded_bridge_slave") #set $nct = 0 #for $nameserver in $name_servers #set $nct = $nct + 1 echo "DNS$nct=$nameserver" >> $devfile #end for #end if #for $route in $static_routes #set routepattern = $re.compile("[0-9/.]+:[0-9.]+") #if $routepattern.match($route) #set $routebits = $route.split(":") #set [$network, $router] = $route.split(":") echo "$network via $router" >> $routesfile #else # Warning: invalid route "$route" #end if #end for #end for #for $iname in $ikeys #set $interface_matched = $subinterfacepattern.match($iname) #if $interface_matched #set $interface_name = $interface_matched.group(1) logical_interface=$interface_name #else logical_interface=$iname #end if unset logical_interface_mapping[\$logical_interface] #end for for logical_interface in \${!logical_interface_mapping[@]}; do physical_interface=\${logical_interface_mapping[\$logical_interface]} if [ -n "\$physical_interface" ]; then devfile="/etc/sysconfig/network-scripts/cobbler/ifcfg-"\$logical_interface mac=\${physical_interface_mac[\$physical_interface]} echo "DEVICE=\$logical_interface" > \$devfile echo "ONBOOT=yes" >> \$devfile echo "BOOTPROTO=static" >> \$devfile if [ -n "\$mac" ]; then echo "HWADDR=\$mac" >> \$devfile fi echo "TYPE=Ethernet" >> \$devfile if [ -f "/etc/modprobe.conf" ] && [ -n "\$physical_interface" ]; then grep \$physical_interface /etc/modprobe.conf | sed "s/\$physical_interface/\$logical_interface/" >> /etc/modprobe.conf.cobbler grep -v \$physical_interface /etc/modprobe.conf >> /etc/modprobe.conf.new rm -f /etc/modprobe.conf mv /etc/modprobe.conf.new /etc/modprobe.conf fi fi done ## Disable all eth interfaces by default before overwriting ## the old files with the new ones in the working directory ## This stops unneccesary (and time consuming) DHCP queries ## during the network initialization sed -i 's/ONBOOT=yes/ONBOOT=no/g' /etc/sysconfig/network-scripts/ifcfg-eth* ## Move all staged files to their final location rm -f /etc/sysconfig/network-scripts/ifcfg-* mv /etc/sysconfig/network-scripts/cobbler/* /etc/sysconfig/network-scripts/ rm -r /etc/sysconfig/network-scripts/cobbler if [ -f "/etc/modprobe.conf" ]; then cat /etc/modprobe.conf.cobbler >> /etc/modprobe.conf rm -f /etc/modprobe.conf.cobbler fi if [ -f "/etc/udev/rules.d/70-persistent-net.rules" ]; then rm -f /etc/udev/rules.d/70-persistent-net.rules fi # End post_install_network_config generated code