def deploy_angel(context, cloudshell_session, cloud_provider_resource,
                     deploy_app_action, connect_subnet_actions,
                     cancellation_context):

        check_cancellation_context(cancellation_context)

        # deployment_model type : HeavenlyCloudAngelDeploymentModel
        deployment_model = deploy_app_action.actionParams.deployment.customModel

        # generate unique name to avoid name collisions
        vm_unique_name = deploy_app_action.actionParams.appName + '__' + str(
            uuid.uuid4())[:6]

        input_user = deploy_app_action.actionParams.appResource.attributes[
            'User']
        encrypted_pass = deploy_app_action.actionParams.appResource.attributes[
            'Password']
        decrypted_input_password = cloudshell_session.DecryptPassword(
            encrypted_pass).Value

        deployed_app_attributes = []

        if not decrypted_input_password:
            decrypted_input_password = HeavenlyCloudService.create_new_password(
                cloud_provider_resource, input_user, decrypted_input_password)
            # optional
            # deployedAppAttributes contains the attributes on the deployed app
            # use to override attributes default values
            deployed_app_attributes.append(
                Attribute('Password', decrypted_input_password))

        # convert the ConnectSubnet actions to networking metadata for cloud provider SDK
        network_data = HeavenlyCloudService.prepare_network_for_instance(
            connect_subnet_actions)

        try:
            # using cloud provider SDK, creating the instance
            vm_instance = HeavenlyCloudService.create_angel_instance(
                input_user, decrypted_input_password, cloud_provider_resource,
                vm_unique_name, deployment_model.wing_count,
                deployment_model.flight_speed, deployment_model.cloud_size,
                deployment_model.cloud_image_id, network_data)
        except Exception as e:
            return DeployAppResult(actionId=deploy_app_action.actionId,
                                   success=False,
                                   errorMessage=e.message)

        # Creating VmDetailsData
        vm_details_data = HeavenlyCloudServiceWrapper.extract_vm_details(
            vm_instance)

        # result must include the action id it results for, so server can match result to action
        action_id = deploy_app_action.actionId

        # optional
        # deployedAppAdditionalData can contain dynamic data on the deployed app
        # similar to AWS tags
        deployed_app_additional_data_dict = {
            'Reservation Id': context.reservation.reservation_id,
            'CreatedBy': str(os.path.abspath(__file__))
        }

        deploy_result = DeployAppResult(
            actionId=action_id,
            success=True,
            vmUuid=vm_instance.id,
            vmName=vm_unique_name,
            deployedAppAddress=vm_instance.private_ip,
            deployedAppAttributes=deployed_app_attributes,
            deployedAppAdditionalData=deployed_app_additional_data_dict,
            vmDetailsData=vm_details_data)

        connect_subnet_results = []
        for connect_subnet_action in connect_subnet_actions:
            connect_subnet_results.append(
                ConnectToSubnetActionResult(
                    connect_subnet_action.actionId,
                    interface=network_data[
                        connect_subnet_action.actionParams.subnetId]))

        check_cancellation_context_and_do_rollback(cancellation_context)

        return [deploy_result] + connect_subnet_results
Пример #2
0
    def deploy_man(context, cloudshell_session, cloud_provider_resource,
                   deploy_app_action, cancellation_context):
        """
        :param ResourceCommandContext context:
        :param CloudShellAPISession cloudshell_session:
        :param L2HeavenlyCloudShell cloud_provider_resource:
        :param DeployApp deploy_app_action:
        :param CancellationContext cancellation_context:
        """

        check_cancellation_context(cancellation_context)

        # deployment_model type : HeavenlyCloudAngelDeploymentModel
        deployment_model = deploy_app_action.actionParams.deployment.customModel

        # generate unique name to avoid name collisions
        vm_unique_name = deploy_app_action.actionParams.appName + '__' + str(
            uuid.uuid4())[:6]

        input_user = deploy_app_action.actionParams.appResource.attributes[
            'User']
        encrypted_pass = deploy_app_action.actionParams.appResource.attributes[
            'Password']
        decrypted_input_password = cloudshell_session.DecryptPassword(
            encrypted_pass).Value

        deployed_app_attributes = []

        if not decrypted_input_password:
            decrypted_input_password = HeavenlyCloudService.create_new_password(
                cloud_provider_resource, input_user, decrypted_input_password)
            # optional
            # deployedAppAttributes contains the attributes on the deployed app
            # use to override attributes default values
            deployed_app_attributes.append(
                Attribute('Password', decrypted_input_password))

        try:
            # using cloud provider SDK, creating the instance
            vm_instance = HeavenlyCloudService.create_man_instance(
                input_user, decrypted_input_password, cloud_provider_resource,
                vm_unique_name, deployment_model.weight,
                deployment_model.height, deployment_model.cloud_size,
                deployment_model.cloud_image_id)
        except Exception as e:
            return DeployAppResult(actionId=deploy_app_action.actionId,
                                   success=False,
                                   errorMessage=traceback.format_exc())

        # Creating VmDetailsData
        vm_details_data = HeavenlyCloudServiceWrapper.extract_vm_details(
            vm_instance)

        # result must include the action id it results for, so server can match result to action
        action_id = deploy_app_action.actionId

        # optional
        # deployedAppAdditionalData can contain dynamic data on the deployed app
        # similar to AWS tags
        deployed_app_additional_data_dict = {
            'Reservation Id': context.reservation.reservation_id,
            'CreatedBy': str(os.path.abspath(__file__))
        }

        check_cancellation_context_and_do_rollback(cancellation_context)

        return DeployAppResult(
            actionId=action_id,
            success=True,
            vmUuid=vm_instance.id,
            vmName=vm_unique_name,
            deployedAppAddress=vm_instance.private_ip,
            deployedAppAttributes=deployed_app_attributes,
            deployedAppAdditionalData=deployed_app_additional_data_dict,
            vmDetailsData=vm_details_data)