From fb5ec927922aefda24009bdf2eb97dacc89022e3 Mon Sep 17 00:00:00 2001 From: Abhinav Bansal Date: Mon, 23 Dec 2024 15:01:35 +0530 Subject: [PATCH] Removed the modules using deprecated v4 sdks (#536) * Removed the modules using deprecated v4 sdks * Fixed flake8 and added some comments * removing deprecated modules from runtime.yml file * Addressed Comments --------- Co-authored-by: George Ghawali --- meta/runtime.yml | 2 - .../ntnx_volume_groups_categories_info_v2.py | 147 ----------------- ...tnx_volume_groups_iscsi_clients_info_v2.py | 65 +------- .../modules/ntnx_volume_groups_vms_info_v2.py | 148 ------------------ .../tasks/iscsi_client_connections.yml | 66 -------- .../tasks/ahv_vm_vg_connections.yml | 82 ---------- 6 files changed, 3 insertions(+), 507 deletions(-) delete mode 100644 plugins/modules/ntnx_volume_groups_categories_info_v2.py delete mode 100644 plugins/modules/ntnx_volume_groups_vms_info_v2.py diff --git a/meta/runtime.yml b/meta/runtime.yml index 74f24506..7bbd5369 100644 --- a/meta/runtime.yml +++ b/meta/runtime.yml @@ -149,8 +149,6 @@ action_groups: - ntnx_volume_groups_info_v2 - ntnx_volume_groups_disks_v2 - ntnx_volume_groups_disks_info_v2 - - ntnx_volume_groups_categories_info_v2 - - ntnx_volume_groups_vms_info_v2 - ntnx_volume_groups_vms_v2 - ntnx_volume_groups_iscsi_clients_v2 - ntnx_volume_groups_iscsi_clients_info_v2 diff --git a/plugins/modules/ntnx_volume_groups_categories_info_v2.py b/plugins/modules/ntnx_volume_groups_categories_info_v2.py deleted file mode 100644 index e7c906a1..00000000 --- a/plugins/modules/ntnx_volume_groups_categories_info_v2.py +++ /dev/null @@ -1,147 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- - -# Copyright: (c) 2024, Nutanix -# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - -from __future__ import absolute_import, division, print_function - -__metaclass__ = type - - -DOCUMENTATION = r""" ---- -module: ntnx_volume_groups_categories_info_v2 -short_description: Fetch list of attached categories to VG -description: - - Fetch list of attached categories to VG - - This module uses PC v4 APIs based SDKs -version_added: "2.0.0" -author: - - Pradeepsingh Bhati (@bhati-pradeep) -options: - ext_id: - description: - - The external ID of VG - type: str - required: true -extends_documentation_fragment: - - nutanix.ncp.ntnx_credentials - - nutanix.ncp.ntnx_info_v2 -""" - -EXAMPLES = r""" -- name: Fetch info of all categories attached to VG - nutanix.ncp.ntnx_volume_groups_categories_info_v2: - nutanix_host: "{{ ip }}" - nutanix_username: "{{ username }}" - nutanix_password: "{{ password }}" - state: "present" - ext_id: 0005b6b1-0b3b-4b3b-8b3b-0b3b4b3b4b35 - register: result -""" - -RETURN = r""" -response: - description: - - list of categories attached to VG - type: list - returned: always - sample: [ - { - "entity_type": "CATEGORY", - "ext_id": "e4bda88f-e5da-5eb1-a031-2c0bb00d923d", - "name": null, - "uris": null - }, - { - "entity_type": "CATEGORY", - "ext_id": "711936c6-7a6b-4b01-ab52-dc19b2e368db", - "name": null, - "uris": null - } - ] - -ext_id: - description: volume group external ID - type: str - returned: always - sample: "0005b6b1-0b3b-4b3b-8b3b-0b3b4b3b4b3b" -error: - description: The error message if any. - type: str - returned: when error occurs - sample: "Failed generating volume group associated categories info Spec" -changed: - description: Indicates whether the resource has changed. - type: bool - returned: always - sample: true -""" -from ..module_utils.utils import remove_param_with_none_value # noqa: E402 -from ..module_utils.v4.base_info_module import BaseInfoModule # noqa: E402 -from ..module_utils.v4.spec_generator import SpecGenerator # noqa: E402 -from ..module_utils.v4.utils import ( # noqa: E402 - raise_api_exception, - strip_internal_attributes, -) -from ..module_utils.v4.volumes.api_client import get_vg_api_instance # noqa: E402 - - -def get_module_spec(): - module_args = dict( - ext_id=dict(type="str", required=True), - ) - return module_args - - -def get_associated_categories(module, result): - vgs = get_vg_api_instance(module) - ext_id = module.params.get("ext_id") - - sg = SpecGenerator(module) - kwargs, err = sg.get_info_spec(attr=module.params) - - if err: - result["error"] = err - module.fail_json( - msg="Failed generating volume group associated categories info Spec", - **result, - ) - - try: - resp = vgs.list_category_associations_by_volume_group_id(extId=ext_id, **kwargs) - except Exception as e: - raise_api_exception( - module=module, - exception=e, - msg="Api Exception raised while fetching categories associated with volume group info", - ) - - result["ext_id"] = ext_id - result["response"] = strip_internal_attributes(resp.to_dict()).get("data") - if not result["response"]: - result["response"] = [] - - -def run_module(): - module = BaseInfoModule( - argument_spec=get_module_spec(), - supports_check_mode=False, - mutually_exclusive=[ - ("ext_id", "filter"), - ], - ) - remove_param_with_none_value(module.params) - result = {"changed": False, "error": None, "response": None} - get_associated_categories(module, result) - - module.exit_json(**result) - - -def main(): - run_module() - - -if __name__ == "__main__": - main() diff --git a/plugins/modules/ntnx_volume_groups_iscsi_clients_info_v2.py b/plugins/modules/ntnx_volume_groups_iscsi_clients_info_v2.py index 2f721d92..66125ed9 100644 --- a/plugins/modules/ntnx_volume_groups_iscsi_clients_info_v2.py +++ b/plugins/modules/ntnx_volume_groups_iscsi_clients_info_v2.py @@ -15,8 +15,6 @@ description: - By default, Fetch all iscsi clients currently attached to any VG - Fetch iscsi client if C(ext_id) is given - - Fetch all iscsi clients attached to a particular VG if C(volume_group_ext_id) is given - - This module uses PC v4 APIs based SDKs version_added: "2.0.0" author: - Pradeepsingh Bhati (@bhati-pradeep) @@ -27,27 +25,12 @@ - This will fetch the iscsi client with the given external ID. type: str required: false - volume_group_ext_id: - description: - - The external ID of the volume group. - - This will fetch all iscsi clients attached to the given volume group. - type: str - required: false extends_documentation_fragment: - nutanix.ncp.ntnx_credentials - nutanix.ncp.ntnx_info_v2 """ EXAMPLES = r""" -- name: Fetch iscsi clients attached to VG - nutanix.ncp.ntnx_volume_groups_iscsi_clients_info_v2: - nutanix_host: "{{ ip }}" - nutanix_username: "{{ username }}" - nutanix_password: "{{ password }}" - state: "present" - volume_group_ext_id: 0005b6b1-0b3b-4b3b-8b3b-0b3b4b3b4b35 - register: result - - name: Fetch specific iscsi client info nutanix.ncp.ntnx_volume_groups_iscsi_clients_info_v2: nutanix_host: "{{ ip }}" @@ -72,7 +55,6 @@ description: - list of iscsi clients currently attached to any VG - specific iscsi client if ext_id given - - List of all iscsi clients attached to a particular VG using volume_group_ext_id type: dict returned: always sample: [ @@ -94,11 +76,6 @@ type: str returned: always sample: "0005b6b1-0b3b-4b3b-8b3b-0b3b4b3b4b3b" -volume_group_ext_id: - description: Volume group external ID. - type: str - returned: always - sample: "0005b6b1-0b3b-4b3b-8b3b-0b3b4b3b4b3b" error: description: The error message if any. type: str @@ -120,47 +97,16 @@ ) from ..module_utils.v4.volumes.api_client import ( # noqa: E402 get_iscsi_client_api_instance, - get_vg_api_instance, ) def get_module_spec(): module_args = dict( ext_id=dict(type="str", required=False), - volume_group_ext_id=dict(type="str", required=False), ) return module_args -def get_vg_iscsi_clients(module, result): - vgs = get_vg_api_instance(module) - volume_group_ext_id = module.params.get("volume_group_ext_id") - - sg = SpecGenerator(module) - kwargs, err = sg.get_info_spec(attr=module.params) - - if err: - result["error"] = err - module.fail_json(msg="Failed generating info Spec", **result) - - try: - resp = vgs.list_external_iscsi_attachments_by_volume_group_id( - volumeGroupExtId=volume_group_ext_id, **kwargs - ) - except Exception as e: - raise_api_exception( - module=module, - exception=e, - msg="Api Exception raised while fetching ISCSI clients attached to VGs", - ) - - result["volume_group_ext_id"] = volume_group_ext_id - resp = strip_internal_attributes(resp.to_dict()).get("data") - if not resp: - resp = [] - result["response"] = resp - - def get_iscsi_client(module, result): clients = get_iscsi_client_api_instance(module) ext_id = module.params.get("ext_id") @@ -208,20 +154,15 @@ def run_module(): argument_spec=get_module_spec(), supports_check_mode=False, mutually_exclusive=[ - ("ext_id", "volume_group_ext_id"), ("ext_id", "filter"), - ("volume_group_ext_id", "filter"), ], ) remove_param_with_none_value(module.params) result = {"changed": False, "error": None, "response": None} - if module.params.get("volume_group_ext_id"): - get_vg_iscsi_clients(module, result) + if module.params.get("ext_id"): + get_iscsi_client(module, result) else: - if module.params.get("ext_id"): - get_iscsi_client(module, result) - else: - get_iscsi_clients(module, result) + get_iscsi_clients(module, result) module.exit_json(**result) diff --git a/plugins/modules/ntnx_volume_groups_vms_info_v2.py b/plugins/modules/ntnx_volume_groups_vms_info_v2.py deleted file mode 100644 index 623ba7be..00000000 --- a/plugins/modules/ntnx_volume_groups_vms_info_v2.py +++ /dev/null @@ -1,148 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- - -# Copyright: (c) 2024, Nutanix -# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - -from __future__ import absolute_import, division, print_function - -__metaclass__ = type - -DOCUMENTATION = r""" ---- -module: ntnx_volume_groups_vms_info_v2 -short_description: Fetch VG attached VMs info -description: - - Fetch all VMs info attached to VM - - This module uses PC v4 APIs based SDKs -version_added: "2.0.0" -author: - - Pradeepsingh Bhati (@bhati-pradeep) -options: - ext_id: - description: - - The external ID of VG - type: str - required: true -extends_documentation_fragment: - - nutanix.ncp.ntnx_credentials - - nutanix.ncp.ntnx_info_v2 -""" - -EXAMPLES = r""" -- name: Fetch particular VM attached to VG using filters - nutanix.ncp.ntnx_volume_groups_vms_info_v2: - nutanix_host: "{{ ip }}" - nutanix_username: "{{ username }}" - nutanix_password: "{{ password }}" - state: "present" - filter: extId eq '{{ vm1_uuid }}' - ext_id: "{{ vg1_uuid }}" - register: result - -- name: Fetch all VMs attached to VG - nutanix.ncp.ntnx_volume_groups_vms_info_v2: - nutanix_host: "{{ ip }}" - nutanix_username: "{{ username }}" - nutanix_password: "{{ password }}" - state: "present" - ext_id: 0005b6b1-0b3b-4b3b-8b3b-0b3b4b3b4b35 - register: result -""" - -RETURN = r""" -response: - description: - - list of VMs attached to VG - type: list - returned: always - sample: [ - { - "created_time": null, - "ext_id": "7b959066-86f4-43e5-4c8b-d870876674da", - "index": null, - "links": null, - "tenant_id": null - } - ] -ext_id: - description: volume group external ID - type: str - returned: always - sample: "0005b6b1-0b3b-4b3b-8b3b-0b3b4b3b4b3b" -error: - description: The error message if any. - type: str - returned: when error occurs - sample: "Api Exception raised while fetching VMs attached to given Volume Group" -changed: - description: Indicates whether the resource has changed. - type: bool - returned: always - sample: true -""" - -from ..module_utils.utils import remove_param_with_none_value # noqa: E402 -from ..module_utils.v4.base_info_module import BaseInfoModule # noqa: E402 -from ..module_utils.v4.spec_generator import SpecGenerator # noqa: E402 -from ..module_utils.v4.utils import ( # noqa: E402 - raise_api_exception, - strip_internal_attributes, -) -from ..module_utils.v4.volumes.api_client import get_vg_api_instance # noqa: E402 - - -def get_module_spec(): - module_args = dict( - ext_id=dict(type="str", required=True), - ) - return module_args - - -def get_vg_vms(module, result): - vgs = get_vg_api_instance(module) - volume_group_ext_id = module.params.get("ext_id") - - sg = SpecGenerator(module) - kwargs, err = sg.get_info_spec(attr=module.params) - - if err: - result["error"] = err - module.fail_json(msg="Failed generating info Spec", **result) - - try: - resp = vgs.list_vm_attachments_by_volume_group_id( - volumeGroupExtId=volume_group_ext_id, **kwargs - ) - except Exception as e: - raise_api_exception( - module=module, - exception=e, - msg="Api Exception raised while fetching VMs attached to given Volume Group", - ) - - result["ext_id"] = volume_group_ext_id - vms = strip_internal_attributes(resp.to_dict()).get("data") - if not vms: - vms = [] - result["response"] = vms - - -def run_module(): - module = BaseInfoModule( - argument_spec=get_module_spec(), - supports_check_mode=False, - ) - remove_param_with_none_value(module.params) - result = {"changed": False, "error": None, "response": None} - get_vg_vms(module, result) - - module.exit_json(**result) - - -def main(): - run_module() - - -if __name__ == "__main__": - main() diff --git a/tests/integration/targets/ntnx_volume_groups_iscsi_clients_v2/tasks/iscsi_client_connections.yml b/tests/integration/targets/ntnx_volume_groups_iscsi_clients_v2/tasks/iscsi_client_connections.yml index e2718391..c8abd40c 100644 --- a/tests/integration/targets/ntnx_volume_groups_iscsi_clients_v2/tasks/iscsi_client_connections.yml +++ b/tests/integration/targets/ntnx_volume_groups_iscsi_clients_v2/tasks/iscsi_client_connections.yml @@ -156,23 +156,6 @@ fail_msg: "Unable to attach iscsi client using initiator name" success_msg: "ISCSI client attached successfully using initiator name" -- name: List all clients attached to VG to verify attachment - ntnx_volume_groups_iscsi_clients_info_v2: - volume_group_ext_id: "{{ vg1_uuid }}" - register: result - -- name: Verify if attachment was correct - ansible.builtin.assert: - that: - - result.error == None - - result.response is defined - - result.changed == false - - result.response | length == 1 - - result.response[0].ext_id == iscsi_client_uuid - - result.volume_group_ext_id == vg1_uuid - fail_msg: "Unable to list iscsi clients attached to VG" - success_msg: "ISCSI clients attached to VG listed successfully" - - name: Fetch specific client ntnx_volume_groups_iscsi_clients_info_v2: ext_id: "{{ iscsi_client_uuid }}" @@ -209,22 +192,6 @@ fail_msg: "Unable to detach iscsi client using initiator name" success_msg: "ISCSI client detached successfully using initiator name" -- name: List all clients attached to VG to verify detachment - ntnx_volume_groups_iscsi_clients_info_v2: - volume_group_ext_id: "{{ vg1_uuid }}" - register: result - -- name: Verify if attachment went fine - ansible.builtin.assert: - that: - - result.error == None - - result.response is defined - - result.changed == false - - result.response | length == 0 - - result.volume_group_ext_id == vg1_uuid - fail_msg: "Unable to verify detachment of iscsi client" - success_msg: "Detachment of client verified successfully" - - name: Attach iscsi client to VG using iscsi client id ntnx_volume_groups_iscsi_clients_v2: volume_group_ext_id: "{{ vg1_uuid }}" @@ -244,23 +211,6 @@ fail_msg: "Unable to attach iscsi client using ext_id" success_msg: "ISCSI client attached successfully using ext_id" -- name: List all clients attached to VG to verify attachment - ntnx_volume_groups_iscsi_clients_info_v2: - volume_group_ext_id: "{{ vg1_uuid }}" - register: result - -- name: Verify if attachment went fine - ansible.builtin.assert: - that: - - result.error == None - - result.response is defined - - result.changed == false - - result.response | length == 1 - - result.response[0].ext_id == iscsi_client_uuid - - result.volume_group_ext_id == vg1_uuid - fail_msg: "Unable to list iscsi clients attached to VG" - success_msg: "ISCSI clients attached to VG listed successfully" - - name: Detach client from VG ntnx_volume_groups_iscsi_clients_v2: volume_group_ext_id: "{{ vg1_uuid }}" @@ -280,22 +230,6 @@ fail_msg: "Unable to detach iscsi client using initiator name" success_msg: "ISCSI client detached successfully using initiator name" -- name: List all clients attached to VG to verify detachment - ntnx_volume_groups_iscsi_clients_info_v2: - volume_group_ext_id: "{{ vg1_uuid }}" - register: result - -- name: Verify if attachment went fine - ansible.builtin.assert: - that: - - result.error == None - - result.response is defined - - result.changed == false - - result.response | length == 0 - - result.volume_group_ext_id == vg1_uuid - fail_msg: "Unable to list iscsi clients attached to VG" - success_msg: "ISCSI clients attached to VG listed successfully" - ############################################ Cleanup ############################################ - name: Delete Volume group diff --git a/tests/integration/targets/ntnx_volume_groups_vms_v2/tasks/ahv_vm_vg_connections.yml b/tests/integration/targets/ntnx_volume_groups_vms_v2/tasks/ahv_vm_vg_connections.yml index c23abb57..05d35e3b 100644 --- a/tests/integration/targets/ntnx_volume_groups_vms_v2/tasks/ahv_vm_vg_connections.yml +++ b/tests/integration/targets/ntnx_volume_groups_vms_v2/tasks/ahv_vm_vg_connections.yml @@ -188,57 +188,6 @@ fail_msg: "Unable to verify VG attachment from VM side" success_msg: "VG attachment verified from VM side" -############################################ Info tests ############################################ -- name: Fetch all VMs attached to VG - ntnx_volume_groups_vms_info_v2: - ext_id: "{{ vg1_uuid }}" - register: result - -- name: Verify all VMs attached to VG - ansible.builtin.assert: - that: - - result.error == None - - result.changed == false - - result.response | length == 2 - - result.response[0].ext_id in [ "{{ vm1_uuid }}", "{{ vm2_uuid }}" ] - - result.response[1].ext_id in [ "{{ vm1_uuid }}", "{{ vm2_uuid }}" ] - - fail_msg: "Unable to verify all VMs attached to VG" - success_msg: "All VMs attached to VG verified successfully" - -- name: Fetch all VMs attached to VG with limit - ntnx_volume_groups_vms_info_v2: - limit: 1 - ext_id: "{{ vg1_uuid }}" - register: result - -- name: Verify all VMs attached to VG with limit - ansible.builtin.assert: - that: - - result.error == None - - result.changed == false - - result.response | length == 1 - - fail_msg: "Unable to verify all VMs attached to VG with limit query" - success_msg: "All VMs attached to VG with limit verified successfully query" - -- name: Fetch all VMs attached to VG with filter - ntnx_volume_groups_vms_info_v2: - filter: extId eq '{{ vm1_uuid }}' - ext_id: "{{ vg1_uuid }}" - register: result - -- name: Verify fetching VM attached using filter - ansible.builtin.assert: - that: - - result.error == None - - result.changed == false - - result.response | length == 1 - - result.response[0].ext_id == "{{ vm1_uuid }}" - - fail_msg: "Unable to verify fetching VM attached using filter" - success_msg: "Fetching VM attached using filter verified successfully" - ############################################ Detach VM tests ############################################ - name: Detach VM1 from VG @@ -259,22 +208,6 @@ fail_msg: "Unable to detach VM from VG" success_msg: "VM detached from VG successfully" -- name: Fetch all VMs attached to VG - ntnx_volume_groups_vms_info_v2: - ext_id: "{{ vg1_uuid }}" - register: result - -- name: Verify VM1 is detached from VG - ansible.builtin.assert: - that: - - result.error == None - - result.changed == false - - result.response | length == 1 - - result.response[0].ext_id == "{{ vm2_uuid }}" - - fail_msg: "Unable to verify VM1 is detached from VG" - success_msg: "VM1 is detached from VG verified successfully" - - name: Detach VM2 from VG ntnx_volume_groups_vms_v2: state: absent @@ -293,21 +226,6 @@ fail_msg: "Unable to detach VM2 from VG" success_msg: "VM2 detached from VG successfully" -- name: Fetch all VMs attached to VG - ntnx_volume_groups_vms_info_v2: - ext_id: "{{ vg1_uuid }}" - register: result - -- name: Verify VM2 is detached from VG - ansible.builtin.assert: - that: - - result.error == None - - result.changed == false - - result.response | length == 0 - - fail_msg: "Unable to verify VM2 is detached from VG" - success_msg: "VM2 is detached from VG verified successfully" - ############################################ Cleanup tests ############################################ - name: Delete VM1