Skip to content

Commit

Permalink
Merge branch 'ansible-collections:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
dmnagornyi authored Dec 4, 2024
2 parents df995cc + 290bc26 commit 8abd0e3
Show file tree
Hide file tree
Showing 17 changed files with 286 additions and 230 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/extra-docs-linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- name: Install dependent collections
run: >
ansible-galaxy collection install
'vmware.vmware>=1.6.0'
'vmware.vmware>=1.7.1'
- name: Run collection docs linter
run: antsibull-docs lint-collection-docs . --plugin-docs --skip-rstcheck
22 changes: 22 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,28 @@ community.vmware Release Notes

This changelog describes changes after version 4.7.0.

v5.2.0
======

Minor Changes
-------------

- vmware.py - Add logic for handling the case where the `datacenter` property is not provided.
- vmware_guest_info - `datacenter` property is now optional as it only required in cases where the VM is not uniquely identified by `name`.

Bugfixes
--------

- vm_device_helper - Fix 'invalid configuration for device' error caused by missing fileoperation parameter. (https://github.com/ansible-collections/community.vmware/pull/2009).
- vmware_guest - Fix errors occuring during hardware version upgrade not being reported. (https://github.com/ansible-collections/community.vmware/pull/2010).
- vmware_guest - Fix vmware_guest always reporting change when using dvswitch. (https://github.com/ansible-collections/community.vmware/pull/2000).
- vmware_guest_tools_upgrade - Account for all possible tools status (https://github.com/ansible-collections/community.vmware/issues/2237).

New Modules
-----------

- vmware_drs_override - Configure DRS behavior for a specific VM in vSphere

v5.1.0
======

Expand Down
26 changes: 26 additions & 0 deletions changelogs/changelog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,29 @@ releases:
- 2217-deprecate-vmware_cluster_dpm.yml
- 2218-deprecate-vmware_cluster_drs_recommendations.yml
release_date: '2024-11-01'
5.2.0:
changes:
bugfixes:
- vm_device_helper - Fix 'invalid configuration for device' error caused by
missing fileoperation parameter. (https://github.com/ansible-collections/community.vmware/pull/2009).
- vmware_guest - Fix errors occuring during hardware version upgrade not being
reported. (https://github.com/ansible-collections/community.vmware/pull/2010).
- vmware_guest - Fix vmware_guest always reporting change when using dvswitch.
(https://github.com/ansible-collections/community.vmware/pull/2000).
- vmware_guest_tools_upgrade - Account for all possible tools status (https://github.com/ansible-collections/community.vmware/issues/2237).
minor_changes:
- vmware.py - Add logic for handling the case where the `datacenter` property
is not provided.
- vmware_guest_info - `datacenter` property is now optional as it only required
in cases where the VM is not uniquely identified by `name`.
fragments:
- 2000-fix-vmware-guest-idempotency-with-dvswitch.yml
- 2009-fix-disk-add-failing-with-invalid-configuration-for-device.yml
- 2010-fix-vm-hardware-version-upgrade-error-not-being-reported.yml
- 2237-vmware_guest_tools_upgrade.yml
- 2241-vmware_guest_info-make-datacenter-property-optional.yaml
modules:
- description: Configure DRS behavior for a specific VM in vSphere
name: vmware_drs_override
namespace: ''
release_date: '2024-11-30'

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions changelogs/fragments/2237-vmware_guest_tools_upgrade.yml

This file was deleted.

3 changes: 3 additions & 0 deletions changelogs/fragments/2260-deprecate-vmware_cluster_info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
deprecated_features:
- vmware_cluster_info - the module has been deprecated and will be removed in community.vmware 7.0.0
(https://github.com/ansible-collections/community.vmware/pull/2260).
5 changes: 5 additions & 0 deletions meta/runtime.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ action_groups:
- vmware_drs_group
- vmware_drs_group_info
- vmware_drs_group_manager
- vmware_drs_override
- vmware_drs_rule_info
- vmware_dvs_host
- vmware_dvs_portgroup
Expand Down Expand Up @@ -196,6 +197,10 @@ plugin_routing:
deprecation:
removal_version: 6.0.0
warning_text: Use vmware.vmware.cluster_drs_recommendations instead.
vmware_cluster_info:
deprecation:
removal_version: 7.0.0
warning_text: Use vmware.vmware.cluster_info instead.
vmware_cluster_vcls:
deprecation:
removal_version: 6.0.0
Expand Down
4 changes: 2 additions & 2 deletions plugins/module_utils/vmware.py
Original file line number Diff line number Diff line change
Expand Up @@ -1226,9 +1226,9 @@ def get_vm(self):
# following code tries to find user desired one depending upon the folder specified.
if len(vms) > 1:
# We have found multiple virtual machines, decide depending upon folder value
if self.params['folder'] is None:
if self.params['folder'] is None or self.params['datacenter'] is None:
self.module.fail_json(msg="Multiple virtual machines with same name [%s] found, "
"Folder value is a required parameter to find uniqueness "
"try to specify folder and / or datacenter to ensure uniqueness "
"of the virtual machine" % self.params['name'],
details="Please see documentation of the vmware_guest module "
"for folder parameter.")
Expand Down
4 changes: 4 additions & 0 deletions plugins/modules/vmware_cluster_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
DOCUMENTATION = r'''
---
module: vmware_cluster_info
deprecated:
removed_in: 7.0.0
why: This module has been moved to the L(new vmware.vmware collection,https://forum.ansible.com/t/5880)
alternative: Use M(vmware.vmware.cluster_info) instead.
short_description: Gather info about clusters available in given vCenter
description:
- This module can be used to gather information about clusters in VMWare infrastructure.
Expand Down
123 changes: 123 additions & 0 deletions plugins/modules/vmware_drs_override.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later

DOCUMENTATION = '''
---
module: vmware_drs_override
version_added: '5.2.0'
short_description: Configure DRS behavior for a specific VM in vSphere
description:
- This module allows setting a DRS behavior override for individual VMs within a DRS-enabled VMware vSphere cluster.
options:
vm_name:
description:
- Name of the VM for which the DRS override is set.
required: true
type: str
drs_behavior:
description:
- Desired DRS behavior for the VM.
choices: ['manual', 'partiallyAutomated', 'fullyAutomated']
default: 'manual'
type: str
extends_documentation_fragment:
- community.vmware.vmware.documentation
author:
- Sergey Goncharov (@svg1007)
'''

EXAMPLES = '''
- name: Set DRS behavior for a VM
vmware_drs_override:
hostname: "vcenter.example.com"
username: "[email protected]"
password: "yourpassword"
port: 443
validate_certs: False
vm_name: "my_vm_name"
drs_behavior: "manual"
'''

RETURN = '''
changed:
description: Whether the DRS behavior was changed.
type: bool
returned: always
msg:
description: A message describing the outcome of the task.
type: str
returned: always
'''

try:
from pyVmomi import vim, vmodl
except ImportError:
pass

from ansible.module_utils.basic import AnsibleModule
from ansible_collections.community.vmware.plugins.module_utils.vmware import vmware_argument_spec, wait_for_task, PyVmomi


class VmwareDrsOverride(PyVmomi):
def __init__(self, module):
super(VmwareDrsOverride, self).__init__(module)
self.vm_name = self.params.get('vm_name', None)
self.drs_behavior = module.params['drs_behavior']
self.params['name'] = self.vm_name
self.vm = self.get_vm()
if not self.vm:
self.module.fail_json(msg="VM '%s' not found." % self.vm_name)

if not self.is_vcenter():
self.module.fail_json(msg="DRS configuration is only supported in vCenter environments.")

def set_drs_override(self):
cluster = self.vm.runtime.host.parent

# Check current DRS settings
existing_config = next((config for config in cluster.configuration.drsVmConfig if config.key == self.vm), None)
if existing_config and existing_config.behavior == self.drs_behavior:
self.module.exit_json(changed=False, msg="DRS behavior is already set to the desired state.")

# Create DRS VM config spec
drs_vm_config_spec = vim.cluster.DrsVmConfigSpec(
operation='add',
info=vim.cluster.DrsVmConfigInfo(
key=self.vm,
enabled=True,
behavior=self.drs_behavior
)
)

# Apply the cluster reconfiguration
cluster_config_spec = vim.cluster.ConfigSpec()
cluster_config_spec.drsVmConfigSpec = [drs_vm_config_spec]
try:
task = cluster.ReconfigureCluster_Task(spec=cluster_config_spec, modify=True)
wait_for_task(task)
self.module.exit_json(changed=True, msg="DRS override applied successfully.")
except vmodl.MethodFault as error:
self.module.fail_json(msg="Failed to set DRS override: %s" % error.msg)


def main():
argument_spec = vmware_argument_spec()
argument_spec.update(dict(
vm_name=dict(type='str', required=True),
drs_behavior=dict(type='str', choices=['manual', 'partiallyAutomated', 'fullyAutomated'], default='manual')
))

module = AnsibleModule(
argument_spec=argument_spec,
supports_check_mode=True
)

drs_override = VmwareDrsOverride(module)
drs_override.set_drs_override()


if __name__ == '__main__':
main()
7 changes: 4 additions & 3 deletions plugins/modules/vmware_guest_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
folder:
description:
- Destination folder, absolute or relative path to find an existing guest.
- This is required if O(name) is supplied.
- This is required if O(name) is supplied and not unique.
- The folder should include the datacenter. ESX's datacenter is ha-datacenter
- 'Examples:'
- ' folder: /ha-datacenter/vm'
Expand All @@ -64,7 +64,8 @@
datacenter:
description:
- Destination datacenter for the deploy operation
required: true
- This is required if O(name) is supplied and not unique.
required: false
type: str
tags:
description:
Expand Down Expand Up @@ -262,7 +263,7 @@ def main():
use_instance_uuid=dict(type='bool', default=False),
moid=dict(type='str'),
folder=dict(type='str'),
datacenter=dict(type='str', required=True),
datacenter=dict(type='str'),
tags=dict(type='bool', default=False),
schema=dict(type='str', choices=['summary', 'vsphere'], default='summary'),
properties=dict(type='list', elements='str'),
Expand Down
Loading

0 comments on commit 8abd0e3

Please sign in to comment.