Creating a new VM

VMs are declaredly declaratively in playbooks/vms.yml like this:

- hosts:
  gather_facts: no
  tags: virt
    - role: osas_guest_virt_install
      system_disk_size: 8
      data_disk_size: 30
      mem_size: 2048
      num_cpus: 3
      distribution: Centos
      version: 8
      main_iface_vlan: 'OSCI-Public'
        'OSCI-Public': eth-pub
        'OSCI-Internal': eth-int

The osas_guest_virt_install uses the guest_virt_install role to deploy a VM and tie the network config to our architecture.

The VM base storage (/dev/vda of size system_disk_size GB) may be complemented by an extra disk (/dev/vdb of size data_disk_size GB). Currently the role is limited to these two drives.

main_iface_vlan is the VLAN associated to the default interface. The list of available VLANs is defined in group_vars/all/network.yml in cage_vlans. Each interface is associated to exactly one single VLAN and main_iface_vlan contains the mapping with the interface name; this way the default interface name may also be specified by giving a name for the VLAN in used in main_iface_vlan.

Resources settings are only defined at creation time. Please update the playbook to match production in case we need to recreate a VM. Similarly new network interfaces will be created but removed ones won’t be deconfigured.

Moving a VM on another Hypervisor

Moving a VM is done offline since Hypervisors have no open ports to communicate with each otherfor security reasons. After several checks the playbook will recreate the storage, copy all LVM LVs securely, and sync the VM config before starting the new VM.

The old VM stays around on the source hypervisor and is only stopped with autostart disabled. After the new VM has been tested and confirmed to work fine then it can be removed (see Remove a VM chapter).

To move a VM between hypervisors use:

    ansible-playbook --diff -e hyp_src=<hypervisor1> -e hyp_dst=<hypervisor2> -e playbooks/move_vm.yml

Removing a VM

When a VM is removed all related data are purged:

  • libvirt VM config
  • provisioning config
  • VM storage (all associated LVM LVs)

The VM needs to be manually stopped first as a precaution.

To remove a VM use:

    ansible-playbook --diff -e hyp=<hypervisor> -e playbooks/cleanup_vm.yml

Changing I/O priority of a VM

If a VM is using a lot of I/Os, like a CI node for eg., then it is preferable to lower the priority for this VM in order to avoid slowing down other workloads.

The default priority in libvirt is 500 and we use 100 in this situation; we may define more classes in the future.

This setting is currently set manually but we plan to integrate it in the guest_virt_install role:

    virsh blkiotune <vm_name> --weight 100 --config --live