Skip to content

Commit

Permalink
Plan: add typing
Browse files Browse the repository at this point in the history
  • Loading branch information
myakove committed Dec 16, 2024
1 parent 09a272e commit beccce1
Showing 1 changed file with 25 additions and 39 deletions.
64 changes: 25 additions & 39 deletions ocp_resources/plan.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ocp_resources.constants import TIMEOUT_4MINUTES
from typing import Any
from ocp_resources.mtv import MTV
from ocp_resources.resource import NamespacedResource

Expand Down Expand Up @@ -26,38 +26,24 @@ class Plan(NamespacedResource, MTV):

def __init__(
self,
name=None,
namespace=None,
source_provider_name=None,
source_provider_namespace=None,
destination_provider_name=None,
destination_provider_namespace=None,
storage_map_name=None,
storage_map_namespace=None,
network_map_name=None,
network_map_namespace=None,
virtual_machines_list=None,
target_namespace=None,
warm_migration=False,
pre_hook_name=None,
pre_hook_namespace=None,
after_hook_name=None,
after_hook_namespace=None,
client=None,
teardown=True,
yaml_file=None,
delete_timeout=TIMEOUT_4MINUTES,
source_provider_name: str | None = None,
source_provider_namespace: str | None = None,
destination_provider_name: str | None = None,
destination_provider_namespace: str | None = None,
storage_map_name: str | None = None,
storage_map_namespace: str | None = None,
network_map_name: str | None = None,
network_map_namespace: str | None = None,
virtual_machines_list: list[Any] | None = None,
target_namespace: str | None = None,
warm_migration: bool = False,
pre_hook_name: str | None = None,
pre_hook_namespace: str | None = None,
after_hook_name: str | None = None,
after_hook_namespace: str | None = None,
**kwargs,
):
super().__init__(
name=name,
namespace=namespace,
client=client,
teardown=teardown,
yaml_file=yaml_file,
delete_timeout=delete_timeout,
**kwargs,
)
) -> None:
super().__init__(**kwargs)
self.source_provider_name = source_provider_name
self.source_provider_namespace = source_provider_namespace
self.destination_provider_name = destination_provider_name
Expand All @@ -75,9 +61,10 @@ def __init__(
self.target_namespace = target_namespace or self.namespace
self.condition_message_ready = self.ConditionMessage.PLAN_READY
self.condition_message_succeeded = self.ConditionMessage.PLAN_SUCCEEDED
self.hooks_array = []

def generate_hook_spec(hook_name, hook_namespace, hook_type):
hook = {
def generate_hook_spec(hook_name: str, hook_namespace: str, hook_type: str) -> dict[str, Any]:
hook: dict[str, Any] = {
"hook": {
"name": hook_name,
"namespace": hook_namespace,
Expand All @@ -86,9 +73,8 @@ def generate_hook_spec(hook_name, hook_namespace, hook_type):
}
return hook

hooks_array = []
if self.pre_hook_name and self.pre_hook_namespace:
hooks_array.append(
self.hooks_array.append(
generate_hook_spec(
hook_name=self.pre_hook_name,
hook_namespace=self.pre_hook_namespace,
Expand All @@ -97,17 +83,17 @@ def generate_hook_spec(hook_name, hook_namespace, hook_type):
)

if self.after_hook_name and self.after_hook_namespace:
hooks_array.append(
self.hooks_array.append(
generate_hook_spec(
hook_name=self.after_hook_name,
hook_namespace=self.after_hook_namespace,
hook_type="AfterHook",
)
)

if hooks_array:
if self.hooks_array and self.virtual_machines_list:
for vm in self.virtual_machines_list:
vm["hooks"] = hooks_array
vm["hooks"] = self.hooks_array

def to_dict(self) -> None:
super().to_dict()
Expand Down

0 comments on commit beccce1

Please sign in to comment.