Repository: ansible-collections/community.vmware

Issue:
vPMCEnabled Support
<!--- Verify first that your feature was not already discussed on GitHub -->
<!--- Complete *all* sections as described, this form is processed automatically -->

##### SUMMARY
<!--- Describe the new feature/improvement briefly below -->
Please add vPMCEnabled support under hardware to vmware_guest.py.

##### ISSUE TYPE
- Feature Idea

##### COMPONENT NAME
<!--- Write the short name of the module, plugin, task or feature below, use your best guess if unsure -->

##### ADDITIONAL INFORMATION
<!--- Describe how the feature would be used, why it is needed and what it would solve -->
Virtual performance counters is an option to enable for VMs, vmware_guest is missing that option.

<!--- Paste example playbooks or commands between quotes below -->
Simple implementation following the pattern of other CPU hardware settings:
```
(in configure_cpu_and_memory function)

        vpmc_enabled = self.params['hardware']['vpmc_enabled']
        if vpmc_enabled is not None:
            if vm_obj and vm_obj.runtime.powerState == vim.VirtualMachinePowerState.poweredOn and \
                    vm_obj.config.vPMCEnabled != vpmc_enabled:
                self.module.fail_json(msg="Configure vPMC cpu operation is not supported when VM is power on")
            self.configspec.vPMCEnabled = vpmc_enabled
            if vm_obj is None or self.configspec.vPMCEnabled != vm_obj.config.vPMCEnabled:
                self.change_detected = True
```

<!--- HINT: You can also paste gist.github.com links for larger files -->



Discussion:
Files identified in the description:
None

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->

Resolving patch:
diff --git a/plugins/modules/vmware_guest.py b/plugins/modules/vmware_guest.py
--- a/plugins/modules/vmware_guest.py
+++ b/plugins/modules/vmware_guest.py
@@ -162,6 +162,10 @@
             - The number of shares of CPU allocated to this virtual machine
             - cpu_shares_level will automatically be set to 'custom'
             version_added: '3.2.0'
+        vpmc_enabled:
+            version_added: '3.2.0'
+            type: bool
+            description: Enable virtual CPU Performance Counters.
         scsi:
             type: str
             description:
@@ -1391,6 +1395,16 @@ def configure_cpu_and_memory(self, vm_obj, vm_creation=False):
             if vm_obj is None or self.configspec.memoryReservationLockedToMax != vm_obj.config.memoryReservationLockedToMax:
                 self.change_detected = True
 
+        vpmc_enabled = self.params['hardware']['vpmc_enabled']
+        if vpmc_enabled is not None:
+            # Allow VM to be powered on during this check when in check mode, when no changes will actually be made
+            if vm_obj and vm_obj.runtime.powerState == vim.VirtualMachinePowerState.poweredOn and \
+                    vm_obj.config.vPMCEnabled != vpmc_enabled and not self.module.check_mode:
+                self.module.fail_json(msg="Configure vPMC cpu operation is not supported when VM is power on")
+            if vm_obj is None or vpmc_enabled != vm_obj.config.vPMCEnabled:
+                self.change_detected = True
+                self.configspec.vPMCEnabled = vpmc_enabled
+
         boot_firmware = self.params['hardware']['boot_firmware']
         if boot_firmware is not None:
             # boot firmware re-config can cause boot issue
@@ -3381,6 +3395,7 @@ def main():
                 hotadd_cpu=dict(type='bool'),
                 hotadd_memory=dict(type='bool'),
                 hotremove_cpu=dict(type='bool'),
+                vpmc_enabled=dict(type='bool'),
                 max_connections=dict(type='int'),
                 mem_limit=dict(type='int'),
                 cpu_shares_level=dict(type='str', choices=['low', 'normal', 'high', 'custom']),


Test patch: