Skip to content

Commit

Permalink
Merge branch 'develop' into noamw_169417_static_vm_details
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomer Admon authored Jan 23, 2019
2 parents 98c04de + e2bb5b0 commit 9543e08
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package/cloudshell/cp/vcenter/commands/save_sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def _execute_save_actions_using_pool(self, artifactSaversToActions, cancellation
results = self._rollback(destroy_params, logger, results, results_before_deploy, thread_id)

elif operation_error:
logger.error('[{0}] Save Sandbox operation failed, rolling backed saved apps'.format(thread_id))
logger.error('[{0}] Save Sandbox operation failed, rolling backed saved apps. See logs for more information'.format(thread_id))
results = self._rollback(destroy_params, logger, results, results_before_deploy, thread_id)

return results
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,11 @@ def _validate_vm_storage(self, si, all_items_in_vc, auto_att, dc_name, attribute

def _validate_saved_sandbox_storage(self, si, all_items_in_vc, auto_att, dc_name, attributes, key):
accepted_types = (vim.Datastore, vim.StoragePod)

# saved sandbox storage isnt mandatory so if not configured exit without validation
if key not in attributes or not attributes[key]:
return

datastore = self._validate_attribute(si, attributes, accepted_types, key, dc_name)
if not datastore:
datastore = self._get_default(all_items_in_vc, accepted_types, key)
Expand Down
27 changes: 25 additions & 2 deletions package/cloudshell/cp/vcenter/common/wrappers/command_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@

from retrying import retry

from pyVmomi import vim
from cloudshell.cp.vcenter.common.model_factory import ResourceModelParser
from cloudshell.cp.vcenter.common.vcenter.vmomi_service import pyVmomiService, VCenterAuthError
from cloudshell.shell.core.session.cloudshell_session import CloudShellSessionContext
from cloudshell.cp.vcenter.common.cloud_shell.conn_details_retriever import ResourceConnectionDetailsRetriever


DISCONNCTING_VCENERT = 'disconnecting from vcenter: {0}'
COMMAND_ERROR = 'error has occurred while executing command: {0}'
DEBUG_COMMAND_RESULT = 'finished executing with the result: {0}'
Expand Down Expand Up @@ -134,9 +136,9 @@ def execute_command_with_connection(self, context, command, *args):

def get_py_service_connection(self, req_connection_details, logger):
logger.info("get_py_service_connection")
if self.si is None or self.has_connection_details_changed(req_connection_details):
if self.need_a_new_service_connection(req_connection_details, logger):
with self.lock:
if self.si is None or self.has_connection_details_changed(req_connection_details):
if self.need_a_new_service_connection(req_connection_details, logger):
logger.info("Creating a new connection.")
self.si = self.pv_service.connect(req_connection_details.host,
req_connection_details.username,
Expand All @@ -145,6 +147,27 @@ def get_py_service_connection(self, req_connection_details, logger):
self.connection_details = req_connection_details
return self.si

def need_a_new_service_connection(self, req_connection_details, logger):
# the idea is if we haven't instantiated the ServiceInstance session,
# or if the connect details were changed
# or if an SI no longer is authorized to work with host due to timing out,
# we try to get a new connection
return (

self.si is None or
self.has_connection_details_changed(req_connection_details) or
self.service_instance_disconnected_by_server(logger)

)

def service_instance_disconnected_by_server(self, logger):
try:
self.si.CurrentTime()
except vim.fault.NotAuthenticated:
logger.info("ServiceInstance was disconnected. Will try to retrieve a new serviceinstance")
return True
return False

def has_connection_details_changed(self, req_connection_details):
"""
:param cloudshell.cp.vcenter.models.VCenterConnectionDetails.VCenterConnectionDetails req_connection_details:
Expand Down
14 changes: 10 additions & 4 deletions package/cloudshell/cp/vcenter/vm/deploy.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import traceback

from cloudshell.cp.core.models import DeployAppResult
from cloudshell.cp.core.utils import convert_to_bool

from cloudshell.cp.vcenter.models.VCenterDeployVMFromLinkedCloneResourceModel import \
VCenterDeployVMFromLinkedCloneResourceModel
from cloudshell.cp.vcenter.models.vCenterCloneVMFromVMResourceModel import vCenterCloneVMFromVMResourceModel
Expand Down Expand Up @@ -126,7 +128,7 @@ def _deploy_a_clone(self, si, logger, app_name, template_name, other_params, vce
datastore_name=other_params.vm_storage,
cluster_name=other_params.vm_cluster,
resource_pool=other_params.vm_resource_pool,
power_on=other_params.auto_power_on,
power_on=False,
snapshot=snapshot)

if cancellation_context.is_cancelled:
Expand All @@ -149,7 +151,9 @@ def _deploy_a_clone(self, si, logger, app_name, template_name, other_params, vce
vmUuid=clone_vm_result.vm.summary.config.uuid,
vmDetailsData=vm_details_data,
deployedAppAdditionalData={'ip_regex': other_params.ip_regex,
'refresh_ip_timeout': other_params.refresh_ip_timeout})
'refresh_ip_timeout': other_params.refresh_ip_timeout,
'auto_power_off': convert_to_bool(other_params.auto_power_off),
'auto_delete': convert_to_bool(other_params.auto_delete)})

def deploy_from_image(self, si, logger, session, vcenter_data_model, data_holder, resource_context, reservation_id,
cancellation_context):
Expand Down Expand Up @@ -182,7 +186,9 @@ def deploy_from_image(self, si, logger, session, vcenter_data_model, data_holder
logger)

additional_data = {'ip_regex': data_holder.image_params.ip_regex,
'refresh_ip_timeout': data_holder.image_params.refresh_ip_timeout}
'refresh_ip_timeout': data_holder.image_params.refresh_ip_timeout,
'auto_power_off': convert_to_bool(data_holder.image_params.auto_power_off),
'auto_delete': convert_to_bool(data_holder.image_params.auto_delete)}

return DeployAppResult(vmName=vm_name,
vmUuid=vm.config.uuid,
Expand Down Expand Up @@ -223,7 +229,7 @@ def _get_deploy_image_params(data_holder, host_info, vm_name):
image_params.datastore = data_holder.vm_storage
image_params.datacenter = data_holder.default_datacenter
image_params.image_url = data_holder.vcenter_image
image_params.power_on = data_holder.auto_power_on
image_params.power_on = False
image_params.vcenter_name = data_holder.vcenter_name
return image_params

Expand Down
5 changes: 1 addition & 4 deletions package/cloudshell/tests/test_vm/test_deployer.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,8 @@ def test_vm_deployer_image(self):
"vcenter_image_arguments": "--compress=9,--schemaValidate,--etc",
'ip_regex': '',
'refresh_ip_timeout': '10',
'auto_power_on': 'True',
'auto_power_off': 'True',
'wait_for_ip': 'True',
'auto_delete': 'True',
'autoload': 'True'
'auto_delete': 'True'
}
})

Expand Down
3 changes: 1 addition & 2 deletions vCenterShellPackage/DataModel/datamodel.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@
<ns0:Rule Name="Setting" />
</ns0:Rules>
</ns0:AttributeInfo>
<ns0:AttributeInfo DefaultValue="" Name="Behavior during save" Description="Determines the VM behavior when the sandbox is saved. If Power off is selected, and the VM was powered on before the save, then the VM will shut down for the duration of the save, and then be powered on at the end.
Restricted Values: Remain Powered On (Default), Power Off" IsReadOnly="false" Type="String">
<ns0:AttributeInfo DefaultValue="" Name="Behavior during save" Description="Determines the VM behavior when the sandbox is saved. If Power off is selected, and the VM was powered on before the save, then the VM will shut down for the duration of the save, and then be powered on at the end." IsReadOnly="false" Type="String">
<ns0:Rules>
<ns0:Rule Name="Configuration" />
<ns0:Rule Name="Setting" />
Expand Down

0 comments on commit 9543e08

Please sign in to comment.