-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathnode_info.py
More file actions
96 lines (80 loc) · 2.32 KB
/
node_info.py
File metadata and controls
96 lines (80 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright: (c) 2022, XLAB Steampunk <steampunk@xlab.si>
#
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
__metaclass__ = type
# language=yaml
DOCUMENTATION = r"""
module: node_info
author:
- Polona Mihalič (@PolonaM)
short_description: Returns information about the nodes in a cluster.
description:
- Returns information about the nodes in a cluster.
version_added: 1.0.0
extends_documentation_fragment:
- scale_computing.hypercore.cluster_instance
seealso:
- module: scale_computing.hypercore.vm_node_affinity
"""
# language=yaml
EXAMPLES = r"""
- name: List all cluster nodes
scale_computing.hypercore.node_info:
register: nodes
"""
# language=yaml
RETURN = r"""
records:
description:
- A list of node records.
returned: success
type: list
elements: dict
contains:
node_uuid:
description: Unique identifier
type: str
sample: 51e6d073-7566-4273-9196-58720117bd7f
backplane_ip:
description: IP address on the backplane network
type: str
sample: 10.0.0.1
lan_ip:
description: IP address on the LAN network
type: str
sample: 10.0.0.2
peer_id:
description: Cluster map peer identifier
type: str
sample: 1
"""
from ansible.module_utils.basic import AnsibleModule
from ..module_utils import arguments
from ..module_utils import errors
from ..module_utils.client import Client
from ..module_utils.node import Node
from ..module_utils.rest_client import RestClient
def run(rest_client):
return [
Node.from_hypercore(hypercore_data=hypercore_dict).to_ansible()
for hypercore_dict in rest_client.list_records("/rest/v1/Node")
]
def main():
module = AnsibleModule(
supports_check_mode=True,
argument_spec=dict(arguments.get_spec("cluster_instance")),
)
try:
with Client.get_client(module.params["cluster_instance"]) as client:
rest_client = RestClient(client)
records = run(rest_client)
module.exit_json(changed=False, records=records)
except errors.ScaleComputingError as e:
module.fail_json(msg=str(e))
if __name__ == "__main__":
main()