Debian Codegraph @

ansible_collections/community/proxmox/plugins/modules/proxmox_node_info.py

raw
1 #!/usr/bin/python
2 #
3 # Copyright John Berninger (@jberning) <john.berninger at gmail.com>
4 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
5 # SPDX-License-Identifier: GPL-3.0-or-later
6
7
8 DOCUMENTATION = r"""
9 module: proxmox_node_info
10 short_description: Retrieve information about one or more Proxmox VE nodes
11 description:
12 - Retrieve information about one or more Proxmox VE nodes.
13 author: John Berninger (@jwbernin)
14 extends_documentation_fragment:
15 - community.proxmox.proxmox.actiongroup_proxmox
16 - community.proxmox.proxmox.documentation
17 - community.proxmox.attributes
18 - community.proxmox.attributes.info_module
19 """
20
21
22 EXAMPLES = r"""
23 - name: List existing nodes
24 community.proxmox.proxmox_node_info:
25 register: proxmox_nodes
26 """
27
28
29 RETURN = r"""
30 proxmox_nodes:
31 description: List of Proxmox VE nodes.
32 returned: always, but can be empty
33 type: list
34 elements: dict
35 contains:
36 cpu:
37 description: Current CPU usage in fractional shares of this host's total available CPU.
38 returned: on success
39 type: float
40 disk:
41 description: Current local disk usage of this host.
42 returned: on success
43 type: int
44 id:
45 description: Identity of the node.
46 returned: on success
47 type: str
48 level:
49 description: Support level. Can be blank if not under a paid support contract.
50 returned: on success
51 type: str
52 maxcpu:
53 description: Total number of available CPUs on this host.
54 returned: on success
55 type: int
56 maxdisk:
57 description: Size of local disk in bytes.
58 returned: on success
59 type: int
60 maxmem:
61 description: Memory size in bytes.
62 returned: on success
63 type: int
64 mem:
65 description: Used memory in bytes.
66 returned: on success
67 type: int
68 network:
69 description: Active network interfaces on the node
70 returned: on success
71 type: dict
72 node:
73 description: Short hostname of this node.
74 returned: on success
75 type: str
76 ssl_fingerprint:
77 description: SSL fingerprint of the node certificate.
78 returned: on success
79 type: str
80 status:
81 description: Node status.
82 returned: on success
83 type: str
84 type:
85 description: Object type being returned.
86 returned: on success
87 type: str
88 uptime:
89 description: Node uptime in seconds.
90 returned: on success
91 type: int
92 version:
93 description: Version of PVE on the node
94 returned: on success
95 type: dict
96 """
97
98
99 from ansible_collections.community.proxmox.plugins.module_utils.proxmox import (
100 ProxmoxAnsible,
101 create_proxmox_module,
102 )
103
104
105 def module_args():
106 return dict()
107
108
109 def module_options():
110 return {}
111
112
113 class ProxmoxNodeInfoAnsible(ProxmoxAnsible):
114 def get_nodes(self):
115 nodes = self.proxmox_api.nodes.get()
116 for node in nodes:
117 node_name = node["node"]
118 ifaces = self.proxmox_api.nodes(node_name).network.get()
119 node["network"] = ifaces
120 node["version"] = self.proxmox_api.nodes(node_name).version.get()
121 return nodes
122
123
124 def main():
125 module = create_proxmox_module(module_args(), **module_options())
126 proxmox = ProxmoxNodeInfoAnsible(module)
127
128 result = dict(changed=False)
129
130 nodes = proxmox.get_nodes()
131 result["proxmox_nodes"] = nodes
132
133 module.exit_json(**result)
134
135
136 if __name__ == "__main__":
137 main()