Debian Codegraph @

ansible_collections/community/vmware/plugins/modules/vmware_resource_pool_info.py

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright: (c) 2018, Abhijeet Kasurde <[email protected]>
5 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
6 # SPDX-License-Identifier: GPL-3.0-or-later
7
8 from __future__ import absolute_import, division, print_function
9 __metaclass__ = type
10
11
12 DOCUMENTATION = r'''
13 ---
14 module: vmware_resource_pool_info
15 short_description: Gathers info about resource pool information
16 description:
17 - This module can be used to gather information about all resource configuration information.
18 author:
19 - Abhijeet Kasurde (@Akasurde)
20 extends_documentation_fragment:
21 - vmware.vmware.base_options
22
23 '''
24
25 EXAMPLES = r'''
26 - name: Gather resource pool info about all resource pools available
27 community.vmware.vmware_resource_pool_info:
28 hostname: '{{ vcenter_hostname }}'
29 username: '{{ vcenter_username }}'
30 password: '{{ vcenter_password }}'
31 register: rp_info
32 delegate_to: localhost
33 '''
34
35 RETURN = r'''
36 resource_pool_info:
37 description: metadata about resource pool configuration
38 returned: on success
39 type: list
40 sample: [
41 {
42 "cpu_allocation_expandable_reservation": false,
43 "cpu_allocation_limit": 4121,
44 "cpu_allocation_overhead_limit": null,
45 "cpu_allocation_reservation": 4121,
46 "cpu_allocation_shares": 9000,
47 "cpu_allocation_shares_level": "custom",
48 "mem_allocation_expandable_reservation": false,
49 "mem_allocation_limit": 961,
50 "mem_allocation_overhead_limit": null,
51 "mem_allocation_reservation": 961,
52 "mem_allocation_shares": 9000,
53 "mem_allocation_shares_level": "custom",
54 "name": "Resources",
55 "overall_status": "green",
56 "owner": "DC0_H0",
57 "runtime_cpu_max_usage": 4121,
58 "runtime_cpu_overall_usage": 0,
59 "runtime_cpu_reservation_used": 0,
60 "runtime_cpu_reservation_used_vm": 0,
61 "runtime_cpu_unreserved_for_pool": 4121,
62 "runtime_cpu_unreserved_for_vm": 4121,
63 "runtime_memory_max_usage": 1007681536,
64 "runtime_memory_overall_usage": 0,
65 "runtime_memory_reservation_used": 0,
66 "runtime_memory_reservation_used_vm": 0,
67 "runtime_memory_unreserved_for_pool": 1007681536,
68 "runtime_memory_unreserved_for_vm": 1007681536
69 },
70 ]
71 '''
72
73 try:
74 from pyVmomi import vim
75 except ImportError:
76 pass
77
78 from ansible.module_utils.basic import AnsibleModule
79 from ansible_collections.community.vmware.plugins.module_utils.vmware import PyVmomi, get_all_objs
80 from ansible_collections.vmware.vmware.plugins.module_utils.argument_spec import base_argument_spec
81
82
83 class ResourcePoolInfoManager(PyVmomi):
84 def __init__(self, module):
85 super(ResourcePoolInfoManager, self).__init__(module)
86
87 def gather_rp_info(self):
88 resource_pool_info = []
89 rps = get_all_objs(self.content, [vim.ResourcePool])
90 for rp in rps:
91 tmp_info = dict(
92 name=rp.name,
93 cpu_allocation_reservation=rp.config.cpuAllocation.reservation,
94 cpu_allocation_expandable_reservation=rp.config.cpuAllocation.expandableReservation,
95 cpu_allocation_limit=rp.config.cpuAllocation.limit,
96 cpu_allocation_shares=rp.config.cpuAllocation.shares.shares,
97 cpu_allocation_shares_level=rp.config.cpuAllocation.shares.level,
98 cpu_allocation_overhead_limit=rp.config.cpuAllocation.overheadLimit,
99 mem_allocation_reservation=rp.config.memoryAllocation.reservation,
100 mem_allocation_expandable_reservation=rp.config.memoryAllocation.expandableReservation,
101 mem_allocation_limit=rp.config.memoryAllocation.limit,
102 mem_allocation_shares=rp.config.memoryAllocation.shares.shares,
103 mem_allocation_shares_level=rp.config.memoryAllocation.shares.level,
104 mem_allocation_overhead_limit=rp.config.memoryAllocation.overheadLimit,
105 owner=rp.owner.name,
106 overall_status=rp.summary.runtime.overallStatus,
107 runtime_cpu_reservation_used=rp.summary.runtime.cpu.reservationUsed,
108 runtime_cpu_reservation_used_vm=rp.summary.runtime.cpu.reservationUsedForVm,
109 runtime_cpu_unreserved_for_pool=rp.summary.runtime.cpu.unreservedForPool,
110 runtime_cpu_unreserved_for_vm=rp.summary.runtime.cpu.unreservedForVm,
111 runtime_cpu_overall_usage=rp.summary.runtime.cpu.overallUsage,
112 runtime_cpu_max_usage=rp.summary.runtime.cpu.maxUsage,
113 runtime_memory_reservation_used=rp.summary.runtime.memory.reservationUsed,
114 runtime_memory_reservation_used_vm=rp.summary.runtime.memory.reservationUsedForVm,
115 runtime_memory_unreserved_for_pool=rp.summary.runtime.memory.unreservedForPool,
116 runtime_memory_unreserved_for_vm=rp.summary.runtime.memory.unreservedForVm,
117 runtime_memory_overall_usage=rp.summary.runtime.memory.overallUsage,
118 runtime_memory_max_usage=rp.summary.runtime.memory.maxUsage,
119 )
120
121 resource_pool_info.append(tmp_info)
122 return resource_pool_info
123
124
125 def main():
126 argument_spec = base_argument_spec()
127 module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
128
129 vmware_rp_mgr = ResourcePoolInfoManager(module)
130 module.exit_json(changed=False, resource_pool_info=vmware_rp_mgr.gather_rp_info())
131
132
133 if __name__ == "__main__":
134 main()