From 26338cb2d656ceaba0b09e3c639560c2b3451ad2 Mon Sep 17 00:00:00 2001 From: Gevorg-Khachatryaan Date: Thu, 27 Jan 2022 12:28:22 +0400 Subject: [PATCH 1/2] device index calculation fixes, updates for get by name functionality to support storage container --- plugins/module_utils/prism/vms.py | 53 +++++++++++++++++-------------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/plugins/module_utils/prism/vms.py b/plugins/module_utils/prism/vms.py index 8d137feaa..7ee39bcb7 100644 --- a/plugins/module_utils/prism/vms.py +++ b/plugins/module_utils/prism/vms.py @@ -27,24 +27,25 @@ def get_attr_spec(self, param, param_spec, **kwargs): return handler(param_spec, get_ref=self.get_entity_by_name) return param_spec - def get_entity_by_name(self, name="", kind=""): - url = self.generate_url_from_operations(kind, netloc=self.url, ops=["list"]) - data = {"filter": "name=={0}".format(name), "length": 1} + def get_entity_by_name(self, payload=None): + url = self.generate_url_from_operations("groups", netloc=self.url) resp = self.send_request( self.module, - self.methods_of_actions["list"], + "post", url, - data, + payload, self.credentials["username"], self.credentials["password"], ) try: - return resp["entities"][0]["metadata"] + return resp["group_results"][0]["entity_results"][0]["entity_id"] except IndexError: - self.result["message"] = "Entity with name {0} does not exist.".format(name) + self.result["message"] = "Entity does not exist. payload - {}".format( + payload + ) self.result["failed"] = True self.module.exit_json(**self.result) @@ -110,13 +111,18 @@ def get_default_spec(): def __get_image_ref(self, name, **kwargs): get_entity_by_name = kwargs["get_ref"] - entity = get_entity_by_name(name, "images") - return {"kind": entity["kind"], "uuid": entity["uuid"]} + payload = {"entity_type": "image", "filter_criteria": "name=={}".format(name)} + entity_uuid = get_entity_by_name(payload=payload) + return {"kind": "image", "uuid": entity_uuid} def __get_storage_container_ref(self, name, **kwargs): get_entity_by_name = kwargs["get_ref"] - entity = get_entity_by_name(name, "storage-containers") - return {"kind": entity["kind"], "uuid": entity["uuid"]} + payload = { + "entity_type": "storage_container", + "filter_criteria": "container_name=={}".format(name), + } + entity_uuid = get_entity_by_name(payload=payload) + return {"kind": "storage_container", "uuid": entity_uuid} def _get_api_spec(self, param_spec, **kwargs): @@ -136,23 +142,23 @@ def _get_api_spec(self, param_spec, **kwargs): ] = disk_param["bus"] # Calculating device_index for the DISK - if disk_param["type"] not in _di_map: - _di_map[disk_param["type"]] = {} - if disk_param["bus"] not in _di_map[disk_param["type"]]: - _di_map[disk_param["type"]][disk_param["bus"]] = 0 - disk_final["device_properties"]["disk_address"]["device_index"] = _di_map[ - disk_param["type"] - ][disk_param["bus"]] - _di_map[disk_param["type"]][disk_param["bus"]] += 1 + if disk_param["bus"] not in _di_map: + _di_map[disk_param["bus"]] = 0 + disk_final["device_properties"]["disk_address"]["device_index"] = _di_map[ + disk_param["bus"] + ] + _di_map[disk_param["bus"]] += 1 # Size of disk if disk_param.get("size_gb"): disk_final["disk_size_mib"] = disk_param["size_gb"] * 1024 - if disk_param.get("storage_container_name"): + if disk_param["storage_config"] and disk_param["storage_config"].get( + "storage_container_name" + ): disk_final["storage_config"] = { "storage_container_reference": self.__get_storage_container_ref( - disk_param["storage_container_name"], **kwargs + disk_param["storage_config"]["storage_container_name"], **kwargs ) } elif disk_param.get("storage_container_uuid"): @@ -191,8 +197,9 @@ def get_default_spec(): def __get_subnet_ref(self, name, **kwargs): get_entity_by_name = kwargs["get_ref"] - entity = get_entity_by_name(name, "subnets") - return {"kind": entity["kind"], "uuid": entity["uuid"]} + payload = {"entity_type": "subnet", "filter_criteria": "name=={}".format(name)} + entity_uuid = get_entity_by_name(payload=payload) + return {"kind": "subnet", "uuid": entity_uuid} def _get_api_spec(self, param_spec, **kwargs): From a85d799a22ef3f80c6b20931ea60aea09de5dc31 Mon Sep 17 00:00:00 2001 From: Gevorg-Khachatryaan Date: Thu, 27 Jan 2022 12:36:45 +0400 Subject: [PATCH 2/2] sanity fixes --- plugins/module_utils/prism/vms.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/module_utils/prism/vms.py b/plugins/module_utils/prism/vms.py index 7ee39bcb7..508de1226 100644 --- a/plugins/module_utils/prism/vms.py +++ b/plugins/module_utils/prism/vms.py @@ -43,7 +43,7 @@ def get_entity_by_name(self, payload=None): except IndexError: - self.result["message"] = "Entity does not exist. payload - {}".format( + self.result["message"] = "Entity does not exist. payload - {0}".format( payload ) self.result["failed"] = True @@ -111,7 +111,7 @@ def get_default_spec(): def __get_image_ref(self, name, **kwargs): get_entity_by_name = kwargs["get_ref"] - payload = {"entity_type": "image", "filter_criteria": "name=={}".format(name)} + payload = {"entity_type": "image", "filter_criteria": "name=={0}".format(name)} entity_uuid = get_entity_by_name(payload=payload) return {"kind": "image", "uuid": entity_uuid} @@ -119,7 +119,7 @@ def __get_storage_container_ref(self, name, **kwargs): get_entity_by_name = kwargs["get_ref"] payload = { "entity_type": "storage_container", - "filter_criteria": "container_name=={}".format(name), + "filter_criteria": "container_name=={0}".format(name), } entity_uuid = get_entity_by_name(payload=payload) return {"kind": "storage_container", "uuid": entity_uuid} @@ -197,7 +197,7 @@ def get_default_spec(): def __get_subnet_ref(self, name, **kwargs): get_entity_by_name = kwargs["get_ref"] - payload = {"entity_type": "subnet", "filter_criteria": "name=={}".format(name)} + payload = {"entity_type": "subnet", "filter_criteria": "name=={0}".format(name)} entity_uuid = get_entity_by_name(payload=payload) return {"kind": "subnet", "uuid": entity_uuid}