Adding mnaio qemu file backends

mnaio uses LVM as default VM disk backend but that
requires a lot of available disk space.
A alternative option, the qcow2 file based backend
is added to take benefit of thin provisioning.
This backend can be triggered by setting the override
`default_vm_disk_mode` to `file`

Change-Id: Iaf97fef601f656901b6913eaafb9a6c28d4b7ba6
This commit is contained in:
Bjoern Teipel 2018-03-23 21:28:38 -05:00
parent e55b331d2d
commit d625057b7a
4 changed files with 40 additions and 4 deletions

View File

@ -38,22 +38,41 @@
- name: Delete VM LV
lvol:
vg: vg01
vg: "{{ default_vm_disk_vg }}"
lv: "{{ hostvars[item]['server_hostname'] }}"
state: absent
force: yes
failed_when: false
when:
- hostvars[item]['server_vm'] | default(false) | bool
- default_vm_disk_mode | default('lvm') == "lvm"
with_items: "{{ groups['pxe_servers'] }}"
- name: Delete VM Disk Image
command: |
rm -f /var/lib/libvirt/images/{{ hostvars[item]['server_hostname'] }}.img
failed_when: false
when:
- hostvars[item]['server_vm'] | default(false) | bool
- default_vm_disk_mode | default('lvm') == "file"
with_items: "{{ groups['pxe_servers'] }}"
- name: Create VM LV
lvol:
vg: vg01
vg: "{{ default_vm_disk_vg }}"
lv: "{{ hostvars[item]['server_hostname'] }}"
size: "{{ default_vm_storage }}"
when:
- hostvars[item]['server_vm'] | default(false) | bool
- default_vm_disk_mode | default('lvm') == "lvm"
with_items: "{{ groups['pxe_servers'] }}"
- name: Create VM Disk Image
command: |
qemu-img create -f qcow2 /var/lib/libvirt/images/{{ hostvars[item]['server_hostname'] }}.img {{ default_vm_storage }}m
when:
- hostvars[item]['server_vm'] | default(false) | bool
- default_vm_disk_mode | default('lvm') == "file"
with_items: "{{ groups['pxe_servers'] }}"
- name: Create the VM template

View File

@ -14,6 +14,8 @@
default_interface: "{{ default_network | default('eth0') }}"
default_vm_image: "{{ default_image | default('ubuntu-16.04-amd64') }}"
default_vm_storage: "{{ vm_disk_size | default(92160) }}"
default_vm_disk_mode: lvm
default_vm_disk_vg: vg01
default_acng_bind_address: 0.0.0.0
default_os_families:
ubuntu-16.04-amd64: debian
@ -26,7 +28,7 @@ default_ubuntu_mirror_directory: /ubuntu
default_container_tech: "{{ container_tech | default('lxc') }}"
ipxe_kernel_url: "{{ ipxe_kernel_url | default('http://boot.ipxe.org/ipxe.lkrn') }}"
ipxe_kernel_url: "http://boot.ipxe.org/ipxe.lkrn"
# IP address, or domain name of the TFTP server
tftp_server: "{{ hostvars[groups['pxe_hosts'][0]]['ansible_host'] | default(ansible_host) }}"

View File

@ -34,9 +34,15 @@
</pm>
<devices>
<emulator>/usr/bin/kvm-spice</emulator>
{% if default_vm_disk_mode == "lvm" %}
<disk type='block' device='disk'>
<driver name='qemu' type='raw' cache='none' io='native'/>
<source dev='/dev/vg01/{{ hostvars[item]["server_hostname"] }}'/>
<source dev='/dev/{{ default_vm_disk_vg }}/{{ hostvars[item]["server_hostname"] }}'/>
{% elif default_vm_disk_mode == "file" %}
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2' cache='none' io='native'/>
<source file='/var/lib/libvirt/images/{{ hostvars[item]["server_hostname"] }}.img'/>
{% endif %}
<target dev='vda' bus='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
<boot order='1'/>

View File

@ -174,6 +174,8 @@
- name: Locate data volume
command: "vgdisplay vg01"
failed_when: false
when:
- default_vm_disk_mode | default('lvm') == "lvm"
register: data_volume
- name: Locate data disk
@ -181,17 +183,20 @@
lsblk -brndo NAME,TYPE,FSTYPE,RO,SIZE | awk '/d[b-z]+ disk +0/{ if ($4>m){m=$4; d=$1}}; END{print d}'
register: lsblk
when:
- default_vm_disk_mode | default('lvm') == "lvm"
- data_volume.rc != 0
- mnaio_data_disk is undefined
- name: Create data disk label
command: "parted --script /dev/{{ mnaio_data_disk | default(lsblk.stdout) }} mklabel gpt"
when:
- default_vm_disk_mode | default('lvm') == "lvm"
- data_volume.rc != 0
- name: Create data disk partition
command: "parted --align optimal --script /dev/{{ mnaio_data_disk | default(lsblk.stdout) }} mkpart data1 ext4 0% 100%"
when:
- default_vm_disk_mode | default('lvm') == "lvm"
- data_volume.rc != 0
- name: Create data volume group
@ -199,11 +204,14 @@
vg: vg01
pvs: "/dev/{{ mnaio_data_disk | default(lsblk.stdout) }}1"
when:
- default_vm_disk_mode | default('lvm') == "lvm"
- data_volume.rc != 0
- name: Locate virsh data volume
command: "virsh pool-info vg01"
failed_when: false
when:
- default_vm_disk_mode | default('lvm') == "lvm"
register: virsh_data_volume
- name: Create /etc/libvirt/storage directory
@ -218,6 +226,7 @@
virsh pool-define /etc/libvirt/storage/vg01.xml
virsh pool-autostart vg01 || true
when:
- default_vm_disk_mode | default('lvm') == "lvm"
- virsh_data_volume.rc != 0
- name: Load virtio kernel modules