From f75789f963fcb4d4e6d9f9563c85eeccfcbaf1e1 Mon Sep 17 00:00:00 2001 From: Jesse Pretorius Date: Sun, 21 Aug 2016 19:20:37 +0100 Subject: [PATCH] Implement LVM-backed CoW containers This patch implements the ability to set 'copy-on-write' as the 'lxc_container_backing_method' for containers where the 'lxc_container_backing_store' is 'lvm'. Change-Id: I571fe60d6d051a7d377ec95d83a2617e3f0dd384 Depends-On: I0bf227891a85bd7c8db53ca73fc5380b95e514fa --- ...ainer-create-lvm-cow-77c049188b8a2676.yaml | 6 +++++ tasks/container_create.yml | 22 +++++++++++-------- 2 files changed, 19 insertions(+), 9 deletions(-) create mode 100644 releasenotes/notes/container-create-lvm-cow-77c049188b8a2676.yaml diff --git a/releasenotes/notes/container-create-lvm-cow-77c049188b8a2676.yaml b/releasenotes/notes/container-create-lvm-cow-77c049188b8a2676.yaml new file mode 100644 index 0000000..f428344 --- /dev/null +++ b/releasenotes/notes/container-create-lvm-cow-77c049188b8a2676.yaml @@ -0,0 +1,6 @@ +--- +features: + - The container creation process now allows ``copy-on-write`` to be set as + the ``lxc_container_backing_method`` when the + ``lxc_container_backing_store`` is set to ``lvm``. When this is set it + will use a snapshot of the base container to build the containers. diff --git a/tasks/container_create.yml b/tasks/container_create.yml index c2f4914..22b2787 100644 --- a/tasks/container_create.yml +++ b/tasks/container_create.yml @@ -69,37 +69,41 @@ vg_name: "{{ lxc_container_vg_name }}" template_options: "{{ lxc_container_download_template_options }}" delegate_to: "{{ physical_host }}" - when: - - lxc_container_backing_store != "overlayfs" + when: > + lxc_container_backing_store != "overlayfs" or + (lxc_container_backing_store == 'lvm' and not lxc_container_backing_method == 'copy-on-write') tags: - lxc-container-create # Due to https://github.com/ansible/ansible-modules-extras/issues/2577 the # next two tasks do not use the lxc_container module. # TODO(odyssey4me): Revisit this once a fix has merged -- name: Check if container exists (overlayfs) +- name: Check if container exists (copy-on-write backing store) command: "lxc-info -n {{ inventory_hostname }}" failed_when: false delegate_to: "{{ physical_host }}" register: lxc_container_info - when: lxc_container_backing_store == "overlayfs" + when: > + lxc_container_backing_store == "overlayfs" or + (lxc_container_backing_store == 'lvm' and lxc_container_backing_method == 'copy-on-write') # Due to https://bugs.launchpad.net/ubuntu/+source/lxc/+bug/1591510 # the '-B' option is used, instead of the more understandable # '--backingstore'. # TODO(odyssey4me): Revisit this once a fix has merged -- name: Create container (overlayfs) +- name: Create container (copy-on-write backing store) command: > - lxc-copy --snapshot -B overlayfs + lxc-copy --snapshot -B {{ lxc_container_backing_store }} --name {{ lxc_container_map.distro }}-{{ lxc_container_map.release }}-{{ lxc_container_map.arch }} --newname {{ inventory_hostname }} -L {{ properties.container_fs_size | default(lxc_container_fs_size) }} --logfile {{ lxc_container_log_path }}/lxc-{{ inventory_hostname }}.log --logpriority {{ (debug | bool) | ternary('DEBUG', 'INFO') }} delegate_to: "{{ physical_host }}" - when: - - lxc_container_backing_store == "overlayfs" - - lxc_container_info.rc != 0 + when: > + (lxc_container_backing_store == "overlayfs" or + (lxc_container_backing_store == 'lvm' and lxc_container_backing_method == 'copy-on-write')) and + lxc_container_info.rc != 0 tags: - lxc-container-create