From 03e2cd7f610df27890404cc9570f8e14a5766712 Mon Sep 17 00:00:00 2001 From: alaa-bish Date: Sun, 23 Oct 2022 09:55:54 +0300 Subject: [PATCH] sanity fix --- plugins/module_utils/prism/iscsi_clients.py | 53 ++++++++------------- plugins/module_utils/prism/volume_groups.py | 21 +++----- plugins/modules/ntnx_volume_groups.py | 17 ++++--- 3 files changed, 38 insertions(+), 53 deletions(-) diff --git a/plugins/module_utils/prism/iscsi_clients.py b/plugins/module_utils/prism/iscsi_clients.py index 812fec6db..148b8b85f 100644 --- a/plugins/module_utils/prism/iscsi_clients.py +++ b/plugins/module_utils/prism/iscsi_clients.py @@ -6,11 +6,8 @@ from copy import deepcopy -from .groups import get_entity_uuid - class Clients: - @classmethod def get_spec(cls, iscsi_client, chap_auth=False): payload = cls._get_default_spec() @@ -23,32 +20,28 @@ def get_spec(cls, iscsi_client, chap_auth=False): def _get_default_spec(): return deepcopy( { - #for iqn + # for iqn "iscsiInitiatorName": "", - #for ip + # for ip "iscsiInitiatorNetworkId": { "$objectType": "common.v1.config.IPAddressOrFQDN", "$reserved": { "$fqObjectType": "common.v1.r0.a3.config.IPAddressOrFQDN" }, - "$unknownFields": { - - }, + "$unknownFields": {}, "ipv4": { "$objectType": "common.v1.config.IPv4Address", "$reserved": { "$fqObjectType": "common.v1.r0.a3.config.IPv4Address" }, - "$unknownFields": { - - }, - "value": "10.10.20.5" - } + "$unknownFields": {}, + "value": "10.10.20.5", + }, }, - #for uuid + # for uuid "extId": "d70626f2-7575-4773-a5fb-ded32dd208e2", "clientSecret": "", - "enabledAuthentications": "NONE" # CHAP/NONE + "enabledAuthentications": "NONE", # CHAP/NONE } ) @@ -61,28 +54,24 @@ def _build_spec_iscsi_client(payload, iscsi_client, chap_auth): payload["iscsiInitiatorName"] = iscsi_client["iscsi_iqn"] elif iscsi_client.get("iscsi_ip"): payload["iscsiInitiatorNetworkId"] = { - "$objectType": "common.v1.config.IPAddressOrFQDN", + "$objectType": "common.v1.config.IPAddressOrFQDN", + "$reserved": { + "$fqObjectType": "common.v1.r0.a3.config.IPAddressOrFQDN" + }, + "$unknownFields": {}, + "ipv4": { + "$objectType": "common.v1.config.IPv4Address", "$reserved": { - "$fqObjectType": "common.v1.r0.a3.config.IPAddressOrFQDN" + "$fqObjectType": "common.v1.r0.a3.config.IPv4Address" }, - "$unknownFields": { - - }, - "ipv4": { - "$objectType": "common.v1.config.IPv4Address", - "$reserved": { - "$fqObjectType": "common.v1.r0.a3.config.IPv4Address" - }, - "$unknownFields": { - - }, - "value": iscsi_client["iscsi_ip"] - } - } + "$unknownFields": {}, + "value": iscsi_client["iscsi_ip"], + }, + } if chap_auth and iscsi_client.get("client_password"): payload["clientSecret"] = iscsi_client["client_password"] - # if iscsi_client.get("CHAP_auth"): + # if iscsi_client.get("CHAP_auth"): payload["enabledAuthentications"] = "CHAP" return payload, None diff --git a/plugins/module_utils/prism/volume_groups.py b/plugins/module_utils/prism/volume_groups.py index 9a461b833..9f9e3b72e 100644 --- a/plugins/module_utils/prism/volume_groups.py +++ b/plugins/module_utils/prism/volume_groups.py @@ -66,22 +66,14 @@ def _build_spec_load_balance(self, payload, value): def _build_spec_flash_mode(self, payload, value): payload["storageFeatures"] = { "$objectType": "storage.v4.config.StorageFeatures", - "$reserved": { - "$fqObjectType": "storage.v4.r0.a2.config.StorageFeatures" - }, - "$unknownFields": { - - }, + "$reserved": {"$fqObjectType": "storage.v4.r0.a2.config.StorageFeatures"}, + "$unknownFields": {}, "flashMode": { "$objectType": "storage.v4.config.FlashMode", - "$reserved": { - "$fqObjectType": "storage.v4.r0.a2.config.FlashMode" - }, - "$unknownFields": { - - }, - "isEnabled": True - } + "$reserved": {"$fqObjectType": "storage.v4.r0.a2.config.FlashMode"}, + "$unknownFields": {}, + "isEnabled": True, + }, } return payload, None @@ -106,6 +98,7 @@ def get_client_spec(self, client): spec = {"extId": client["uuid"]} return spec, None + # Helper functions diff --git a/plugins/modules/ntnx_volume_groups.py b/plugins/modules/ntnx_volume_groups.py index ad47c3566..56078e6ae 100644 --- a/plugins/modules/ntnx_volume_groups.py +++ b/plugins/modules/ntnx_volume_groups.py @@ -60,10 +60,10 @@ """ from ..module_utils.base_module import BaseModule # noqa: E402 +from ..module_utils.prism.iscsi_clients import Clients # noqa: E402 from ..module_utils.prism.tasks import Task # noqa: E402 from ..module_utils.prism.vdisks import VDisks # noqa: E402 from ..module_utils.prism.volume_groups import VolumeGroup # noqa: E402 -from ..module_utils.prism.iscsi_clients import Clients # noqa: E402 from ..module_utils.utils import remove_param_with_none_value # noqa: E402 @@ -102,14 +102,14 @@ def get_module_spec(): type="list", elements="dict", options=entity_by_spec, - mutually_exclusive=mutually_exclusive + mutually_exclusive=mutually_exclusive, ), load_balance=dict(type="bool", default=False), clients=dict( type="list", elements="dict", options=client_spec, - mutually_exclusive=mutually_exclusive + mutually_exclusive=mutually_exclusive, ), CHAP_auth=dict(type="bool", default=False), target_password=dict(type="str", no_log=True), @@ -145,7 +145,7 @@ def create_volume_group(module, result): vdisk = VDisks() disks_response = [] for disk in module.params["disks"]: - spec, _ = vdisk.get_spec(module, disk) + spec, err = vdisk.get_spec(module, disk) resp = volume_group.update( spec, volume_group_uuid, method="POST", endpoint="disks" ) @@ -156,7 +156,7 @@ def create_volume_group(module, result): if module.params.get("vms"): vms_response = [] for vm in module.params["vms"]: - spec, _ = volume_group.get_vm_spec(vm) + spec, err = volume_group.get_vm_spec(vm) resp = volume_group.update( spec, volume_group_uuid, method="POST", endpoint="$actions/attach-vm" ) @@ -167,9 +167,12 @@ def create_volume_group(module, result): if module.params.get("clients"): clients_response = [] for client in module.params["clients"]: - spec, _ = Clients.get_spec(client, module.params.get("CHAP_auth")) + spec, err = Clients.get_spec(client, module.params.get("CHAP_auth")) resp = volume_group.update( - spec, volume_group_uuid, method="POST", endpoint="/$actions/attach-iscsi-client" + spec, + volume_group_uuid, + method="POST", + endpoint="/$actions/attach-iscsi-client", ) clients_response.append(resp) result["response"]["clients"] = clients_response