Skip to content

Commit

Permalink
v0.18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jriddle-linode authored Jul 20, 2023
2 parents 147c2d7 + fac0c81 commit 75b60a5
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 257 deletions.
4 changes: 1 addition & 3 deletions plugins/module_utils/linode_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
format_api_error,
format_generic_error,
)
from ansible_collections.linode.cloud.plugins.module_utils.linode_timeout import (
TimeoutContext,
)

try:
from ansible.module_utils.ansible_release import (
Expand Down Expand Up @@ -41,6 +38,7 @@
StackScript,
UnexpectedResponseError,
)
from linode_api4.polling import TimeoutContext

HAS_LINODE = True
except ImportError:
Expand Down
174 changes: 0 additions & 174 deletions plugins/module_utils/linode_event_poller.py

This file was deleted.

43 changes: 0 additions & 43 deletions plugins/module_utils/linode_timeout.py

This file was deleted.

45 changes: 19 additions & 26 deletions plugins/modules/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
global_authors,
global_requirements,
)
from ansible_collections.linode.cloud.plugins.module_utils.linode_event_poller import (
EventPoller,
wait_for_resource_free,
)
from ansible_collections.linode.cloud.plugins.module_utils.linode_helper import (
drop_empty_strings,
filter_null_values,
Expand Down Expand Up @@ -653,14 +649,14 @@ def _delete_config_register(self, config: Config) -> None:
def _create_disk_register(self, **kwargs: Any) -> None:
size = kwargs.pop("size")

create_poller = EventPoller(
self.client, "disks", "disk_create", entity_id=self._instance.id
create_poller = self.client.polling.event_poller_create(
"disks", "disk_create", entity_id=self._instance.id
)
self._instance.disk_create(size, **kwargs)

# The disk must be ready before the next disk is created
create_poller.wait_for_next_event_finished(
self._timeout_ctx.seconds_remaining
timeout=self._timeout_ctx.seconds_remaining
)

self.register_action("Created disk {0}".format(kwargs.get("label")))
Expand Down Expand Up @@ -778,14 +774,14 @@ def _update_disk(self, disk: Disk, disk_params: Dict[str, Any]) -> None:
new_size = disk_params.pop("size")

if disk.size != new_size:
resize_poller = EventPoller(
self.client, "disks", "disk_resize", entity_id=self._instance.id
resize_poller = self.client.polling.event_poller_create(
"disks", "disk_resize", entity_id=self._instance.id
)

disk.resize(new_size)

resize_poller.wait_for_next_event_finished(
self._timeout_ctx.seconds_remaining
timeout=self._timeout_ctx.seconds_remaining
)

self.register_action(
Expand Down Expand Up @@ -912,8 +908,7 @@ def _handle_instance_boot(self) -> None:
should_poll = self.module.params.get("wait")

# Wait for instance to not be busy
wait_for_resource_free(
self.client,
self.client.polling.wait_for_entity_free(
"linode",
self._instance.id,
self._timeout_ctx.seconds_remaining,
Expand All @@ -924,8 +919,7 @@ def _handle_instance_boot(self) -> None:
event_poller = None

if boot_status and self._instance.status != "running":
event_poller = EventPoller(
self.client,
event_poller = self.client.polling.event_poller_create(
"linode",
"linode_boot",
entity_id=self._instance.id,
Expand All @@ -937,8 +931,7 @@ def _handle_instance_boot(self) -> None:
)

if not boot_status and self._instance.status != "offline":
event_poller = EventPoller(
self.client,
event_poller = self.client.polling.event_poller_create(
"linode",
"linode_shutdown",
entity_id=self._instance.id,
Expand All @@ -952,7 +945,7 @@ def _handle_instance_boot(self) -> None:
if should_poll and event_poller is not None:
# Poll for the instance to be booted if necessary
event_poller.wait_for_next_event_finished(
self._timeout_ctx.seconds_remaining
timeout=self._timeout_ctx.seconds_remaining
)

def _handle_instance_reboot(self) -> None:
Expand All @@ -962,8 +955,7 @@ def _handle_instance_reboot(self) -> None:
should_poll = self.module.params.get("wait")

# Wait for instance to not be busy
wait_for_resource_free(
self.client,
self.client.polling.wait_for_entity_free(
"linode",
self._instance.id,
self._timeout_ctx.seconds_remaining,
Expand All @@ -975,8 +967,8 @@ def _handle_instance_reboot(self) -> None:
if self._instance.status != "running":
return

reboot_poller = EventPoller(
self.client, "linode", "linode_reboot", entity_id=self._instance.id
reboot_poller = self.client.polling.event_poller_create(
"linode", "linode_reboot", entity_id=self._instance.id
)

self._instance.reboot()
Expand All @@ -986,7 +978,7 @@ def _handle_instance_reboot(self) -> None:

if should_poll:
reboot_poller.wait_for_next_event_finished(
self._timeout_ctx.seconds_remaining
timeout=self._timeout_ctx.seconds_remaining
)

def _handle_present(self) -> None:
Expand All @@ -999,7 +991,9 @@ def _handle_present(self) -> None:
already_exists = self._instance is not None

if not already_exists:
create_poller = EventPoller(self.client, "linode", "linode_create")
create_poller = self.client.polling.event_poller_create(
"linode", "linode_create"
)

result = self._create_instance()

Expand All @@ -1012,7 +1006,7 @@ def _handle_present(self) -> None:

if should_wait:
create_poller.wait_for_next_event_finished(
self._timeout_ctx.seconds_remaining
timeout=self._timeout_ctx.seconds_remaining
)

if self.module.params.get("additional_ipv4") is not None:
Expand All @@ -1029,8 +1023,7 @@ def _handle_present(self) -> None:
configs = self.module.params.get("configs") or []

if len(configs) > 0 or len(disks) > 0:
wait_for_resource_free(
self.client,
self.client.polling.wait_for_entity_free(
"linode",
self._instance.id,
self._timeout_ctx.seconds_remaining,
Expand Down
Loading

0 comments on commit 75b60a5

Please sign in to comment.