mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-08-03 20:54:24 -07:00
refactor(review): Apply code review suggestions
This commit is contained in:
parent
356c42ba3b
commit
220bb72d6c
3 changed files with 56 additions and 45 deletions
|
@ -64,6 +64,7 @@ def pacemaker_runner(module, **kwargs):
|
||||||
resource_meta=cmd_runner_fmt.stack(cmd_runner_fmt.as_opt_val)("meta"),
|
resource_meta=cmd_runner_fmt.stack(cmd_runner_fmt.as_opt_val)("meta"),
|
||||||
resource_argument=cmd_runner_fmt.as_func(fmt_resource_argument),
|
resource_argument=cmd_runner_fmt.as_func(fmt_resource_argument),
|
||||||
apply_all=cmd_runner_fmt.as_bool("--all"),
|
apply_all=cmd_runner_fmt.as_bool("--all"),
|
||||||
|
agent_validation=cmd_runner_fmt.as_bool("--agent-validation"),
|
||||||
wait=cmd_runner_fmt.as_opt_eq_val("--wait"),
|
wait=cmd_runner_fmt.as_opt_eq_val("--wait"),
|
||||||
config=cmd_runner_fmt.as_fixed("config"),
|
config=cmd_runner_fmt.as_fixed("config"),
|
||||||
force=cmd_runner_fmt.as_bool("--force"),
|
force=cmd_runner_fmt.as_bool("--force"),
|
||||||
|
|
|
@ -11,12 +11,12 @@ __metaclass__ = type
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = '''
|
||||||
---
|
---
|
||||||
module: pacemaker_stonith
|
module: pacemaker_stonith
|
||||||
short_description: Manage pacemaker stonith
|
short_description: Manage pacemaker STONITH
|
||||||
author:
|
author:
|
||||||
- Dexter Le (@munchtoast)
|
- Dexter Le (@munchtoast)
|
||||||
version_added: 10.8.0
|
version_added: 11.1.0
|
||||||
description:
|
description:
|
||||||
- This module can manage stonith in a Pacemaker cluster using the pacemaker CLI.
|
- This module can manage STONITH in a Pacemaker cluster using the pacemaker CLI.
|
||||||
extends_documentation_fragment:
|
extends_documentation_fragment:
|
||||||
- community.general.attributes
|
- community.general.attributes
|
||||||
attributes:
|
attributes:
|
||||||
|
@ -27,95 +27,95 @@ attributes:
|
||||||
options:
|
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:
|
||||||
description:
|
description:
|
||||||
- Specify the stonith name to create.
|
- Specify the STONITH name to create.
|
||||||
required: true
|
required: true
|
||||||
type: str
|
type: str
|
||||||
stonith_type:
|
stonith_type:
|
||||||
description:
|
description:
|
||||||
- Specify the stonith device type
|
- Specify the STONITH device type
|
||||||
type: str
|
type: str
|
||||||
stonith_option:
|
stonith_options:
|
||||||
description:
|
description:
|
||||||
- Specify the stonith option to create.
|
- Specify the STONITH option to create.
|
||||||
type: list
|
type: list
|
||||||
elements: str
|
elements: str
|
||||||
default: []
|
default: []
|
||||||
stonith_operation:
|
stonith_operations:
|
||||||
description:
|
description:
|
||||||
- List of operations to associate with stonith.
|
- List of operations to associate with STONITH.
|
||||||
type: list
|
type: list
|
||||||
elements: dict
|
elements: dict
|
||||||
default: []
|
default: []
|
||||||
suboptions:
|
suboptions:
|
||||||
operation_action:
|
operation_action:
|
||||||
description:
|
description:
|
||||||
- Operation action to associate with stonith.
|
- Operation action to associate with STONITH.
|
||||||
type: str
|
type: str
|
||||||
operation_option:
|
operation_options:
|
||||||
description:
|
description:
|
||||||
- Operation option to associate with action.
|
- Operation option to associate with action.
|
||||||
type: list
|
type: list
|
||||||
elements: str
|
elements: str
|
||||||
stonith_meta:
|
stonith_metas:
|
||||||
description:
|
description:
|
||||||
- List of meta to associate with stonith.
|
- List of meta to associate with STONITH.
|
||||||
type: list
|
type: list
|
||||||
elements: str
|
elements: str
|
||||||
stonith_argument:
|
stonith_argument:
|
||||||
description:
|
description:
|
||||||
- Action to associate with stonith.
|
- Action to associate with STONITH.
|
||||||
type: dict
|
type: dict
|
||||||
suboptions:
|
suboptions:
|
||||||
argument_action:
|
argument_action:
|
||||||
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_option:
|
argument_options:
|
||||||
description:
|
description:
|
||||||
- Options to associate with stonith action.
|
- Options to associate with STONITH action.
|
||||||
type: list
|
type: list
|
||||||
elements: str
|
elements: str
|
||||||
agent_validation:
|
agent_validation:
|
||||||
description:
|
description:
|
||||||
- enabled agent validation for stonith creation.
|
- enabled agent validation for STONITH creation.
|
||||||
type: bool
|
type: bool
|
||||||
default: false
|
default: false
|
||||||
wait:
|
wait:
|
||||||
description:
|
description:
|
||||||
- Timeout period for polling the stonith creation.
|
- Timeout period for polling the STONITH creation.
|
||||||
type: int
|
type: int
|
||||||
default: 300
|
default: 300
|
||||||
'''
|
'''
|
||||||
|
|
||||||
EXAMPLES = '''
|
EXAMPLES = '''
|
||||||
---
|
---
|
||||||
- name: Create pacemaker stonith
|
- name: Create pacemaker STONITH
|
||||||
hosts: localhost
|
hosts: localhost
|
||||||
gather_facts: false
|
gather_facts: false
|
||||||
tasks:
|
tasks:
|
||||||
- name: Create virtual-ip stonith
|
- name: Create virtual-ip STONITH
|
||||||
community.general.pacemaker_stonith:
|
community.general.pacemaker_stonith:
|
||||||
state: present
|
state: present
|
||||||
name: virtual-stonith
|
name: virtual-stonith
|
||||||
stonith_type: fence_virt
|
stonith_type: fence_virt
|
||||||
stonith_option:
|
stonith_options:
|
||||||
- "pcmk_host_list=f1"
|
- "pcmk_host_list=f1"
|
||||||
stonith_operation:
|
stonith_operations:
|
||||||
- operation_action: monitor
|
- operation_action: monitor
|
||||||
operation_option:
|
operation_options:
|
||||||
- "interval=30s"
|
- "interval=30s"
|
||||||
'''
|
'''
|
||||||
|
|
||||||
RETURN = '''
|
RETURN = '''
|
||||||
cluster_stonith:
|
cluster_stonith:
|
||||||
description: The cluster stonith output message.
|
description: The cluster STONITH output message.
|
||||||
type: str
|
type: str
|
||||||
sample: ""
|
sample: ""
|
||||||
returned: always
|
returned: always
|
||||||
|
@ -132,20 +132,20 @@ class PacemakerStonith(StateModuleHelper):
|
||||||
'present', 'absent', 'enabled', 'disabled']),
|
'present', 'absent', 'enabled', 'disabled']),
|
||||||
name=dict(type='str', required=True),
|
name=dict(type='str', required=True),
|
||||||
stonith_type=dict(type='str'),
|
stonith_type=dict(type='str'),
|
||||||
stonith_option=dict(type='list', elements='str', default=list()),
|
stonith_options=dict(type='list', elements='str', default=list()),
|
||||||
stonith_operation=dict(type='list', elements='dict', default=list(), options=dict(
|
stonith_operations=dict(type='list', elements='dict', default=list(), options=dict(
|
||||||
operation_action=dict(type='str'),
|
operation_action=dict(type='str'),
|
||||||
operation_option=dict(type='list', elements='str'),
|
operation_options=dict(type='list', elements='str'),
|
||||||
)),
|
)),
|
||||||
stonith_meta=dict(type='list', elements='str'),
|
stonith_metas=dict(type='list', elements='str'),
|
||||||
stonith_argument=dict(type='dict', options=dict(
|
stonith_argument=dict(type='dict', options=dict(
|
||||||
argument_action=dict(type='str', choices=['before', 'after', 'group']),
|
argument_action=dict(type='str', choices=['before', 'after', 'group']),
|
||||||
argument_option=dict(type='list', elements='str'),
|
argument_options=dict(type='list', elements='str'),
|
||||||
)),
|
)),
|
||||||
agent_validation=dict(type='bool', default=False),
|
agent_validation=dict(type='bool', default=False),
|
||||||
wait=dict(type='int', default=300),
|
wait=dict(type='int', default=300),
|
||||||
),
|
),
|
||||||
required_if=[('state', 'present', ['stonith_type', 'stonith_option'])],
|
required_if=[('state', 'present', ['stonith_type', 'stonith_options'])],
|
||||||
supports_check_mode=True
|
supports_check_mode=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -156,11 +156,6 @@ class PacemakerStonith(StateModuleHelper):
|
||||||
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())
|
||||||
self.vars.set('value', self.vars.previous_value, change=True, diff=True)
|
self.vars.set('value', self.vars.previous_value, change=True, diff=True)
|
||||||
self.module.params['resource_type'] = dict(resource_name=self.vars.stonith_type)
|
|
||||||
self.module.params['resource_option'] = self.vars.stonith_option
|
|
||||||
self.module.params['resource_operation'] = self.vars.stonith_operation
|
|
||||||
self.module.params['resource_meta'] = self.vars.stonith_meta
|
|
||||||
self.module.params['resource_argument'] = self.vars.stonith_argument
|
|
||||||
|
|
||||||
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):
|
||||||
|
@ -174,6 +169,17 @@ class PacemakerStonith(StateModuleHelper):
|
||||||
with self.runner('state name', output_process=self._process_command_output(False)) as ctx:
|
with self.runner('state name', output_process=self._process_command_output(False)) as ctx:
|
||||||
return ctx.run(state='status')
|
return ctx.run(state='status')
|
||||||
|
|
||||||
|
def _fmt_stonith_resource(self):
|
||||||
|
return dict([("resource_name", self.vars.stonith_type)])
|
||||||
|
|
||||||
|
# TODO: Pluralize operation_options in separate PR and remove this helper fmt function
|
||||||
|
def _fmt_stonith_operations(self):
|
||||||
|
modified_stonith_operations = []
|
||||||
|
for stonith_operation in self.vars.stonith_operations:
|
||||||
|
modified_stonith_operations.append(dict([("operation_action", stonith_operation.get('operation_action')),
|
||||||
|
("operation_option", stonith_operation.get('operation_options'))]))
|
||||||
|
return modified_stonith_operations
|
||||||
|
|
||||||
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()
|
||||||
|
@ -184,10 +190,14 @@ class PacemakerStonith(StateModuleHelper):
|
||||||
|
|
||||||
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 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()
|
ctx.run(resource_type=self._fmt_stonith_resource(),
|
||||||
|
resource_option=self.vars.stonith_options,
|
||||||
|
resource_operation=self._fmt_stonith_operations(),
|
||||||
|
resource_meta=self.vars.stonith_metas,
|
||||||
|
resource_argument=self.vars.stonith_argument)
|
||||||
self.vars.set('value', self._get())
|
self.vars.set('value', self._get())
|
||||||
self.vars.stdout = ctx.results_out
|
self.vars.stdout = ctx.results_out
|
||||||
self.vars.stderr = ctx.results_err
|
self.vars.stderr = ctx.results_err
|
||||||
|
|
|
@ -17,11 +17,11 @@ test_cases:
|
||||||
state: present
|
state: present
|
||||||
name: virtual-stonith
|
name: virtual-stonith
|
||||||
stonith_type: fence_virt
|
stonith_type: fence_virt
|
||||||
stonith_option:
|
stonith_options:
|
||||||
- "pcmk_host_list=f1"
|
- "pcmk_host_list=f1"
|
||||||
stonith_operation:
|
stonith_operations:
|
||||||
- operation_action: monitor
|
- operation_action: monitor
|
||||||
operation_option:
|
operation_options:
|
||||||
- "interval=30s"
|
- "interval=30s"
|
||||||
output:
|
output:
|
||||||
changed: true
|
changed: true
|
||||||
|
@ -49,11 +49,11 @@ test_cases:
|
||||||
state: present
|
state: present
|
||||||
name: virtual-stonith
|
name: virtual-stonith
|
||||||
stonith_type: fence_virt
|
stonith_type: fence_virt
|
||||||
stonith_option:
|
stonith_options:
|
||||||
- "pcmk_host_list=f1"
|
- "pcmk_host_list=f1"
|
||||||
stonith_operation:
|
stonith_operations:
|
||||||
- operation_action: monitor
|
- operation_action: monitor
|
||||||
operation_option:
|
operation_options:
|
||||||
- "interval=30s"
|
- "interval=30s"
|
||||||
output:
|
output:
|
||||||
changed: false
|
changed: false
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue