mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
* pythonification
* added changelog fragment
* adjustment per PR
(cherry picked from commit 0f9311c3d9
)
Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
This commit is contained in:
parent
134f6132ce
commit
73de447489
2 changed files with 19 additions and 29 deletions
2
changelogs/fragments/3332-zpool_facts-pythonify.yaml
Normal file
2
changelogs/fragments/3332-zpool_facts-pythonify.yaml
Normal file
|
@ -0,0 +1,2 @@
|
|||
minor_changes:
|
||||
- zpool_facts - minor refactoring (https://github.com/ansible-collections/community.general/pull/3332).
|
|
@ -125,23 +125,16 @@ class ZPoolFacts(object):
|
|||
def __init__(self, module):
|
||||
|
||||
self.module = module
|
||||
|
||||
self.name = module.params['name']
|
||||
self.parsable = module.params['parsable']
|
||||
self.properties = module.params['properties']
|
||||
|
||||
self._pools = defaultdict(dict)
|
||||
self.facts = []
|
||||
|
||||
def pool_exists(self):
|
||||
cmd = [self.module.get_bin_path('zpool'), 'list', self.name]
|
||||
|
||||
(rc, out, err) = self.module.run_command(cmd)
|
||||
|
||||
if rc == 0:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
rc, dummy, dummy = self.module.run_command(cmd)
|
||||
return rc == 0
|
||||
|
||||
def get_facts(self):
|
||||
cmd = [self.module.get_bin_path('zpool'), 'get', '-H']
|
||||
|
@ -153,41 +146,36 @@ class ZPoolFacts(object):
|
|||
if self.name:
|
||||
cmd.append(self.name)
|
||||
|
||||
(rc, out, err) = self.module.run_command(cmd)
|
||||
rc, out, err = self.module.run_command(cmd, check_rc=True)
|
||||
|
||||
if rc == 0:
|
||||
for line in out.splitlines():
|
||||
pool, property, value = line.split('\t')
|
||||
for line in out.splitlines():
|
||||
pool, prop, value = line.split('\t')
|
||||
|
||||
self._pools[pool].update({property: value})
|
||||
self._pools[pool].update({prop: value})
|
||||
|
||||
for k, v in iteritems(self._pools):
|
||||
v.update({'name': k})
|
||||
self.facts.append(v)
|
||||
for k, v in iteritems(self._pools):
|
||||
v.update({'name': k})
|
||||
self.facts.append(v)
|
||||
|
||||
return {'ansible_zfs_pools': self.facts}
|
||||
else:
|
||||
self.module.fail_json(msg='Error while trying to get facts about ZFS pool: %s' % self.name,
|
||||
stderr=err,
|
||||
rc=rc)
|
||||
return {'ansible_zfs_pools': self.facts}
|
||||
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
name=dict(required=False, aliases=['pool', 'zpool'], type='str'),
|
||||
parsable=dict(required=False, default=False, type='bool'),
|
||||
properties=dict(required=False, default='all', type='str'),
|
||||
name=dict(aliases=['pool', 'zpool'], type='str'),
|
||||
parsable=dict(default=False, type='bool'),
|
||||
properties=dict(default='all', type='str'),
|
||||
),
|
||||
supports_check_mode=True
|
||||
)
|
||||
|
||||
zpool_facts = ZPoolFacts(module)
|
||||
|
||||
result = {}
|
||||
result['changed'] = False
|
||||
result['name'] = zpool_facts.name
|
||||
|
||||
result = {
|
||||
'changed': False,
|
||||
'name': zpool_facts.name,
|
||||
}
|
||||
if zpool_facts.parsable:
|
||||
result['parsable'] = zpool_facts.parsable
|
||||
|
||||
|
|
Loading…
Reference in a new issue