diff --git a/packetnetworking/distros/redhat/bonded.py b/packetnetworking/distros/redhat/bonded.py index 5c89560..390c96f 100644 --- a/packetnetworking/distros/redhat/bonded.py +++ b/packetnetworking/distros/redhat/bonded.py @@ -16,23 +16,28 @@ def build_tasks(self): self.task_template( "etc/modprobe.d/bonding.conf", "bonded/etc_modprobe.d_bonding.conf.j2" ) - self.task_template( - "etc/sysconfig/network-scripts/ifcfg-bond0", - "bonded/etc_sysconfig_network-scripts_ifcfg-bond0.j2", - ) - if self.ipv4pub: - # Only needed when a public ip is used, otherwise private ip is - # already set and no special routes are needed. + for bond in self.network.bonds: self.task_template( - "etc/sysconfig/network-scripts/ifcfg-bond0:0", - "bonded/etc_sysconfig_network-scripts_ifcfg-bond0_0.j2", - ) - self.task_template( - "etc/sysconfig/network-scripts/route-bond0", - "bonded/etc_sysconfig_network-scripts_route-bond0.j2", + "etc/sysconfig/network-scripts/ifcfg-{}".format(bond), + "bonded/etc_sysconfig_network-scripts_ifcfg-bondX.j2", + fmt={"bond": bond}, ) + if self.ipv4pub and bond == "bond0": + # Only needed when a public ip is used, otherwise private ip is + # already set and no special routes are needed. + self.task_template( + "etc/sysconfig/network-scripts/ifcfg-{}:0".format(bond), + "bonded/etc_sysconfig_network-scripts_ifcfg-bondX_0.j2", + fmt={"bond": bond}, + ) + self.task_template( + "etc/sysconfig/network-scripts/route-{}".format(bond), + "bonded/etc_sysconfig_network-scripts_route-bondX.j2", + fmt={"bond": bond}, + ) + for i, iface in enumerate(self.network.interfaces): name = iface["name"] self.task_template( diff --git a/packetnetworking/distros/redhat/templates/bonded/etc_modprobe.d_bonding.conf.j2 b/packetnetworking/distros/redhat/templates/bonded/etc_modprobe.d_bonding.conf.j2 index fecbe38..b0afbf7 100644 --- a/packetnetworking/distros/redhat/templates/bonded/etc_modprobe.d_bonding.conf.j2 +++ b/packetnetworking/distros/redhat/templates/bonded/etc_modprobe.d_bonding.conf.j2 @@ -1,2 +1,4 @@ -alias bond0 bonding -options bond0 mode={{ net.bonding.mode }} miimon=100 downdelay=200 updelay=200 xmit_hash_policy=layer3+4 lacp_rate=1 +{% for bond in net.bonds %} +alias {{ bond }} bonding +options {{ bond }} mode={{ net.bonding.mode }} miimon=100 downdelay=200 updelay=200 xmit_hash_policy=layer3+4 lacp_rate=1 +{% endfor %} diff --git a/packetnetworking/distros/redhat/templates/bonded/etc_sysconfig_network-scripts_ifcfg-bond0.j2 b/packetnetworking/distros/redhat/templates/bonded/etc_sysconfig_network-scripts_ifcfg-bond0.j2 deleted file mode 100644 index cf96fb2..0000000 --- a/packetnetworking/distros/redhat/templates/bonded/etc_sysconfig_network-scripts_ifcfg-bond0.j2 +++ /dev/null @@ -1,25 +0,0 @@ -DEVICE=bond0 -NAME=bond0 -{% if ip4pub %} -IPADDR={{ ip4pub.address }} -NETMASK={{ ip4pub.netmask }} -GATEWAY={{ ip4pub.gateway }} -{% else %} -IPADDR={{ ip4priv.address }} -NETMASK={{ ip4priv.netmask }} -GATEWAY={{ ip4priv.gateway }} -{% endif %} -BOOTPROTO=none -ONBOOT=yes -USERCTL=no -TYPE=Bond -BONDING_OPTS="mode={{ net.bonding.mode }} miimon=100 downdelay=200 updelay=200" - -{% if ip6pub %} -IPV6INIT=yes -IPV6ADDR={{ ip6pub.address }}/{{ ip6pub.cidr }} -IPV6_DEFAULTGW={{ ip6pub.gateway }} -{% endif %} -{% for dns in resolvers %} -DNS{{ loop.index }}={{ dns }} -{% endfor %} diff --git a/packetnetworking/distros/redhat/templates/bonded/etc_sysconfig_network-scripts_ifcfg-bond0_0.j2 b/packetnetworking/distros/redhat/templates/bonded/etc_sysconfig_network-scripts_ifcfg-bond0_0.j2 deleted file mode 100644 index d588cc0..0000000 --- a/packetnetworking/distros/redhat/templates/bonded/etc_sysconfig_network-scripts_ifcfg-bond0_0.j2 +++ /dev/null @@ -1,11 +0,0 @@ -DEVICE=bond0:0 -NAME=bond0:0 -IPADDR={{ ip4priv.address }} -NETMASK={{ ip4priv.netmask }} -GATEWAY={{ ip4priv.gateway }} -BOOTPROTO=none -ONBOOT=yes -USERCTL=no -{% for dns in resolvers %} -DNS{{ loop.index }}={{ dns }} -{% endfor %} diff --git a/packetnetworking/distros/redhat/templates/bonded/etc_sysconfig_network-scripts_ifcfg-bondX.j2 b/packetnetworking/distros/redhat/templates/bonded/etc_sysconfig_network-scripts_ifcfg-bondX.j2 new file mode 100644 index 0000000..8478a7e --- /dev/null +++ b/packetnetworking/distros/redhat/templates/bonded/etc_sysconfig_network-scripts_ifcfg-bondX.j2 @@ -0,0 +1,25 @@ +DEVICE={bond} +NAME={bond} +{{% if ip4pub %}} +IPADDR={{{{ ip4pub.address }}}} +NETMASK={{{{ ip4pub.netmask }}}} +GATEWAY={{{{ ip4pub.gateway }}}} +{{% else %}} +IPADDR={{{{ ip4priv.address }}}} +NETMASK={{{{ ip4priv.netmask }}}} +GATEWAY={{{{ ip4priv.gateway }}}} +{{% endif %}} +BOOTPROTO=none +ONBOOT=yes +USERCTL=no +TYPE=Bond +BONDING_OPTS="mode={{{{ net.bonding.mode }}}} miimon=100 downdelay=200 updelay=200" + +{{% if ip6pub %}} +IPV6INIT=yes +IPV6ADDR={{{{ ip6pub.address }}}}/{{{{ ip6pub.cidr }}}} +IPV6_DEFAULTGW={{{{ ip6pub.gateway }}}} +{{% endif %}} +{{% for dns in resolvers %}} +DNS{{{{ loop.index }}}}={{{{ dns }}}} +{{% endfor %}} diff --git a/packetnetworking/distros/redhat/templates/bonded/etc_sysconfig_network-scripts_ifcfg-bondX_0.j2 b/packetnetworking/distros/redhat/templates/bonded/etc_sysconfig_network-scripts_ifcfg-bondX_0.j2 new file mode 100644 index 0000000..2c36ec8 --- /dev/null +++ b/packetnetworking/distros/redhat/templates/bonded/etc_sysconfig_network-scripts_ifcfg-bondX_0.j2 @@ -0,0 +1,11 @@ +DEVICE={bond}:0 +NAME={bond}:0 +IPADDR={{{{ ip4priv.address }}}} +NETMASK={{{{ ip4priv.netmask }}}} +GATEWAY={{{{ ip4priv.gateway }}}} +BOOTPROTO=none +ONBOOT=yes +USERCTL=no +{{% for dns in resolvers %}} +DNS{{{{ loop.index }}}}={{{{ dns }}}} +{{% endfor %}} diff --git a/packetnetworking/distros/redhat/templates/bonded/etc_sysconfig_network-scripts_ifcfg-template.j2 b/packetnetworking/distros/redhat/templates/bonded/etc_sysconfig_network-scripts_ifcfg-template.j2 index 2f265b9..9b8a489 100644 --- a/packetnetworking/distros/redhat/templates/bonded/etc_sysconfig_network-scripts_ifcfg-template.j2 +++ b/packetnetworking/distros/redhat/templates/bonded/etc_sysconfig_network-scripts_ifcfg-template.j2 @@ -1,6 +1,6 @@ DEVICE={iface} ONBOOT=yes HWADDR={{{{ interfaces[{i}].mac }}}} -MASTER=bond0 +MASTER={{{{ interfaces[{i}].bond }}}} SLAVE=yes BOOTPROTO=none diff --git a/packetnetworking/distros/redhat/templates/bonded/etc_sysconfig_network-scripts_route-bond0.j2 b/packetnetworking/distros/redhat/templates/bonded/etc_sysconfig_network-scripts_route-bond0.j2 deleted file mode 100644 index 21ce10f..0000000 --- a/packetnetworking/distros/redhat/templates/bonded/etc_sysconfig_network-scripts_route-bond0.j2 +++ /dev/null @@ -1,3 +0,0 @@ -{% for subnet in private_subnets %} -{{ subnet }} via {{ ip4priv.gateway }} dev bond0:0 -{% endfor %} diff --git a/packetnetworking/distros/redhat/templates/bonded/etc_sysconfig_network-scripts_route-bondX.j2 b/packetnetworking/distros/redhat/templates/bonded/etc_sysconfig_network-scripts_route-bondX.j2 new file mode 100644 index 0000000..0ee177c --- /dev/null +++ b/packetnetworking/distros/redhat/templates/bonded/etc_sysconfig_network-scripts_route-bondX.j2 @@ -0,0 +1,3 @@ +{{% for subnet in private_subnets %}} +{{{{ subnet }}}} via {{{{ ip4priv.gateway }}}} dev {bond}:0 +{{% endfor %}}