Skip to content

Commit

Permalink
copy source UUID attribute flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Costya-Y committed Apr 28, 2024
1 parent dc6490c commit 7f2996d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
37 changes: 27 additions & 10 deletions cloudshell/cp/vcenter/flows/save_restore_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from attrs import define

from cloudshell.api.cloudshell_api import CloudShellAPISession
from cloudshell.api.common_cloudshell_api import CloudShellAPIError

from cloudshell.cp.core.cancellation_manager import CancellationContextManager
from cloudshell.cp.core.request_actions import DriverResponse
from cloudshell.cp.core.request_actions.models import (
Expand Down Expand Up @@ -118,7 +120,7 @@ def _validate_app_attrs(self, attrs: dict[str, str]):
if not attrs.get(VMFromVMDeployApp.ATTR_NAMES.vm_storage):
raise SaveRestoreAttributeMissed(VMFromVMDeployApp.ATTR_NAMES.vm_storage)
if not attrs.get(
VMFromVMDeployApp.ATTR_NAMES.vm_resource_pool
VMFromVMDeployApp.ATTR_NAMES.vm_resource_pool
) or not attrs.get(VMFromVMDeployApp.ATTR_NAMES.vm_cluster):
raise SaveRestoreAttributeMissed(VMFromVMDeployApp.ATTR_NAMES.vm_cluster)
if not attrs.get(VMFromVMDeployApp.ATTR_NAMES.vm_location):
Expand Down Expand Up @@ -159,13 +161,28 @@ def _save_app(self, save_action: SaveApp) -> SaveAppResult:
)

with self._behavior_during_save(vm, app_attrs):
attr_names = VCenterVMFromCloneDeployAppAttributeNames
new_vm_name = f"Clone of {vm.name[0:32]}"
config_spec = ConfigSpecHandler(None, None, [], None)
copy_source_uuid = app_attrs.get(
VMFromVMDeployApp.ATTR_NAMES.copy_source_uuid, False
attr_names.copy_source_uuid, False
)
try:
copy_source_uuid_attr = self._cs_api.GetAttributeValue(
save_action.actionParams.sourceAppName, attr_names.copy_source_uuid
)
if copy_source_uuid_attr:
copy_source_uuid = copy_source_uuid_attr.Value.lower() == "true"
except CloudShellAPIError:
pass
if copy_source_uuid:
config_spec.bios_uuid = vm.bios_uuid
for save_attribute in save_action.actionParams.deploymentPathAttributes:
if save_attribute.attributeName.endswith(
f".{attr_names.copy_source_uuid}"
):
save_attribute.attributeValue = "True"

cloned_vm = self._clone_vm(
vm,
new_vm_name,
Expand Down Expand Up @@ -200,7 +217,7 @@ def _prepare_result(cloned_vm: VmHandler, save_action: SaveApp) -> SaveAppResult
(
x.attributeValue
for x in save_action.actionParams.deploymentPathAttributes
if x.attributeName == attr_names.copy_source_uuid
if x.attributeName.endswith(f".{attr_names.copy_source_uuid}")
),
"False",
)
Expand All @@ -221,13 +238,13 @@ def _prepare_result(cloned_vm: VmHandler, save_action: SaveApp) -> SaveAppResult
)

def _clone_vm(
self,
vm_template: VmHandler,
vm_name: str,
vm_resource_pool: ResourcePoolHandler,
vm_storage: DatastoreHandler,
vm_folder: FolderHandler,
config_spec: ConfigSpecHandler | None = None,
self,
vm_template: VmHandler,
vm_name: str,
vm_resource_pool: ResourcePoolHandler,
vm_storage: DatastoreHandler,
vm_folder: FolderHandler,
config_spec: ConfigSpecHandler | None = None,
) -> VmHandler:

return CloneVMCommand(
Expand Down
8 changes: 4 additions & 4 deletions cloudshell/cp/vcenter/handlers/vm_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@
from cloudshell.cp.vcenter.handlers.cluster_handler import HostHandler


def _rerun_clone_vm(e: Exception) -> bool:
return isinstance(e, TaskFailed) and "cannot create dvport " in str(e)


class VmNotFound(BaseVCenterException):
def __init__(
self,
Expand Down Expand Up @@ -445,10 +449,6 @@ def clone_vm(
raise
return new_vm

@staticmethod
def _rerun_clone_vm(e: Exception) -> bool:
return isinstance(e, TaskFailed) and "cannot create dvport " in str(e)

@retrying.retry(
stop_max_attempt_number=3,
wait_fixed=1000,
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.0.0
7.0.1

0 comments on commit 7f2996d

Please sign in to comment.