From b9b00f336f20bad8bc58b325172ebf9c71c83b6a Mon Sep 17 00:00:00 2001 From: Manuel Buil Date: Fri, 5 Oct 2018 09:52:06 +0200 Subject: [baremetal] Add two interfaces to the opnfv vm opnfv vm requires connectivity to two physical interfaces of the host. These interfaces are: 1 - admin, where DHCP requests will arrive from blades to do PXE boot 2 - mgmt, which connects to the mgmt of the blades to do the ansible configuration To achive this, it is required: 1 - Two libvirt networks that connect to two different linux bridges. The important physical interfaces are connected to them. The interfaces name is fetched from the idf 2 - Two templates representing the new libvirt networks (net-mgmt.xml.j2 and net-admin.xml.j2) 3 - Two interfaces defined in vm.xml.j2 Change-Id: I9037aa36802cfde44717b9394bab79b22d7dfaab Signed-off-by: Manuel Buil --- xci/playbooks/roles/create-nodes/defaults/main.yml | 13 ++++++----- .../roles/create-nodes/tasks/create_vm.yml | 2 +- xci/playbooks/roles/create-nodes/tasks/main.yml | 2 ++ .../roles/create-nodes/tasks/prepare_libvirt.yml | 26 ++++++++++++++-------- .../roles/create-nodes/templates/net-admin.xml.j2 | 14 ++++++++++++ .../roles/create-nodes/templates/net-mgmt.xml.j2 | 11 +++++++++ .../roles/create-nodes/templates/vm.xml.j2 | 13 ++++++++++- 7 files changed, 65 insertions(+), 16 deletions(-) create mode 100644 xci/playbooks/roles/create-nodes/templates/net-admin.xml.j2 create mode 100644 xci/playbooks/roles/create-nodes/templates/net-mgmt.xml.j2 (limited to 'xci/playbooks') diff --git a/xci/playbooks/roles/create-nodes/defaults/main.yml b/xci/playbooks/roles/create-nodes/defaults/main.yml index 6ac266a5..b03f1386 100644 --- a/xci/playbooks/roles/create-nodes/defaults/main.yml +++ b/xci/playbooks/roles/create-nodes/defaults/main.yml @@ -9,11 +9,12 @@ vm_default_groups: "{{ lookup('env', 'DEFAULT_HOST_GROUPS').split() | default([' vm_disk_cache: unsafe node_names: "{{ lookup('env', 'NODE_NAMES').split() }}" -# NOTE(pas-ha) name and default are chosen to be the same -# as in 'bifrost-ironic-install' role -network_interface: "virbr0" -# NOTE(pas-ha) these correspond to settings for the libvirt network created by default -vm_network: "{{ lookup('env', 'VM_NET_BRIDGE') | default('default', true) }}" +network_bridge_admin: 'br-admin' +network_bridge_mgmt: 'br-mgmt' + +vm_network_admin: "{{ lookup('env', 'VM_NET_BRIDGE') | default('admin', true) }}" +vm_network_mgmt: "{{ lookup('env', 'VM_NET_BRIDGE_MGMT') | default('mgmt', true) }}" + node_network_netmask: "255.255.255.0" node_storage_pool: "{{ lookup('env', 'LIBVIRT_STORAGE_POOL') | default('default', true) }}" @@ -25,3 +26,5 @@ vm_emulator: "/usr/bin/qemu-system-x86_64" vm_libvirt_uri: "{{ lookup('env', 'LIBVIRT_CONNECT_URI') | default('qemu:///system', true) }}" opnfv_image_path: "/var/lib/libvirt/images" + +libvirt_networks: "{{ (baremetal | bool) | ternary([vm_network_admin,vm_network_mgmt],[vm_network_admin]) }}" diff --git a/xci/playbooks/roles/create-nodes/tasks/create_vm.yml b/xci/playbooks/roles/create-nodes/tasks/create_vm.yml index 4afb71cf..bca5b483 100644 --- a/xci/playbooks/roles/create-nodes/tasks/create_vm.yml +++ b/xci/playbooks/roles/create-nodes/tasks/create_vm.yml @@ -35,7 +35,7 @@ path: "{{ opnfv_image_path }}/{{ vm_name }}.qcow2" register: _vm_volume_prepared - - name: Resize opnfv VM image to {{ item.disks[0].disk_capacity }} + - name: Resize opnfv VM image to {{ item.1.disks[0].disk_capacity }} command: "qemu-img resize {{ opnfv_image_path }}/opnfv.qcow2 {{ item.1.disks[0].disk_capacity }}" when: - vm_name == 'opnfv' diff --git a/xci/playbooks/roles/create-nodes/tasks/main.yml b/xci/playbooks/roles/create-nodes/tasks/main.yml index 64857d80..18bc9871 100644 --- a/xci/playbooks/roles/create-nodes/tasks/main.yml +++ b/xci/playbooks/roles/create-nodes/tasks/main.yml @@ -10,6 +10,8 @@ name: "{{ required_packages }}" - include_tasks: prepare_libvirt.yml + with_items: "{{ libvirt_networks }}" + - include_tasks: download_opnfvimage.yml - name: create placeholder var for vm entries in JSON format diff --git a/xci/playbooks/roles/create-nodes/tasks/prepare_libvirt.yml b/xci/playbooks/roles/create-nodes/tasks/prepare_libvirt.yml index 3f49e756..faf19a6f 100644 --- a/xci/playbooks/roles/create-nodes/tasks/prepare_libvirt.yml +++ b/xci/playbooks/roles/create-nodes/tasks/prepare_libvirt.yml @@ -46,15 +46,24 @@ # with the default 192.168.122/0/24 network - name: destroy libvirt network virt_net: - name: "{{ vm_network }}" + name: "{{ item }}" + state: absent + uri: "{{ vm_libvirt_uri }}" + +# Ubuntu creates a default network when installing libvirt. +# This network uses the 192.168.122.0/24 range and thus +# conflicts with our admin network +- name: destroy libvirt network + virt_net: + name: "default" state: absent uri: "{{ vm_libvirt_uri }}" - name: ensure libvirt network is present virt_net: - name: "{{ vm_network }}" + name: "{{ item }}" state: present - xml: "{{ lookup('template', 'net.xml.j2') }}" + xml: "{{ lookup('template', 'net-'+item+'.xml.j2') }}" uri: "{{ vm_libvirt_uri }}" - name: find facts on libvirt networks @@ -62,29 +71,28 @@ command: facts uri: "{{ vm_libvirt_uri }}" -# NOTE(pas-ha) yet another place where non-local libvirt will not work - name: "Delete network interface if virtual network is not active" - command: ip link del {{ ansible_libvirt_networks[vm_network].bridge }} + command: ip link del {{ ansible_libvirt_networks[item].bridge }} when: - - ansible_libvirt_networks[vm_network].state != 'active' + - ansible_libvirt_networks[item].state != 'active' - vm_libvirt_uri == 'qemu:///system' ignore_errors: yes - name: set libvirt network to autostart virt_net: - name: "{{ vm_network }}" + name: "{{ item }}" autostart: yes uri: "{{ vm_libvirt_uri }}" - name: ensure libvirt network is running virt_net: - name: "{{ vm_network }}" + name: "{{ item }}" state: active uri: "{{ vm_libvirt_uri }}" - name: get libvirt network status virt_net: - name: "{{ vm_network }}" + name: "{{ item }}" command: status uri: "{{ vm_libvirt_uri }}" register: test_vm_net_status diff --git a/xci/playbooks/roles/create-nodes/templates/net-admin.xml.j2 b/xci/playbooks/roles/create-nodes/templates/net-admin.xml.j2 new file mode 100644 index 00000000..aedbbeb7 --- /dev/null +++ b/xci/playbooks/roles/create-nodes/templates/net-admin.xml.j2 @@ -0,0 +1,14 @@ + + {{ item }} + + + + + + + + + + + + diff --git a/xci/playbooks/roles/create-nodes/templates/net-mgmt.xml.j2 b/xci/playbooks/roles/create-nodes/templates/net-mgmt.xml.j2 new file mode 100644 index 00000000..4a9964c3 --- /dev/null +++ b/xci/playbooks/roles/create-nodes/templates/net-mgmt.xml.j2 @@ -0,0 +1,11 @@ + + {{ item }} + + + + + + + + + diff --git a/xci/playbooks/roles/create-nodes/templates/vm.xml.j2 b/xci/playbooks/roles/create-nodes/templates/vm.xml.j2 index e4e41eda..6061fc52 100644 --- a/xci/playbooks/roles/create-nodes/templates/vm.xml.j2 +++ b/xci/playbooks/roles/create-nodes/templates/vm.xml.j2 @@ -36,10 +36,21 @@
- + + {%- if vm_name == 'opnfv' -%} + {%- else -%} + + {%- endif -%} + {%- if baremetal | bool -%} + + + + + + {%- endif -%}