Skip to content

Commit

Permalink
Merge pull request #533 from QualiSystems/develop
Browse files Browse the repository at this point in the history
merge dev to master
  • Loading branch information
nahumtimerman committed Aug 30, 2018
2 parents 3d41d12 + fde34f8 commit 617e820
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 53 deletions.
2 changes: 1 addition & 1 deletion drivers/azure_shell/drivermetadata.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Driver Description="This driver orchestrate all the command that will be executed on Azure" MainClass="driver.AzureShellDriver" Name="Azure Shell Driver" Version="1.7.1">
<Driver Description="This driver orchestrate all the command that will be executed on Azure" MainClass="driver.AzureShellDriver" Name="Azure Shell Driver" Version="1.7.2">
<Layout>
<Category Name="Deployment">
<Command Description="" DisplayName="Deploy VM" EnableCancellation="true" Name="deploy_vm" Tags="allow_unreserved" />
Expand Down
2 changes: 1 addition & 1 deletion drivers/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.7.1
1.7.2
55 changes: 25 additions & 30 deletions package/cloudshell/cp/azure/azure_shell.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,44 @@
import jsonpickle
from threading import Lock

from cloudshell.api.cloudshell_api import CommandExecutionCancelledResultInfo
from cloudshell.cp.azure.domain.common.vm_details_provider import VmDetailsProvider
from cloudshell.cp.azure.domain.vm_management.operations.vm_details_operation import VmDetailsOperation
from cloudshell.shell.core.driver_context import ResourceCommandContext, CancellationContext
import jsonpickle
from cloudshell.core.context.error_handling_context import ErrorHandlingContext

from cloudshell.cp.azure.common.helpers.url_helper import URLHelper
from cloudshell.cp.azure.common.profiler.profiler import profileit
from cloudshell.shell.core.driver_context import ResourceCommandContext, CancellationContext
from cloudshell.shell.core.session.cloudshell_session import CloudShellSessionContext
from cloudshell.shell.core.session.logging_session import LoggingSessionContext

from cloudshell.cp.azure.common.azure_clients import AzureClientsManager
from cloudshell.cp.azure.common.deploy_data_holder import DeployDataHolder
from cloudshell.cp.azure.domain.services.cryptography_service import CryptographyService
from cloudshell.cp.azure.common.helpers.url_helper import URLHelper
from cloudshell.cp.azure.common.parsers.azure_model_parser import AzureModelsParser
from cloudshell.cp.azure.common.parsers.azure_resource_id_parser import AzureResourceIdParser
from cloudshell.cp.azure.common.parsers.command_result_parser import CommandResultsParser
from cloudshell.cp.azure.common.parsers.custom_param_extractor import VmCustomParamsExtractor
from cloudshell.cp.azure.domain.common.vm_details_provider import VmDetailsProvider
from cloudshell.cp.azure.domain.services.command_cancellation import CommandCancellationService
from cloudshell.cp.azure.domain.services.image_data import ImageDataFactory
from cloudshell.cp.azure.domain.services.ip_service import IpService
from cloudshell.cp.azure.domain.services.key_pair import KeyPairService
from cloudshell.cp.azure.domain.services.lock_service import GenericLockProvider
from cloudshell.cp.azure.domain.services.tags import TagService
from cloudshell.cp.azure.domain.vm_management.operations.access_key_operation import AccessKeyOperation
from cloudshell.cp.azure.domain.vm_management.operations.delete_operation import DeleteAzureVMOperation
from cloudshell.shell.core.session.logging_session import LoggingSessionContext
from cloudshell.cp.azure.domain.services.name_provider import NameProviderService
from cloudshell.cp.azure.domain.services.network_service import NetworkService
from cloudshell.cp.azure.common.parsers.azure_model_parser import AzureModelsParser
from cloudshell.cp.azure.common.parsers.azure_resource_id_parser import AzureResourceIdParser
from cloudshell.cp.azure.common.parsers.command_result_parser import CommandResultsParser
from cloudshell.cp.azure.domain.services.virtual_machine_service import VirtualMachineService
from cloudshell.cp.azure.domain.services.security_group import SecurityGroupService
from cloudshell.cp.azure.domain.services.storage_service import StorageService
from cloudshell.cp.azure.domain.services.subscription import SubscriptionService
from cloudshell.cp.azure.domain.services.tags import TagService
from cloudshell.cp.azure.domain.services.task_waiter import TaskWaiterService
from cloudshell.cp.azure.domain.services.virtual_machine_service import VirtualMachineService
from cloudshell.cp.azure.domain.services.vm_credentials_service import VMCredentialsService
from cloudshell.cp.azure.domain.services.key_pair import KeyPairService
from cloudshell.cp.azure.domain.services.security_group import SecurityGroupService
from cloudshell.cp.azure.domain.services.name_provider import NameProviderService
from cloudshell.cp.azure.domain.services.vm_extension import VMExtensionService
from cloudshell.cp.azure.domain.services.task_waiter import TaskWaiterService
from cloudshell.cp.azure.domain.services.command_cancellation import CommandCancellationService
from cloudshell.cp.azure.domain.services.subscription import SubscriptionService
from cloudshell.cp.azure.domain.vm_management.operations.deploy_operation import DeployAzureVMOperation
from cloudshell.cp.azure.domain.vm_management.operations.power_operation import PowerAzureVMOperation
from cloudshell.cp.azure.domain.vm_management.operations.refresh_ip_operation import RefreshIPOperation
from cloudshell.cp.azure.domain.vm_management.operations.PrepareSandboxInfraOperation import \
PrepareSandboxInfraOperation
from cloudshell.cp.azure.common.azure_clients import AzureClientsManager
from cloudshell.cp.azure.common.parsers.custom_param_extractor import VmCustomParamsExtractor
from cloudshell.cp.azure.domain.vm_management.operations.access_key_operation import AccessKeyOperation
from cloudshell.cp.azure.domain.vm_management.operations.app_ports_operation import DeployedAppPortsOperation
from cloudshell.cp.azure.domain.vm_management.operations.autoload_operation import AutoloadOperation
from cloudshell.cp.azure.domain.vm_management.operations.delete_operation import DeleteAzureVMOperation
from cloudshell.cp.azure.domain.vm_management.operations.deploy_operation import DeployAzureVMOperation
from cloudshell.cp.azure.domain.vm_management.operations.power_operation import PowerAzureVMOperation
from cloudshell.cp.azure.domain.vm_management.operations.refresh_ip_operation import RefreshIPOperation
from cloudshell.cp.azure.domain.vm_management.operations.vm_details_operation import VmDetailsOperation


class AzureShell(object):
Expand All @@ -59,7 +56,6 @@ def __init__(self):
self.key_pair_service = KeyPairService(storage_service=self.storage_service)
self.security_group_service = SecurityGroupService(self.network_service)
self.vm_custom_params_extractor = VmCustomParamsExtractor()
self.cryptography_service = CryptographyService()
self.name_provider_service = NameProviderService()
self.vm_extension_service = VMExtensionService(URLHelper(), waiter_service)
self.subscription_service = SubscriptionService()
Expand All @@ -84,7 +80,6 @@ def __init__(self):
tags_service=self.tags_service,
key_pair_service=self.key_pair_service,
security_group_service=self.security_group_service,
cryptography_service=self.cryptography_service,
name_provider_service=self.name_provider_service,
cancellation_service=self.cancellation_service,
subnet_locker=self.subnet_locker,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ def __init__(self,
tags_service,
key_pair_service,
security_group_service,
cryptography_service,
name_provider_service,
cancellation_service,
subnet_locker,
Expand All @@ -40,15 +39,13 @@ def __init__(self,
:param cloudshell.cp.azure.domain.services.tags.TagService tags_service:
:param cloudshell.cp.azure.domain.services.key_pair.KeyPairService key_pair_service:
:param cloudshell.cp.azure.domain.services.security_group.SecurityGroupService security_group_service:
:param cloudshell.cp.azure.domain.services.cryptography_service.CryptographyService cryptography_service:
:param cloudshell.cp.azure.domain.services.name_provider.NameProviderService name_provider_service:
:param cloudshell.cp.azure.domain.services.command_cancellation.CommandCancellationService cancellation_service:
:param threading.Lock subnet_locker:
:param AzureResourceIdParser resource_id_parser:
:return:
"""

self.cryptography_service = cryptography_service
self.vm_service = vm_service
self.network_service = network_service
self.storage_service = storage_service
Expand Down Expand Up @@ -87,7 +84,7 @@ def prepare_connectivity(self,
group_name = str(reservation_id)
subnet_name = group_name
tags = self.tags_service.get_tags(reservation=reservation)
network_action_result = PrepareCloudInfraResult()
create_key_action_result = CreateKeysActionResult()

# 1. Create a resource group
logger.info("Creating a resource group: {0} .".format(group_name))
Expand All @@ -101,7 +98,7 @@ def prepare_connectivity(self,
pool = ThreadPool()
storage_res = pool.apply_async(self._create_storage_and_keypairs,
(logger, storage_client, storage_account_name, group_name, cloud_provider_model,
tags, cancellation_context, network_action_result))
tags, cancellation_context, create_key_action_result))

logger.info("Retrieving MGMT vNet from resource group {} by tag {}={}".format(
cloud_provider_model.management_group_name,
Expand Down Expand Up @@ -174,14 +171,17 @@ def prepare_connectivity(self,
pool.join()
storage_res.get(timeout=900) # will wait for 15 min and raise exception if storage account creation failed

return self._prepare_results(network_action_result, actions)
return self._prepare_results(create_key_action_result, actions)

def _prepare_results(self, create_key_action_result, actions):
network_action_result = PrepareCloudInfraResult(self._get_action_id_by_type(actions, PrepareCloudInfra))

def _prepare_results(self, network_action_result, actions):
network_action_result.actionId = self._get_action_id_by_type(actions, PrepareCloudInfra)
subnet_action_results = [PrepareSubnetActionResult(action_id) for action_id in
self._get_action_ids_by_type(actions, PrepareSubnet)]
create_keys_action_result = CreateKeysActionResult(self._get_action_id_by_type(actions, CreateKeys))
return [network_action_result, create_keys_action_result] + subnet_action_results

create_key_action_result.actionId = self._get_action_id_by_type(actions, CreateKeys)

return [network_action_result, create_key_action_result] + subnet_action_results

def _get_action_id_by_type(self, actions, action_class):
return next((action.actionId for action in actions if isinstance(action, action_class)))
Expand All @@ -200,8 +200,19 @@ def _prepare_storage_account_name(self, reservation_id):
return self.name_provider_service.generate_name(name=reservation_id, postfix="cs", max_length=24).replace("-", "")

def _create_storage_and_keypairs(self, logger, storage_client, storage_account_name, group_name,
cloud_provider_model, tags, cancellation_context, action_result):
cloud_provider_model, tags, cancellation_context, create_key_action_result):
"""
:param logger:
:param storage_client:
:param storage_account_name:
:param group_name:
:param cloud_provider_model:
:param tags:
:param cancellation_context:
:param CreateKeysActionResult create_key_action_result:
:return:
"""
try:
# 2. Create a storage account
logger.info("Creating a storage account {0} .".format(storage_account_name))
Expand All @@ -222,10 +233,8 @@ def _create_storage_and_keypairs(self, logger, storage_client, storage_account_n

self.cancellation_service.check_if_cancelled(cancellation_context)

cryptography_dto = self.cryptography_service.encrypt(key_pair.private_key)
create_key_action_result.accessKey = key_pair.private_key

action_result.access_key = cryptography_dto.encrypted_input
action_result.secret_key = cryptography_dto.encrypted_asymmetric_key
except Exception as exc:
logger.error(traceback.format_exc())
raise
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from msrestazure.azure_exceptions import CloudError

from cloudshell.cp.azure.common.exceptions.virtual_network_not_found_exception import VirtualNetworkNotFoundException
from cloudshell.cp.azure.domain.services.cryptography_service import CryptographyService
from cloudshell.cp.azure.domain.services.key_pair import KeyPairService
from cloudshell.cp.azure.domain.services.security_group import SecurityGroupService
from cloudshell.cp.azure.domain.services.tags import TagService
Expand All @@ -27,7 +26,6 @@ def setUp(self):
self.key_pair_service = KeyPairService(storage_service=self.storage_service)
self.security_group_service = SecurityGroupService(self.network_service)
self.logger = MagicMock()
self.cryptography_service = CryptographyService()
self.name_provider_service = MagicMock()
self.resource_id_parser = MagicMock()

Expand All @@ -38,7 +36,6 @@ def setUp(self):
tags_service=self.tag_service,
key_pair_service=self.key_pair_service,
security_group_service=self.security_group_service,
cryptography_service=self.cryptography_service,
name_provider_service=self.name_provider_service,
subnet_locker=Lock(),
cancellation_service=self.cancellation_service,
Expand All @@ -51,7 +48,6 @@ def test_prepare_connectivity(self):
self.network_service.get_virtual_network_by_tag = MagicMock()
self.storage_service.create_storage_account = MagicMock()
self.vm_service.create_resource_group = MagicMock()
self.cryptography_service.encrypt = MagicMock()

network_action = Mock(spec=PrepareCloudInfra)
network_action.actionParams = Mock()
Expand Down Expand Up @@ -137,7 +133,6 @@ def test_prepare_connectivity_throes_exception_on_unavailable_VNETs(self):
self.network_service.create_subnet = MagicMock()
self.network_service.get_virtual_network_by_tag = Mock(return_value=None)
self.network_service.get_virtual_network_by_tag.side_effect = [None, Mock()]
self.cryptography_service.encrypt = MagicMock()

network_action = Mock(spec=PrepareCloudInfra)
network_action.actionParams = Mock()
Expand Down
2 changes: 1 addition & 1 deletion package/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.7.1
1.7.2
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.7.1
1.7.2

0 comments on commit 617e820

Please sign in to comment.