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
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
|
## 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 $hostname != ""
# set the hostname
echo "$hostname" > /etc/hostname
/bin/hostname $hostname
#end if
#set osversion = $getVar("os_version","")
$SNIPPET('preseed_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
echo '' > /tmp/network_log
# get physical interfaces
physical_interfaces=""
for physical_interface in \$(ip -o link | cut -d: -f2 | grep -v lo); do
echo "processing physical interface \${physical_interface}" >> /tmp/network_log
if [ -z "\${physical_interfaces}" ]; then
physical_interfaces="\${physical_interface}"
else
physical_interfaces="\${physical_interfaces} \${physical_interface}"
fi
eval "physical_interface_\${physical_interface}=\${physical_interface}"
done
echo "physical interfaces: \${physical_interfaces}" >> /tmp/network_log
# map physical interface to mac address
mac_names=""
for physical_interface in \${physical_interfaces}; do
set \$(ip link show \${physical_interface})
#if $osversion == "trusty"
mac=\$(echo \$@ | cut -d' ' -f17)
#elif $osversion == "xenial"
mac=\$(echo \$@ | cut -d' ' -f17)
#else
mac=\$(echo \$@ | cut -d' ' -f13)
#end if
mac_name=\$(echo \${mac} |tr 'a-z' 'A-Z' | tr ':' '_')
if [ -z "\${mac_name}" ]; then
mac_names="\${mac_name}"
else
mac_names="\${mac_names} \${mac_name}"
fi
echo "mapping physical interface \${physical_interface} to mac \${mac}" >> /tmp/network_log
eval "physical_interface_mac_\${physical_interface}=\$mac"
eval "physical_mac_interface_\${mac_name}=\${physical_interface}"
eval "mac_name_\${mac_name}=\$mac"
done
echo "list physical interfaces to mac" >> /tmp/network_log
for physical_interface in \${physical_interfaces}; do
eval "mac=\\${physical_interface_mac_\${physical_interface}}"
echo "physical interface to mac: \${physical_interface} => \${mac}" >> /tmp/network_log
done
echo "list mac to physical interface mapping" >> /tmp/network_log
for mac_name in \${mac_names}; do
eval "mac=\\${mac_name_\${mac_name}}"
eval "physical_interface=\\${physical_mac_interface_\${mac_name}}"
echo "mac to physical interface: \${mac} => \${physical_interface}" >> /tmp/network_log
done
logical_interfaces=""
#set ikeys = $interfaces.keys()
#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
if [ -z "\${logical_interfaces}" ]; then
logical_interfaces="\${logical_interface}"
else
logical_interfaces="\${logical_interfaces} \${logical_interface}"
fi
eval "logical_interface_\${logical_interface}=\${logical_interface}"
#if $mac != ""
#set mac_name = $mac.replace(':', '_')
physical_interface=\${physical_mac_interface_${mac_name}}
eval "logical_interface_mapping_\${logical_interface}=\${physical_interface}"
if [ ! -z "\${physical_interface}" ]; then
eval "physical_interface_mapping_\${physical_interface}=\${logical_interface}"
fi
#else
eval "physical_interface=\\${logical_interface_mapping_\${logical_interface}}"
if [ -z "\${physical_interface}" ]; then
eval "logical_interface_mapping_\${logical_interface}="
fi
#end if
#end for
echo "logical interfaces: \${logical_interfaces}" >> /tmp/network_log
echo "finish mapping logical interfaces in network config to physical interfaces" >> /tmp/network_log
for key in \${logical_interfaces}; do
eval "physical_interface=\\${logical_interface_mapping_\${key}}"
echo "map logical interface \${key} to physical interface \${physical_interface}" >> /tmp/network_log
done
for key in \${physical_interfaces}; do
eval "logical_interface=\\${physical_interface_mapping_\${key}}"
echo "map physical interface \${key} to logical interface \${logical_interface}" >> /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_interfaces}; do
eval "physical_interface=\\${logical_interface_mapping_\${logical_interface}}"
if [ ! -z "\${physical_interface}" ]; then
echo "ignore logical interface \${logical_interface} where its physical interface is \${physical_interface}" >> /tmp/network_log
continue
fi
# check if the same name physical interface is mapped
eval "mapped_logical_interface=\\${physical_interface_mapping_\${logical_interface}}"
if [ ! -z "\${mapped_logical_interface}" ]; then
echo "ignore logical interface \${logical_interface} since the same name physical interface is mapped by logical interface \${mapped_logical_interface}" >> /tmp/network_log
continue
fi
# check if the same name physical interface exists
eval "mapped_logical_interface=\\${physical_interface_\${logical_interface}}"
if [ -z "\${mapped_logical_interface}" ]; then
echo "ignore logical interface \${logical_interface} since the same name physical interface does not exist" >> /tmp/network_log
continue
fi
eval "logical_interface_mapping_\${logical_interface}=\${logical_interface}"
eval "physical_interface_mapping_\${logical_interface}=\${logical_interface}"
echo "set logical interface \${logical_interface} to the same physical interface" >> /tmp/network_log
done
echo "finish mapping unmapped logical interfaces in network config to the same name physical interfaces" >> /tmp/network_log
for key in \${logical_interfaces}; do
eval "physical_interface=\\${logical_interface_mapping_\${key}}"
echo "map logical interface \${key} to physical interface \${physical_interface}" >> /tmp/network_log
done
for key in \${physical_interfaces}; do
eval "logical_interface=\\${physical_interface_mapping_\${key}}"
echo "map physical interface \${key} to logical interface \${logical_interface}" >> /tmp/network_log
done
unset_physical_interfaces=""
echo "get unset physical interfaces from \${physical_interfaces}" >> /tmp/network_log
for physical_interface in \${physical_interfaces}; do
eval "logical_interface=\\${physical_interface_mapping_\${physical_interface}}"
if [ ! -z "\${logical_interface}" ]; then
echo "physical interface \${physical_interface} is already set to \${logical_interface}" >> /tmp/network_log
continue
fi
if [ -z "\${unset_physical_interfaces}" ]; then
unset_physical_interfaces="\${physical_interface}"
else
unset_physical_interfaces="\${unset_physical_interfaces} \${physical_interface}"
fi
eval "unset_physical_interface_\${physical_interface}=\${physical_interface}"
done
echo "unset physical interfaces \${unset_physical_interfaces}" >> /tmp/network_log
unset_logical_interfaces=""
echo "get unset logical interfaces from \${logical_interfaces}" >> /tmp/network_log
for logical_interface in \${logical_interfaces}; do
eval "physical_interface=\\${logical_interface_mapping_\${logical_interface}}"
if [ ! -z "\${physical_interface}" ]; then
echo "logical interface \${logical_interface} is already set to \${physical_interface}" >> /tmp/network_log
continue
fi
if [ -z "\${unset_logical_interfaces}" ]; then
unset_logical_interfaces="\${logical_interface}"
else
unset_logical_interfaces="\${unset_logical_interfaces} \${logical_interface}"
fi
done
echo "unset logical interfaces \${unset_logical_interfaces}" >> /tmp/network_log
sorted_unset_physical_interfaces=\$(printf '%s\n' \${unset_physical_interfaces} | sort | xargs)
echo "sorted unset physical interfaces \${sorted_unset_physical_interfaces}" >> /tmp/network_log
sorted_unset_logical_interfaces=\$(printf '%s\n' \${unset_logical_interfaces} | sort | xargs)
echo "sorted unset logical interfaces \${sorted_unset_logical_interfaces}" >> /tmp/network_log
# map unset logical interface to unset physical interface
echo "map unset logical interfaces \${sorted_unset_logical_interfaces} to unset physical interfaces \${sorted_unset_physical_interfaces}" >> /tmp/network_log
unset_logical_interfaces=""
for logical_interface in \${sorted_unset_logical_interfaces}; do
set \${sorted_unset_physical_interfaces}
physical_interface_num=\$#;
if [ \${physical_interface_num} -gt 0 ]; then
physical_interface=\$1
shift 1
sorted_unset_physical_interfaces="\$@"
echo "map unset logical interface \${logical_interface} to unset physical interface \${physical_interface}" >> /tmp/network_log
eval "physical_interface_mapping_\${physical_interface}=\${logical_interface}"
eval "logical_interface_mapping_\${logical_interface}=\${physical_interface}"
else
echo "remain unset logical interface \${logical_interface} since there is no remain unset physical interfaces" >> /tmp/network_log
if [ -z "\${unset_logical_interfaces}" ]; then
unset_logical_interfaces="\${logical_interface}"
else
unset_logical_interfaces="\${unset_logical_interfaces} \${logical_interface}"
fi
fi
done
sorted_unset_logical_interfaces=\${unset_logical_interfaces}
unset_physical_interfaces=\${sorted_unset_physical_interfaces}
echo "finish mapping unmapped logical interfaces in network config to unmapped physical interfaces" >> /tmp/network_log
for key in \${logical_interfaces}; do
eval "physical_interface=\\${logical_interface_mapping_\${key}}"
echo "map logical interface \${key} to physical interface \${physical_interface}" >> /tmp/network_log
done
for key in \${physical_interfaces}; do
eval "logical_interface=\\${physical_interface_mapping_\${key}}"
echo "map physical interface \${key} to logical interface \${logical_interface}" >> /tmp/network_log
done
echo "unset physical interfaces \${sorted_unset_physical_interfaces}" >> /tmp/network_log
echo "unset logical interfaces \${sorted_unset_logical_interfaces}" >> /tmp/network_log
# map remaining unmapped logical interfaces
echo "map remaining unmapped logical interfaces" >> /tmp/network_log
if [ ! -z "\${sorted_unset_logical_interfaces}" ]; then
# get all available logical interfaces which the same name physical interface is not used
available_logical_interfaces=""
for logical_interface in \${logical_interfaces}; do
eval "mapped_logical_interface=\\${physical_interface_mapping_\${logical_interface}}"
if [ -z "\${mapped_logical_interface}" ]; then
eval "available_logical_interface_\${logical_interface}=\${logical_interface}"
if [ -z "\${available_logical_interfaces}" ]; then
available_logical_interfaces="\${logical_interface}"
else
available_logical_interfaces="\${available_logical_interfaces} \${logical_interface}"
fi
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
# add extra logical interfaces name to physical interfaces
if [ -z "\${physical_interfaces}" ]; then
physical_interfaces="\${available_logical_interfaces}"
else
physical_interfaces="\${physical_interfaces} \${available_logical_interfaces}"
fi
echo "updated physical interfaces: \${physical_interfaces}" >> /tmp/network_log
#first map logical interface to the same name physical interface if that physical interface name is not used
unset_logical_interfaces=""
for logical_interface in \${sorted_unset_logical_interfaces}; do
eval "available_logical_interface=\\${available_logical_interface_\${logical_interface}}"
if [ ! -z "\${available_logical_interface}" ]; then
eval "physical_interface_mapping_\${available_logical_interface}=\${logical_interface}"
eval "logical_interface_mapping_\${logical_interface}=\${available_logical_interface}"
else
if [ -z "\${unset_logical_interfaces}" ]; then
unset_logical_interfaces="\${logical_interface}"
else
unset_logical_interfaces="\${unset_logical_interfaces} \${logical_interface}"
fi
fi
done
sorted_unset_logical_interfaces=\${unset_logical_interfaces}
# map remain unset logical interfaces to available logical interface names
for logical_interface in \${sorted_unset_logical_interfaces}; do
for available_logical_interface in \${available_logical_interfaces}; do
eval "mapped_logical_interface=\\${physical_interface_mapping_\${available_logical_interface}}"
if [ -z "\${mapped_logical_interface}" ]; then
eval "physical_interface_mapping_\${available_logical_interface}=\${logical_interface}"
eval "logical_interface_mapping_\${logical_interface}=\${available_logical_interface}"
break
fi
done
done
fi
unset_logical_interfaces=""
sorted_unset_logical_interfaces=""
echo "finish mapping ramaining unmapped logical interfaces" >> /tmp/network_log
for key in \${logical_interfaces}; do
eval "physical_interface=\\${logical_interface_mapping_\${key}}"
echo "map logical interface \${key} to physical interface \${physical_interface}" >> /tmp/network_log
done
for key in \${physical_interfaces}; do
eval "logical_interface=\\${physical_interface_mapping_\${key}}"
echo "map physical interface \${key} to logical interface \${logical_interface}" >> /tmp/network_log
done
# map remaining unmapped physical interfaces
echo "map remaining unmapped physical interfaces" >> /tmp/network_log
if [ ! -z "\${sorted_unset_physical_interfaces}" ]; then
# get all available physical interfaces which the same name logical interface is not used
available_physical_interfaces=""
for physical_interface in \${physical_interfaces}; do
eval "mapped_physical_interface=\\${logical_interface_mapping_\${physical_interface}}"
if [ -z "\${mapped_physical_interface}" ]; then
eval "available_physical_interface_\${physical_interface}=\${physical_interface}"
if [ -z "\${available_physical_interfaces}" ]; then
available_physical_interfaces="\${physical_interface}"
else
available_physical_interfaces="\${available_physical_interfaces} \${physical_interface}"
fi
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
# add extra physical interfaces name to logical interfaces
if [ -z "\${logical_interfaces}" ]; then
logical_interfaces="\${available_physical_interfaces}"
else
logical_interfaces="\${logical_interfaces} \${available_physical_interfaces}"
fi
echo "updated logical interfaces: \${logical_interfaces}" >> /tmp/network_log
#first map physical interface to the same name logical interface if that logical interface name is not used
unset_physical_interfaces=""
for physical_interface in \${sorted_unset_physical_interfaces}; do
eval "available_physical_interface=\\${available_physical_interface_\${physical_interface}}"
if [ ! -z "\${available_physical_interface}" ]; then
eval "logical_interface_mapping_\${available_physical_interface}=\${physical_interface}"
eval "physical_interface_mapping_\${physical_interface}=\${available_physical_interface}"
else
if [ -z "\${unset_physical_interfaces}" ]; then
unset_physical_interfaces="\${physical_interface}"
else
unset_physical_interfaces="\${unset_physical_interfaces} \${physical_interface}"
fi
fi
done
sorted_unset_physical_interfaces=\${unset_physical_interfaces}
# map remain unset physical interfaces to logical interface name as available physical interface names
for physical_interface in \${sorted_unset_physical_interfaces}; do
for available_physical_interface in \${available_physical_interfaces}; do
eval "mapped_physical_interface=\\${logical_interface_mapping_\${available_physical_interface}}"
if [ -z "\${mapped_physical_interface}" ]; then
eval "logical_interface_mapping_\${available_physical_interface}=\${physical_interface}"
eval "physical_interface_mapping_\${physical_interface}=\${available_physical_interface}"
break
fi
done
done
fi
unset_physical_interfaces=""
sorted_unset_physical_interfaces=""
echo "finish mapping ramaining unmapped physical interfaces" >> /tmp/network_log
for key in \${logical_interfaces}; do
eval "physical_interface=\\${logical_interface_mapping_\${key}}"
echo "map logical interface \${key} to physical interface \${physical_interface}" >> /tmp/network_log
done
for key in \${physical_interfaces}; do
eval "logical_interface=\\${physical_interface_mapping_\${key}}"
echo "map physical interface \${key} to logical interface \${logical_interface}" >> /tmp/network_log
done
for key in \${logical_interfaces}; do
eval "physical_interface=\\${logical_interface_mapping_\${key}}"
if [ ! -z "\${physical_interface}" ]; then
eval "physical_mac=\\${physical_interface_mac_\${physical_interface}}"
else
physical_mac=""
fi
if [ ! -z "\${physical_mac}" ]; then
physical_mac=\$(echo \${physical_mac} | tr 'A-Z' 'a-z')
echo "SUBSYSTEM==\"net\", ACTION==\"add\", DRIVERS==\"?*\", ATTR{address}==\"\${physical_mac}\", ATTR{type}==\"1\", KERNEL==\"eth*\", NAME=\"\$key\"" >> /etc/udev/rules.d/70-persistent-net.rules.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
## =============================================================================
## Rewrite the interfaces file and make sure we preserve the loopback device
echo "auto lo" > /etc/network/interfaces
echo " iface lo inet loopback" >> /etc/network/interfaces
echo "" >> /etc/network/interfaces
#set $nameserver_set = 0
#for $iname in $ikeys
#set $idata = $interfaces[$iname]
#set $mac = $idata.get("mac_address", "").upper()
#set $iface_type = $idata.get("interface_type", "").lower()
#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_master = $idata.get("interface_master", "")
#set $bonding_opts = $idata.get("bonding_opts", "")
#set $bridge_opts = $idata.get("bridge_opts", "")
used_logical_interface_$iname=$iname
#if $iface_type in ("slave","bond_slave","bridge_slave","bonded_bridge_slave")
#set $static = 1
#end if
echo "auto $iname" >> /etc/network/interfaces
#if $static
echo "iface $iname inet static" >> /etc/network/interfaces
#else
echo "iface $iname inet dhcp" >> /etc/network/interfaces
#end if
#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
eval "physical_interface=\\${logical_interface_mapping_\${logical_interface}}"
if [ ! -z "\${physical_interface}" ]; then
eval "physical_mac=\\${physical_interface_mac_\${physical_interface}}"
fi
if [ ! -z "\${physical_mac}" ]; then
echo " hwaddress ether \${physical_mac}" >> /etc/network/interfaces
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 /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
#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" >> /etc/network/interfaces
#if $bonding_opts != ""
#for $bondopts in $bonding_opts.split(" ")
#set [$bondkey, $bondvalue] = $bondopts.split("=")
echo " bond-$bondkey $bondvalue" >> /etc/network/interfaces
#end for
#end if
#elif $iface_type in ("slave","bond_slave") and $iface_master != ""
echo " bond-master $iface_master" >> /etc/network/interfaces
#end if
#if $iface_type == "bridge"
#set $bridgeslaves = ""
#for $bridgeiname in $ikeys
#set $bridgeidata = $interfaces[$bridgeiname]
#set $bridgeiface_type = $bridgeidata.get("interface_type", "").lower()
#set $bridgeiface_master = $bridgeidata.get("interface_master", "")
#if $bridgeiface_master == $iname
#set $bridgeslaves += $bridgeiname + " "
#end if
#end for
echo " bridge_ports $bridgeslaves" >> /etc/network/interfaces
#if $bridge_opts != ""
#for $bridgeopts in $bridge_opts.split(" ")
#set [$bridgekey, $bridgevalue] = $bridgeopts.split("=")
echo " bridge_$bridgekey $bridgevalue" >> /etc/network/interfaces
#end for
#end if
#elif $iface_type in ["bridge_slave", "bonded_bridge_slave"] and $iface_master != ""
#pass
#end if
#if $static
#if $iname in $promisc_interfaces
echo " address 0.0.0.0" >> /etc/network/interfaces
echo " up ip link set $iname up" >> /etc/network/interfaces
echo " up ip link set $iname promisc on" >> /etc/network/interfaces
echo " down ip link set $iname promisc off" >> /etc/network/interfaces
echo " down ip link set $iname down" >> /etc/network/interfaces
#elif $ip != ""
echo " address $ip" >> /etc/network/interfaces
#if $netmask == ""
## Default to 255.255.255.0?
#set $netmask = "255.255.255.0"
#end if
echo " netmask $netmask" >> /etc/network/interfaces
#import netaddr
#set interface_network = $netaddr.IPNetwork('%s/%s' % ($ip, $netmask))
#set interface_network_str = $str($interface_network)
#if $if_gateway != ""
echo " gateway $if_gateway" >> /etc/network/interfaces
#elif $gateway != ""
#set gateway_address = $netaddr.IPAddress($gateway)
#if $gateway_address in $interface_network
echo " gateway $gateway" >> /etc/network/interfaces
#end if
#end if
#end if
#else
#pass
#end if
#if $mtu != ""
echo " mtu $mtu" >> /etc/network/interfaces
#end if
#if not $nameserver_set
#if $iface_type not in ("slave","bond_slave","bridge_slave","bonded_bridge_slave")
#set $nameservers = ' '.join($name_servers)
#set $nameserver_search = ' '.join($name_servers_search)
#if $nameservers != ""
echo " dns-nameservers $nameservers" >> /etc/network/interfaces
#end if
#if $nameserver_search != ""
echo " dns-search $nameserver_search" >> /etc/network/interfaces
#end if
#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 [$network, $router] = $route.split(":")
echo " up ip route add $network via $router dev $iname" >> /etc/network/interfaces
#else
echo " # Warning: invalid route: $route" >> /etc/network/interfaces
#end if
#end for
echo "" >> /etc/network/interfaces
#end for
for logical_interface in \${logical_interfaces}; do
eval "used_logical_interface=\\${used_logical_interface_\${logical_interface}}"
if [ ! -z "\${used_logical_interface}" ]; then
# ignore logical interface that is already generated in above
echo "ignore used logical interface \${logical_interface}" >> /tmp/network_log
continue
fi
echo "add logical interface \${logical_interface} into network config since it is not set above" >> /tmp/network_log
eval "physical_interface=\\${logical_interface_mapping_\${logical_interface}}"
if [ ! -z "\${physical_interface}" ]; then
echo "auto \${logical_interface}" >> /etc/network/interfaces
echo "iface \${logical_interface} inet static" >> /etc/network/interfaces
eval "mac=\\${physical_interface_mac_\${physical_interface}}"
if [ ! -z "\$mac" ]; then
echo " hwaddress ether \${mac}" >> /etc/network/interfaces
fi
echo "" >> /etc/network/interfaces
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 /etc/modprobe.conf.new /etc/modprobe.conf
fi
fi
done
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
if [ -f "/etc/udev/rules.d/70-persistent-net.rules.new" ]; then
mv /etc/udev/rules.d/70-persistent-net.rules.new /etc/udev/rules.d/70-persistent-net.rules
fi
## End post_install_network_config generated code
|