Skip to content

Commit

Permalink
hponcfg: using CmdRunner (#5483)
Browse files Browse the repository at this point in the history
* hponcfg: using CmdRunner

* add changelog fragment
  • Loading branch information
russoz authored Nov 7, 2022
1 parent ac6ac73 commit 7a9af2b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/5483-hponcfg-cmd-runner.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- hponcfg - refactored module to use ``CmdRunner`` to execute ``hponcfg`` (https://github.com/ansible-collections/community.general/pull/5483).
28 changes: 15 additions & 13 deletions plugins/modules/hponcfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,11 @@
executable: /opt/hp/tools/hponcfg
'''

from ansible_collections.community.general.plugins.module_utils.module_helper import (
CmdModuleHelper, ArgFormat
)
from ansible_collections.community.general.plugins.module_utils.cmd_runner import CmdRunner, cmd_runner_fmt
from ansible_collections.community.general.plugins.module_utils.module_helper import ModuleHelper


class HPOnCfg(CmdModuleHelper):
class HPOnCfg(ModuleHelper):
module = dict(
argument_spec=dict(
src=dict(type='path', required=True, aliases=['path']),
Expand All @@ -88,20 +87,23 @@ class HPOnCfg(CmdModuleHelper):
)
)
command_args_formats = dict(
src=dict(fmt=["-f", "{0}"]),
verbose=dict(fmt="-v", style=ArgFormat.BOOLEAN),
minfw=dict(fmt=["-m", "{0}"]),
src=cmd_runner_fmt.as_opt_val("-f"),
verbose=cmd_runner_fmt.as_bool("-v"),
minfw=cmd_runner_fmt.as_opt_val("-m"),
)
check_rc = True

def __init_module__(self):
self.command = self.vars.executable
def __run__(self):
runner = CmdRunner(
self.module,
self.vars.executable,
self.command_args_formats,
check_rc=True,
)
runner(['src', 'verbose', 'minfw']).run()

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

def __run__(self):
self.run_command(params=['src', 'verbose', 'minfw'])


def main():
HPOnCfg.execute()
Expand Down

0 comments on commit 7a9af2b

Please sign in to comment.