Merge pull request #677 from wishdev/devel

Add zfs cloning
reviewable/pr18780/r1
Brian Coca 9 years ago
commit 9ca7f2b3c9

@ -115,6 +115,10 @@ options:
- The normalization property. - The normalization property.
required: False required: False
choices: [none,formC,formD,formKC,formKD] choices: [none,formC,formD,formKC,formKD]
origin:
description:
- Name of the snapshot to clone
required: False
primarycache: primarycache:
description: description:
- The primarycache property. - The primarycache property.
@ -221,6 +225,12 @@ EXAMPLES = '''
# Create a new file system called myfs2 with snapdir enabled # Create a new file system called myfs2 with snapdir enabled
- zfs: name=rpool/myfs2 state=present 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
''' '''
@ -253,8 +263,11 @@ class Zfs(object):
properties = self.properties properties = self.properties
volsize = properties.pop('volsize', None) volsize = properties.pop('volsize', None)
volblocksize = properties.pop('volblocksize', None) volblocksize = properties.pop('volblocksize', None)
origin = properties.pop('origin', None)
if "@" in self.name: if "@" in self.name:
action = 'snapshot' action = 'snapshot'
elif origin:
action = 'clone'
else: else:
action = 'create' action = 'create'
@ -272,6 +285,8 @@ class Zfs(object):
if volsize: if volsize:
cmd.append('-V') cmd.append('-V')
cmd.append(volsize) cmd.append(volsize)
if origin:
cmd.append(origin)
cmd.append(self.name) cmd.append(self.name)
(rc, err, out) = self.module.run_command(' '.join(cmd)) (rc, err, out) = self.module.run_command(' '.join(cmd))
if rc == 0: if rc == 0:
@ -360,6 +375,7 @@ def main():
'mountpoint': {'required': False}, 'mountpoint': {'required': False},
'nbmand': {'required': False, 'choices':['on', 'off']}, 'nbmand': {'required': False, 'choices':['on', 'off']},
'normalization': {'required': False, 'choices':['none', 'formC', 'formD', 'formKC', 'formKD']}, 'normalization': {'required': False, 'choices':['none', 'formC', 'formD', 'formKC', 'formKD']},
'origin': {'required': False},
'primarycache': {'required': False, 'choices':['all', 'none', 'metadata']}, 'primarycache': {'required': False, 'choices':['all', 'none', 'metadata']},
'quota': {'required': False}, 'quota': {'required': False},
'readonly': {'required': False, 'choices':['on', 'off']}, 'readonly': {'required': False, 'choices':['on', 'off']},

Loading…
Cancel
Save