From d52d5b21a8309537fc30767f4a209f067fc509bb Mon Sep 17 00:00:00 2001 From: Markos Chandras Date: Wed, 29 Aug 2018 10:43:50 +0100 Subject: xci: roles: create-vm-nodes: Always provision VM nodes The role used to get the output of 'virsh list --all' to determine how many VMs are present and shut off in the system. This takes *all* VMs on the system into consideration so it may skip creation of some or all of the XCI VMs if we happen to have other VMs present. We can improve the situation by simply dropping this check and always provision the VMs we want. If the VM is already present, then the module will simply do a sanity check of its configuration. This allows XCI to run alongside other VMs. Change-Id: I54255a1959509671c0305f48f23a55b6e900684f Signed-off-by: Markos Chandras --- .../roles/create-vm-nodes/tasks/create_vm.yml | 29 +++++++++------------- xci/playbooks/roles/create-vm-nodes/tasks/main.yml | 2 +- .../roles/create-vm-nodes/templates/vm.xml.j2 | 10 ++++---- 3 files changed, 18 insertions(+), 23 deletions(-) diff --git a/xci/playbooks/roles/create-vm-nodes/tasks/create_vm.yml b/xci/playbooks/roles/create-vm-nodes/tasks/create_vm.yml index 008e5531..700c6c72 100644 --- a/xci/playbooks/roles/create-vm-nodes/tasks/create_vm.yml +++ b/xci/playbooks/roles/create-vm-nodes/tasks/create_vm.yml @@ -1,13 +1,8 @@ --- -# Create a VM and volume for it, save its MAC address -- shell: "sudo virsh list --all | grep 'shut off' | wc -l" - register: num_vms - - name: "Creating VM" block: - # NOTE(pas-ha) item here refers to name of the vm - set_fact: - vm_name: "{{ node_names[num_vms.stdout | int] }}" + vm_name: "{{ node_names[item.0 | int] }}" - set_fact: vm_log_file: "{{ node_logdir }}/{{ vm_name }}_console.log" @@ -41,7 +36,7 @@ register: _vm_volume_prepared - name: Resize opnfv VM image to {{ item.disks[0].disk_capacity }} - command: "qemu-img resize {{ opnfv_image_path }}/opnfv.qcow2 {{ item.disks[0].disk_capacity }}" + command: "qemu-img resize {{ opnfv_image_path }}/opnfv.qcow2 {{ item.1.disks[0].disk_capacity }}" when: - vm_name == 'opnfv' - _vm_volume_prepared.stat.exists @@ -52,7 +47,7 @@ command: > virsh --connect {{ vm_libvirt_uri }} vol-create-as {{ node_storage_pool }} {{ vm_name }}.qcow2 - {{ item.disks[0].disk_capacity }} + {{ item.1.disks[0].disk_capacity }} --format qcow2 {{ prealloc|default("") }} when: - not _vm_volume_prepared.stat.exists @@ -115,7 +110,7 @@ when: vbmc_list.stdout.find(vm_name) != -1 - set_fact: - virtual_ipmi_port: "{{ (vm_ipmi_port_start|default(623) | int ) + (num_vms.stdout | int ) }}" + virtual_ipmi_port: "{{ (vm_ipmi_port_start|default(623) | int ) + (item.0 | int) }}" - name: plug vm into vbmc command: vbmc add {{ vm_name }} --libvirt-uri {{ vm_libvirt_uri }} --port {{ virtual_ipmi_port }} @@ -135,7 +130,7 @@ - name: Fetch the ip set_fact: - vm_ip: "{%- for interface in item.interfaces %}{%- if 'native' in (interface.vlan | string) %}{{ interface.address }}{%- endif %}{%- endfor %}" + vm_ip: "{%- for interface in item.1.interfaces %}{%- if 'native' in (interface.vlan | string) %}{{ interface.address }}{%- endif %}{%- endfor %}" # Assumes there is only a single NIC per VM - name: get MAC from vm XML @@ -155,17 +150,17 @@ power: ipmi_address: "192.168.122.1" ipmi_port: "{{ virtual_ipmi_port }}" - ipmi_username: "{{ item.remote_management.user }}" - ipmi_password: "{{ item.remote_management.pass }}" + ipmi_username: "{{ item.1.remote_management.user }}" + ipmi_password: "{{ item.1.remote_management.pass }}" nics: - mac: "{{ vm_mac }}" ansible_ssh_host: "{{ vm_ip }}" ipv4_address: "{{ vm_ip }}" properties: - cpu_arch: "{{ item.node.arch }}" - ram: "{{ item.node.memory.rstrip('G') }}" - cpus: "{{ item.node.cpus }}" - disk_size: "{{ item.disks[0].disk_capacity.rstrip('G') }}" + cpu_arch: "{{ item.1.node.arch }}" + ram: "{{ item.1.node.memory.rstrip('G') }}" + cpus: "{{ item.1.node.cpus }}" + disk_size: "{{ item.1.disks[0].disk_capacity.rstrip('G') }}" - name: add created vm info set_fact: @@ -177,4 +172,4 @@ opnfv_vm_ip: "{{ vm_ip }}" when: vm_name == 'opnfv' - when: (num_nodes | int) > (num_vms.stdout | int) + when: (num_nodes | int) > (item.0 | int) diff --git a/xci/playbooks/roles/create-vm-nodes/tasks/main.yml b/xci/playbooks/roles/create-vm-nodes/tasks/main.yml index 7e0090e4..c1cee6dc 100644 --- a/xci/playbooks/roles/create-vm-nodes/tasks/main.yml +++ b/xci/playbooks/roles/create-vm-nodes/tasks/main.yml @@ -18,7 +18,7 @@ # First we create the opnfv_vm - include_tasks: create_vm.yml - with_items: "{{ [opnfv_vm] + nodes }}" + with_indexed_items: "{{ [opnfv_vm] + nodes }}" - name: Start the opnfv vm virt: diff --git a/xci/playbooks/roles/create-vm-nodes/templates/vm.xml.j2 b/xci/playbooks/roles/create-vm-nodes/templates/vm.xml.j2 index c44fa6aa..5c235f55 100644 --- a/xci/playbooks/roles/create-vm-nodes/templates/vm.xml.j2 +++ b/xci/playbooks/roles/create-vm-nodes/templates/vm.xml.j2 @@ -1,9 +1,9 @@ {{ vm_name }} - {{ item.node.memory.rstrip('G') }} - {{ item.node.cpus }} + {{ item.1.node.memory.rstrip('G') }} + {{ item.1.node.cpus }} - hvm + hvm {%- if 'opnfv' in vm_name -%} {%- else -%} @@ -17,7 +17,7 @@ - + @@ -36,7 +36,7 @@
{% set native_interfaces = [] %} - {%- for interface in item.interfaces %} + {%- for interface in item.1.interfaces %} {%- if 'native' in (interface.vlan | string) %} {%- set _ = native_interfaces.append(interface) %} {%- endif %} -- cgit 1.2.3-korg