Skip to content

Commit

Permalink
instance: add create by snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
resmo committed Jan 20, 2023
1 parent 5ed7df2 commit 36fb9be
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion plugins/modules/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@
- List of SSH key names passed to the instance on creation.
type: list
elements: str
snapshot:
description:
- Description or ID of the snapshot.
- Only considered while creating the instance.
type: str
version_added: "1.7.0"
reserved_ipv4:
description:
- IP address of the floating IP to use as the main IP of this instance.
Expand Down Expand Up @@ -454,6 +460,15 @@ def get_firewall_group(self):
fail_not_found=True,
)

def get_snapshot(self):
return self.query_filter_list_by_name(
key_name="description",
param_key="snapshot",
path="/snapshots",
result_key="snapshots",
fail_not_found=True,
)

def get_startup_script(self):
return self.query_filter_list_by_name(
key_name="name",
Expand Down Expand Up @@ -524,6 +539,9 @@ def configure(self):
if self.module.params["startup_script"] is not None:
self.module.params["script_id"] = self.get_startup_script()["id"]

if self.module.params["snapshot"] is not None:
self.module.params["snapshot_id"] = self.get_snapshot()["id"]

if self.module.params["firewall_group"] is not None:
self.module.params["firewall_group_id"] = self.get_firewall_group()["id"]

Expand Down Expand Up @@ -607,6 +625,7 @@ def main():
hostname=dict(type="str"),
app=dict(type="str"),
image=dict(type="str"),
snapshot=dict(type="str"),
os=dict(type="str"),
plan=dict(type="str"),
activation_email=dict(type="bool", default=False),
Expand Down Expand Up @@ -637,7 +656,7 @@ def main():
module = AnsibleModule(
argument_spec=argument_spec,
required_if=(("state", "present", ("plan",)),),
mutually_exclusive=(("os", "app", "image"),),
mutually_exclusive=(("os", "app", "image", "snapshot"),),
supports_check_mode=True,
)

Expand All @@ -654,6 +673,7 @@ def main():
"os_id",
"iso_id",
"image_id",
"snapshot_id",
"script_id",
"region",
"enable_ipv6",
Expand Down

0 comments on commit 36fb9be

Please sign in to comment.