mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-27 23:21:22 -07:00
pacemaker_cluster: PEP8 compliancy and doc changes (#33001)
This PR includes: - PEP8 compliancy changes - DOcumentation changes
This commit is contained in:
parent
a314faae0e
commit
5f36932adf
2 changed files with 31 additions and 36 deletions
|
@ -1,24 +1,23 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
#coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# (c) 2016, Mathieu Bultel <mbultel@redhat.com>
|
# Copyright: (c) 2016, Mathieu Bultel <mbultel@redhat.com>
|
||||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
||||||
'status': ['preview'],
|
'status': ['preview'],
|
||||||
'supported_by': 'community'}
|
'supported_by': 'community'}
|
||||||
|
|
||||||
|
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = '''
|
||||||
---
|
---
|
||||||
module: pacemaker_cluster
|
module: pacemaker_cluster
|
||||||
short_description: Manage a pacemaker cluster
|
short_description: Manage pacemaker clusters
|
||||||
version_added: "2.3"
|
version_added: "2.3"
|
||||||
author: "Mathieu Bultel (matbu)"
|
author:
|
||||||
|
- Mathieu Bultel (@matbu)
|
||||||
description:
|
description:
|
||||||
- This module can manage a pacemaker cluster and nodes from Ansible using
|
- This module can manage a pacemaker cluster and nodes from Ansible using
|
||||||
the pacemaker cli.
|
the pacemaker cli.
|
||||||
|
@ -26,26 +25,21 @@ options:
|
||||||
state:
|
state:
|
||||||
description:
|
description:
|
||||||
- Indicate desired state of the cluster
|
- Indicate desired state of the cluster
|
||||||
choices: ['online', 'offline', 'restart', 'cleanup']
|
choices: [ cleanup, offline, online, restart ]
|
||||||
required: true
|
required: yes
|
||||||
node:
|
node:
|
||||||
description:
|
description:
|
||||||
- Specify which node of the cluster you want to manage. None == the
|
- Specify which node of the cluster you want to manage. None == the
|
||||||
cluster status itself, 'all' == check the status of all nodes.
|
cluster status itself, 'all' == check the status of all nodes.
|
||||||
required: false
|
|
||||||
default: None
|
|
||||||
timeout:
|
timeout:
|
||||||
description:
|
description:
|
||||||
- Timeout when the module should considered that the action has failed
|
- Timeout when the module should considered that the action has failed
|
||||||
required: false
|
|
||||||
default: 300
|
default: 300
|
||||||
force:
|
force:
|
||||||
description:
|
description:
|
||||||
- Force the change of the cluster state
|
- Force the change of the cluster state
|
||||||
required: false
|
type: bool
|
||||||
default: true
|
default: 'yes'
|
||||||
requirements:
|
|
||||||
- "python >= 2.6"
|
|
||||||
'''
|
'''
|
||||||
EXAMPLES = '''
|
EXAMPLES = '''
|
||||||
---
|
---
|
||||||
|
@ -53,8 +47,9 @@ EXAMPLES = '''
|
||||||
hosts: localhost
|
hosts: localhost
|
||||||
gather_facts: no
|
gather_facts: no
|
||||||
tasks:
|
tasks:
|
||||||
- name: get cluster state
|
- name: Get cluster state
|
||||||
pacemaker_cluster: state=online
|
pacemaker_cluster:
|
||||||
|
state: online
|
||||||
'''
|
'''
|
||||||
|
|
||||||
RETURN = '''
|
RETURN = '''
|
||||||
|
@ -79,7 +74,7 @@ import time
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
|
|
||||||
|
|
||||||
_PCS_CLUSTER_DOWN="Error: cluster is not currently running on this node"
|
_PCS_CLUSTER_DOWN = "Error: cluster is not currently running on this node"
|
||||||
|
|
||||||
|
|
||||||
def get_cluster_status(module):
|
def get_cluster_status(module):
|
||||||
|
@ -90,6 +85,7 @@ def get_cluster_status(module):
|
||||||
else:
|
else:
|
||||||
return 'online'
|
return 'online'
|
||||||
|
|
||||||
|
|
||||||
def get_node_status(module, node='all'):
|
def get_node_status(module, node='all'):
|
||||||
if node == 'all':
|
if node == 'all':
|
||||||
cmd = "pcs cluster pcsd-status %s" % node
|
cmd = "pcs cluster pcsd-status %s" % node
|
||||||
|
@ -103,12 +99,14 @@ def get_node_status(module, node='all'):
|
||||||
status.append(o.split(':'))
|
status.append(o.split(':'))
|
||||||
return status
|
return status
|
||||||
|
|
||||||
|
|
||||||
def clean_cluster(module, timeout):
|
def clean_cluster(module, timeout):
|
||||||
cmd = "pcs resource cleanup"
|
cmd = "pcs resource cleanup"
|
||||||
rc, out, err = module.run_command(cmd)
|
rc, out, err = module.run_command(cmd)
|
||||||
if rc is 1:
|
if rc is 1:
|
||||||
module.fail_json(msg="Command execution failed.\nCommand: `%s`\nError: %s" % (cmd, err))
|
module.fail_json(msg="Command execution failed.\nCommand: `%s`\nError: %s" % (cmd, err))
|
||||||
|
|
||||||
|
|
||||||
def set_cluster(module, state, timeout, force):
|
def set_cluster(module, state, timeout, force):
|
||||||
if state == 'online':
|
if state == 'online':
|
||||||
cmd = "pcs cluster start"
|
cmd = "pcs cluster start"
|
||||||
|
@ -122,7 +120,7 @@ def set_cluster(module, state, timeout, force):
|
||||||
|
|
||||||
t = time.time()
|
t = time.time()
|
||||||
ready = False
|
ready = False
|
||||||
while time.time() < t+timeout:
|
while time.time() < t + timeout:
|
||||||
cluster_state = get_cluster_status(module)
|
cluster_state = get_cluster_status(module)
|
||||||
if cluster_state == state:
|
if cluster_state == state:
|
||||||
ready = True
|
ready = True
|
||||||
|
@ -130,6 +128,7 @@ def set_cluster(module, state, timeout, force):
|
||||||
if not ready:
|
if not ready:
|
||||||
module.fail_json(msg="Failed to set the state `%s` on the cluster\n" % (state))
|
module.fail_json(msg="Failed to set the state `%s` on the cluster\n" % (state))
|
||||||
|
|
||||||
|
|
||||||
def set_node(module, state, timeout, force, node='all'):
|
def set_node(module, state, timeout, force, node='all'):
|
||||||
# map states
|
# map states
|
||||||
if state == 'online':
|
if state == 'online':
|
||||||
|
@ -149,7 +148,7 @@ def set_node(module, state, timeout, force, node='all'):
|
||||||
|
|
||||||
t = time.time()
|
t = time.time()
|
||||||
ready = False
|
ready = False
|
||||||
while time.time() < t+timeout:
|
while time.time() < t + timeout:
|
||||||
nodes_state = get_node_status(module)
|
nodes_state = get_node_status(module)
|
||||||
for node in nodes_state:
|
for node in nodes_state:
|
||||||
if node[1].strip().lower() == state:
|
if node[1].strip().lower() == state:
|
||||||
|
@ -158,15 +157,17 @@ def set_node(module, state, timeout, force, node='all'):
|
||||||
if not ready:
|
if not ready:
|
||||||
module.fail_json(msg="Failed to set the state `%s` on the cluster\n" % (state))
|
module.fail_json(msg="Failed to set the state `%s` on the cluster\n" % (state))
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
argument_spec = dict(
|
argument_spec = dict(
|
||||||
state = dict(choices=['online', 'offline', 'restart', 'cleanup']),
|
state=dict(type='str', choices=['online', 'offline', 'restart', 'cleanup']),
|
||||||
node = dict(default=None),
|
node=dict(type='str'),
|
||||||
timeout=dict(default=300, type='int'),
|
timeout=dict(type='int', default=300),
|
||||||
force=dict(default=True, type='bool'),
|
force=dict(type='bool', default=True),
|
||||||
)
|
)
|
||||||
|
|
||||||
module = AnsibleModule(argument_spec,
|
module = AnsibleModule(
|
||||||
|
argument_spec,
|
||||||
supports_check_mode=True,
|
supports_check_mode=True,
|
||||||
)
|
)
|
||||||
changed = False
|
changed = False
|
||||||
|
@ -180,14 +181,12 @@ def main():
|
||||||
if node is None:
|
if node is None:
|
||||||
cluster_state = get_cluster_status(module)
|
cluster_state = get_cluster_status(module)
|
||||||
if cluster_state == state:
|
if cluster_state == state:
|
||||||
module.exit_json(changed=changed,
|
module.exit_json(changed=changed, out=cluster_state)
|
||||||
out=cluster_state)
|
|
||||||
else:
|
else:
|
||||||
set_cluster(module, state, timeout, force)
|
set_cluster(module, state, timeout, force)
|
||||||
cluster_state = get_cluster_status(module)
|
cluster_state = get_cluster_status(module)
|
||||||
if cluster_state == state:
|
if cluster_state == state:
|
||||||
module.exit_json(changed=True,
|
module.exit_json(changed=True, out=cluster_state)
|
||||||
out=cluster_state)
|
|
||||||
else:
|
else:
|
||||||
module.fail_json(msg="Fail to bring the cluster %s" % state)
|
module.fail_json(msg="Fail to bring the cluster %s" % state)
|
||||||
else:
|
else:
|
||||||
|
@ -195,14 +194,12 @@ def main():
|
||||||
# Check cluster state
|
# Check cluster state
|
||||||
for node_state in cluster_state:
|
for node_state in cluster_state:
|
||||||
if node_state[1].strip().lower() == state:
|
if node_state[1].strip().lower() == state:
|
||||||
module.exit_json(changed=changed,
|
module.exit_json(changed=changed, out=cluster_state)
|
||||||
out=cluster_state)
|
|
||||||
else:
|
else:
|
||||||
# Set cluster status if needed
|
# Set cluster status if needed
|
||||||
set_cluster(module, state, timeout, force)
|
set_cluster(module, state, timeout, force)
|
||||||
cluster_state = get_node_status(module, node)
|
cluster_state = get_node_status(module, node)
|
||||||
module.exit_json(changed=True,
|
module.exit_json(changed=True, out=cluster_state)
|
||||||
out=cluster_state)
|
|
||||||
|
|
||||||
if state in ['restart']:
|
if state in ['restart']:
|
||||||
set_cluster(module, 'offline', timeout, force)
|
set_cluster(module, 'offline', timeout, force)
|
||||||
|
@ -211,8 +208,7 @@ def main():
|
||||||
set_cluster(module, 'online', timeout, force)
|
set_cluster(module, 'online', timeout, force)
|
||||||
cluster_state = get_cluster_status(module)
|
cluster_state = get_cluster_status(module)
|
||||||
if cluster_state == 'online':
|
if cluster_state == 'online':
|
||||||
module.exit_json(changed=True,
|
module.exit_json(changed=True, out=cluster_state)
|
||||||
out=cluster_state)
|
|
||||||
else:
|
else:
|
||||||
module.fail_json(msg="Failed during the restart of the cluster, the cluster can't be started")
|
module.fail_json(msg="Failed during the restart of the cluster, the cluster can't be started")
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -110,7 +110,6 @@ lib/ansible/modules/cloud/webfaction/webfaction_db.py
|
||||||
lib/ansible/modules/cloud/webfaction/webfaction_domain.py
|
lib/ansible/modules/cloud/webfaction/webfaction_domain.py
|
||||||
lib/ansible/modules/cloud/webfaction/webfaction_site.py
|
lib/ansible/modules/cloud/webfaction/webfaction_site.py
|
||||||
lib/ansible/modules/clustering/consul_session.py
|
lib/ansible/modules/clustering/consul_session.py
|
||||||
lib/ansible/modules/clustering/pacemaker_cluster.py
|
|
||||||
lib/ansible/modules/database/misc/kibana_plugin.py
|
lib/ansible/modules/database/misc/kibana_plugin.py
|
||||||
lib/ansible/modules/database/misc/riak.py
|
lib/ansible/modules/database/misc/riak.py
|
||||||
lib/ansible/modules/database/mongodb/mongodb_parameter.py
|
lib/ansible/modules/database/mongodb/mongodb_parameter.py
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue