Skip to content

Commit

Permalink
Merge branch 'develop' into feature/apiddubny_bug_350_vm_size_should_…
Browse files Browse the repository at this point in the history
…have_default_value
  • Loading branch information
alexazarh committed Jan 10, 2017
2 parents 632fb09 + 2081286 commit e93cf1b
Show file tree
Hide file tree
Showing 13 changed files with 305 additions and 205 deletions.
12 changes: 12 additions & 0 deletions drivers/azure_shellPackage/DataModel/datamodel.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@
<Rule Name="Setting" />
</Rules>
</AttributeInfo>
<AttributeInfo Name="Extension Script Timeout" DefaultValue="1200" Description="Extension Script Timeout in seconds" IsReadOnly="false" Type="String">
<Rules>
<Rule Name="Configuration" />
<Rule Name="Setting" />
</Rules>
</AttributeInfo>
<AttributeInfo Name="Public IP" DefaultValue="" Description="Static Public IP Type ensures that the VM always uses the same public IP. By default, Public IPs are dynamic and the address associated to them may change when the VM is deleted from Azure" IsReadOnly="false" Type="String">
<Rules>
<Rule Name="Configuration" />
Expand Down Expand Up @@ -264,6 +270,9 @@
<AttachedAttribute IsLocal="true" IsOverridable="true" Name="Extension Script Configurations" UserInput="true">
<AllowedValues />
</AttachedAttribute>
<AttachedAttribute IsLocal="true" IsOverridable="true" Name="Extension Script Timeout" UserInput="false">
<AllowedValues />
</AttachedAttribute>
<AttachedAttribute IsLocal="true" IsOverridable="true" Name="Public IP Type" UserInput="true">
<AllowedValues>
<AllowedValue>Static</AllowedValue>
Expand Down Expand Up @@ -314,6 +323,9 @@
<AttachedAttribute IsLocal="true" IsOverridable="true" Name="Extension Script Configurations" UserInput="true">
<AllowedValues />
</AttachedAttribute>
<AttachedAttribute IsLocal="true" IsOverridable="true" Name="Extension Script Timeout" UserInput="false">
<AllowedValues />
</AttachedAttribute>
<AttachedAttribute IsLocal="true" IsOverridable="true" Name="Public IP Type" UserInput="true">
<AllowedValues>
<AllowedValue>Static</AllowedValue>
Expand Down
193 changes: 98 additions & 95 deletions package/cloudshell/cp/azure/azure_shell.py

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def _set_base_deploy_azure_vm_model_params(self, deployed_resource, resource):
deployed_resource.public_ip_type = resource.attributes['Public IP Type']
deployed_resource.extension_script_file = resource.attributes['Extension Script file']
deployed_resource.extension_script_configurations = resource.attributes['Extension Script Configurations']
deployed_resource.extension_script_timeout = int(resource.attributes['Extension Script Timeout'])

app_request = jsonpickle.decode(resource.app_context.app_request_json)
attrs = app_request["logicalResource"]["attributes"]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
class AutoloadException(Exception):
pass
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class QualiTimeoutException(Exception):
pass


class QualiScriptExecutionTimeoutException(Exception):
pass
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ def _set_base_deploy_azure_vm_model_params(deployment_resource_model, data_holde
deployment_resource_model.username = data_holder.ami_params.username
deployment_resource_model.password = data_holder.ami_params.password
deployment_resource_model.extension_script_file = data_holder.ami_params.extension_script_file
deployment_resource_model.extension_script_configurations = (
data_holder.ami_params.extension_script_configurations)
deployment_resource_model.extension_script_configurations = (data_holder.ami_params.extension_script_configurations)
deployment_resource_model.extension_script_timeout= (int(data_holder.ami_params.extension_script_timeout))

if deployment_resource_model.password:
logger.info('Decrypting Azure VM password...')
Expand Down
27 changes: 26 additions & 1 deletion package/cloudshell/cp/azure/domain/services/task_waiter.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from datetime import datetime, timedelta
import time

from cloudshell.cp.azure.common.exceptions.quali_timeout_exception import QualiTimeoutException

class TaskWaiterService(object):

class TaskWaiterService(object):
def __init__(self, cancellation_service):
"""
Expand All @@ -23,3 +25,26 @@ def wait_for_task(self, operation_poller, cancellation_context, wait_time=30):
time.sleep(wait_time)

return operation_poller.result()

def wait_for_task_with_timeout(self, operation_poller, cancellation_context, wait_time=30, timeout=1800):
"""Wait for Azure operation end
:param timeout:
:param operation_poller: msrestazure.azure_operation.AzureOperationPoller instance
:param cancellation_context cloudshell.shell.core.driver_context.CancellationContext instance
:param wait_time: (int) seconds to wait before polling request
:return: Azure Operation Poller result
"""

datetime_now = datetime.now()
next_time = datetime_now + timedelta(seconds=timeout)

while not operation_poller.done() and (datetime_now < next_time):
self.cancellation_service.check_if_cancelled(cancellation_context)
time.sleep(wait_time)
datetime_now = datetime.now()

if not operation_poller.done() and (datetime_now > next_time):
raise QualiTimeoutException()

return operation_poller.result()
16 changes: 13 additions & 3 deletions package/cloudshell/cp/azure/domain/services/vm_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@


class VMExtensionService(object):
def __init__(self,url_helper):
def __init__(self, url_helper, waiter_service):
"""
:param cloudshell.cp.azure.common.helpers.url_helper.URLHelper url_helper:
:param cloudshell.cp.azure.domain.services.task_waiter.TaskWaiterService waiter_service:
:return:
"""
self.waiter_service = waiter_service
self.url_helper = url_helper

WINDOWS_PUBLISHER = "Microsoft.Compute"
Expand Down Expand Up @@ -82,9 +89,10 @@ def _prepare_windows_vm_script_extension(self, location, script_file, script_con

@retry(stop_max_attempt_number=5, wait_fixed=2000, retry_on_exception=retry_if_connection_error)
def create_script_extension(self, compute_client, location, group_name, vm_name, image_os_type, script_file,
script_configurations, tags=None):
script_configurations,timeout=1800, cancellation_context=None, tags=None):
"""Create VM Script extension on the Azure
:param CancellationContext cancellation_context:
:param compute_client: azure.mgmt.compute.compute_management_client.ComputeManagementClient instance
:param location: (str) Azure region
:param group_name: (str) the name of the resource group on Azure
Expand Down Expand Up @@ -117,4 +125,6 @@ def create_script_extension(self, compute_client, location, group_name, vm_name,
vm_extension_name=vm_name,
extension_parameters=vm_extension)

return operation_poller.result()
return self.waiter_service.wait_for_task_with_timeout(operation_poller=operation_poller,
cancellation_context=cancellation_context,
timeout=timeout)

0 comments on commit e93cf1b

Please sign in to comment.