Skip to content

Commit

Permalink
enhancement: moved disks and desc defintion in the utils module where…
Browse files Browse the repository at this point in the history
… all other definitions already are + added vtpm support with explicit configuration
  • Loading branch information
EdenCore committed Dec 10, 2024
1 parent ddf9675 commit fdd6eac
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 32 deletions.
28 changes: 28 additions & 0 deletions plugins/module_utils/prism/spec/vms.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class DefaultVMSpec:
type="dict", options=entity_by_spec, mutually_exclusive=mutually_exclusive
),
)

network_spec = dict(
uuid=dict(type="str"),
state=dict(type="str", choices=["absent"]),
Expand All @@ -38,15 +39,40 @@ class DefaultVMSpec:
),
)

vtpm_config_spec = dict(
vtpm_enabled=dict(
type="bool", required=True
),
vtpm_secret=dict(
type="str", required=False
)
)

gc_spec = dict(
type=dict(type="str", choices=["cloud_init", "sysprep"], required=True),
script_path=dict(type="path", required=True),
is_overridable=dict(type="bool", default=False),
)

disk_spec = dict(
type=dict(type="str", choices=["CDROM", "DISK"], default="DISK"),
uuid=dict(type="str"),
state=dict(type="str", choices=["absent"]),
size_gb=dict(type="int"),
bus=dict(type="str", choices=["SCSI", "PCI", "SATA", "IDE"], default="SCSI"),
storage_container=dict(
type="dict", options=entity_by_spec, mutually_exclusive=mutually_exclusive
),
clone_image=dict(
type="dict", options=entity_by_spec, mutually_exclusive=mutually_exclusive
),
empty_cdrom=dict(type="bool"),
)

vm_argument_spec = dict(
name=dict(type="str", required=False),
vm_uuid=dict(type="str"),
desc=dict(type="str"),
project=dict(
type="dict", options=entity_by_spec, mutually_exclusive=mutually_exclusive
),
Expand All @@ -60,9 +86,11 @@ class DefaultVMSpec:
cores_per_vcpu=dict(type="int"),
memory_gb=dict(type="int"),
networks=dict(type="list", elements="dict", options=network_spec),
disks=dict(type="list", elements="dict", options=disk_spec),
boot_config=dict(type="dict", options=boot_config_spec),
guest_customization=dict(type="dict", options=gc_spec),
timezone=dict(type="str", default="UTC"),
categories=dict(type="dict"),
force_power_off=dict(type="bool", default=False),
vtpm_config=dict(type="dict", options=vtpm_config_spec),
)
15 changes: 15 additions & 0 deletions plugins/module_utils/prism/vms.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def __init__(self, module):
"timezone": self._build_spec_timezone,
"categories": CategoriesMapping.build_categories_mapping_spec,
"remove_categories": CategoriesMapping.build_remove_all_categories_spec,
"vtpm_config": self._build_spec_vtpm_config,
}

def list(
Expand Down Expand Up @@ -161,6 +162,7 @@ def _get_default_spec(self):
"disk_list": [],
"nic_list": [],
"gpu_list": [],
"vtpm_config": {},
"boot_config": {
"boot_type": "LEGACY",
"boot_device_order_list": ["CDROM", "DISK", "NETWORK"],
Expand All @@ -179,6 +181,13 @@ def _get_default_boot_config_spec(self):
}
)

def _get_default_vtpm_config_spec(self):
return deepcopy(
{
"vtpm_enabled": True
}
)

def _get_default_network_spec(self):
return deepcopy(
{
Expand Down Expand Up @@ -384,6 +393,12 @@ def _build_spec_boot_config(self, payload, param):
payload["spec"]["resources"]["machine_type"] = "Q35"
return payload, None

def _build_spec_vtpm_config(self, payload, param):
payload["spec"]["resources"]["vtpm_config"] = {"vtpm_enabled": param["vtpm_enabled"]}
if param.get("vtpm_secret"):
payload["spec"]["resources"]["vtpm_config"].update({"vtpm_secret", param["vtpm_secret"]})
return payload, None

def _build_spec_gc(self, payload, param):
fpath = param["script_path"]

Expand Down
33 changes: 1 addition & 32 deletions plugins/modules/ntnx_vms.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,26 +751,6 @@

def get_module_spec():
default_vm_spec = deepcopy(DefaultVMSpec.vm_argument_spec)

mutually_exclusive = [("name", "uuid")]

entity_by_spec = dict(name=dict(type="str"), uuid=dict(type="str"))

disk_spec = dict(
type=dict(type="str", choices=["CDROM", "DISK"], default="DISK"),
uuid=dict(type="str"),
state=dict(type="str", choices=["absent"]),
size_gb=dict(type="int"),
bus=dict(type="str", choices=["SCSI", "PCI", "SATA", "IDE"], default="SCSI"),
storage_container=dict(
type="dict", options=entity_by_spec, mutually_exclusive=mutually_exclusive
),
clone_image=dict(
type="dict", options=entity_by_spec, mutually_exclusive=mutually_exclusive
),
empty_cdrom=dict(type="bool"),
)

module_args = dict(
state=dict(
type="str",
Expand All @@ -784,18 +764,7 @@ def get_module_spec():
],
default="present",
),
desc=dict(type="str"),
remove_categories=dict(type="bool", required=False, default=False),
disks=dict(
type="list",
elements="dict",
options=disk_spec,
mutually_exclusive=[
("storage_container", "clone_image", "empty_cdrom"),
("size_gb", "empty_cdrom"),
("uuid", "bus"),
],
),
remove_categories=dict(type="bool", required=False, default=False)
)
default_vm_spec.update(module_args)
return default_vm_spec
Expand Down

0 comments on commit fdd6eac

Please sign in to comment.