| 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_host_capability_info |
| 15 |
short_description: Gathers info about an ESXi host's capability information |
| 16 |
description: |
| 17 |
- This module can be used to gather information about an ESXi host's capability information when ESXi hostname or Cluster name is given. |
| 18 |
author: |
| 19 |
- Abhijeet Kasurde (@Akasurde) |
| 20 |
options: |
| 21 |
cluster_name: |
| 22 |
description: |
| 23 |
- Name of the cluster from all host systems to be used for information gathering. |
| 24 |
- If O(esxi_hostname) is not given, this parameter is required. |
| 25 |
type: str |
| 26 |
esxi_hostname: |
| 27 |
description: |
| 28 |
- ESXi hostname to gather information from. |
| 29 |
- If O(cluster_name) is not given, this parameter is required. |
| 30 |
type: str |
| 31 |
extends_documentation_fragment: |
| 32 |
- vmware.vmware.base_options |
| 33 |
|
| 34 |
''' |
| 35 |
|
| 36 |
EXAMPLES = r''' |
| 37 |
- name: Gather capability info about all ESXi Host in given Cluster |
| 38 |
community.vmware.vmware_host_capability_info: |
| 39 |
hostname: '{{ vcenter_hostname }}' |
| 40 |
username: '{{ vcenter_username }}' |
| 41 |
password: '{{ vcenter_password }}' |
| 42 |
cluster_name: cluster_name |
| 43 |
delegate_to: localhost |
| 44 |
register: all_cluster_hosts_info |
| 45 |
|
| 46 |
- name: Gather capability info about ESXi Host |
| 47 |
community.vmware.vmware_host_capability_info: |
| 48 |
hostname: '{{ vcenter_hostname }}' |
| 49 |
username: '{{ vcenter_username }}' |
| 50 |
password: '{{ vcenter_password }}' |
| 51 |
esxi_hostname: '{{ esxi_hostname }}' |
| 52 |
delegate_to: localhost |
| 53 |
register: hosts_info |
| 54 |
''' |
| 55 |
|
| 56 |
RETURN = r''' |
| 57 |
hosts_capability_info: |
| 58 |
description: metadata about host's capability info |
| 59 |
returned: always |
| 60 |
type: dict |
| 61 |
sample: { |
| 62 |
"esxi_hostname_0001": { |
| 63 |
"accel3dSupported": false, |
| 64 |
"backgroundSnapshotsSupported": false, |
| 65 |
"checkpointFtCompatibilityIssues": [], |
| 66 |
"checkpointFtSupported": false, |
| 67 |
"cloneFromSnapshotSupported": true, |
| 68 |
"cpuHwMmuSupported": true, |
| 69 |
} |
| 70 |
} |
| 71 |
''' |
| 72 |
|
| 73 |
from ansible.module_utils.basic import AnsibleModule |
| 74 |
from ansible_collections.community.vmware.plugins.module_utils.vmware import PyVmomi |
| 75 |
from ansible_collections.vmware.vmware.plugins.module_utils.argument_spec import base_argument_spec |
| 76 |
|
| 77 |
|
| 78 |
class CapabilityInfoManager(PyVmomi): |
| 79 |
def __init__(self, module): |
| 80 |
super(CapabilityInfoManager, self).__init__(module) |
| 81 |
cluster_name = self.params.get('cluster_name', None) |
| 82 |
esxi_host_name = self.params.get('esxi_hostname', None) |
| 83 |
self.hosts = self.get_all_host_objs(cluster_name=cluster_name, esxi_host_name=esxi_host_name) |
| 84 |
|
| 85 |
def gather_host_capability_info(self): |
| 86 |
hosts_capability_info = dict() |
| 87 |
for host in self.hosts: |
| 88 |
hc = host.capability |
| 89 |
hosts_capability_info[host.name] = dict( |
| 90 |
recursiveResourcePoolsSupported=hc.recursiveResourcePoolsSupported, |
| 91 |
cpuMemoryResourceConfigurationSupported=hc.cpuMemoryResourceConfigurationSupported, |
| 92 |
rebootSupported=hc.rebootSupported, |
| 93 |
shutdownSupported=hc.shutdownSupported, |
| 94 |
vmotionSupported=hc.vmotionSupported, |
| 95 |
standbySupported=hc.standbySupported, |
| 96 |
ipmiSupported=hc.ipmiSupported, |
| 97 |
maxSupportedVMs=hc.maxSupportedVMs, |
| 98 |
maxRunningVMs=hc.maxRunningVMs, |
| 99 |
maxSupportedVcpus=hc.maxSupportedVcpus, |
| 100 |
maxRegisteredVMs=hc.maxRegisteredVMs, |
| 101 |
datastorePrincipalSupported=hc.datastorePrincipalSupported, |
| 102 |
sanSupported=hc.sanSupported, |
| 103 |
nfsSupported=hc.nfsSupported, |
| 104 |
iscsiSupported=hc.iscsiSupported, |
| 105 |
vlanTaggingSupported=hc.vlanTaggingSupported, |
| 106 |
nicTeamingSupported=hc.nicTeamingSupported, |
| 107 |
highGuestMemSupported=hc.highGuestMemSupported, |
| 108 |
maintenanceModeSupported=hc.maintenanceModeSupported, |
| 109 |
suspendedRelocateSupported=hc.suspendedRelocateSupported, |
| 110 |
restrictedSnapshotRelocateSupported=hc.restrictedSnapshotRelocateSupported, |
| 111 |
perVmSwapFiles=hc.perVmSwapFiles, |
| 112 |
localSwapDatastoreSupported=hc.localSwapDatastoreSupported, |
| 113 |
unsharedSwapVMotionSupported=hc.unsharedSwapVMotionSupported, |
| 114 |
backgroundSnapshotsSupported=hc.backgroundSnapshotsSupported, |
| 115 |
preAssignedPCIUnitNumbersSupported=hc.preAssignedPCIUnitNumbersSupported, |
| 116 |
screenshotSupported=hc.screenshotSupported, |
| 117 |
scaledScreenshotSupported=hc.scaledScreenshotSupported, |
| 118 |
storageVMotionSupported=hc.storageVMotionSupported, |
| 119 |
vmotionWithStorageVMotionSupported=hc.vmotionWithStorageVMotionSupported, |
| 120 |
vmotionAcrossNetworkSupported=hc.vmotionAcrossNetworkSupported, |
| 121 |
maxNumDisksSVMotion=hc.maxNumDisksSVMotion, |
| 122 |
hbrNicSelectionSupported=hc.hbrNicSelectionSupported, |
| 123 |
vrNfcNicSelectionSupported=hc.vrNfcNicSelectionSupported, |
| 124 |
recordReplaySupported=hc.recordReplaySupported, |
| 125 |
ftSupported=hc.ftSupported, |
| 126 |
replayUnsupportedReason=hc.replayUnsupportedReason, |
| 127 |
smpFtSupported=hc.smpFtSupported, |
| 128 |
maxVcpusPerFtVm=hc.maxVcpusPerFtVm, |
| 129 |
loginBySSLThumbprintSupported=hc.loginBySSLThumbprintSupported, |
| 130 |
cloneFromSnapshotSupported=hc.cloneFromSnapshotSupported, |
| 131 |
deltaDiskBackingsSupported=hc.deltaDiskBackingsSupported, |
| 132 |
perVMNetworkTrafficShapingSupported=hc.perVMNetworkTrafficShapingSupported, |
| 133 |
tpmSupported=hc.tpmSupported, |
| 134 |
virtualExecUsageSupported=hc.virtualExecUsageSupported, |
| 135 |
storageIORMSupported=hc.storageIORMSupported, |
| 136 |
vmDirectPathGen2Supported=hc.vmDirectPathGen2Supported, |
| 137 |
vmDirectPathGen2UnsupportedReasonExtended=hc.vmDirectPathGen2UnsupportedReasonExtended, |
| 138 |
vStorageCapable=hc.vStorageCapable, |
| 139 |
snapshotRelayoutSupported=hc.snapshotRelayoutSupported, |
| 140 |
firewallIpRulesSupported=hc.firewallIpRulesSupported, |
| 141 |
servicePackageInfoSupported=hc.servicePackageInfoSupported, |
| 142 |
maxHostRunningVms=hc.maxHostRunningVms, |
| 143 |
maxHostSupportedVcpus=hc.maxHostSupportedVcpus, |
| 144 |
vmfsDatastoreMountCapable=hc.vmfsDatastoreMountCapable, |
| 145 |
eightPlusHostVmfsSharedAccessSupported=hc.eightPlusHostVmfsSharedAccessSupported, |
| 146 |
nestedHVSupported=hc.nestedHVSupported, |
| 147 |
vPMCSupported=hc.vPMCSupported, |
| 148 |
interVMCommunicationThroughVMCISupported=hc.interVMCommunicationThroughVMCISupported, |
| 149 |
scheduledHardwareUpgradeSupported=hc.scheduledHardwareUpgradeSupported, |
| 150 |
featureCapabilitiesSupported=hc.featureCapabilitiesSupported, |
| 151 |
latencySensitivitySupported=hc.latencySensitivitySupported, |
| 152 |
storagePolicySupported=hc.storagePolicySupported, |
| 153 |
accel3dSupported=hc.accel3dSupported, |
| 154 |
reliableMemoryAware=hc.reliableMemoryAware, |
| 155 |
multipleNetworkStackInstanceSupported=hc.multipleNetworkStackInstanceSupported, |
| 156 |
messageBusProxySupported=hc.messageBusProxySupported, |
| 157 |
vsanSupported=hc.vsanSupported, |
| 158 |
vFlashSupported=hc.vFlashSupported, |
| 159 |
hostAccessManagerSupported=hc.hostAccessManagerSupported, |
| 160 |
provisioningNicSelectionSupported=hc.provisioningNicSelectionSupported, |
| 161 |
nfs41Supported=hc.nfs41Supported, |
| 162 |
nfs41Krb5iSupported=hc.nfs41Krb5iSupported, |
| 163 |
turnDiskLocatorLedSupported=hc.turnDiskLocatorLedSupported, |
| 164 |
virtualVolumeDatastoreSupported=hc.virtualVolumeDatastoreSupported, |
| 165 |
markAsSsdSupported=hc.markAsSsdSupported, |
| 166 |
markAsLocalSupported=hc.markAsLocalSupported, |
| 167 |
smartCardAuthenticationSupported=hc.smartCardAuthenticationSupported, |
| 168 |
cryptoSupported=hc.cryptoSupported, |
| 169 |
oneKVolumeAPIsSupported=hc.oneKVolumeAPIsSupported, |
| 170 |
gatewayOnNicSupported=hc.gatewayOnNicSupported, |
| 171 |
upitSupported=hc.upitSupported, |
| 172 |
cpuHwMmuSupported=hc.cpuHwMmuSupported, |
| 173 |
encryptedVMotionSupported=hc.encryptedVMotionSupported, |
| 174 |
encryptionChangeOnAddRemoveSupported=hc.encryptionChangeOnAddRemoveSupported, |
| 175 |
encryptionHotOperationSupported=hc.encryptionHotOperationSupported, |
| 176 |
encryptionWithSnapshotsSupported=hc.encryptionWithSnapshotsSupported, |
| 177 |
encryptionFaultToleranceSupported=hc.encryptionFaultToleranceSupported, |
| 178 |
encryptionMemorySaveSupported=hc.encryptionMemorySaveSupported, |
| 179 |
encryptionRDMSupported=hc.encryptionRDMSupported, |
| 180 |
encryptionVFlashSupported=hc.encryptionVFlashSupported, |
| 181 |
encryptionCBRCSupported=hc.encryptionCBRCSupported, |
| 182 |
encryptionHBRSupported=hc.encryptionHBRSupported, |
| 183 |
supportedVmfsMajorVersion=list(hc.supportedVmfsMajorVersion), |
| 184 |
vmDirectPathGen2UnsupportedReason=list(hc.vmDirectPathGen2UnsupportedReason), |
| 185 |
ftCompatibilityIssues=list(hc.ftCompatibilityIssues), |
| 186 |
smpFtCompatibilityIssues=list(hc.smpFtCompatibilityIssues), |
| 187 |
replayCompatibilityIssues=list(hc.replayCompatibilityIssues), |
| 188 |
) |
| 189 |
|
| 190 |
# The `checkpointFtSupported` and `checkpointFtCompatibilityIssues` properties have been removed from pyvmomi 7.0. |
| 191 |
# The parameters can be substituted as follows. |
| 192 |
# checkpointFtSupported => smpFtSupported |
| 193 |
# checkpointFtSupported => smpFtCompatibilityIssues. |
| 194 |
# So add `checkpointFtSupported` and `checkpointFtCompatibilityIssues` keys for compatibility with previous versions. |
| 195 |
# https://github.com/ansible-collections/vmware/pull/118 |
| 196 |
hosts_capability_info[host.name]['checkpointFtSupported'] = hosts_capability_info[host.name]['smpFtSupported'] |
| 197 |
hosts_capability_info[host.name]['checkpointFtCompatibilityIssues'] = hosts_capability_info[host.name]['smpFtCompatibilityIssues'] |
| 198 |
|
| 199 |
return hosts_capability_info |
| 200 |
|
| 201 |
|
| 202 |
def main(): |
| 203 |
argument_spec = base_argument_spec() |
| 204 |
argument_spec.update( |
| 205 |
cluster_name=dict(type='str', required=False), |
| 206 |
esxi_hostname=dict(type='str', required=False), |
| 207 |
) |
| 208 |
|
| 209 |
module = AnsibleModule( |
| 210 |
argument_spec=argument_spec, |
| 211 |
required_one_of=[ |
| 212 |
['cluster_name', 'esxi_hostname'], |
| 213 |
], |
| 214 |
supports_check_mode=True, |
| 215 |
) |
| 216 |
|
| 217 |
host_capability_manager = CapabilityInfoManager(module) |
| 218 |
module.exit_json(changed=False, |
| 219 |
hosts_capability_info=host_capability_manager.gather_host_capability_info()) |
| 220 |
|
| 221 |
|
| 222 |
if __name__ == "__main__": |
| 223 |
main() |