mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-06 10:40:32 -07:00
* Add initial pacemaker resource * Additional fixes on pacemaker_resource * Fix up module parameters * fix doc and lint * fix group command build * Apply suggestions for removing status and improve descriptions * fix cmd builder list * Apply suggestions and add initial unit tests * Fix unit tests expected output * Initial refactor on pacemaker resource Refactorization on pacemaker_resource to utilize module helpers. * Apply suggestions and fix up initial unit test * Apply suggestions from code review * Fix pep8 format for utils * Fix unit tests for pacemaker resource * Add botmeta maintainers for new moduules * Apply suggestions from code review Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com> * Apply unit test suggestion * Add disable and enable states for pacemaker_resource * Fix state names and add cli_action for runner * Remove unnecessary variables * Fix documentation example playbook * Fix IP Address for resource_option * Refactor and remove unnecessary facts * Apply suggestions from code review --------- Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
56 lines
1.8 KiB
Python
56 lines
1.8 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Copyright (c) 2025, Dexter Le <dextersydney2001@gmail.com>
|
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
from __future__ import absolute_import, division, print_function
|
|
__metaclass__ = type
|
|
|
|
from ansible_collections.community.general.plugins.module_utils.cmd_runner import CmdRunner, cmd_runner_fmt
|
|
|
|
|
|
_state_map = {
|
|
"present": "create",
|
|
"absent": "remove",
|
|
"status": "status",
|
|
"enabled": "enable",
|
|
"disabled": "disable"
|
|
}
|
|
|
|
|
|
def fmt_resource_type(value):
|
|
return [value[k] for k in ['resource_standard', 'resource_provider', 'resource_name'] if value.get(k) is not None]
|
|
|
|
|
|
def fmt_resource_operation(value):
|
|
cmd = []
|
|
for op in value:
|
|
cmd.append("op")
|
|
cmd.append(op.get('operation_action'))
|
|
for operation_option in op.get('operation_option'):
|
|
cmd.append(operation_option)
|
|
|
|
return cmd
|
|
|
|
|
|
def fmt_resource_argument(value):
|
|
return ['--group' if value['argument_action'] == 'group' else value['argument_action']] + value['argument_option']
|
|
|
|
|
|
def pacemaker_runner(module, cli_action, **kwargs):
|
|
runner = CmdRunner(
|
|
module,
|
|
command=['pcs', cli_action],
|
|
arg_formats=dict(
|
|
state=cmd_runner_fmt.as_map(_state_map),
|
|
name=cmd_runner_fmt.as_list(),
|
|
resource_type=cmd_runner_fmt.as_func(fmt_resource_type),
|
|
resource_option=cmd_runner_fmt.as_list(),
|
|
resource_operation=cmd_runner_fmt.as_func(fmt_resource_operation),
|
|
resource_meta=cmd_runner_fmt.stack(cmd_runner_fmt.as_opt_val)("meta"),
|
|
resource_argument=cmd_runner_fmt.as_func(fmt_resource_argument),
|
|
wait=cmd_runner_fmt.as_opt_eq_val("--wait"),
|
|
),
|
|
**kwargs
|
|
)
|
|
return runner
|