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

Consider cluster reference as well for getting subnet uuid #266

Merged
merged 2 commits into from
Sep 19, 2022
Merged
Show file tree
Hide file tree
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
18 changes: 17 additions & 1 deletion plugins/module_utils/prism/subnets.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,23 @@ def get_subnet_uuid(config, module):
if "name" in config or "subnet_name" in config:
subnet = Subnet(module)
name = config.get("name") or config.get("subnet_name")
uuid = subnet.get_uuid(name)
uuid = ""

# incase subnet of particular cluster is needed
if config.get("cluster_uuid"):
filter_spec = {"filter": "{0}=={1}".format("name", name)}
resp = subnet.list(
data=filter_spec
)
entities = resp.get("entities") if resp else None
if entities:
for entity in entities:
if entity["status"]["cluster_reference"]["uuid"] == config["cluster_uuid"]:
uuid = entity["metadata"]["uuid"]
break
else:
uuid = subnet.get_uuid(name)

if not uuid:
error = "Subnet {0} not found.".format(name)
return None, error
Expand Down
28 changes: 21 additions & 7 deletions plugins/module_utils/prism/vms.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

from ansible.module_utils.basic import _load_params

from .clusters import Cluster
from .clusters import Cluster, get_cluster_uuid
from .groups import get_entity_uuid
from .images import get_image_uuid
from .prism import Prism
from .projects import Project
from .spec.categories_mapping import CategoriesMapping
from .subnets import Subnet
from .subnets import get_subnet_uuid


class VM(Prism):
Expand Down Expand Up @@ -246,12 +246,26 @@ def _build_spec_networks(self, payload, networks):
uuid = network["subnet"]["uuid"]

elif network.get("subnet", {}).get("name"):
subnet = Subnet(self.module)
name = network["subnet"]["name"]
uuid = subnet.get_uuid(name)
if not uuid:
error = "Subnet {0} not found.".format(name)
return None, error

# consider cluster as well to get subnet from given cluster only
cluster_ref = None
if self.module.params.get("cluster"):
cluster_ref = self.module.params["cluster"]
else:
cluster_ref = payload["spec"]["cluster_reference"]

cluster_uuid, err = get_cluster_uuid(cluster_ref, self.module)
if err:
return None, err

config = {
"name": name,
"cluster_uuid": cluster_uuid
}
uuid, err = get_subnet_uuid(config, self.module)
if err:
return None, err

nic["subnet_reference"]["uuid"] = uuid

Expand Down