Example #1
0
def get_deployment_plan(parsed_deployment,
                        inputs,
                        runtime_only_evaluation=False):
    try:
        return tasks.prepare_deployment_plan(
            parsed_deployment, get_secret_method, inputs=inputs,
            runtime_only_evaluation=runtime_only_evaluation)
    except parser_exceptions.MissingRequiredInputError as e:
        raise manager_exceptions.MissingRequiredDeploymentInputError(
            str(e))
    except parser_exceptions.UnknownInputError as e:
        raise manager_exceptions.UnknownDeploymentInputError(str(e))
    except parser_exceptions.UnknownSecretError as e:
        raise manager_exceptions.UnknownDeploymentSecretError(str(e))
    except parser_exceptions.UnsupportedGetSecretError as e:
        raise manager_exceptions.UnsupportedDeploymentGetSecretError(
            str(e))
Example #2
0
    def stage_deployment_update(self,
                                deployment_id,
                                app_dir,
                                app_blueprint,
                                additional_inputs,
                                new_blueprint_id=None,
                                preview=False,
                                runtime_only_evaluation=False):
        # enables reverting to original blueprint resources
        deployment = self.sm.get(models.Deployment, deployment_id)
        old_blueprint = deployment.blueprint
        file_server_root = config.instance.file_server_root
        blueprint_resource_dir = os.path.join(file_server_root, 'blueprints',
                                              old_blueprint.tenant_name,
                                              old_blueprint.id)
        runtime_only_evaluation = runtime_only_evaluation or \
            deployment.runtime_only_evaluation
        # The dsl parser expects a URL
        blueprint_resource_dir_url = 'file:{0}'.format(blueprint_resource_dir)
        app_path = os.path.join(file_server_root, app_dir, app_blueprint)

        # parsing the blueprint from here
        try:
            plan = tasks.parse_dsl(
                app_path,
                resources_base_path=file_server_root,
                additional_resources=[blueprint_resource_dir_url],
                **app_context.get_parser_context())
        except parser_exceptions.DSLParsingException as ex:
            raise manager_exceptions.InvalidBlueprintError(
                'Invalid blueprint - {0}'.format(ex))

        # Updating the new inputs with the deployment inputs
        # (overriding old values and adding new ones)
        old_inputs = copy.deepcopy(deployment.inputs)
        new_inputs = {
            k: old_inputs[k]
            for k in plan.inputs.keys() if k in old_inputs
        }
        new_inputs.update(additional_inputs)

        # applying intrinsic functions
        try:
            prepared_plan = tasks.prepare_deployment_plan(
                plan,
                get_secret_method,
                inputs=new_inputs,
                runtime_only_evaluation=runtime_only_evaluation)
        except parser_exceptions.MissingRequiredInputError as e:
            raise manager_exceptions.MissingRequiredDeploymentInputError(
                str(e))
        except parser_exceptions.UnknownInputError as e:
            raise manager_exceptions.UnknownDeploymentInputError(str(e))
        except parser_exceptions.UnknownSecretError as e:
            raise manager_exceptions.UnknownDeploymentSecretError(str(e))
        except parser_exceptions.UnsupportedGetSecretError as e:
            raise manager_exceptions.UnsupportedDeploymentGetSecretError(
                str(e))

        deployment_update_id = '{0}-{1}'.format(deployment.id, uuid.uuid4())
        deployment_update = models.DeploymentUpdate(
            id=deployment_update_id,
            deployment_plan=prepared_plan,
            runtime_only_evaluation=runtime_only_evaluation,
            created_at=utils.get_formatted_timestamp())
        deployment_update.set_deployment(deployment)
        deployment_update.preview = preview
        deployment_update.old_inputs = old_inputs
        deployment_update.new_inputs = new_inputs
        if new_blueprint_id:
            new_blueprint = self.sm.get(models.Blueprint, new_blueprint_id)
            deployment_update.old_blueprint = old_blueprint
            deployment_update.new_blueprint = new_blueprint
        self.sm.put(deployment_update)
        return deployment_update
Example #3
0
        # applying intrinsic functions
        try:
            prepared_plan = tasks.prepare_deployment_plan(
                plan,
                get_secret_method,
                inputs=new_inputs,
                runtime_only_evaluation=runtime_only_evaluation)
        except parser_exceptions.MissingRequiredInputError, e:
            raise manager_exceptions.MissingRequiredDeploymentInputError(
                str(e))
        except parser_exceptions.UnknownInputError, e:
            raise manager_exceptions.UnknownDeploymentInputError(str(e))
        except parser_exceptions.UnknownSecretError, e:
            raise manager_exceptions.UnknownDeploymentSecretError(str(e))
        except parser_exceptions.UnsupportedGetSecretError, e:
            raise manager_exceptions.UnsupportedDeploymentGetSecretError(
                str(e))

        deployment_update_id = '{0}-{1}'.format(deployment.id, uuid.uuid4())
        deployment_update = models.DeploymentUpdate(
            id=deployment_update_id,
            deployment_plan=prepared_plan,
            runtime_only_evaluation=runtime_only_evaluation,
            created_at=utils.get_formatted_timestamp())
        deployment_update.set_deployment(deployment)
        deployment_update.preview = preview
        deployment_update.old_inputs = old_inputs
        deployment_update.new_inputs = new_inputs
        if new_blueprint_id:
            new_blueprint = self.sm.get(models.Blueprint, new_blueprint_id)
            deployment_update.old_blueprint = old_blueprint
            deployment_update.new_blueprint = new_blueprint