def orchestration_restore(self, context, saved_artifact_info, custom_params):
        """Restores a saved artifact previously saved by this Shell.

        :param ResourceCommandContext context: The context object
         for the command with resource and reservation info
        :param str saved_artifact_info: A JSON string representing the state
         to restore including saved artifacts and info
        :param str custom_params: Set of custom parameters for the restore operation
        """
        logger = get_logger_with_thread_id(context)
        logger.info("Orchestration restore command started")

        with ErrorHandlingContext(logger):
            resource_config = create_firewall_resource_from_context(
                self.SHELL_NAME, self.SUPPORTED_OS, context
            )
            cs_api = get_api(context)

            cli_handler = F5CliHandler(self._cli, resource_config, logger, cs_api)

            configuration_operations = F5ConfigurationRunner(
                cli_handler=cli_handler,
                logger=logger,
                resource_config=resource_config,
                api=cs_api,
            )

            configuration_operations.orchestration_restore(
                saved_artifact_info=saved_artifact_info, custom_params=custom_params
            )

            logger.info("Orchestration restore command completed")
Beispiel #2
0
    def orchestration_save(self, context, mode, custom_params):
        """Saves the Shell state and returns a description of the saved artifacts.

        This command is intended for API use only by sandbox orchestration
        scripts to implement a save and restore workflow
        :param ResourceCommandContext context: the context object containing
         resource and reservation info
        :param str mode: Snapshot save mode, can be one of two values
         'shallow' (default) or 'deep'
        :param str custom_params: Set of custom parameters for the save operation
        :return: SavedResults serialized as JSON
        :rtype: OrchestrationSaveResult
        """
        logger = get_logger_with_thread_id(context)
        logger.info("Orchestration save command started")

        with ErrorHandlingContext(logger):
            resource_config = create_load_balancing_resource_from_context(
                shell_name=self.SHELL_NAME,
                supported_os=self.SUPPORTED_OS,
                context=context,
            )
            cs_api = get_api(context)
            mode = mode or "shallow"
            cli_handler = F5CliHandler(
                cli=self._cli,
                resource_config=resource_config,
                api=cs_api,
                logger=logger,
            )

            configuration_operations = F5ConfigurationRunner(
                cli_handler=cli_handler,
                logger=logger,
                resource_config=resource_config,
                api=cs_api,
            )

            response = configuration_operations.orchestration_save(
                mode=mode, custom_params=custom_params
            )
            logger.info(
                "Orchestration save command completed with response: {}".format(
                    response
                )
            )

            return response
Beispiel #3
0
    def restore(self, context, path, configuration_type, restore_method):
        """Restores a configuration file.

        :param ResourceCommandContext context: The context object for the
         command with resource and reservation info
        :param str path: The path to the configuration file, including
         the configuration file name
        :param str restore_method: Determines whether the restore
         should append or override the current configuration
        :param str configuration_type: Specify whether the file should update
         the startup or running config
        """
        logger = get_logger_with_thread_id(context)
        logger.info("Restore command started")

        with ErrorHandlingContext(logger):
            resource_config = create_load_balancing_resource_from_context(
                shell_name=self.SHELL_NAME,
                supported_os=self.SUPPORTED_OS,
                context=context,
            )
            cs_api = get_api(context)
            configuration_type = configuration_type or "running"
            restore_method = restore_method or "override"

            cli_handler = F5CliHandler(
                cli=self._cli,
                resource_config=resource_config,
                api=cs_api,
                logger=logger,
            )

            configuration_operations = F5ConfigurationRunner(
                cli_handler=cli_handler,
                logger=logger,
                resource_config=resource_config,
                api=cs_api,
            )
            logger.info("Restoring started...")
            configuration_operations.restore(
                path=path,
                restore_method=restore_method,
                configuration_type=configuration_type,
            )

            logger.info("Restore command completed")
Beispiel #4
0
    def save(self, context, folder_path, configuration_type):
        """Save a configuration file to the provided destination.

        :param ResourceCommandContext context: The context object for the
         command with resource and reservation info
        :param str folder_path: The path to the folder in which the configuration
         file will be saved
        :param str configuration_type: startup or running config
        :return The configuration file name
        :rtype: str
        """
        logger = get_logger_with_thread_id(context)
        logger.info("Save command started")

        with ErrorHandlingContext(logger):
            resource_config = create_load_balancing_resource_from_context(
                shell_name=self.SHELL_NAME,
                supported_os=self.SUPPORTED_OS,
                context=context,
            )
            cs_api = get_api(context)
            configuration_type = configuration_type or "running"

            cli_handler = F5CliHandler(
                cli=self._cli,
                resource_config=resource_config,
                api=cs_api,
                logger=logger,
            )

            configuration_operations = F5ConfigurationRunner(
                cli_handler=cli_handler,
                logger=logger,
                resource_config=resource_config,
                api=cs_api,
            )
            logger.info("Saving started... ")
            response = configuration_operations.save(
                folder_path=folder_path, configuration_type=configuration_type
            )
            logger.info("Save command completed")

            return response