From 7d8954032a381bccfb9f618ddeea1ad58249a6ad Mon Sep 17 00:00:00 2001 From: Andy McCrae Date: Thu, 29 Sep 2016 15:46:21 +0100 Subject: [PATCH] Allow network Alias addresses For nova flat networking to work /w neutron we need to allow an alias address for some interfaces. This PR exposes a "alias:" option which is an address that will be added as an alias for the interface. For Debian this means an additional block at the bottom of the configuration file. For RedHat this means an :0 file is created. Change-Id: I39c396ce3b6eab321d5eb70645c1d0af71dcf5c6 --- README.rst | 4 ++- .../debian_interface_default.cfg.j2 | 6 +++++ .../redhat_interface_alias.cfg.j2 | 5 ++++ test-prepare-host.yml | 25 +++++++++++++++++++ 4 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 network_interfaces/redhat_interface_alias.cfg.j2 diff --git a/README.rst b/README.rst index 17fb8d3b..2135341d 100644 --- a/README.rst +++ b/README.rst @@ -54,6 +54,7 @@ To allow a more complicated network setup we can specify ``netmask``: Netmask of the interface (defaults to 255.255.255.0) ``name``: Name of the interface ``veth_peer``: Set up a veth peer for the interface +``alias``: Add an alias IP address For example, a Nova setup may look like this: @@ -65,6 +66,7 @@ For example, a Nova setup may look like this: - name: "br-vxlan" ip_addr: "10.1.1.1" - name: "br-vlan" - ip_addr: "10.1.2.1" + ip_addr: "10.1.2.200" veth_peer: "eth12" + alias: "10.1.2.1" diff --git a/network_interfaces/debian_interface_default.cfg.j2 b/network_interfaces/debian_interface_default.cfg.j2 index f35fd6a2..ce134466 100644 --- a/network_interfaces/debian_interface_default.cfg.j2 +++ b/network_interfaces/debian_interface_default.cfg.j2 @@ -19,3 +19,9 @@ iface {{ item.name | default('br-mgmt') }} inet static {% else %} bridge_ports none {% endif %} + +{% if item.alias is defined %} +iface {{ item.name | default('br-mgmt') }} inet static + address {{ item.alias }} + netmask {{ item.netmask | default('255.255.255.0') }} +{% endif %} diff --git a/network_interfaces/redhat_interface_alias.cfg.j2 b/network_interfaces/redhat_interface_alias.cfg.j2 new file mode 100644 index 00000000..79a04a85 --- /dev/null +++ b/network_interfaces/redhat_interface_alias.cfg.j2 @@ -0,0 +1,5 @@ +# This interface is an alias +DEVICE={{ item.name | default('br-mgmt') }}:0 +IPADDR={{ item.alias | default('10.1.0.1') }} +NETMASK={{ item.netmask | default('255.255.255.0') }} +ONBOOT=yes diff --git a/test-prepare-host.yml b/test-prepare-host.yml index dd074253..fd908d5e 100644 --- a/test-prepare-host.yml +++ b/test-prepare-host.yml @@ -64,6 +64,15 @@ when: - ansible_pkg_mgr == 'yum' + - name: Create alias file when required + template: + src: "network_interfaces/redhat_interface_alias.cfg.j2" + dest: "/etc/sysconfig/network-scripts/ifcfg-{{ item.name | default('br-mgmt')}}:0" + with_items: "{{ bridges }}" + when: + - ansible_pkg_mgr == 'yum' + - item.alias is defined + - name: Put down post-up script for veth-peer interfaces (RedHat) template: src: "network_interfaces/redhat_interface_{{ item[0] | default('default') }}.cfg.j2" @@ -90,12 +99,28 @@ - (network_interfaces_rhel | changed) or (network_interfaces_deb | changed) with_items: "{{ bridges }}" + - name: Shut down the alias interface (RedHat) + command: "ifdown {{ item.name | default('br-mgmt') }}:0" + when: + - ansible_pkg_mgr == 'yum' + - network_interfaces_rhel | changed + - item.alias is defined + with_items: "{{ bridges }}" + - name: Start the network interfaces command: "ifup {{ item.name | default('br-mgmt') }}" when: - (network_interfaces_rhel | changed) or (network_interfaces_deb | changed) with_items: "{{ bridges }}" + - name: Start the alias interface (RedHat) + command: "ifup {{ item.name | default('br-mgmt') }}:0" + when: + - ansible_pkg_mgr == 'yum' + - network_interfaces_rhel | changed + - item.alias is defined + with_items: "{{ bridges }}" + - name: Add iptables rule to ensure ssh checksum is correct command: /sbin/iptables -A POSTROUTING -t mangle -p tcp --dport 22 -j CHECKSUM --checksum-fill