Skip to content

Commit 3962093

Browse files
committed
fixed clone part
1 parent effdd5b commit 3962093

File tree

4 files changed

+24
-11
lines changed

4 files changed

+24
-11
lines changed

cloudshell/cp/proxmox/flows/deploy_flow/base_flow.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ def _deploy(self, request_actions: DeployVMRequestActions) -> DeployAppResult:
175175
deploy_app=deploy_app,
176176
instance_name=instance_name,
177177
)
178-
self.proxmox_api.get_node_by_vmid(deployed_vm_id)
179178
if deploy_app.auto_power_on:
180179
self.proxmox_api.start_instance(
181180
deployed_vm_id,

cloudshell/cp/proxmox/flows/deploy_flow/commands/clone_vm.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import annotations
22

3-
from contextlib import suppress
4-
3+
import logging
54
import time
65

76
from cloudshell.cp.core.cancellation_manager import CancellationContextManager
@@ -11,6 +10,8 @@
1110
from cloudshell.cp.proxmox.handlers.proxmox_handler import ProxmoxHandler
1211
from cloudshell.shell.core.driver_utils import GlobalLock
1312

13+
logger = logging.getLogger(__name__)
14+
1415

1516
class CloneVMCommand(RollbackCommand, GlobalLock):
1617
def __init__(
@@ -42,22 +43,26 @@ def _execute(self) -> int:
4243

4344
retry = 0
4445
while retry <= 5:
45-
with suppress(UnsuccessfulOperationException):
46+
# with suppress(UnsuccessfulOperationException):
47+
try:
4648
new_vm_id, up_id = self._execute_deploy(src_node)
4749
self._api.wait_for_deploy_to_complete(
4850
instance_node=src_node,
4951
upid=up_id,
5052
instance_name=self._instance_name
5153
)
54+
self._api.get_node_by_vmid(new_vm_id)
55+
return new_vm_id
56+
except UnsuccessfulOperationException as e:
57+
logger.warning(f"Deploy request for {self._instance_name} failed with:"
58+
f" {e}\n Retrying...", exc_info=True)
5259
retry += 1
5360

54-
return new_vm_id
55-
5661
raise UnsuccessfulOperationException(f"Failed to deploy {self._instance_name}")
5762

5863
@GlobalLock.lock
59-
def _execute_deploy(self, node) -> int:
60-
return self._api.clone_instance(
64+
def _execute_deploy(self, node) -> tuple[str, str]:
65+
result = self._api.clone_instance(
6166
instance_id=self._src_instance_id,
6267
instance_name=self._instance_name,
6368
instance_node=node,
@@ -66,6 +71,8 @@ def _execute_deploy(self, node) -> int:
6671
target_storage=self._target_storage,
6772
target_node=self._target_node,
6873
)
74+
time.sleep(5)
75+
return result
6976

7077
def rollback(self):
7178
if self._cloned_vm_id:

cloudshell/cp/proxmox/handlers/proxmox_handler.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,13 @@ def start_instance(
108108
skip_check
109109
or not self.get_instance_status(instance_id, node) == PowerState.RUNNING
110110
):
111-
self._obj.start_instance(node=node, instance_id=instance_id)
111+
upid = self._obj.start_instance(node=node, instance_id=instance_id)
112+
113+
self._task_waiter(
114+
node=node,
115+
upid=upid,
116+
msg=f"Failed to start instance {instance_id} during {{attempt*timeout}} sec",
117+
)
112118

113119
def stop_instance(
114120
self,

cloudshell/cp/proxmox/handlers/rest_api_handler.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,13 +478,14 @@ def get_instance_ifaces(self, node: str, instance_id: int) -> requests.Response:
478478
cookies={COOKIES: self.ticket},
479479
)
480480

481-
def start_instance(self, node: str, instance_id: int) -> None:
481+
@Decorators.get_data()
482+
def start_instance(self, node: str, instance_id: int) -> requests.Response:
482483
"""Start Virtual Machine."""
483484
error_map = {
484485
400: ParamsException,
485486
401: AuthAPIException,
486487
}
487-
self._do_post(
488+
return self._do_post(
488489
path=f"nodes/{node}/{self.instance_type.value}/{instance_id}/status/start",
489490
http_error_map=error_map,
490491
json={"node": node, "vmid": instance_id},

0 commit comments

Comments
 (0)