Skip to content

Commit

Permalink
Added support for --check in zfs module
Browse files Browse the repository at this point in the history
  • Loading branch information
johanwiren committed Feb 22, 2013
1 parent e4ccf2d commit ee517ea
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions library/zfs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ class Zfs(object):
return False

def create(self):
if self.module.check_mode:
self.changed = True
return
properties=self.properties
volsize = properties.pop('volsize', None)
volblocksize = properties.pop('volblocksize', None)
Expand All @@ -266,6 +269,9 @@ class Zfs(object):
self.module.fail_json(msg=out)

def destroy(self):
if self.module.check_mode:
self.changed = True
return
cmd = [self.module.get_bin_path('zfs', True)]
cmd.append('destroy')
cmd.append(self.name)
Expand All @@ -276,6 +282,9 @@ class Zfs(object):
self.module.fail_json(msg=out)

def set_property(self, prop, value):
if self.module.check_mode:
self.changed = True
return
cmd = [self.module.get_bin_path('zfs', True)]
cmd.append('set')
cmd.append(prop + '=' + value)
Expand Down Expand Up @@ -356,18 +365,21 @@ def main():
'vscan': {'required': False, 'choices':['on', 'off']},
'xattr': {'required': False, 'choices':['on', 'off']},
'zoned': {'required': False, 'choices':['on', 'off']},
}
},
supports_check_mode=True
)

state = module.params.pop('state')
name = module.params.pop('name')
# Remaining items in module.params are zfs properties

# Remove 'null' value properties
# Get all valid zfs-properties
properties = dict()
for prop, value in module.params.iteritems():
if prop in ['CHECKMODE']:
continue
if value:
properties[prop] = value

result = {}
result['name'] = name
result['state'] = state
Expand Down

0 comments on commit ee517ea

Please sign in to comment.