From d8023c225d83ba33454d9b6958d92151216a293f Mon Sep 17 00:00:00 2001 From: John W Higgins Date: Thu, 2 Jul 2015 17:07:07 -0700 Subject: [PATCH 1/2] Add zfs cloning --- system/zfs.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/system/zfs.py b/system/zfs.py index c3c87634377..00a81e32c54 100644 --- a/system/zfs.py +++ b/system/zfs.py @@ -66,6 +66,10 @@ options: - The checksum property. required: False choices: ['on','off',fletcher2,fletcher4,sha256] + clone: + description: + - Name of the snapshot to clone + required: False compression: description: - The compression property. @@ -253,8 +257,11 @@ class Zfs(object): properties = self.properties volsize = properties.pop('volsize', None) volblocksize = properties.pop('volblocksize', None) + clone = properties.pop('clone', None) if "@" in self.name: action = 'snapshot' + elif clone: + action = 'clone' else: action = 'create' @@ -272,6 +279,8 @@ class Zfs(object): if volsize: cmd.append('-V') cmd.append(volsize) + if clone: + cmd.append(clone) cmd.append(self.name) (rc, err, out) = self.module.run_command(' '.join(cmd)) if rc == 0: @@ -347,6 +356,7 @@ def main(): 'canmount': {'required': False, 'choices':['on', 'off', 'noauto']}, 'casesensitivity': {'required': False, 'choices':['sensitive', 'insensitive', 'mixed']}, 'checksum': {'required': False, 'choices':['on', 'off', 'fletcher2', 'fletcher4', 'sha256']}, + 'clone': {'required': False}, 'compression': {'required': False, 'choices':['on', 'off', 'lzjb', 'gzip', 'gzip-1', 'gzip-2', 'gzip-3', 'gzip-4', 'gzip-5', 'gzip-6', 'gzip-7', 'gzip-8', 'gzip-9', 'lz4', 'zle']}, 'copies': {'required': False, 'choices':['1', '2', '3']}, 'createparent': {'required': False, 'choices':['on', 'off']}, From 094ef92aeee49d97e754109df13affdf4739f71f Mon Sep 17 00:00:00 2001 From: John W Higgins Date: Fri, 3 Jul 2015 16:16:18 -0700 Subject: [PATCH 2/2] Switch to origin and cleanup --- system/zfs.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/system/zfs.py b/system/zfs.py index 00a81e32c54..f8a72a44f01 100644 --- a/system/zfs.py +++ b/system/zfs.py @@ -66,10 +66,6 @@ options: - The checksum property. required: False choices: ['on','off',fletcher2,fletcher4,sha256] - clone: - description: - - Name of the snapshot to clone - required: False compression: description: - The compression property. @@ -119,6 +115,10 @@ options: - The normalization property. required: False choices: [none,formC,formD,formKC,formKD] + origin: + description: + - Name of the snapshot to clone + required: False primarycache: description: - The primarycache property. @@ -225,6 +225,12 @@ EXAMPLES = ''' # Create a new file system called myfs2 with snapdir enabled - zfs: name=rpool/myfs2 state=present snapdir=enabled + +# Create a new file system by cloning a snapshot +- zfs: name=rpool/cloned_fs state=present origin=rpool/myfs@mysnapshot + +# Destroy a filesystem +- zfs: name=rpool/myfs state=absent ''' @@ -257,10 +263,10 @@ class Zfs(object): properties = self.properties volsize = properties.pop('volsize', None) volblocksize = properties.pop('volblocksize', None) - clone = properties.pop('clone', None) + origin = properties.pop('origin', None) if "@" in self.name: action = 'snapshot' - elif clone: + elif origin: action = 'clone' else: action = 'create' @@ -279,8 +285,8 @@ class Zfs(object): if volsize: cmd.append('-V') cmd.append(volsize) - if clone: - cmd.append(clone) + if origin: + cmd.append(origin) cmd.append(self.name) (rc, err, out) = self.module.run_command(' '.join(cmd)) if rc == 0: @@ -356,7 +362,6 @@ def main(): 'canmount': {'required': False, 'choices':['on', 'off', 'noauto']}, 'casesensitivity': {'required': False, 'choices':['sensitive', 'insensitive', 'mixed']}, 'checksum': {'required': False, 'choices':['on', 'off', 'fletcher2', 'fletcher4', 'sha256']}, - 'clone': {'required': False}, 'compression': {'required': False, 'choices':['on', 'off', 'lzjb', 'gzip', 'gzip-1', 'gzip-2', 'gzip-3', 'gzip-4', 'gzip-5', 'gzip-6', 'gzip-7', 'gzip-8', 'gzip-9', 'lz4', 'zle']}, 'copies': {'required': False, 'choices':['1', '2', '3']}, 'createparent': {'required': False, 'choices':['on', 'off']}, @@ -370,6 +375,7 @@ def main(): 'mountpoint': {'required': False}, 'nbmand': {'required': False, 'choices':['on', 'off']}, 'normalization': {'required': False, 'choices':['none', 'formC', 'formD', 'formKC', 'formKD']}, + 'origin': {'required': False}, 'primarycache': {'required': False, 'choices':['all', 'none', 'metadata']}, 'quota': {'required': False}, 'readonly': {'required': False, 'choices':['on', 'off']},