diff --git a/glean/cmd.py b/glean/cmd.py index 5bebf50..a9a296c 100644 --- a/glean/cmd.py +++ b/glean/cmd.py @@ -30,8 +30,10 @@ from glean import systemlock log = logging.getLogger("glean") -post_up = " post-up route add -net {net} netmask {mask} gw {gw} || true\n" -pre_down = " pre-down route del -net {net} netmask {mask} gw {gw} || true\n" +route_add = " up route add -net {net} netmask {mask} gw {gw} || true\n" +route_del = " down route del -net {net} netmask {mask} gw {gw} || true\n" +slaves_add = " post-up ifenslave {0} {1}\n" +slaves_del = " pre-down ifenslave -d {0} {1}\n" def _exists_rh_interface(name): @@ -393,7 +395,9 @@ def write_debian_interfaces(interfaces, sys_interfaces): slave_devices = [sys_interfaces[mac] for mac in interface['raw_macs']] slaves = ' '.join(slave_devices) - result += " bond-slaves {0}\n".format(slaves) + result += " bond-slaves none\n" + result += slaves_add.format(interface_name, slaves) + result += slaves_del.format(interface_name, slaves) files_to_write[iface_path] = result continue @@ -417,7 +421,9 @@ def write_debian_interfaces(interfaces, sys_interfaces): slave_devices = [sys_interfaces[mac] for mac in interface['raw_macs']] slaves = ' '.join(slave_devices) - result += " bond-slaves {0}\n".format(slaves) + result += " bond-slaves none\n" + result += slaves_add.format(interface_name, slaves) + result += slaves_del.format(interface_name, slaves) files_to_write[iface_path] = result continue @@ -452,17 +458,19 @@ def write_debian_interfaces(interfaces, sys_interfaces): slave_devices = [sys_interfaces[mac] for mac in interface['raw_macs']] slaves = ' '.join(slave_devices) - result += " bond-slaves {0}\n".format(slaves) + result += " bond-slaves none\n" + result += slaves_add.format(interface_name, slaves) + result += slaves_del.format(interface_name, slaves) result += " address {0}\n".format(interface['ip_address']) result += " netmask {0}\n".format(interface['netmask']) for route in interface['routes']: if route['network'] == '0.0.0.0' and route['netmask'] == '0.0.0.0': result += " gateway {0}\n".format(route['gateway']) else: - result += post_up.format( + result += route_add.format( net=route['network'], mask=route['netmask'], gw=route['gateway']) - result += pre_down.format( + result += route_del.format( net=route['network'], mask=route['netmask'], gw=route['gateway']) files_to_write[iface_path] = result diff --git a/glean/tests/fixtures/test/liberty.debian.network.out b/glean/tests/fixtures/test/liberty.debian.network.out index 20ee98b..0e2f425 100644 --- a/glean/tests/fixtures/test/liberty.debian.network.out +++ b/glean/tests/fixtures/test/liberty.debian.network.out @@ -13,10 +13,10 @@ auto eth1 iface eth1 inet static address 10.208.169.118 netmask 255.255.224.0 - post-up route add -net 10.176.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true - pre-down route del -net 10.176.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true - post-up route add -net 10.208.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true - pre-down route del -net 10.208.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true + up route add -net 10.176.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true + down route del -net 10.176.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true + up route add -net 10.208.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true + down route del -net 10.208.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true ### Write /etc/network/interfaces.d/eth3.cfg auto eth3 iface eth3 inet dhcp @@ -46,7 +46,9 @@ iface bond0 inet dhcp bond-miimon 100 bond-lacp-rate slow bond-xmit_hash_policy layer3+4 - bond-slaves eth5 eth6 + bond-slaves none + post-up ifenslave bond0 eth5 eth6 + pre-down ifenslave -d bond0 eth5 eth6 ### Write /etc/network/interfaces.d/eth7.cfg auto eth7 iface eth7 inet manual @@ -63,7 +65,9 @@ iface bond1 inet manual bond-miimon 100 bond-lacp-rate slow bond-xmit_hash_policy layer3+4 - bond-slaves eth7 eth8 + bond-slaves none + post-up ifenslave bond1 eth7 eth8 + pre-down ifenslave -d bond1 eth7 eth8 ### Write /etc/network/interfaces.d/bond1.27.cfg auto bond1.27 iface bond1.27 inet dhcp @@ -77,7 +81,9 @@ iface bond2 inet static bond-miimon 100 bond-lacp-rate slow bond-xmit_hash_policy layer3+4 - bond-slaves eth9 eth10 + bond-slaves none + post-up ifenslave bond2 eth9 eth10 + pre-down ifenslave -d bond2 eth9 eth10 address 192.0.2.2 netmask 255.255.255.0 gateway 192.0.2.1 diff --git a/glean/tests/fixtures/test/liberty.ubuntu.network.out b/glean/tests/fixtures/test/liberty.ubuntu.network.out index 08c9e2e..2951ed5 100644 --- a/glean/tests/fixtures/test/liberty.ubuntu.network.out +++ b/glean/tests/fixtures/test/liberty.ubuntu.network.out @@ -13,10 +13,10 @@ auto eth1 iface eth1 inet static address 10.208.169.118 netmask 255.255.224.0 - post-up route add -net 10.176.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true - pre-down route del -net 10.176.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true - post-up route add -net 10.208.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true - pre-down route del -net 10.208.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true + up route add -net 10.176.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true + down route del -net 10.176.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true + up route add -net 10.208.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true + down route del -net 10.208.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true ### Write /etc/network/interfaces.d/eth3.cfg auto eth3 iface eth3 inet dhcp @@ -46,7 +46,9 @@ iface bond0 inet dhcp bond-miimon 100 bond-lacp-rate slow bond-xmit_hash_policy layer3+4 - bond-slaves eth5 eth6 + bond-slaves none + post-up ifenslave bond0 eth5 eth6 + pre-down ifenslave -d bond0 eth5 eth6 ### Write /etc/network/interfaces.d/eth7.cfg auto eth7 iface eth7 inet manual @@ -63,7 +65,9 @@ iface bond1 inet manual bond-miimon 100 bond-lacp-rate slow bond-xmit_hash_policy layer3+4 - bond-slaves eth7 eth8 + bond-slaves none + post-up ifenslave bond1 eth7 eth8 + pre-down ifenslave -d bond1 eth7 eth8 ### Write /etc/network/interfaces.d/bond1.27.cfg auto bond1.27 iface bond1.27 inet dhcp diff --git a/glean/tests/fixtures/test/rax.debian.network.out b/glean/tests/fixtures/test/rax.debian.network.out index be8cdac..13c344b 100644 --- a/glean/tests/fixtures/test/rax.debian.network.out +++ b/glean/tests/fixtures/test/rax.debian.network.out @@ -13,10 +13,10 @@ auto eth1 iface eth1 inet static address 10.208.169.118 netmask 255.255.224.0 - post-up route add -net 10.176.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true - pre-down route del -net 10.176.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true - post-up route add -net 10.208.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true - pre-down route del -net 10.208.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true + up route add -net 10.176.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true + down route del -net 10.176.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true + up route add -net 10.208.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true + down route del -net 10.208.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true ### Write /etc/network/interfaces.d/eth3.cfg auto eth3 iface eth3 inet dhcp diff --git a/glean/tests/fixtures/test/rax.ubuntu.network.out b/glean/tests/fixtures/test/rax.ubuntu.network.out index be8cdac..13c344b 100644 --- a/glean/tests/fixtures/test/rax.ubuntu.network.out +++ b/glean/tests/fixtures/test/rax.ubuntu.network.out @@ -13,10 +13,10 @@ auto eth1 iface eth1 inet static address 10.208.169.118 netmask 255.255.224.0 - post-up route add -net 10.176.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true - pre-down route del -net 10.176.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true - post-up route add -net 10.208.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true - pre-down route del -net 10.208.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true + up route add -net 10.176.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true + down route del -net 10.176.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true + up route add -net 10.208.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true + down route del -net 10.208.0.0 netmask 255.240.0.0 gw 10.208.160.1 || true ### Write /etc/network/interfaces.d/eth3.cfg auto eth3 iface eth3 inet dhcp