Ejemplo n.º 1
0
    def save(self, context, folder_path, configuration_type, vrf_management_name):
        """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
        :param vrf_management_name:
        :return The configuration file name
        :rtype: str
        """
        with LoggingSessionContext(context) as logger, LogCommand(logger, "save"):
            api = CloudShellSessionContext(context).get_api()

            resource_config = FirewallResourceConfig.from_context(
                self.SHELL_NAME, context, api, self.SUPPORTED_OS
            )

            cli_configurator = CheckpointCliConfigurator(
                self._cli, resource_config, logger
            )

            configuration_flow = CheckpointConfigurationFlow(
                logger, resource_config, cli_configurator
            )
            configuration_type = configuration_type or "running"
            return configuration_flow.save(
                folder_path, configuration_type, vrf_management_name
            )
Ejemplo n.º 2
0
    def health_check(self, context):
        """Checks if the device is up and connectable.

        :param ResourceCommandContext context: ResourceCommandContext
            object with all Resource Attributes inside
        :return: Success or fail message
        :rtype: str
        """
        with LoggingSessionContext(context) as logger, LogCommand(
            logger, "health_check"
        ):
            api = CloudShellSessionContext(context).get_api()

            resource_config = FirewallResourceConfig.from_context(
                self.SHELL_NAME, context, api, self.SUPPORTED_OS
            )

            cli_configurator = CheckpointCliConfigurator(
                self._cli, resource_config, logger
            )

            state_flow = CheckpointStateFlow(
                logger, resource_config, cli_configurator, api
            )
            return state_flow.health_check()
Ejemplo n.º 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
        """
        with LoggingSessionContext(context) as logger, LogCommand(logger, "restore"):
            api = CloudShellSessionContext(context).get_api()

            resource_config = FirewallResourceConfig.from_context(
                self.SHELL_NAME, context, api, self.SUPPORTED_OS
            )

            cli_configurator = CheckpointCliConfigurator(
                self._cli, resource_config, logger
            )

            configuration_flow = CheckpointConfigurationFlow(
                logger, resource_config, cli_configurator
            )
            configuration_type = configuration_type or "running"
            restore_method = restore_method or "override"
            return configuration_flow.restore(path, configuration_type, restore_method)
Ejemplo n.º 4
0
    def get_inventory(self, context):
        """Discovers the resource structure and attributes.

        :param ResourceCommandContext context: ResourceCommandContext object
            with all Resource Attributes inside
        :return Attribute and sub-resource information for the Shell resource
        :rtype: AutoLoadDetails
        """
        with LoggingSessionContext(context) as logger, LogCommand(
            logger, "get_inventory"
        ):
            api = CloudShellSessionContext(context).get_api()

            resource_config = FirewallResourceConfig.from_context(
                self.SHELL_NAME, context, api, self.SUPPORTED_OS
            )

            cli_configurator = CheckpointCliConfigurator(
                self._cli, resource_config, logger
            )
            enable_disable_snmp_flow = CheckpointEnableDisableSnmpFlow(
                cli_configurator, logger
            )
            snmp_configurator = EnableDisableSnmpConfigurator(
                enable_disable_snmp_flow, resource_config, logger
            )

            resource_model = FirewallResourceModel.from_resource_config(resource_config)

            autoload_operations = CheckpointSnmpAutoloadFlow(logger, snmp_configurator)
            logger.info("Autoload started")
            response = autoload_operations.discover(self.SUPPORTED_OS, resource_model)
            logger.info("Autoload completed")
            return response
Ejemplo n.º 5
0
    def orchestration_restore(self, context, saved_artifact_info, custom_params):
        """Restores a saved artifact.

        Restores a saved artifact previously saved by this Shell driver using the
            orchestration_save function.

        :param ResourceCommandContext context: The context object for the command
            with resource andreservation 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
        """
        with LoggingSessionContext(context) as logger, LogCommand(
            logger, "orchestration_restore"
        ):
            api = CloudShellSessionContext(context).get_api()

            resource_config = FirewallResourceConfig.from_context(
                self.SHELL_NAME, context, api, self.SUPPORTED_OS
            )

            cli_configurator = CheckpointCliConfigurator(
                self._cli, resource_config, logger
            )

            configuration_flow = CheckpointConfigurationFlow(
                logger, resource_config, cli_configurator
            )
            return configuration_flow.orchestration_restore(
                saved_artifact_info, custom_params
            )
Ejemplo n.º 6
0
    def orchestration_save(self, context, mode, custom_params):
        """Saves the shell state.

        Saves the shell state and returns a description of the saved
            artifacts and information. 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
        """
        with LoggingSessionContext(context) as logger, LogCommand(
            logger, "orchestration_save"
        ):
            api = CloudShellSessionContext(context).get_api()

            resource_config = FirewallResourceConfig.from_context(
                self.SHELL_NAME, context, api, self.SUPPORTED_OS
            )

            cli_configurator = CheckpointCliConfigurator(
                self._cli, resource_config, logger
            )

            configuration_flow = CheckpointConfigurationFlow(
                logger, resource_config, cli_configurator
            )
            return configuration_flow.orchestration_save(mode, custom_params)
Ejemplo n.º 7
0
    def shutdown(self, context):
        """Sends a graceful shutdown to the device.

        :param ResourceCommandContext context: The context object
        for the command with resource and reservation info
        """
        with LoggingSessionContext(context) as logger, LogCommand(logger, "shutdown"):
            api = CloudShellSessionContext(context).get_api()

            resource_config = FirewallResourceConfig.from_context(
                self.SHELL_NAME, context, api, self.SUPPORTED_OS
            )

            cli_configurator = CheckpointCliConfigurator(
                self._cli, resource_config, logger
            )

            state_flow = CheckpointStateFlow(
                logger, resource_config, cli_configurator, api
            )
            return state_flow.shutdown()
Ejemplo n.º 8
0
    def run_custom_config_command(self, context, custom_command):
        """Executes a custom command on the device in configuration mode.

        :param ResourceCommandContext context: The context object for the
         command with resource and reservation info
        :param str custom_command: The command to run
        :return: the command result text
        :rtype: str
        """
        with LoggingSessionContext(context) as logger, LogCommand(
            logger, "run custom config command"
        ):
            api = CloudShellSessionContext(context).get_api()

            resource_config = FirewallResourceConfig.from_context(
                self.SHELL_NAME, context, api, self.SUPPORTED_OS
            )

            cli_configurator = CheckpointCliConfigurator(
                self._cli, resource_config, logger
            )

            run_command_flow = RunCommandFlow(logger, cli_configurator)
            return run_command_flow.run_custom_config_command(custom_command)