xci: bootstrap-host: Fetch netmask information from IDF 79/57479/3
authorMarkos Chandras <mchandras@suse.de>
Wed, 16 May 2018 14:59:23 +0000 (15:59 +0100)
committerMarkos Chandras <mchandras@suse.de>
Wed, 16 May 2018 15:37:19 +0000 (16:37 +0100)
The IDF file contains the netmask for every network so we should use
that information instead of using hardcoded values.

Change-Id: Ie798cb49563bdb72fdfb7b6e9e269692bf1f7bc9
Signed-off-by: Markos Chandras <mchandras@suse.de>
xci/playbooks/dynamic_inventory.py
xci/playbooks/roles/bootstrap-host/tasks/network_debian.yml
xci/playbooks/roles/bootstrap-host/tasks/network_redhat.yml
xci/playbooks/roles/bootstrap-host/tasks/network_suse.yml
xci/playbooks/roles/bootstrap-host/templates/osa/debian.interface.j2
xci/playbooks/roles/bootstrap-host/templates/osa/redhat.interface.j2
xci/playbooks/roles/bootstrap-host/templates/osa/suse.interface.j2
xci/playbooks/roles/bootstrap-host/templates/osa/suse.routes.j2

index 8f49874..552a133 100755 (executable)
@@ -39,10 +39,15 @@ class XCIInventory(object):
 
         self.opnfv_networks = {}
         self.opnfv_networks['opnfv'] = {}
-        self.opnfv_networks['opnfv']['admin'] = '172.29.236.10'
-        self.opnfv_networks['opnfv']['public'] = '192.168.122.2'
-        self.opnfv_networks['opnfv']['private'] = '172.29.240.10'
-        self.opnfv_networks['opnfv']['storage'] = '172.29.244.10'
+        self.opnfv_networks['opnfv']['admin'] = {}
+        self.opnfv_networks['opnfv']['admin']['address'] = '172.29.236.10/22'
+        self.opnfv_networks['opnfv']['public'] = {}
+        self.opnfv_networks['opnfv']['public']['address'] = '192.168.122.2/24'
+        self.opnfv_networks['opnfv']['public']['gateway'] = '192.168.122.1'
+        self.opnfv_networks['opnfv']['private'] = {}
+        self.opnfv_networks['opnfv']['private']['address'] = '172.29.240.10/22'
+        self.opnfv_networks['opnfv']['storage'] = {}
+        self.opnfv_networks['opnfv']['storage']['address'] = '172.29.244.10/24'
 
         self.read_pdf_idf()
 
@@ -95,9 +100,12 @@ class XCIInventory(object):
             self.add_hostvar(hostname, 'ansible_host', native_vlan_if[0]['address'])
             host_networks[hostname] = {}
             # And now record the rest of the information
-            for network in idf['idf']['net_config'].keys():
+            for network, ndata in idf['idf']['net_config'].items():
                 network_interface_num = idf['idf']['net_config'][network]['interface']
-                host_networks[hostname][network] = pdf_host_info['interfaces'][int(network_interface_num)]['address']
+                host_networks[hostname][network] = {}
+                host_networks[hostname][network]['address'] = pdf_host_info['interfaces'][int(network_interface_num)]['address'] + "/" + str(ndata['mask'])
+                if 'gateway' in ndata.keys():
+                    host_networks[hostname][network]['gateway'] = str(ndata['gateway']) + "/" + str(ndata['mask'])
 
             host_networks.update(self.opnfv_networks)
 
index 380e4c5..3cac1e2 100644 (file)
     - { name: "{{ ansible_local.xci.network.xci_interface }}.10", vlan_id: 10 }
     - { name: "{{ ansible_local.xci.network.xci_interface }}.30", vlan_id: 30 }
     - { name: "{{ ansible_local.xci.network.xci_interface }}.20", vlan_id: 20 }
-    - { name: "br-mgmt", bridge_ports: "{{ ansible_local.xci.network.xci_interface }}.10", ip: "{{ host_info[inventory_hostname].admin }}", prefix: "255.255.252.0" }
-    - { name: "br-vxlan", bridge_ports: "{{ ansible_local.xci.network.xci_interface }}.30", ip: "{{ host_info[inventory_hostname].private }}", prefix: "255.255.252.0" }
-    - { name: "br-vlan", bridge_ports: "{{ ansible_local.xci.network.xci_interface }}", ip: "{{ host_info[inventory_hostname].public }}", prefix: "255.255.255.0", gateway: "192.168.122.1" }
-    - { name: "br-storage", bridge_ports: "{{ ansible_local.xci.network.xci_interface }}.20", ip: "{{ host_info[inventory_hostname].storage }}", prefix: "255.255.252.0" }
+    - { name: "br-mgmt", bridge_ports: "{{ ansible_local.xci.network.xci_interface }}.10", network: "{{ host_info[inventory_hostname].admin }}" }
+    - { name: "br-vxlan", bridge_ports: "{{ ansible_local.xci.network.xci_interface }}.30", network: "{{ host_info[inventory_hostname].private }}" }
+    - { name: "br-vlan", bridge_ports: "{{ ansible_local.xci.network.xci_interface }}", network: "{{ host_info[inventory_hostname].public }}" }
+    - { name: "br-storage", bridge_ports: "{{ ansible_local.xci.network.xci_interface }}.20", network: "{{ host_info[inventory_hostname].storage }}" }
   loop_control:
     label: "{{ item.name }}"
 
index 9dce50b..b06a869 100644 (file)
     - { name: "{{ ansible_local.xci.network.xci_interface }}.10", bridge: "br-mgmt"   , vlan_id: 10 }
     - { name: "{{ ansible_local.xci.network.xci_interface }}.20", bridge: "br-storage", vlan_id: 20 }
     - { name: "{{ ansible_local.xci.network.xci_interface }}.30", bridge: "br-vxlan"  , vlan_id: 30 }
-    - { name: "br-vlan"   , ip: "{{ host_info[inventory_hostname].public }}",    prefix: 24 }
-    - { name: "br-mgmt"   , ip: "{{ host_info[inventory_hostname].admin }}",    prefix: 22 }
-    - { name: "br-storage", ip: "{{ host_info[inventory_hostname].storage }}", prefix: 22 }
-    - { name: "br-vxlan"  , ip: "{{ host_info[inventory_hostname].private}}",   prefix: 22 }
+    - { name: "br-vlan"   , network: "{{ host_info[inventory_hostname].public }}" }
+    - { name: "br-mgmt"   , network: "{{ host_info[inventory_hostname].admin }}" }
+    - { name: "br-storage", network: "{{ host_info[inventory_hostname].storage }}" }
+    - { name: "br-vxlan"  , network: "{{ host_info[inventory_hostname].private }}" }
   loop_control:
     label: "{{ item.name }}"
 
 - name: Add default route through br-vlan
   lineinfile:
     path: "/etc/sysconfig/network-scripts/ifcfg-br-vlan"
-    line: "GATEWAY=192.168.122.1"
+    line: "GATEWAY={{ host_info[inventory_hostname]['public']['gateway'] | ipaddr('address') }}"
 
 - name: restart network service
   service:
index b1059c8..c9c9d83 100644 (file)
     - { name: "{{ ansible_local.xci.network.xci_interface }}.10", vlan_id: 10 }
     - { name: "{{ ansible_local.xci.network.xci_interface }}.30", vlan_id: 30 }
     - { name: "{{ ansible_local.xci.network.xci_interface }}.20", vlan_id: 20 }
-    - { name: "br-mgmt", bridge_ports: "{{ ansible_local.xci.network.xci_interface }}.10", ip: "{{ host_info[inventory_hostname].admin }}/22" }
-    - { name: "br-vxlan", bridge_ports: "{{ ansible_local.xci.network.xci_interface }}.30", ip: "{{ host_info[inventory_hostname].private }}/22" }
-    - { name: "br-vlan", bridge_ports: "{{ ansible_local.xci.network.xci_interface }}", ip: "{{ host_info[inventory_hostname].public }}/24" }
-    - { name: "br-storage", bridge_ports: "{{ ansible_local.xci.network.xci_interface }}.20", ip: "{{ host_info[inventory_hostname].storage }}/22" }
+    - { name: "br-mgmt", bridge_ports: "{{ ansible_local.xci.network.xci_interface }}.10", network: "{{ host_info[inventory_hostname].admin }}" }
+    - { name: "br-vxlan", bridge_ports: "{{ ansible_local.xci.network.xci_interface }}.30", network: "{{ host_info[inventory_hostname].private }}" }
+    - { name: "br-vlan", bridge_ports: "{{ ansible_local.xci.network.xci_interface }}", network: "{{ host_info[inventory_hostname].public }}" }
+    - { name: "br-storage", bridge_ports: "{{ ansible_local.xci.network.xci_interface }}.20", network: "{{ host_info[inventory_hostname].storage }}" }
   loop_control:
     label: "{{ item.name }}"
 
@@ -35,7 +35,7 @@
     src: "{{ installer_type }}/{{ ansible_os_family | lower }}.routes.j2"
     dest: "/etc/sysconfig/network/ifroute-{{ item.name }}"
   with_items:
-    - { name: "br-vlan", gateway: "192.168.122.1", route: "default" }
+    - { name: "br-vlan", gateway: "{{ host_info[inventory_hostname]['public']['gateway'] }}", route: "default" }
 
 - name: restart network service
   service:
index 56db509..3eddce4 100644 (file)
@@ -25,14 +25,12 @@ iface {{ item.name }} inet static
     post-down ip link del br-vlan-veth || true
     bridge_ports br-vlan-veth
 {% endif %}
-{% if item.ip is defined %}
-    address {{ item.ip }}
+{% if item.network is defined %}
+    address {{ item.network.address | ipaddr('address') }}
+    netmask {{ item.network.address | ipaddr('netmask') }}
 {% endif %}
-{% if item.prefix is defined %}
-    netmask {{ item.prefix }}
-{% endif %}
-{% if item.gateway is defined %}
-    gateway {{ item.gateway }}
+{% if item.network is defined and item.network.gateway is defined %}
+    gateway {{ item.network.gateway | ipaddr('address') }}
 {% endif %}
 
 {% endif %}
index d336438..fa95776 100644 (file)
@@ -14,9 +14,6 @@ TYPE=Bridge
 DELAY=0
 STP=off
 {% endif %}
-{% if item.ip is defined %}
-IPADDR={{ item.ip }}
-{% endif %}
-{% if item.prefix is defined %}
-PREFIX={{ item.prefix }}
+{% if item.network is defined %}
+IPADDR={{ item.network.address }}
 {% endif %}
index 27b01eb..70811a0 100644 (file)
@@ -10,8 +10,8 @@ BRIDGE_FORWARDDELAY='0'
 BRIDGE_STP=off
 BRIDGE_PORTS={{ item.bridge_ports }}
 {% endif %}
-{% if item.ip is defined %}
-IPADDR={{ item.ip }}
+{% if item.network is defined %}
+IPADDR={{ item.network.address }}
 {% endif %}
 PRE_UP_SCRIPT="compat:suse:network-config-suse"
 POST_DOWN_SCRIPT="compat:suse:network-config-suse"