Skip to content

Commit

Permalink
Retries during deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
alexquali committed Oct 16, 2024
1 parent 802b680 commit effdd5b
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions cloudshell/cp/proxmox/flows/deploy_flow/commands/clone_vm.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
from __future__ import annotations

from contextlib import suppress

import time

from cloudshell.cp.core.cancellation_manager import CancellationContextManager
from cloudshell.cp.core.rollback import RollbackCommand, RollbackCommandsManager

from cloudshell.cp.proxmox.exceptions import UnsuccessfulOperationException
from cloudshell.cp.proxmox.handlers.proxmox_handler import ProxmoxHandler
from cloudshell.shell.core.driver_utils import GlobalLock

Expand Down Expand Up @@ -35,11 +39,21 @@ def __init__(

def _execute(self) -> int:
src_node = self._api.get_node_by_vmid(self._src_instance_id)
new_vm_id, up_id = self._execute_deploy(src_node)
self._api.wait_for_deploy_to_complete(
instance_node=src_node, upid=up_id, instance_name=self._instance_name
)
return new_vm_id

retry = 0
while retry <= 5:
with suppress(UnsuccessfulOperationException):
new_vm_id, up_id = self._execute_deploy(src_node)
self._api.wait_for_deploy_to_complete(
instance_node=src_node,
upid=up_id,
instance_name=self._instance_name
)
retry += 1

return new_vm_id

raise UnsuccessfulOperationException(f"Failed to deploy {self._instance_name}")

@GlobalLock.lock
def _execute_deploy(self, node) -> int:
Expand All @@ -52,7 +66,6 @@ def _execute_deploy(self, node) -> int:
target_storage=self._target_storage,
target_node=self._target_node,
)
time.sleep(2)

def rollback(self):
if self._cloned_vm_id:
Expand Down

0 comments on commit effdd5b

Please sign in to comment.