Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

device index calculation fixes, updates for get by name functionality… #42

Merged
merged 2 commits into from
Jan 27, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 30 additions & 23 deletions plugins/module_utils/prism/vms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 - {0}".format(
payload
)
self.result["failed"] = True

self.module.exit_json(**self.result)
Expand Down Expand Up @@ -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=={0}".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=={0}".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):

Expand All @@ -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"):
Expand Down Expand Up @@ -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=={0}".format(name)}
entity_uuid = get_entity_by_name(payload=payload)
return {"kind": "subnet", "uuid": entity_uuid}

def _get_api_spec(self, param_spec, **kwargs):

Expand Down