Skip to content

Commit

Permalink
hponcfg - revamped the module using ModuleHelper (#3840)
Browse files Browse the repository at this point in the history
* hponcfg - revamped the module using ModuleHelper

* added changelog fragment

* fixed imports

* Update plugins/modules/remote_management/hpilo/hponcfg.py

* fixed

(cherry picked from commit 7cbe1bc)
  • Loading branch information
russoz authored and patchback[bot] committed Dec 11, 2021
1 parent aad4c55 commit 3d392fc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 23 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/3840-hponcfg-mh-revamp.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- hponcfg - revamped module using ModuleHelper (https://github.com/ansible-collections/community.general/pull/3840).
42 changes: 19 additions & 23 deletions plugins/modules/remote_management/hpilo/hponcfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,42 +69,38 @@
executable: /opt/hp/tools/hponcfg
'''

from ansible.module_utils.basic import AnsibleModule
from ansible_collections.community.general.plugins.module_utils.module_helper import (
CmdModuleHelper, ArgFormat
)


def main():

module = AnsibleModule(
class HPOnCfg(CmdModuleHelper):
module = dict(
argument_spec=dict(
src=dict(type='path', required=True, aliases=['path']),
minfw=dict(type='str'),
executable=dict(default='hponcfg', type='str'),
verbose=dict(default=False, type='bool'),
)
)
command_args_formats = dict(
src=dict(fmt=["-f", "{0}"]),
verbose=dict(fmt="-v", style=ArgFormat.BOOLEAN),
minfw=dict(fmt=["-m", "{0}"]),
)
check_rc = True

# Consider every action a change (not idempotent yet!)
changed = True

src = module.params['src']
minfw = module.params['minfw']
executable = module.params['executable']
verbose = module.params['verbose']

options = ' -f %s' % src

if verbose:
options += ' -v'

if minfw:
options += ' -m %s' % minfw
def __init_module__(self):
self.command = self.vars.executable
# Consider every action a change (not idempotent yet!)
self.changed = True

rc, stdout, stderr = module.run_command('%s %s' % (executable, options))
def __run__(self):
self.run_command(params=['src', 'verbose', 'minfw'])

if rc != 0:
module.fail_json(rc=rc, msg="Failed to run hponcfg", stdout=stdout, stderr=stderr)

module.exit_json(changed=changed, stdout=stdout, stderr=stderr)
def main():
HPOnCfg.execute()


if __name__ == '__main__':
Expand Down

0 comments on commit 3d392fc

Please sign in to comment.