Пример #1
0
def verify_blueprint_uploaded_state(blueprint):
    if blueprint.state in BlueprintUploadState.FAILED_STATES:
        raise manager_exceptions.InvalidBlueprintError(
            'Required blueprint `{}` has failed to upload. State: {}, '
            'Error: {}'.format(blueprint.id, blueprint.state, blueprint.error))
    if blueprint.state and blueprint.state != BlueprintUploadState.UPLOADED:
        raise manager_exceptions.InvalidBlueprintError(
            'Required blueprint `{}` is still {}.'
            .format(blueprint.id, blueprint.state))
Пример #2
0
    def _prepare_and_submit_blueprint(cls, file_server_root, app_dir,
                                      blueprint_id, visibility):
        args = get_args_and_verify_arguments([
            Argument('private_resource', type=boolean),
            Argument('visibility'),
            Argument('application_file_name', default='')
        ])

        app_file_name = cls._extract_application_file(
            file_server_root, app_dir, args.application_file_name)

        # add to blueprints manager (will also dsl_parse it)
        try:
            blueprint = get_resource_manager().publish_blueprint(
                app_dir, app_file_name, file_server_root, blueprint_id,
                args.private_resource, visibility)

            # moving the app directory in the file server to be under a
            # directory named after the blueprint id
            tenant_dir = os.path.join(file_server_root,
                                      FILE_SERVER_BLUEPRINTS_FOLDER,
                                      current_tenant.name)
            mkdirs(tenant_dir)
            shutil.move(os.path.join(file_server_root, app_dir),
                        os.path.join(tenant_dir, blueprint.id))
            cls._process_plugins(file_server_root, blueprint.id)
            return blueprint
        except manager_exceptions.DslParseException, ex:
            shutil.rmtree(os.path.join(file_server_root, app_dir))
            raise manager_exceptions.InvalidBlueprintError(
                'Invalid blueprint - {0}'.format(ex.message))
Пример #3
0
    def _prepare_and_submit_blueprint(cls, file_server_root, app_dir,
                                      blueprint_id):

        args = cls._get_args()
        app_dir, app_file_name = cls._extract_application_file(
            file_server_root, app_dir, args.application_file_name)

        # add to blueprints manager (will also dsl_parse it)
        try:
            blueprint = get_resource_manager().publish_blueprint(
                app_dir,
                app_file_name,
                file_server_root,
                blueprint_id,
                private_resource=args.private_resource)

            # moving the app directory in the file server to be under a
            # directory named after the blueprint id
            tenant_dir = os.path.join(
                file_server_root, FILE_SERVER_BLUEPRINTS_FOLDER,
                current_app.config[CURRENT_TENANT_CONFIG].name)
            mkdirs(tenant_dir)
            shutil.move(os.path.join(file_server_root, app_dir),
                        os.path.join(tenant_dir, blueprint.id))
            cls._process_plugins(file_server_root, blueprint.id)
            return blueprint
        except manager_exceptions.DslParseException, ex:
            shutil.rmtree(os.path.join(file_server_root, app_dir))
            raise manager_exceptions.InvalidBlueprintError(
                'Invalid blueprint - {0}'.format(ex.message))
Пример #4
0
    def _prepare_and_submit_blueprint(self, file_server_root, application_dir,
                                      blueprint_id):
        application_file = self._extract_application_file(
            file_server_root, application_dir)

        file_server_base_url = config.instance().file_server_base_uri
        dsl_path = '{0}/{1}'.format(file_server_base_url, application_file)
        alias_mapping = '{0}/{1}'.format(file_server_base_url,
                                         'cloudify/alias-mappings.yaml')
        resources_base = file_server_base_url + '/'

        # add to blueprints manager (will also dsl_parse it)
        try:
            blueprint = get_blueprints_manager().publish_blueprint(
                dsl_path, alias_mapping, resources_base, blueprint_id)

            # moving the app directory in the file server to be under a
            # directory named after the blueprint id
            shutil.move(
                os.path.join(file_server_root, application_dir),
                os.path.join(file_server_root,
                             config.instance().file_server_blueprints_folder,
                             blueprint.id))
            self._process_plugins(file_server_root, blueprint.id)
            return blueprint
        except DslParseException, ex:
            shutil.rmtree(os.path.join(file_server_root, application_dir))
            raise manager_exceptions.InvalidBlueprintError(
                'Invalid blueprint - {0}'.format(ex.args))
Пример #5
0
    def stage_deployment_update(self,
                                deployment_id,
                                app_dir,
                                app_blueprint,
                                additional_inputs):
        """Stage a deployment update

        :param app_blueprint:
        :param app_dir:
        :param deployment_id: the deployment id for the update
        :return:
        """

        # enables reverting to original blueprint resources
        deployment = self.sm.get(models.Deployment, deployment_id)
        blueprint_id = deployment.blueprint_id
        file_server_root = config.instance.file_server_root

        blueprint_resource_dir = os.path.join(
            file_server_root,
            'blueprints',
            current_app.config[CURRENT_TENANT_CONFIG].name,
            blueprint_id)
        # 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)
        inputs = copy.deepcopy(deployment.inputs)
        inputs.update(additional_inputs)

        # applying intrinsic functions
        try:
            prepared_plan = tasks.prepare_deployment_plan(plan,
                                                          get_secret_method(),
                                                          inputs=inputs)
        except parser_exceptions.MissingRequiredInputError, e:
            raise manager_exceptions.MissingRequiredDeploymentInputError(
                str(e))
Пример #6
0
def get_uploaded_blueprint(sm, blueprint):
    wait_for_execution(sm, blueprint.upload_execution.id)
    blueprint = sm.get(models.Blueprint, blueprint.id)
    if blueprint.state in BlueprintUploadState.FAILED_STATES:
        if blueprint.state == BlueprintUploadState.INVALID:
            state_display = 'is invalid'
        else:
            state_display = 'has {}'.format(blueprint.state.replace('_', ' '))
        raise manager_exceptions.InvalidBlueprintError(
            'Blueprint `{}` {}. Error: {}'.format(
                blueprint.id, state_display, blueprint.error))
    return blueprint, 201
Пример #7
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, e:
            raise manager_exceptions.MissingRequiredDeploymentInputError(
                str(e))
Пример #8
0
    def _prepare_and_submit_blueprint(cls, file_server_root, app_dir,
                                      blueprint_id, visibility):
        args = get_args_and_verify_arguments(
            [Argument('application_file_name', default='')])

        app_file_name = cls._extract_application_file(
            file_server_root, app_dir, args.application_file_name)

        # add to blueprints manager (will also dsl_parse it)
        try:
            get_resource_manager().validate_blueprint(app_dir, app_file_name,
                                                      file_server_root)
        except manager_exceptions.DslParseException as ex:
            raise manager_exceptions.InvalidBlueprintError(
                'Invalid blueprint - {0}'.format(ex))

        return {}
Пример #9
0
    def stage_deployment_update(self, deployment_id, app_dir, app_blueprint,
                                additional_inputs):
        """Stage a deployment update

        :param app_blueprint:
        :param app_dir:
        :param deployment_id: the deployment id for the update
        :return:
        """

        # enables reverting to original blueprint resources
        deployment = self.sm.get_deployment(deployment_id)
        blueprint_id = deployment.blueprint_id

        # enables reverting to original blueprint resources
        file_server_base_url = \
            '{0}/'.format(config.instance.file_server_base_uri)

        blueprint_resource_dir = os.path.join(file_server_base_url,
                                              'blueprints', blueprint_id)

        app_path = os.path.join(file_server_base_url, app_dir, app_blueprint)

        # parsing the blueprint from here
        try:
            plan = tasks.parse_dsl(
                app_path,
                resources_base_url=file_server_base_url,
                additional_resources=[blueprint_resource_dir],
                **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)
        inputs = copy.deepcopy(deployment.inputs)
        inputs.update(additional_inputs)

        # applying intrinsic functions
        try:
            prepared_plan = tasks.prepare_deployment_plan(plan, inputs=inputs)
        except parser_exceptions.MissingRequiredInputError, e:
            raise manager_exceptions.MissingRequiredDeploymentInputError(
                str(e))
Пример #10
0
def get_parsed_deployment(blueprint, app_dir, app_blueprint):
    file_server_root = config.instance.file_server_root
    blueprint_resource_dir = os.path.join(file_server_root, 'blueprints',
                                          blueprint.tenant_name, blueprint.id)
    # 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)

    try:
        return 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))
Пример #11
0
 def _extract_schedules_changes(self, dep_update):
     deployment = self.sm.get(models.Deployment, dep_update.deployment_id)
     old_settings = deployment.blueprint.plan.get('deployment_settings')
     new_settings = dep_update.deployment_plan.get('deployment_settings')
     schedules_to_delete = []
     schedules_to_create = {}
     if old_settings:
         for schedule_id in old_settings.get('default_schedules', {}):
             try:
                 schedule = self.sm.get(
                     models.ExecutionSchedule,
                     None,
                     filters={'id': schedule_id,
                              'deployment_id': deployment.id})
                 if schedule.deployment_id == deployment.id:
                     schedules_to_delete.append(schedule_id)
             except manager_exceptions.NotFoundError:
                 continue
     if new_settings:
         name_conflict_error_msg = \
             'The Blueprint used for the deployment update contains a ' \
             'default schedule `{0}`, but a deployment schedule `{0}` ' \
             'already exists for the deployment `{1}` . Please either ' \
             'delete the existing schedule or fix the blueprint.'
         schedules_to_create = new_settings.get('default_schedules', {})
         for schedule_id in schedules_to_create:
             try:
                 self.sm.get(models.ExecutionSchedule,
                             None,
                             filters={'id': schedule_id,
                                      'deployment_id': deployment.id})
                 if schedule_id not in schedules_to_delete:
                     raise manager_exceptions.InvalidBlueprintError(
                         name_conflict_error_msg.format(schedule_id,
                                                        deployment.id))
             except manager_exceptions.NotFoundError:
                 continue
     return schedules_to_create, schedules_to_delete