Update network handling to fit flexible definition
Update from four defined networks to a flexible definition.
But "public" network is still required as that will be used
to configure the dns if specified.
Change-Id: I8f0de85eb97876144279cebb1e555c232eec401f
diff --git a/engine/infra/bifrost/playbooks/roles/create-libvirt-vms/templates/libvirt-vm.xml.j2 b/engine/infra/bifrost/playbooks/roles/create-libvirt-vms/templates/libvirt-vm.xml.j2
index ee02365..6034dd1 100644
--- a/engine/infra/bifrost/playbooks/roles/create-libvirt-vms/templates/libvirt-vm.xml.j2
+++ b/engine/infra/bifrost/playbooks/roles/create-libvirt-vms/templates/libvirt-vm.xml.j2
@@ -47,30 +47,14 @@
<controller type='pci' index='0' model='pci-root'>
<alias name='pci.0'/>
</controller>
+{%- for net_key, net_name in networks.network_mapping.iteritems() -%}
<interface type='network'>
- <source network='{{ networks.network_mapping.net_admin }}' bridge='br_{{ networks.network_mapping.net_admin }}'/>
- <mac address='{{ node.interfaces.0.mac_address }}'/>
+ <source network='{{ net_name }}' bridge='br_{{ net_name }}'/>
+ <mac address='{{ node.interfaces[idf.net_config[net_name].interface].mac_address }}'/>
<model type='virtio'/>
- <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x0{{idf.net_config[net_name].interface + 3 }}' function='0x0'/>
</interface>
- <interface type='network'>
- <source network='{{ networks.network_mapping.net_public }}' bridge='br_{{ networks.network_mapping.net_public }}'/>
- <mac address='{{ node.interfaces.1.mac_address }}'/>
- <model type='virtio'/>
- <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
- </interface>
- <interface type='network'>
- <source network='{{ networks.network_mapping.net_mgmt }}' bridge='br_{{ networks.network_mapping.net_mgmt }}'/>
- <mac address='{{ node.interfaces.2.mac_address }}'/>
- <model type='virtio'/>
- <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
- </interface>
- <interface type='network'>
- <source network='{{ networks.network_mapping.net_neutron }}' bridge='br_{{ networks.network_mapping.net_neutron }}'/>
- <mac address='{{ node.interfaces.3.mac_address }}'/>
- <model type='virtio'/>
- <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
- </interface>
+{%- endfor -%}
<serial type='file'>
<source path='{{ vm_console_log_path }}/{{ hostname }}_console.log'/>
<target port='1'/>
diff --git a/engine/installer/kubespray/playbooks/roles/configure-targethosts/tasks/configure-network-ubuntu16.yml b/engine/installer/kubespray/playbooks/roles/configure-targethosts/tasks/configure-network-ubuntu16.yml
index 04c5870..30eeccb 100644
--- a/engine/installer/kubespray/playbooks/roles/configure-targethosts/tasks/configure-network-ubuntu16.yml
+++ b/engine/installer/kubespray/playbooks/roles/configure-targethosts/tasks/configure-network-ubuntu16.yml
@@ -49,17 +49,21 @@
source /etc/network/interfaces.d/*.cfg
dest: "/etc/network/interfaces"
+- name: Compute mapping dict from mac address to device name
+ set_fact:
+ device_mac_dict: "{{ (device_mac_dict | default({})) | combine({item.macaddress: item.device}) }}"
+ loop: "{{ ansible_interfaces | map('regex_replace', '-', '_') | map('regex_replace', '^', 'ansible_') | map('extract', hostvars[inventory_hostname]) | selectattr('macaddress','defined') | list }}"
+
+- name: Compute mapping dict from mac address to interface name (device name with/without VLAN info)
+ set_fact:
+ if_mac_dict: "{{ ( if_mac_dict | default({}) ) | combine({item.mac_address: (item.vlan == 'native') | ternary(device_mac_dict[item.mac_address], device_mac_dict[item.mac_address] + '.' + item.vlan) }) }}"
+ loop: "{{ node.interfaces }}"
+
- name: Configure networking for host
template:
src: "{{ distribution }}.interface.j2"
- dest: "/etc/network/interfaces.d/{{ item.name }}.cfg"
- with_items:
- - { name: "{{ admin_if }}", vlan_id: "{{ (admin_vlan == 'native') | ternary(omit, admin_vlan) }}", nw: "{{ admin_nw }}", ip: "{{ admin_ip }}", gw: "{{ admin_gw }}"}
- - { name: "{{ public_if }}", vlan_id: "{{ (public_vlan == 'native') | ternary(omit, public_vlan) }}", nw: "{{ public_nw }}", ip: "{{ public_ip }}", gw: "{{ public_gw }}"}
- - { name: "{{ mgmt_if }}", vlan_id: "{{ (mgmt_vlan == 'native') | ternary(omit, mgmt_vlan) }}", nw: "{{ mgmt_nw }}", ip: "{{ mgmt_ip }}", gw: "{{ mgmt_gw }}"}
- - { name: "{{ neutron_if }}", vlan_id: "{{ (neutron_vlan == 'native') | ternary(omit, neutron_vlan) }}", nw: "{{ neutron_nw }}", ip: "{{ neutron_ip }}", gw: "{{ neutron_gw }}"}
- loop_control:
- label: "{{ item.name }}"
+ dest: "/etc/network/interfaces.d/{{ item.value }}.cfg"
+ loop: "{{ if_mac_dict | dict2items }}"
- name: Ensure systemd resolved.conf has the correct content
lineinfile:
diff --git a/engine/installer/kubespray/playbooks/roles/configure-targethosts/tasks/configure-network.yml b/engine/installer/kubespray/playbooks/roles/configure-targethosts/tasks/configure-network.yml
index efd7eb0..cf37339 100644
--- a/engine/installer/kubespray/playbooks/roles/configure-targethosts/tasks/configure-network.yml
+++ b/engine/installer/kubespray/playbooks/roles/configure-targethosts/tasks/configure-network.yml
@@ -38,6 +38,7 @@
- name: Reboot the machine
reboot:
- reboot_timeout: 900
+ connect_timeout: 30
+ reboot_timeout: 600
# vim: set ts=2 sw=2 expandtab:
diff --git a/engine/installer/kubespray/playbooks/roles/configure-targethosts/templates/ubuntu16.interface.j2 b/engine/installer/kubespray/playbooks/roles/configure-targethosts/templates/ubuntu16.interface.j2
index e9c68e5..aea86c4 100644
--- a/engine/installer/kubespray/playbooks/roles/configure-targethosts/templates/ubuntu16.interface.j2
+++ b/engine/installer/kubespray/playbooks/roles/configure-targethosts/templates/ubuntu16.interface.j2
@@ -1,16 +1,23 @@
-auto {{ item.name }}
-{% if item.ip == "dhcp" %}
-iface {{ item.name }} inet dhcp
-{% if item.gw %}
- up route add default gw {{ item.gw | ipaddr('address') }}
+{%- set macaddress = item.key -%}
+{%- set device = item.value -%}
+{%- for selected_net_name, selected_net in idf.net_config.iteritems() if node.interfaces[selected_net.interface].mac_address == macaddress -%}
+{%- set selected_inf = node.interfaces[selected_net.interface] -%}
+
+auto {{ device }}
+{% if selected_inf.address == "dhcp" %}
+iface {{ device }} inet dhcp
+{% if selected_net.gateway is defined %}
+up route add default gateway {{ selected_net.gateway | ipaddr('address') }}
{% endif %}
-{% elif item.ip == "manual" %}
-iface {{ item.name }} inet manual
+{% elif selected_inf.address == "manual" %}
+iface {{ device }} inet manual
{% else %}
-iface {{ item.name }} inet static
- address {{ item.ip | ipaddr('address') }}
- netmask {{ item.nw | ipaddr('netmask') }}
-{% if item.gw %}
- gateway {{ item.gw | ipaddr('address') }}
+iface {{ device }} inet static
+address {{ selected_inf.address | ipaddr('address') }}
+netmask {{ (selected_net.network + "/" + (selected_net.mask | string)) | ipaddr('netmask') }}
+{% if selected_net.gateway is defined %}
+gateway {{ selected_net.gateway | ipaddr('address') }}
{% endif %}
{% endif %}
+
+{%- endfor -%}
\ No newline at end of file
diff --git a/engine/installer/kubespray/playbooks/roles/configure-targethosts/vars/main.yml b/engine/installer/kubespray/playbooks/roles/configure-targethosts/vars/main.yml
deleted file mode 100644
index fb607c7..0000000
--- a/engine/installer/kubespray/playbooks/roles/configure-targethosts/vars/main.yml
+++ /dev/null
@@ -1,82 +0,0 @@
----
-# admin network information
-admin_mac: "{{ node.interfaces[idf.net_config.admin.interface].mac_address }}"
-admin_vlan: "{{ node.interfaces[idf.net_config.admin.interface].vlan }}"
-admin_if: >-
- {% for x in (ansible_interfaces | map('regex_replace', '-', '_') | map('regex_replace', '^', 'ansible_') | map('extract', hostvars[inventory_hostname]) | selectattr('macaddress','defined')) -%}
- {%- if x.macaddress == admin_mac -%}
- {%- if admin_vlan == 'native' -%}
- {{ x.device }}
- {%- else -%}
- {{ x.device }}.{{ admin_vlan }}
- {%- endif -%}
- {%- endif -%}
- {%- endfor -%}
-admin_nw: "{{ idf.net_config.admin.network }}/{{ idf.net_config.admin.mask }}"
-admin_ip: "{{ node.interfaces[idf.net_config.admin.interface].address }}"
-admin_gw: >-
- {%- if idf.net_config.admin.gateway is defined -%}
- {{ idf.net_config.admin.gateway }}
- {%- endif -%}
-
-# public network information
-public_mac: "{{ node.interfaces[idf.net_config.public.interface].mac_address }}"
-public_vlan: "{{ node.interfaces[idf.net_config.public.interface].vlan }}"
-public_if: >-
- {% for x in (ansible_interfaces | map('regex_replace', '-', '_') | map('regex_replace', '^', 'ansible_') | map('extract', hostvars[inventory_hostname]) | selectattr('macaddress','defined')) -%}
- {%- if x.macaddress == public_mac -%}
- {%- if public_vlan == 'native' -%}
- {{ x.device }}
- {%- else -%}
- {{ x.device }}.{{ public_vlan }}
- {%- endif -%}
- {%- endif -%}
- {%- endfor -%}
-public_nw: "{{ idf.net_config.public.network }}/{{ idf.net_config.public.mask }}"
-public_ip: "{{ node.interfaces[idf.net_config.public.interface].address }}"
-public_gw: >-
- {%- if idf.net_config.public.gateway is defined -%}
- {{ idf.net_config.public.gateway }}
- {%- endif -%}
-
-# mgmt network information
-mgmt_mac: "{{ node.interfaces[idf.net_config.mgmt.interface].mac_address }}"
-mgmt_vlan: "{{ node.interfaces[idf.net_config.mgmt.interface].vlan }}"
-mgmt_if: >-
- {% for x in (ansible_interfaces | map('regex_replace', '-', '_') | map('regex_replace', '^', 'ansible_') | map('extract', hostvars[inventory_hostname]) | selectattr('macaddress','defined')) -%}
- {%- if x.macaddress == mgmt_mac -%}
- {%- if mgmt_vlan == 'native' -%}
- {{ x.device }}
- {%- else -%}
- {{ x.device }}.{{ mgmt_vlan }}
- {%- endif -%}
- {%- endif -%}
- {%- endfor -%}
-mgmt_nw: "{{ idf.net_config.mgmt.network }}/{{ idf.net_config.mgmt.mask }}"
-mgmt_ip: "{{ node.interfaces[idf.net_config.mgmt.interface].address }}"
-mgmt_gw: >-
- {%- if idf.net_config.mgmt.gateway is defined -%}
- {{ idf.net_config.mgmt.gateway }}
- {%- endif -%}
-
-# neutron network information
-neutron_mac: "{{ node.interfaces[idf.net_config.neutron.interface].mac_address }}"
-neutron_vlan: "{{ node.interfaces[idf.net_config.neutron.interface].vlan }}"
-neutron_if: >-
- {% for x in (ansible_interfaces | map('regex_replace', '-', '_') | map('regex_replace', '^', 'ansible_') | map('extract', hostvars[inventory_hostname]) | selectattr('macaddress','defined')) -%}
- {%- if x.macaddress == neutron_mac -%}
- {%- if neutron_vlan == 'native' -%}
- {{ x.device }}
- {%- else -%}
- {{ x.device }}.{{ neutron_vlan }}
- {%- endif -%}
- {%- endif -%}
- {%- endfor -%}
-neutron_nw: "{{ idf.net_config.neutron.network }}/{{ idf.net_config.neutron.mask }}"
-neutron_ip: "{{ node.interfaces[idf.net_config.neutron.interface].address }}"
-neutron_gw: >-
- {%- if idf.net_config.neutron.gateway is defined -%}
- {{ idf.net_config.neutron.gateway }}
- {%- endif -%}
-
-# vim: set ts=2 sw=2 expandtab: