Beispiel #1
0
    def restore(self, context, path, configuration_type, restore_method,
                vrf_management_name):
        """Restore selected file to the provided destination

        :param ResourceCommandContext context: ResourceCommandContext object with all Resource Attributes inside
        :param path: source config file
        :param configuration_type: running or startup configs
        :param restore_method: append or override methods
        :param vrf_management_name: VRF management Name
        """

        if not configuration_type:
            configuration_type = 'running'

        if not restore_method:
            restore_method = 'override'

        if not vrf_management_name:
            vrf_management_name = get_attribute_by_name(
                context=context, attribute_name='VRF Management Name')

        logger = get_logger_with_thread_id(context)
        api = get_api(context)

        configuration_operations = ConfigurationRunner(logger=logger,
                                                       api=api,
                                                       cli=self._cli,
                                                       context=context)
        logger.info('Restore started')
        configuration_operations.restore(
            path=path,
            restore_method=restore_method,
            configuration_type=configuration_type,
            vrf_management_name=vrf_management_name)
        logger.info('Restore completed')
Beispiel #2
0
    def orchestration_save(self, context, mode, custom_params):
        """

        :param ResourceCommandContext context: ResourceCommandContext object with all Resource Attributes inside
        :param mode: mode
        :param custom_params: json with custom save parameters
        :return str response: response json
        """

        if not mode:
            mode = 'shallow'

        logger = get_logger_with_thread_id(context)
        api = get_api(context)

        configuration_operations = ConfigurationRunner(logger=logger,
                                                       api=api,
                                                       cli=self._cli,
                                                       context=context)
        logger.info(
            'Orchestration save started, request is: {}'.format(custom_params))
        response = configuration_operations.orchestration_save(
            mode=mode, custom_params=custom_params)
        logger.info(
            'Orchestration save completed, response is: {}'.format(response))
        return response
Beispiel #3
0
    def orchestration_restore(self, context, saved_artifact_info,
                              custom_params):
        """

        :param ResourceCommandContext context: ResourceCommandContext object with all Resource Attributes inside
        :param saved_artifact_info: OrchestrationSavedArtifactInfo json
        :param custom_params: json with custom restore parameters
        """

        logger = get_logger_with_thread_id(context)
        api = get_api(context)

        resource_config = create_networking_resource_from_context(
            shell_name=self.SHELL_NAME,
            supported_os=self.SUPPORTED_OS,
            context=context)

        cli_handler = CliHandler(self._cli, resource_config, logger, api)
        configuration_operations = ConfigurationRunner(
            cli_handler=cli_handler,
            logger=logger,
            resource_config=resource_config,
            api=api)

        logger.info('Orchestration restore started')
        configuration_operations.orchestration_restore(
            saved_artifact_info=saved_artifact_info,
            custom_params=custom_params)
        logger.info('Orchestration restore completed')
Beispiel #4
0
    def save(self, context, folder_path, configuration_type,
             vrf_management_name):
        """Save selected file to the provided destination

        :param ResourceCommandContext context: ResourceCommandContext object with all Resource Attributes inside
        :param configuration_type: source file, which will be saved
        :param folder_path: destination path where file will be saved
        :param vrf_management_name: VRF management Name
        :return str saved configuration file name:
        """

        if not configuration_type:
            configuration_type = 'running'

        if not vrf_management_name:
            vrf_management_name = get_attribute_by_name(
                context=context, attribute_name='VRF Management Name')

        logger = get_logger_with_thread_id(context)
        api = get_api(context)

        configuration_operations = ConfigurationRunner(logger=logger,
                                                       cli=self._cli,
                                                       context=context,
                                                       api=api)
        logger.info('Save started')
        response = configuration_operations.save(
            folder_path=folder_path,
            configuration_type=configuration_type,
            vrf_management_name=vrf_management_name)
        logger.info('Save completed')
        return response
Beispiel #5
0
    def orchestration_save(self, context, mode, custom_params):
        """

        :param ResourceCommandContext context: ResourceCommandContext object with all Resource Attributes inside
        :param mode: mode
        :param custom_params: json with custom save parameters
        :return str response: response json
        """

        if not mode:
            mode = 'shallow'

        logger = get_logger_with_thread_id(context)
        api = get_api(context)

        resource_config = create_networking_resource_from_context(
            shell_name=self.SHELL_NAME,
            supported_os=self.SUPPORTED_OS,
            context=context)

        cli_handler = CliHandler(self._cli, resource_config, logger, api)
        configuration_operations = ConfigurationRunner(
            cli_handler=cli_handler,
            logger=logger,
            resource_config=resource_config,
            api=api)

        logger.info('Orchestration save started')
        response = configuration_operations.orchestration_save(
            mode=mode, custom_params=custom_params)
        logger.info('Orchestration save completed')
        return response
class TestCiscoConfigurationRunner(TestCase):
    TEST_NAME = "resource_name"

    def setUp(self):
        self._logger = MagicMock()
        self._cli_handler = MagicMock()
        self._resource_config = MagicMock()
        self._resource_config.name = self.TEST_NAME
        self._handler = CiscoConfigurationRunner(
            logger=self._logger,
            cli_handler=self._cli_handler,
            resource_config=self._resource_config,
            api=MagicMock())

    def test_save(self):
        with patch(
                "cloudshell.networking.cisco.runners.cisco_configuration_runner.CiscoSaveFlow"
        ) as save_mock:
            config_type = "running"
            result = self._handler.save("tftp://10.10.10.10", "running", "")
            self.assertEqual(
                "{}-{}-{}".format(
                    self.TEST_NAME, config_type,
                    time.strftime("%d%m%y-%H%M%S", time.localtime())), result)
            save_mock.assert_called_once_with(cli_handler=self._cli_handler,
                                              logger=self._logger)

    def test_restore(self):
        with patch(
                "cloudshell.networking.cisco.runners.cisco_configuration_runner.CiscoRestoreFlow"
        ) as restore_mock:
            self._handler.restore("tftp://10.10.10.10", "running", "", "")
            restore_mock.assert_called_once_with(cli_handler=self._cli_handler,
                                                 logger=self._logger)
 def setUp(self):
     self._logger = MagicMock()
     self._cli_handler = MagicMock()
     self._resource_config = MagicMock()
     self._resource_config.name = self.TEST_NAME
     self._handler = CiscoConfigurationRunner(
         logger=self._logger,
         cli_handler=self._cli_handler,
         resource_config=self._resource_config,
         api=MagicMock())
Beispiel #8
0
    def restore(self, context, path, configuration_type, restore_method,
                vrf_management_name):
        """Restore selected file to the provided destination

        :param ResourceCommandContext context: ResourceCommandContext object with all Resource Attributes inside
        :param path: source config file
        :param configuration_type: running or startup configs
        :param restore_method: append or override methods
        :param vrf_management_name: VRF management Name
        """

        logger = get_logger_with_thread_id(context)
        api = get_api(context)

        resource_config = create_networking_resource_from_context(
            shell_name=self.SHELL_NAME,
            supported_os=self.SUPPORTED_OS,
            context=context)

        if not configuration_type:
            configuration_type = 'running'

        if not restore_method:
            restore_method = 'override'

        if not vrf_management_name:
            vrf_management_name = resource_config.vrf_management_name

        cli_handler = CliHandler(self._cli, resource_config, logger, api)
        configuration_operations = ConfigurationRunner(
            cli_handler=cli_handler,
            logger=logger,
            resource_config=resource_config,
            api=api)
        logger.info('Restore started')
        configuration_operations.restore(
            path=path,
            restore_method=restore_method,
            configuration_type=configuration_type,
            vrf_management_name=vrf_management_name)
        logger.info('Restore completed')
Beispiel #9
0
    def orchestration_restore(self, context, saved_artifact_info,
                              custom_params):
        """

        :param ResourceCommandContext context: ResourceCommandContext object with all Resource Attributes inside
        :param saved_artifact_info: OrchestrationSavedArtifactInfo json
        :param custom_params: json with custom restore parameters
        """

        logger = get_logger_with_thread_id(context)
        api = get_api(context)

        configuration_operations = ConfigurationRunner(logger=logger,
                                                       api=api,
                                                       cli=self._cli,
                                                       context=context)
        logger.info('Orchestration restore started, request is: {}'.format(
            saved_artifact_info))
        configuration_operations.orchestration_restore(
            saved_artifact_info=saved_artifact_info,
            custom_params=custom_params)
        logger.info('Orchestration restore completed')
Beispiel #10
0
    def save(self, context, folder_path, configuration_type,
             vrf_management_name):
        """Save selected file to the provided destination

        :param ResourceCommandContext context: ResourceCommandContext object with all Resource Attributes inside
        :param configuration_type: source file, which will be saved
        :param folder_path: destination path where file will be saved
        :param vrf_management_name: VRF management Name
        :return str saved configuration file name:
        """

        logger = get_logger_with_thread_id(context)
        api = get_api(context)

        resource_config = create_networking_resource_from_context(
            shell_name=self.SHELL_NAME,
            supported_os=self.SUPPORTED_OS,
            context=context)

        if not configuration_type:
            configuration_type = 'running'

        if not vrf_management_name:
            vrf_management_name = resource_config.vrf_management_name

        cli_handler = CliHandler(self._cli, resource_config, logger, api)
        configuration_operations = ConfigurationRunner(
            cli_handler=cli_handler,
            logger=logger,
            resource_config=resource_config,
            api=api)
        logger.info('Save started')
        response = configuration_operations.save(
            folder_path=folder_path,
            configuration_type=configuration_type,
            vrf_management_name=vrf_management_name)
        logger.info('Save completed')
        return response