mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-08-04 05:04:22 -07:00
refactor(review): Additional code review items
This commit is contained in:
parent
cfd1167ee8
commit
00b87134f8
2 changed files with 129 additions and 141 deletions
|
@ -27,7 +27,7 @@ options:
|
||||||
state:
|
state:
|
||||||
description:
|
description:
|
||||||
- Indicate desired state for cluster STONITH.
|
- Indicate desired state for cluster STONITH.
|
||||||
choices: [ present, absent, enabled, disabled ]
|
choices: [present, absent, enabled, disabled]
|
||||||
default: present
|
default: present
|
||||||
type: str
|
type: str
|
||||||
name:
|
name:
|
||||||
|
@ -75,7 +75,7 @@ options:
|
||||||
description:
|
description:
|
||||||
- Action to apply to STONITH.
|
- Action to apply to STONITH.
|
||||||
type: str
|
type: str
|
||||||
choices: [ group, before, after ]
|
choices: [group, before, after]
|
||||||
argument_options:
|
argument_options:
|
||||||
description:
|
description:
|
||||||
- Options to associate with STONITH action.
|
- Options to associate with STONITH action.
|
||||||
|
@ -143,13 +143,14 @@ class PacemakerStonith(StateModuleHelper):
|
||||||
supports_check_mode=True
|
supports_check_mode=True
|
||||||
)
|
)
|
||||||
|
|
||||||
default_state = "present"
|
|
||||||
|
|
||||||
def __init_module__(self):
|
def __init_module__(self):
|
||||||
self.runner = pacemaker_runner(self.module, cli_action='stonith')
|
self.runner = pacemaker_runner(self.module, cli_action='stonith')
|
||||||
self.vars.set('previous_value', self._get())
|
self.vars.set('previous_value', self._get()['out'])
|
||||||
self.vars.set('value', self.vars.previous_value, change=True, diff=True)
|
self.vars.set('value', self.vars.previous_value, change=True, diff=True)
|
||||||
|
|
||||||
|
def __quit_module__(self):
|
||||||
|
self.vars.set('value', self._get()['out'])
|
||||||
|
|
||||||
def _process_command_output(self, fail_on_err, ignore_err_msg=""):
|
def _process_command_output(self, fail_on_err, ignore_err_msg=""):
|
||||||
def process(rc, out, err):
|
def process(rc, out, err):
|
||||||
if fail_on_err and rc != 0 and err and ignore_err_msg not in err:
|
if fail_on_err and rc != 0 and err and ignore_err_msg not in err:
|
||||||
|
@ -159,14 +160,17 @@ class PacemakerStonith(StateModuleHelper):
|
||||||
return process
|
return process
|
||||||
|
|
||||||
def _get(self):
|
def _get(self):
|
||||||
with self.runner('state name', output_process=self._process_command_output(False)) as ctx:
|
with self.runner('state name') as ctx:
|
||||||
return ctx.run(state='status')
|
result = ctx.run(state='status')
|
||||||
|
return dict([('rc', result[0]),
|
||||||
|
('out', result[1] if result[1] != "" else None),
|
||||||
|
('err', result[2])])
|
||||||
|
|
||||||
def _fmt_stonith_resource(self):
|
def fmt_stonith_resource(self):
|
||||||
return dict([("resource_name", self.vars.stonith_type)])
|
return dict([("resource_name", self.vars.stonith_type)])
|
||||||
|
|
||||||
# TODO: Pluralize operation_options in separate PR and remove this helper fmt function
|
# TODO: Pluralize operation_options in separate PR and remove this helper fmt function
|
||||||
def _fmt_stonith_operations(self):
|
def fmt_stonith_operations(self):
|
||||||
modified_stonith_operations = []
|
modified_stonith_operations = []
|
||||||
for stonith_operation in self.vars.stonith_operations:
|
for stonith_operation in self.vars.stonith_operations:
|
||||||
modified_stonith_operations.append(dict([("operation_action", stonith_operation.get('operation_action')),
|
modified_stonith_operations.append(dict([("operation_action", stonith_operation.get('operation_action')),
|
||||||
|
@ -176,41 +180,25 @@ class PacemakerStonith(StateModuleHelper):
|
||||||
def state_absent(self):
|
def state_absent(self):
|
||||||
with self.runner('state name', output_process=self._process_command_output(True, "does not exist"), check_mode_skip=True) as ctx:
|
with self.runner('state name', output_process=self._process_command_output(True, "does not exist"), check_mode_skip=True) as ctx:
|
||||||
ctx.run()
|
ctx.run()
|
||||||
self.vars.set('value', self._get())
|
|
||||||
self.vars.stdout = ctx.results_out
|
|
||||||
self.vars.stderr = ctx.results_err
|
|
||||||
self.vars.cmd = ctx.cmd
|
|
||||||
|
|
||||||
def state_present(self):
|
def state_present(self):
|
||||||
with self.runner(
|
with self.runner(
|
||||||
'state name resource_type resource_option resource_operation resource_meta resource_argument agent_validation wait',
|
'state name resource_type resource_option resource_operation resource_meta resource_argument agent_validation wait',
|
||||||
output_process=self._process_command_output(True, "already exists"),
|
output_process=self._process_command_output(True, "already exists"),
|
||||||
check_mode_skip=True) as ctx:
|
check_mode_skip=True) as ctx:
|
||||||
ctx.run(resource_type=self._fmt_stonith_resource(),
|
ctx.run(resource_type=self.fmt_stonith_resource(),
|
||||||
resource_option=self.vars.stonith_options,
|
resource_option=self.vars.stonith_options,
|
||||||
resource_operation=self._fmt_stonith_operations(),
|
resource_operation=self.fmt_stonith_operations(),
|
||||||
resource_meta=self.vars.stonith_metas,
|
resource_meta=self.vars.stonith_metas,
|
||||||
resource_argument=self.vars.stonith_argument)
|
resource_argument=self.vars.stonith_argument)
|
||||||
self.vars.set('value', self._get())
|
|
||||||
self.vars.stdout = ctx.results_out
|
|
||||||
self.vars.stderr = ctx.results_err
|
|
||||||
self.vars.cmd = ctx.cmd
|
|
||||||
|
|
||||||
def state_enabled(self):
|
def state_enabled(self):
|
||||||
with self.runner('state name', output_process=self._process_command_output(True, "Starting"), check_mode_skip=True) as ctx:
|
with self.runner('state name', output_process=self._process_command_output(True, "Starting"), check_mode_skip=True) as ctx:
|
||||||
ctx.run()
|
ctx.run()
|
||||||
self.vars.set('value', self._get())
|
|
||||||
self.vars.stdout = ctx.results_out
|
|
||||||
self.vars.stderr = ctx.results_err
|
|
||||||
self.vars.cmd = ctx.cmd
|
|
||||||
|
|
||||||
def state_disabled(self):
|
def state_disabled(self):
|
||||||
with self.runner('state name', output_process=self._process_command_output(True, "Stopped"), check_mode_skip=True) as ctx:
|
with self.runner('state name', output_process=self._process_command_output(True, "Stopped"), check_mode_skip=True) as ctx:
|
||||||
ctx.run()
|
ctx.run()
|
||||||
self.vars.set('value', self._get())
|
|
||||||
self.vars.stdout = ctx.results_out
|
|
||||||
self.vars.stderr = ctx.results_err
|
|
||||||
self.vars.cmd = ctx.cmd
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue