aboutsummaryrefslogtreecommitdiffstats
path: root/deploy/adapters/cobbler/snippets/kickstart_post_install_network_config
blob: 1a5a7f66f3bb152eda8e902bb966f56838190b89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
# 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 -f /etc/sysconfig/network.cobbler /etc/sysconfig/network
#end if

cat << EOF > /sbin/ifup-local
#raw
#!/bin/bash
RC=0
PROM=\$(egrep -i 'promisc' /etc/sysconfig/network-scripts/ifcfg-\$1 | awk -F"=" '{ print \$2 }')
if [[ "\$PROM" == "yes" ]]; then
  ip link set dev \$1 promisc on
  RC=\$?
fi
exit \$RC
#end raw
EOF
chmod +x /sbin/ifup-local

#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 -f /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

# get physical interfaces
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

# map physical interface to mac address
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_interfaces
declare -A logical_interface_mapping
declare -A physical_interface_mapping

#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 $interface_type in ("master","bond","bridge","bonded_bridge_slave")
        #continue
    #end if
    #if $vlanpattern.match($iname)
        #set $interface_matched = $vlanpattern.match($iname)
        #set $interface_name = $interface_matched.group(1)
logical_interface=${interface_name}
    #elif $subinterfacepattern.match($iname)
        #set $interface_matched = $subinterfacepattern.match($iname)
        #set $interface_name = $interface_matched.group(1)
logical_interface=${interface_name}
    #else
logical_interface=$iname
    #end if
logical_interfaces[\${logical_interface}]=\${logical_interface}
    #if $mac != ""
physical_interface=\${physical_mac_interface[$mac]}
logical_interface_mapping[\${logical_interface}]=\${physical_interface}
if [ ! -z "\$physical_interface" ]; then
    physical_interface_mapping[\${physical_interface}]=\${logical_interface}
fi
    #else
if [ -z "\${logical_interface_mapping[\${logical_interface}]}" ]; then
    logical_interface_mapping[\${logical_interface}]=""
fi
    #end if
#end for

echo "finish mapping logical interfaces in network config to physical interfaces" >> /tmp/network_log
for key in \${!logical_interface_mapping[@]}; do
    echo "map logical interface to physical interface: \$key => \${logical_interface_mapping[\$key]}" >> /tmp/network_log
done

for key in \${!physical_interface_mapping[@]}; do
    echo "map physical interface to logical interface: \$key => \${physical_interface_mapping[\$key]}" >> /tmp/network_log
done

# map unmapped logical interface to the same name physical interface
echo "mapping unmapped logical interfaces to the same name physical interfaces" >> /tmp/network_log
for logical_interface in \${!logical_interface_mapping[@]}; do
    physical_interface=\${logical_interface_mapping[\${logical_interface}]}
    if [ -z "\${physical_interface}" ]; then
        # check if the same name physical interface is mapped
    mapped_logical_interface=\${physical_interface_mapping[\${logical_interface}]}
    if [ -z "\${mapped_logical_interface}" ]; then
            # check if the same name physical interface exists
            if [ ! -z "\${physical_interfaces[\${logical_interface}]}" ]; then
                logical_interface_mapping[\${logical_interface}]=\${logical_interface}
            physical_interface_mapping[\${logical_interface}]=\${logical_interface}
        else
            echo "ignore logical interface \${logical_interface} since the same name physical interface does not exist" >> /tmp/network_log
            fi
    else
        echo "ignore logical interface \${logical_interface} since the same name physical interface is mapped by logical interface \${mapped_logical_interface}" >> /tmp/network_log
    fi
    else
        echo "ignore logical interface \${logical_interface} since it is mapped to physical interface \${physical_interface}" >> /tmp/network_log
    fi
done

echo "finish mapping unmapped logical interfaces in network config to the same name physical interfaces" >> /tmp/network_log
for key in \${!logical_interface_mapping[@]}; do
    echo "map logical interface to physical interface: \$key => \${logical_interface_mapping[\$key]}" >> /tmp/network_log
done

for key in \${!physical_interface_mapping[@]}; do
    echo "map physical interface to logical interface: \$key => \${physical_interface_mapping[\$key]}" >> /tmp/network_log
done

declare -A unset_logical_interfaces
declare -A unset_physical_interfaces

echo "get unset logical interfaces from \${logical_interfaces[@]}" >> /tmp/network_log
for logical_interface in \${logical_interfaces[@]}; do
    physical_interface=\${logical_interface_mapping[\${logical_interface}]}
    if [ -z "\${physical_interface}" ]; then
        unset_logical_interfaces[\${logical_interface}]=\${logical_interface}
    else
        echo "ignore logical interface \${logical_interface} => \${physical_interface}" >> /tmp/network_log
    fi
done
echo "got unset logical interfaces: \${unset_logical_interfaces[@]}" >> /tmp/network_log

echo "get unset physical interfaces" >> /tmp/network_log
for physical_interface in \${physical_interfaces[@]}; do
    logical_interface=\${physical_interface_mapping[\${physical_interface}]}
    if [ -z "\${logical_interface}" ]; then
        unset_physical_interfaces[\${physical_interface}]=\${physical_interface}
    else
        echo "ignore physical interface \${physical_interface} => \${logical_interface}" >> /tmp/network_log
    fi
done
echo "got unset physical interfaces: \${unset_physical_interfaces[@]}" >> /tmp/network_log

sorted_unset_physical_interfaces=(\$(printf '%s\n' \${unset_physical_interfaces[@]} | sort))
echo "sorted unset physical interfaces: \${sorted_unset_physical_interfaces[@]}" >> /tmp/network_log
sorted_unset_logical_interfaces=(\$(printf '%s\n' \${unset_logical_interfaces[@]} | sort))
echo "sorted unset logical interfaces: \${sorted_unset_logical_interfaces[@]}" >> /tmp/network_log

# map unset logical interface to unset physical interface
while [ \${#sorted_unset_physical_interfaces[@]} -gt 0 -a \${#sorted_unset_logical_interfaces[@]} -gt 0 ]; do
    physical_interface=\${sorted_unset_physical_interfaces[0]}
    logical_interface=\${sorted_unset_logical_interfaces[0]}
    echo "map unset logical interface \${logical_interface} to unset physical interface \${physical_interface}" >> /tmp/network_log
    unset sorted_unset_physical_interfaces[0]
    unset sorted_unset_logical_interfaces[0]
    unset unset_physical_interfaces[\${physical_interface}]
    unset unset_logical_interfaces[\${logical_interface}]
    logical_interface_mapping[\${logical_interface}]=\${physical_interface}
    physical_interface_mapping[\${physical_interface}]=\${logical_interface}
done

echo "finish mapping unmapped logical interfaces in network config to unmapped physical interfaces" >> /tmp/network_log
for key in \${!logical_interface_mapping[@]}; do
    echo "map logical interface to physical interface: \$key => \${logical_interface_mapping[\$key]}" >> /tmp/network_log
done

for key in \${!physical_interface_mapping[@]}; do
    echo "map physical interface to logical interface: \$key => \${physical_interface_mapping[\$key]}" >> /tmp/network_log
done

echo "unset logical interfaces: \${unset_logical_interfaces[@]}" >> /tmp/network_log
echo "unset physical interfaces: \${unset_physical_interfaces[@]}" >> /tmp/network_log

# map any unmapped logical interfaces
echo "map unmapped logical interfaces" >> /tmp/network_log
if [ \${#sorted_unset_logical_interfaces[@]} -gt 0 ]; then
    declare -A available_logical_interfaces
    # get all available logical interfaces which the same name physical interface is not used
    for logical_interface in \${logical_interfaces[@]}; do
        mapped_logical_interface=\${physical_interface_mapping[\${logical_interface}]}
    if [ -z "\${mapped_logical_interface}" ]; then
        available_logical_interfaces[\${logical_interface}]=\${logical_interface}
    else
        echo "ignore logical interface \${logical_interface} since the same name physical interface mapped to logical interface \${mapped_logical_interface}" >> /tmp/network_log
    fi
    done

    #first map logical interface to the same name physical interface if that physical interface name is not used
    for logical_interface in \${sorted_unset_logical_interfaces[@]}; do
        available_logical_interface=\${available_logical_interfaces[\${logical_interface}]}
    if [ ! -z "\${available_logical_interface}" ]; then
        unset unset_logical_interfaces[\${logical_interface}]
        unset available_logical_interfaces[\${available_logical_interface}]
        logical_interface_mapping[\${logical_interface}]=\${available_logical_interface}
        physical_interface_mapping[\${available_logical_interface}]=\${logical_interface}
    fi
    done

    echo "finish mapping ramaining unmapped logical interfaces to the same name physical interface" >> /tmp/network_log
    for key in \${!logical_interface_mapping[@]}; do
        echo "map logical interface to physical interface: \$key => \${logical_interface_mapping[\$key]}" >> /tmp/network_log
    done

    for key in \${!physical_interface_mapping[@]}; do
        echo "map physical interface to logical interface: \$key => \${physical_interface_mapping[\$key]}" >> /tmp/network_log
    done

    echo "unset logical interfaces: \${unset_logical_interfaces[@]}" >> /tmp/network_log
    echo "unset physical interfaces: \${unset_physical_interfaces[@]}" >> /tmp/network_log

    # map remain unset logical interfaces to available logical interface names
    sorted_unset_logical_interfaces=(\$(printf '%s\n' \${unset_logical_interfaces[@]} | sort))
    echo "sorted unset logical interfaces: \${sorted_unset_logical_interfaces[@]}" >> /tmp/network_log
    sorted_available_logical_interfaces=(\$(printf '%s\n' \${available_logical_interfaces[@]} | sort))
    echo "sorted available logical interfaces: \${sorted_available_logical_interfaces[@]}" >> /tmp/network_log
    while [ \${#sorted_unset_logical_interfaces[@]} -gt 0 -a \${#sorted_available_logical_interfaces[@]} -gt 0 ]; do
        logical_interface=\${sorted_unset_logical_interfaces[0]}
    available_logical_interface=\${sorted_available_logical_interfaces[0]}
    echo "map logical interface \${logical_interface} to unused physical interface \${available_logical_interface}" >> /tmp/network_log
        unset sorted_unset_logical_interfaces[0]
    unset unset_logical_interfaces[\${logical_interface}]
    unset sorted_available_logical_interfaces[0]
    unset available_logical_interfaces[\${available_logical_interface}]
    logical_interface_mapping[\${logical_interface}]=\${available_logical_interface}
    physical_interface_mapping[\${available_logical_interface}]=\${logical_interface}
    done
fi

echo "finish mapping ramaining unmapped logical interfaces" >> /tmp/network_log
for key in \${!logical_interface_mapping[@]}; do
    echo "map logical interface to physical interface: \$key => \${logical_interface_mapping[\$key]}" >> /tmp/network_log
done

for key in \${!physical_interface_mapping[@]}; do
    echo "map physical interface to logical interface: \$key => \${physical_interface_mapping[\$key]}" >> /tmp/network_log
done

echo "unset logical interfaces: \${unset_logical_interfaces[@]}" >> /tmp/network_log
echo "unset physical interfaces: \${unset_physical_interfaces[@]}" >> /tmp/network_log

# map any unmapped physical interfaces
echo "map unmapped physical interfaces" >> /tmp/network_log
if [ \${#sorted_unset_physical_interfaces[@]} -gt 0 ]; then
    declare -A available_physical_interfaces
    # get all available physical interfaces which the same name logical interface is not used
    for physical_interface in \${physical_interfaces[@]}; do
        mapped_physical_interface=\${logical_interface_mapping[\${physical_interface}]}
    if [ -z "\${mapped_physical_interface}" ]; then
        available_physical_interfaces[\${physical_interface}]=\${physical_interface}
    else
        echo "ignore physical interface \${physical_interface} since the same name logical interface mapped to physical interface \${mapped_physical_interface}" >> /tmp/network_log
    fi
    done

    #first map physical interface to the same name logical interface if that logical interface name is not used
    for physical_interface in \${sorted_unset_physical_interfaces[@]}; do
        available_physical_interface=\${available_physical_interfaces[\${physical_interface}]}
    if [ ! -z "\${available_physical_interface}" ]; then
        unset unset_physical_interfaces[\${physical_interface}]
        unset available_physical_interfaces[\${available_physical_interface}]
        logical_interface_mapping[\${available_physical_interface}]=\${physical_interface}
        physical_interface_mapping[\${physical_interface}]=\${available_physical_interface}
    fi
    done
    echo "finish mapping ramaining unmapped physical interfaces to the same name logical interface" >> /tmp/network_log
    for key in \${!logical_interface_mapping[@]}; do
        echo "map logical interface to physical interface: \$key => \${logical_interface_mapping[\$key]}" >> /tmp/network_log
    done

    for key in \${!physical_interface_mapping[@]}; do
        echo "map physical interface to logical interface: \$key => \${physical_interface_mapping[\$key]}" >> /tmp/network_log
    done

    echo "unset logical interfaces: \${unset_logical_interfaces[@]}" >> /tmp/network_log
    echo "unset physical interfaces: \${unset_physical_interfaces[@]}" >> /tmp/network_log

    # map remain unset physical interfaces to logical interface name as available physical interface names
    sorted_unset_physical_interfaces=(\$(printf '%s\n' \${unset_physical_interfaces[@]} | sort))
    echo "sorted unset physical interfaces: \${sorted_unset_physical_interfaces[@]}" >> /tmp/network_log
    sorted_available_physical_interfaces=(\$(printf '%s\n' \${available_physical_interfaces[@]} | sort))
    echo "sorted available physical interfaces: \${sorted_available_physical_interfaces[@]}" >> /tmp/network_log
    while [ \${#sorted_unset_physical_interfaces[@]} -gt 0 -a \${#sorted_available_physical_interfaces[@]} -gt 0 ]; do
        physical_interface=\${sorted_unset_physical_interfaces[0]}
    available_physical_interface=\${sorted_available_physical_interfaces[0]}
    echo "map physical interface \${physical_interface} to unused logical interface \${available_physical_interface}" >> /tmp/network_log
        unset sorted_unset_physical_interfaces[0]
    unset unset_physical_interfaces[\${physical_interface}]
    unset sorted_available_physical_interfaces[0]
    unset available_physical_interfaces[\${available_physical_interface}]
    physical_interface_mapping[\${available_physical_interface}]=\${physical_interface}
    logical_interface_mapping[\${physical_interface}]=\${available_physical_interface}
    done
fi

echo "finish mapping ramaining unmapped physical interfaces" >> /tmp/network_log
for key in \${!logical_interface_mapping[@]}; do
    echo "map logical interface to physical interface: \$key => \${logical_interface_mapping[\$key]}" >> /tmp/network_log
done

for key in \${!physical_interface_mapping[@]}; do
    echo "map physical interface to logical interface: \$key => \${physical_interface_mapping[\$key]}" >> /tmp/network_log
done

echo "unset logical interfaces: \${unset_logical_interfaces[@]}" >> /tmp/network_log
echo "unset physical interfaces: \${unset_physical_interfaces[@]}" >> /tmp/network_log

for key in \${!logical_interface_mapping[@]}; do
    echo "map logical interface to physical interface: \$key => \${logical_interface_mapping[\$key]}" >> /tmp/network_log
done

for key in \${!physical_interface_mapping[@]}; do
    echo "map physical interface to logical interface: \$key => \${physical_interface_mapping[\$key]}" >> /tmp/network_log
done

# generate udev network rules
#if $osversion == "rhel7"
udev_network_rule_filename=80-net-name-slot.rules
#else
udev_network_rule_filename=70-persistent-net.rules
#end if
for key in \${!logical_interface_mapping[@]}; do
    physical_interface=\${logical_interface_mapping[\$key]}
    if [ ! -z "\${physical_interface}" ]; then
        physical_mac=\${physical_interface_mac[\${physical_interface}]}
    else
        physical_mac=""
    fi
    if [ ! -z "\${physical_mac}" ]; then
        physical_mac=\${physical_mac,,}
        echo "SUBSYSTEM==\"net\", ACTION==\"add\", DRIVERS==\"?*\", ATTR{address}==\"\${physical_mac}\", ATTR{type}==\"1\", KERNEL==\"eth*\", NAME=\"\$key\"" >> /etc/udev/rules.d/\${udev_network_rule_filename}.new
    echo "add network interface \$key mac \$physical_mac into udev rules" >> /tmp/network_log
    else
        echo "network interface \$key does not find mac address to add to udev rules" >> /tmp/network_log
    fi
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/

declare -A used_logical_interfaces

#set $nameserver_set = 0

#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

used_logical_interfaces[$iname]=$iname

    #if $iface_type in ("slave","bridge_slave","bonded_bridge_slave")
        #set $static = 1
    #end if
    #if $ip == ""
        #set $static = ""
    #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 [ ! -z "\$physical_interface" ]; then
    physical_mac=\${physical_interface_mac[\$physical_interface]}
fi
if [ ! -z "\$physical_mac" ]; then
    echo "HWADDR=\$physical_mac" >> $devfile
fi
            #if not $subinterfacepattern.match($iname)
if [ -f "/etc/modprobe.conf" ] && [ ! -z "\${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 -f /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 $static
echo "BOOTPROTO=static" >> $devfile
        #if $iname in $promisc_interfaces
echo "PROMISC=yes" >> $devfile
        #elif $ip != ""
echo "IPADDR=$ip" >> $devfile
            #if $if_gateway != ""
echo "GATEWAY=$if_gateway" >> $devfile
            #end if

            #if $netmask == ""
            ## Default to 255.255.255.0?
                #set $netmask = "255.255.255.0"
            #end if
echo "NETMASK=$netmask" >> $devfile
        #end if
    #else
echo "BOOTPROTO=manual" >> $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 not $nameserver_set
        #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
        #set $nameserver_set = 1
        #end if
   #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 logical_interface in \${!logical_interface_mapping[@]}; do
    if [ ! -z "\${used_logical_interfaces[\${logical_interface}]}" ]; then
        # ignore logical interface that is already generated in above
        continue
    fi
    physical_interface=\${logical_interface_mapping[\${logical_interface}]}
    if [ ! -z "\${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 [ ! -z "\$mac" ]; then
            echo "HWADDR=\$mac" >> \$devfile
        fi
        echo "TYPE=Ethernet" >> \$devfile
        if [ -f "/etc/modprobe.conf" ] && [ ! -z "\${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 -f /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-*

## Move all staged files to their final location
rm -f /etc/sysconfig/network-scripts/ifcfg-*
mv -f /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/\${udev_network_rule_filename}" ]; then
    rm -f /etc/udev/rules.d/\${udev_network_rule_filename}
fi

if [ -f "/etc/udev/rules.d/\${udev_network_rule_filename}.new" ]; then
    mv -f /etc/udev/rules.d/\${udev_network_rule_filename}.new /etc/udev/rules.d/\${udev_network_rule_filename}
fi
# End post_install_network_config generated code