From 79878c9089c6b3a9e07febf1b0412386c3e991f5 Mon Sep 17 00:00:00 2001 From: Mario Lenz Date: Thu, 8 Sep 2022 07:36:42 +0200 Subject: [PATCH] vmware_guest_vnc: Remove deprecated module --- ...ove_deprecated_vmware_guest_vnc_module.yml | 2 + meta/runtime.yml | 5 - plugins/modules/vmware_guest_vnc.py | 271 ------------------ 3 files changed, 2 insertions(+), 276 deletions(-) create mode 100644 changelogs/fragments/remove_deprecated_vmware_guest_vnc_module.yml delete mode 100644 plugins/modules/vmware_guest_vnc.py diff --git a/changelogs/fragments/remove_deprecated_vmware_guest_vnc_module.yml b/changelogs/fragments/remove_deprecated_vmware_guest_vnc_module.yml new file mode 100644 index 000000000..10cb62fe8 --- /dev/null +++ b/changelogs/fragments/remove_deprecated_vmware_guest_vnc_module.yml @@ -0,0 +1,2 @@ +removed_features: + - vmware_guest_vnc - The deprecated module ``vmware_guest_vnc`` has been removed. diff --git a/meta/runtime.yml b/meta/runtime.yml index c8e886a81..5e268d56c 100644 --- a/meta/runtime.yml +++ b/meta/runtime.yml @@ -76,7 +76,6 @@ action_groups: - vmware_guest_tools_wait - vmware_guest_vgpu - vmware_guest_video - - vmware_guest_vnc - vmware_host - vmware_host_acceptance - vmware_host_active_directory @@ -163,7 +162,3 @@ plugin_routing: deprecation: removal_date: 2022-06-01 warning_text: see plugin documentation for details - vmware_guest_vnc: - deprecation: - removal_date: 2022-10-15 - warning_text: see plugin documentation for details diff --git a/plugins/modules/vmware_guest_vnc.py b/plugins/modules/vmware_guest_vnc.py deleted file mode 100644 index 9ee27fdd0..000000000 --- a/plugins/modules/vmware_guest_vnc.py +++ /dev/null @@ -1,271 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- - -# Copyright (c) 2018, Armin Ranjbar Daemi -# 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 - -from __future__ import absolute_import, division, print_function -__metaclass__ = type - - -DOCUMENTATION = r''' ---- -module: vmware_guest_vnc -deprecated: - removed_at_date: '2022-10-15' - why: VNC has been removed in 7.0 and 2022-10-15 is the End of General Support date for 6.5 / 6.7. - alternative: Users should use the VM Console via the vSphere Client, the ESXi Host Client, or the VMware Remote Console to connect to virtual machines. - removed_from_collection: 'community.vmware' -short_description: Manages VNC remote display on virtual machines in vCenter -description: - - This module can be used to enable and disable VNC remote display on virtual machine. -author: - - Armin Ranjbar Daemi (@rmin) -options: - datacenter: - description: - - Destination datacenter for the deploy operation. - - This parameter is case sensitive. - default: ha-datacenter - type: str - state: - description: - - Set the state of VNC on virtual machine. - choices: [present, absent] - default: present - required: false - type: str - name: - description: - - Name of the virtual machine to work with. - - Virtual machine names in vCenter are not necessarily unique, which may be problematic, see C(name_match). - required: false - type: str - name_match: - description: - - If multiple virtual machines matching the name, use the first or last found. - default: first - choices: [first, last] - required: false - type: str - uuid: - description: - - UUID of the instance to manage if known, this is VMware's unique identifier. - - This is required, if C(name) or C(moid) is not supplied. - required: false - type: str - moid: - description: - - Managed Object ID of the instance to manage if known, this is a unique identifier only within a single vCenter instance. - - This is required if C(name) or C(uuid) is not supplied. - type: str - folder: - description: - - Destination folder, absolute or relative path to find an existing guest. - - The folder should include the datacenter. ESX's datacenter is ha-datacenter - required: false - type: str - vnc_ip: - description: - - Sets an IP for VNC on virtual machine. - - This is required only when I(state) is set to present and will be ignored if I(state) is absent. - default: 0.0.0.0 - required: false - type: str - vnc_port: - description: - - The port that VNC listens on. Usually a number between 5900 and 7000 depending on your config. - - This is required only when I(state) is set to present and will be ignored if I(state) is absent. - default: 0 - required: false - type: int - vnc_password: - description: - - Sets a password for VNC on virtual machine. - - This is required only when I(state) is set to present and will be ignored if I(state) is absent. - default: "" - required: false - type: str -extends_documentation_fragment: -- community.vmware.vmware.documentation - -''' - -EXAMPLES = r''' -- name: Enable VNC remote display on the VM - community.vmware.vmware_guest_vnc: - hostname: "{{ vcenter_hostname }}" - username: "{{ vcenter_username }}" - password: "{{ vcenter_password }}" - folder: /mydatacenter/vm - name: testvm1 - vnc_port: 5990 - vnc_password: vNc5ecr3t - datacenter: "{{ datacenter_name }}" - state: present - delegate_to: localhost - register: vnc_result - -- name: Disable VNC remote display on the VM - community.vmware.vmware_guest_vnc: - hostname: "{{ vcenter_hostname }}" - username: "{{ vcenter_username }}" - password: "{{ vcenter_password }}" - datacenter: "{{ datacenter_name }}" - uuid: 32074771-7d6b-699a-66a8-2d9cf8236fff - state: absent - delegate_to: localhost - register: vnc_result - -- name: Disable VNC remote display on the VM using MoID - community.vmware.vmware_guest_vnc: - hostname: "{{ vcenter_hostname }}" - username: "{{ vcenter_username }}" - password: "{{ vcenter_password }}" - datacenter: "{{ datacenter_name }}" - moid: vm-42 - state: absent - delegate_to: localhost - register: vnc_result -''' - -RETURN = r''' -changed: - description: If anything changed on VM's extraConfig. - returned: always - type: bool -failed: - description: If changes failed. - returned: always - type: bool -instance: - description: Dictionary describing the VM, including VNC info. - returned: On success in both I(state) - type: dict -''' - -try: - from pyVmomi import vim -except ImportError: - pass - -from ansible.module_utils.basic import AnsibleModule -from ansible_collections.community.vmware.plugins.module_utils.vmware import ( - PyVmomi, vmware_argument_spec, get_vnc_extraconfig, wait_for_task, - gather_vm_facts, TaskError) -from ansible.module_utils._text import to_native - - -def set_vnc_extraconfig(content, vm, enabled, ip, port, password): - result = dict( - changed=False, - failed=False, - ) - # set new values - key_prefix = "remotedisplay.vnc." - new_values = dict() - for key in ['enabled', 'ip', 'port', 'password']: - new_values[key_prefix + key] = "" - if enabled: - new_values[key_prefix + "enabled"] = "true" - new_values[key_prefix + "password"] = str(password).strip() - new_values[key_prefix + "ip"] = str(ip).strip() - new_values[key_prefix + "port"] = str(port).strip() - - # get current vnc config - current_values = get_vnc_extraconfig(vm) - # check if any value is changed - reconfig_vm = False - for key, val in new_values.items(): - key = key.replace(key_prefix, "") - current_value = current_values.get(key, "") - # enabled is not case-sensitive - if key == "enabled": - current_value = current_value.lower() - val = val.lower() - if current_value != val: - reconfig_vm = True - if not reconfig_vm: - return result - # reconfigure vm - spec = vim.vm.ConfigSpec() - spec.extraConfig = [] - for key, val in new_values.items(): - opt = vim.option.OptionValue() - opt.key = key - opt.value = val - spec.extraConfig.append(opt) - task = vm.ReconfigVM_Task(spec) - try: - wait_for_task(task) - except TaskError as task_err: - result['failed'] = True - result['msg'] = to_native(task_err) - - if task.info.state == 'error': - result['failed'] = True - result['msg'] = task.info.error.msg - else: - result['changed'] = True - result['instance'] = gather_vm_facts(content, vm) - return result - - -def main(): - argument_spec = vmware_argument_spec() - argument_spec.update( - state=dict(type='str', default='present', choices=['present', 'absent']), - name=dict(type='str'), - name_match=dict(type='str', choices=['first', 'last'], default='first'), - uuid=dict(type='str'), - moid=dict(type='str'), - folder=dict(type='str'), - vnc_ip=dict(type='str', default='0.0.0.0'), - vnc_port=dict(type='int', default=0), - vnc_password=dict(type='str', default='', no_log=True), - datacenter=dict(type='str', default='ha-datacenter') - ) - - module = AnsibleModule( - argument_spec=argument_spec, - supports_check_mode=True, - required_one_of=[ - ['name', 'uuid', 'moid'] - ], - mutually_exclusive=[ - ['name', 'uuid', 'moid'] - ] - ) - - module.deprecate( - msg="The 'vmware_guest_vnc' module is deprecated because vSphere 7.0 removed the built-in VNC server", - date="2022-10-15", - collection_name="community.vmware" - ) - - result = dict(changed=False, failed=False) - - pyv = PyVmomi(module) - vm = pyv.get_vm() - if vm: - result = set_vnc_extraconfig( - pyv.content, - vm, - (module.params['state'] == "present"), - module.params['vnc_ip'], - module.params['vnc_port'], - module.params['vnc_password'] - ) - else: - vm_id = module.params.get('uuid') or module.params.get('name') or module.params.get('moid') - module.fail_json(msg="Unable to set VNC config for non-existing virtual machine : '%s'" % vm_id) - - if result.get('failed') is True: - module.fail_json(**result) - - module.exit_json(**result) - - -if __name__ == "__main__": - main()