예제 #1
0
    def post(self, id, phase):
        """
        Provides support for two phases of deployment update. The phase is
        chosen according to the phase arg, and the id is used by this step.

        In the first phase the deployment update is
        1. Staged (from a new blueprint)
        2. The steps are extracted and saved onto the data model.
        3. The data storage is manipulated according to the
        addition/modification steps.
        4. The update workflow is run, executing any lifecycles of add/removed
        nodes or relationships.

        The second step finalizes the commit by manipulating the data model
        according to any removal steps.

        In order
        :param id: for the initiate step it's the deployment_id, and for the
        finalize step it's the update_id
        :param phase: initiate or finalize
        :return: update response
        """
        if phase == PHASES.INITIAL:
            return self._commit(id)
        elif phase == PHASES.FINAL:
            return get_deployment_updates_manager().finalize_commit(id)
 def _get_params_and_validate(deployment_id,
                              request_json,
                              preserve_old_behavior=False):
     skip_install = verify_and_convert_bool(
         'skip_install', request_json.get('skip_install', 'false'))
     skip_uninstall = verify_and_convert_bool(
         'skip_uninstall', request_json.get('skip_uninstall', 'false'))
     skip_reinstall = verify_and_convert_bool(
         'skip_reinstall', request_json.get('skip_reinstall',
                                            preserve_old_behavior))
     force = verify_and_convert_bool(
         'force', request_json.get('force', 'false'))
     ignore_failure = verify_and_convert_bool(
         'ignore_failure', request_json.get('ignore_failure', 'false'))
     install_first = verify_and_convert_bool(
         'install_first', request_json.get('install_first',
                                           preserve_old_behavior))
     preview = not preserve_old_behavior and verify_and_convert_bool(
         'preview', request_json.get('preview', 'false'))
     workflow_id = request_json.get('workflow_id', None)
     manager = get_deployment_updates_manager(preview)
     manager.validate_no_active_updates_per_deployment(deployment_id,
                                                       force=force)
     return (manager,
             skip_install,
             skip_uninstall,
             skip_reinstall,
             workflow_id,
             ignore_failure,
             install_first,
             preview)
    def post(self, id, phase):
        """
        Provides support for two phases of deployment update. The phase is
        chosen according to the phase arg, and the id is used by this step.

        In the first phase the deployment update is
        1. Staged (from a new blueprint)
        2. The steps are extracted and saved onto the data model.
        3. The data storage is manipulated according to the
        addition/modification steps.
        4. The update workflow is run, executing any lifecycles of add/removed
        nodes or relationships.

        The second step finalizes the commit by manipulating the data model
        according to any removal steps.

        In order
        :param id: for the initiate step it's the deployment_id, and for the
        finalize step it's the update_id
        :param phase: initiate or finalize
        :return: update response
        """
        if phase == PHASES.INITIAL:
            return self._commit(id)
        elif phase == PHASES.FINAL:
            return get_deployment_updates_manager().finalize_commit(id)
예제 #4
0
 def _get_params_and_validate(deployment_id,
                              request_json,
                              preserve_old_behavior=False):
     skip_install = verify_and_convert_bool(
         'skip_install', request_json.get('skip_install', 'false'))
     skip_uninstall = verify_and_convert_bool(
         'skip_uninstall', request_json.get('skip_uninstall', 'false'))
     skip_reinstall = verify_and_convert_bool(
         'skip_reinstall',
         request_json.get('skip_reinstall', preserve_old_behavior))
     force = verify_and_convert_bool('force',
                                     request_json.get('force', 'false'))
     ignore_failure = verify_and_convert_bool(
         'ignore_failure', request_json.get('ignore_failure', 'false'))
     install_first = verify_and_convert_bool(
         'install_first',
         request_json.get('install_first', preserve_old_behavior))
     preview = not preserve_old_behavior and verify_and_convert_bool(
         'preview', request_json.get('preview', 'false'))
     workflow_id = request_json.get('workflow_id', None)
     manager = get_deployment_updates_manager(preview)
     manager.validate_no_active_updates_per_deployment(deployment_id,
                                                       force=force)
     return (manager, skip_install, skip_uninstall, skip_reinstall,
             workflow_id, ignore_failure, install_first, preview)
예제 #5
0
    def _get_params_and_validate(deployment_id, request_json):
        manager = get_deployment_updates_manager()
        skip_install = verify_and_convert_bool(
            'skip_install',
            request_json.get('skip_install', 'false'))
        skip_uninstall = verify_and_convert_bool(
            'skip_uninstall',
            request_json.get('skip_uninstall', 'false'))
        force = verify_and_convert_bool(
            'force',
            request_json.get('force', 'false'))
        workflow_id = request_json.get('workflow_id', None)

        if (skip_install or skip_uninstall) and workflow_id:
            raise manager_exceptions.BadParametersError(
                'skip_install has been set to {0}, skip uninstall has been'
                ' set to {1}, and a custom workflow {2} has been set to '
                'replace "update". However, skip_install and '
                'skip_uninstall are mutually exclusive with a custom '
                'workflow'.format(skip_install,
                                  skip_uninstall,
                                  workflow_id))
        manager.validate_no_active_updates_per_deployment(
            deployment_id=deployment_id, force=force)
        return manager, skip_install, skip_uninstall, workflow_id
예제 #6
0
    def _commit(deployment_id):
        manager = get_deployment_updates_manager()
        request_json = request.args
        skip_install = verify_and_convert_bool(
            'skip_install', request_json.get('skip_install', 'false'))
        skip_uninstall = verify_and_convert_bool(
            'skip_uninstall', request_json.get('skip_uninstall', 'false'))
        force = verify_and_convert_bool('force',
                                        request_json.get('force', 'false'))
        workflow_id = request_json.get('workflow_id', None)

        if (skip_install or skip_uninstall) and workflow_id:
            raise manager_exceptions.BadParametersError(
                'skip_install has been set to {0}, skip uninstall has been'
                ' set to {1}, and a custom workflow {2} has been set to '
                'replace "update". However, skip_install and '
                'skip_uninstall are mutually exclusive with a custom '
                'workflow'.format(skip_install, skip_uninstall, workflow_id))

        manager.validate_no_active_updates_per_deployment(
            deployment_id=deployment_id, force=force)

        deployment_update, _ = \
            UploadedBlueprintsDeploymentUpdateManager(). \
            receive_uploaded_data(deployment_id)

        manager.extract_steps_from_deployment_update(deployment_update)

        return manager.commit_deployment_update(deployment_update,
                                                skip_install=skip_install,
                                                skip_uninstall=skip_uninstall,
                                                workflow_id=workflow_id)
 def _parse_args(deployment_id, request_json, using_post_request=False):
     skip_install = verify_and_convert_bool(
         'skip_install', request_json.get('skip_install', 'false'))
     skip_uninstall = verify_and_convert_bool(
         'skip_uninstall', request_json.get('skip_uninstall', 'false'))
     skip_reinstall = verify_and_convert_bool(
         'skip_reinstall',
         request_json.get('skip_reinstall', using_post_request))
     force = verify_and_convert_bool('force',
                                     request_json.get('force', 'false'))
     ignore_failure = verify_and_convert_bool(
         'ignore_failure', request_json.get('ignore_failure', 'false'))
     install_first = verify_and_convert_bool(
         'install_first',
         request_json.get('install_first', using_post_request))
     preview = not using_post_request and verify_and_convert_bool(
         'preview', request_json.get('preview', 'false'))
     workflow_id = request_json.get('workflow_id', None)
     update_plugins = verify_and_convert_bool(
         'update_plugins', request_json.get('update_plugins', 'true'))
     runtime_only_evaluation = verify_and_convert_bool(
         'runtime_only_evaluation',
         request_json.get('runtime_only_evaluation', 'false'))
     manager = get_deployment_updates_manager(preview)
     manager.validate_no_active_updates_per_deployment(deployment_id,
                                                       force=force)
     return (manager, skip_install, skip_uninstall, skip_reinstall,
             workflow_id, ignore_failure, install_first, preview,
             update_plugins, runtime_only_evaluation)
예제 #8
0
 def get(self, _include=None, filters=None, pagination=None,
         sort=None, **kwargs):
     """
     List deployment modification stages
     """
     deployment_updates = \
         get_deployment_updates_manager().list_deployment_updates(
                 include=_include, filters=filters, pagination=pagination,
                 sort=sort, **kwargs)
     return deployment_updates
 def get(self, _include=None, filters=None, pagination=None,
         sort=None, **kwargs):
     """
     List deployment modification stages
     """
     deployment_updates = \
         get_deployment_updates_manager().deployment_updates_list(
                 include=None, filters=None, pagination=None,
                 sort=None, **kwargs)
     return deployment_updates
    def _prepare_and_submit_blueprint(cls,
                                      file_server_root,
                                      app_dir,
                                      deployment_id,
                                      additional_inputs=None,
                                      runtime_only_evaluation=False):

        app_file_name = cls._extract_application_file(file_server_root,
                                                      app_dir)

        # add to deployment update manager (will also dsl_parse it)
        try:
            cls._process_plugins(file_server_root, app_dir)
            update = get_deployment_updates_manager().stage_deployment_update(
                    deployment_id,
                    app_dir,
                    app_file_name,
                    additional_inputs=additional_inputs or {},
                    runtime_only_evaluation=runtime_only_evaluation
                )

            # Moving the contents of the app dir to the dest dir, while
            # overwriting any file encountered

            # create the destination root dir
            file_server_deployment_root = \
                os.path.join(file_server_root,
                             FILE_SERVER_DEPLOYMENTS_FOLDER,
                             current_tenant.name,
                             deployment_id)

            app_root_dir = os.path.join(file_server_root, app_dir)

            for root, dirs, files in os.walk(app_root_dir):
                # Creates a corresponding dir structure in the deployment dir
                dest_rel_dir = os.path.relpath(root, app_root_dir)
                dest_dir = os.path.abspath(
                        os.path.join(file_server_deployment_root,
                                     dest_rel_dir))
                mkdirs(dest_dir)

                # Calculate source dir
                source_dir = os.path.join(file_server_root, app_dir, root)

                for file_name in files:
                    source_file = os.path.join(source_dir, file_name)
                    relative_dest_path = os.path.relpath(source_file,
                                                         app_root_dir)
                    dest_file = os.path.join(file_server_deployment_root,
                                             relative_dest_path)
                    shutil.copy(source_file, dest_file)

            return update
        finally:
            shutil.rmtree(os.path.join(file_server_root, app_dir))
    def _prepare_and_submit_blueprint(cls,
                                      file_server_root,
                                      app_dir,
                                      deployment_id,
                                      additional_inputs=None):

        app_file_name = cls._extract_application_file(file_server_root,
                                                      app_dir)

        # add to deployment update manager (will also dsl_parse it)
        try:
            cls._process_plugins(file_server_root, app_dir)
            update = get_deployment_updates_manager().stage_deployment_update(
                    deployment_id,
                    app_dir,
                    app_file_name,
                    additional_inputs=additional_inputs or {}
                )

            # Moving the contents of the app dir to the dest dir, while
            # overwriting any file encountered

            # create the destination root dir
            file_server_deployment_root = \
                os.path.join(file_server_root,
                             FILE_SERVER_DEPLOYMENTS_FOLDER,
                             current_tenant.name,
                             deployment_id)

            app_root_dir = os.path.join(file_server_root, app_dir)

            for root, dirs, files in os.walk(app_root_dir):
                # Creates a corresponding dir structure in the deployment dir
                dest_rel_dir = os.path.relpath(root, app_root_dir)
                dest_dir = os.path.abspath(
                        os.path.join(file_server_deployment_root,
                                     dest_rel_dir))
                mkdirs(dest_dir)

                # Calculate source dir
                source_dir = os.path.join(file_server_root, app_dir, root)

                for file_name in files:
                    source_file = os.path.join(source_dir, file_name)
                    relative_dest_path = os.path.relpath(source_file,
                                                         app_root_dir)
                    dest_file = os.path.join(file_server_deployment_root,
                                             relative_dest_path)
                    shutil.copy(source_file, dest_file)

            return update
        finally:
            shutil.rmtree(os.path.join(file_server_root, app_dir))
    def post(self, update_id):
        verify_json_content_type()
        request_json = request.json

        manager = get_deployment_updates_manager()
        update_step = \
            manager.create_deployment_update_step(
                    update_id,
                    request_json.get('operation'),
                    request_json.get('entity_type'),
                    request_json.get('entity_id')
            )
        return update_step
 def get(self,
         _include=None,
         filters=None,
         pagination=None,
         sort=None,
         search=None,
         **kwargs):
     """List deployment updates"""
     deployment_updates = \
         get_deployment_updates_manager().list_deployment_updates(
             include=_include,
             filters=filters,
             pagination=pagination,
             sort=sort,
             substr_filters=search
         )
     return deployment_updates
 def get(self,
         _include=None,
         filters=None,
         pagination=None,
         sort=None,
         search=None,
         **kwargs):
     """List deployment updates"""
     deployment_updates = \
         get_deployment_updates_manager().list_deployment_updates(
             include=_include,
             filters=filters,
             pagination=pagination,
             sort=sort,
             substr_filters=search
         )
     return deployment_updates
    def post(self, **kwargs):
        """
        Receives an archive to stage. This archive must contain a
        main blueprint file, and specify its name in the application_file_name,
        defaults to 'blueprint.yaml'

        :param kwargs:
        :return: update response
        """
        query_params = request.args
        main_blueprint_key = 'application_file_name'
        blueprint_archive_url_key = 'blueprint_archive_url'
        deployment_id = query_params['deployment_id']

        blueprint_filename = \
            query_params.get(main_blueprint_key,
                             CONVENTION_APPLICATION_BLUEPRINT_FILE)

        temp_dir = tempfile.mkdtemp()
        try:
            archive_destination = \
                os.path.join(temp_dir, "{0}-{1}"
                             .format(deployment_id, blueprint_filename))

            # Saving the archive locally
            utils.save_request_content_to_file(request, archive_destination,
                                               blueprint_archive_url_key,
                                               'blueprint')

            # Unpacking the archive
            relative_app_dir = \
                utils.extract_blueprint_archive_to_mgr(archive_destination,
                                                       temp_dir)

            # retrieving and parsing the blueprint
            temp_app_path = os.path.join(temp_dir, relative_app_dir,
                                         blueprint_filename)
            blueprint = parse_from_path(temp_app_path)

            # create a staging object
            update = get_deployment_updates_manager(). \
                stage_deployment_update(deployment_id, blueprint)
        finally:
            shutil.rmtree(temp_dir, ignore_errors=True)
        return update, 201
 def get(self, update_id):
     """Get a deployment update by id"""
     return get_deployment_updates_manager().get_deployment_update(
         update_id)
예제 #17
0
 def get(self, update_id):
     return \
         get_deployment_updates_manager().get_deployment_update(update_id)
 def get(self, update_id):
     """Get a deployment update by id"""
     return get_deployment_updates_manager().get_deployment_update(
         update_id)
 def get(self, update_id, _include=None):
     """Get a deployment update by id"""
     return get_deployment_updates_manager().get_deployment_update(
         update_id, include=_include)
 def post(self, update_id):
     manager = get_deployment_updates_manager()
     return manager.commit_deployment_update(update_id)
 def post(self, update_id):
     manager = get_deployment_updates_manager()
     return manager.finalize_commit(update_id)