示例#1
0
    def get_inventory(self, context):
        """ Return device structure with all standard attributes
        :type context: cloudshell.shell.core.driver_context.AutoLoadCommandContext
        :rtype: cloudshell.shell.core.driver_context.AutoLoadDetails
        """

        resource_config = GenericTrafficChassisResource.from_context(
            self.SHELL_NAME, self.SUPPORTED_OS, context)

        logger = get_logger_with_thread_id(context)
        api = get_api(context)
        autoload_runner = BPAutoloadRunner(resource_config, self.SHELL_NAME,
                                           api, logger)
        auto_load_details = autoload_runner.discover()

        # Here comes PS...

        address = context.resource.address
        user = context.resource.attributes['{}.User'.format(
            PerfectStorm2GDriver.SHELL_NAME)]
        encripted_password = context.resource.attributes['{}.Password'.format(
            PerfectStorm2GDriver.SHELL_NAME)]
        password = get_api(context).DecryptPassword(encripted_password).Value
        import paramiko
        self.ssh = paramiko.SSHClient()
        self.ssh.load_system_host_keys()
        self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        self.ssh.connect(hostname=address, username=user, password=password)
        self.chan = self.ssh.invoke_shell()
        self.ssh_call('bpsh')
        self.ssh_call('set chassis [$bps getChassis]')
        modules = {}
        for resource in auto_load_details.resources:
            if resource.model == '{}.GenericTrafficGeneratorModule'.format(
                    PerfectStorm2GDriver.SHELL_NAME):
                relative_address = resource.relative_address
                modules[relative_address] = self.ssh_call(
                    '$chassis getCardMode ' + relative_address[1:]).split()[0]
        for resource in auto_load_details.resources:
            if resource.model == '{}.GenericTrafficGeneratorPort'.format(
                    PerfectStorm2GDriver.SHELL_NAME):
                port_module = resource.relative_address.split('/')[0]
                if port_module in modules.keys():
                    auto_load_details.attributes.append(
                        AutoLoadAttribute(
                            relative_address=resource.relative_address,
                            attribute_name=
                            'CS_TrafficGeneratorPort.Configured Controllers',
                            attribute_value=modules[port_module]))
        return auto_load_details
    def get_inventory(self, context):
        """Discovers the resource structure and attributes.

        :param AutoLoadCommandContext context: the context the command runs on
        :return Attribute and sub-resource information for the Shell resource
        :rtype: AutoLoadDetails
        """
        logger = get_logger_with_thread_id(context)
        logger.info("Autoload 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)
            snmp_handler = F5SnmpHandler(resource_config, logger, cs_api, cli_handler)

            autoload_operations = F5FirewallAutoloadRunner(
                logger=logger,
                resource_config=resource_config,
                snmp_handler=snmp_handler,
            )

            autoload_details = autoload_operations.discover()
            logger.info("Autoload command completed")

            return autoload_details
    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
        """
        logger = get_logger_with_thread_id(context)
        logger.info("Health check 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)

            state_operations = StateRunner(
                logger=logger,
                api=cs_api,
                resource_config=resource_config,
                cli_handler=cli_handler,
            )

            response = state_operations.health_check()
            logger.info("Health check command ended with response: {}".format(response))

            return response
    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")
    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
        """
        logger = get_logger_with_thread_id(context)
        logger.info("Shutdown 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)

            state_operations = StateRunner(
                logger=logger,
                api=cs_api,
                resource_config=resource_config,
                cli_handler=cli_handler,
            )

            response = state_operations.shutdown()
            logger.info("Shutdown command completed with response: {}".format(response))

            return response
    def load_firmware(self, context, path):
        """Upload and updates firmware on the resource.

        :param ResourceCommandContext context: The context object
         for the command with resource and reservation info
        :param str path: path to tftp server where firmware file is stored
        """
        logger = get_logger_with_thread_id(context)
        logger.info("Load firmware 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)

            logger.info("Start Loading Firmware...")
            firmware_operations = F5FirmwareRunner(
                cli_handler=cli_handler, logger=logger
            )

            response = firmware_operations.load_firmware(path=path)
            logger.info(
                "Load firmware command completed with response: {}".format(response)
            )

            return response
示例#7
0
    def get_inventory(self, context):
        """Return device structure with all standard attributes

        :type context: cloudshell.shell.core.driver_context.AutoLoadCommandContext
        :rtype: cloudshell.shell.core.driver_context.AutoLoadDetails
        """
        logger = get_logger_with_thread_id(context)
        logger.info('Autoload started')

        with ErrorHandlingContext(logger):
            resource_config = TrafficGeneratorChassisResource.from_context(
                context=context, shell_name=self.SHELL_NAME)
            cs_api = get_api(context)
            password = cs_api.DecryptPassword(resource_config.password).Value

            tvm_client = TeraVMClient(address=resource_config.address,
                                      user=resource_config.user,
                                      password=password,
                                      port=int(resource_config.port))

            autoload_runner = TeraVMAutoloadRunner(
                tvm_client=tvm_client,
                resource_config=resource_config,
                logger=logger)

            response = autoload_runner.discover()
            logger.info('Autoload completed')

            return response
    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: startup or running
        :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(
            self.SHELL_NAME, self.SUPPORTED_OS, context)
        cli_handler = CliHandler(self._cli, resource_config, logger, api)

        configuration_type = configuration_type or 'running'
        vrf_management_name = vrf_management_name or resource_config.vrf_management_name

        configuration_operations = ConfigurationRunner(logger, resource_config,
                                                       api, cli_handler)
        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
    def start_traffic(self, context):
        """Start traffic on all ports

        :param context: the context the command runs on
        :param bool blocking: True - return after traffic finish to run, False - return immediately
        """
        logger = get_logger_with_thread_id(context)
        logger.info('Start traffic command started')

        with ErrorHandlingContext(logger):
            cs_api = get_api(context)
            resource_config = TrafficGeneratorControllerResource.create_from_chassis_resource(
                context=context,
                shell_name=self.SHELL_NAME,
                shell_type=self.SHELL_TYPE,
                cs_api=cs_api)

            test_runner = TeraVMTestsRunner(resource_config=resource_config,
                                            cs_api=cs_api,
                                            cli=self._cli,
                                            logger=logger)

            response = test_runner.start_tests()
            logger.info('Start traffic command ended')

            return response
    def run_custom_command(self, context, custom_command):
        """Executes a custom command on the device.

        :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
        """
        logger = get_logger_with_thread_id(context)
        logger.info("Run custom 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)

            send_command_operations = RunCommandRunner(
                logger=logger, cli_handler=cli_handler
            )

            response = send_command_operations.run_custom_command(
                custom_command=parse_custom_commands(custom_command)
            )
            logger.info("Run custom command ended with response: {}".format(response))

            return response
示例#11
0
    def get_inventory(self, context):
        """Return device structure with all standard attributes

        :param ResourceCommandContext context: ResourceCommandContext object with all Resource Attributes inside
        :return: response
        :rtype: str
        """

        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 "true" in resource_config.enable_snmp.lower() and "3" in resource_config.snmp_version:
            raise Exception("Enabling of snmp v3 is not supported")
        cli_handler = CliHandler(self._cli, resource_config, logger, api)
        snmp_handler = SNMPHandler(resource_config, logger, api, cli_handler)

        autoload_operations = AutoloadRunner(logger=logger,
                                             resource_config=resource_config,
                                             snmp_handler=snmp_handler)
        logger.info('Autoload started')
        response = autoload_operations.discover()
        logger.info('Autoload completed')
        return response
示例#12
0
    def get_inventory(self, context):
        """Return device structure with all standard attributes

        :param ResourceCommandContext context: ResourceCommandContext object with all Resource Attributes inside
        :return: response
        :rtype: str
        """

        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)
        snmp_handler = SNMPHandler(resource_config, logger, api, cli_handler)

        autoload_operations = AutoloadRunner(logger=logger,
                                             resource_config=resource_config,
                                             snmp_handler=snmp_handler)
        logger.info('Autoload started')
        response = autoload_operations.discover()
        logger.info('Autoload completed')
        return response
    def run_custom_config_command(self, context, cancellation_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 CancellationContext cancellation_context: Object to signal a request for cancellation. Must be enabled in drivermetadata.xml as well
        :param str custom_command: The command to run. Note that commands that require a response are not supported.
        :return: the command result text
        :rtype: str
        """
        logger = get_logger_with_thread_id(context)
        logger.info('Run Custom Config command started')

        with ErrorHandlingContext(logger):
            api = get_api(context)
            resource_config = create_load_balancing_resource_from_context(shell_name=self.SHELL_NAME,
                                                                          supported_os=self.SUPPORTED_OS,
                                                                          context=context)

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

            send_command_operations = RunCommandRunner(logger=logger,
                                                       cli_handler=cli_handler)

            response = send_command_operations.run_custom_config_command(
                custom_command=parse_custom_commands(custom_command))

            logger.info('Run Custom Config command ended with response: {}'.format(response))

            return response
    def get_statistics(self, context):
        """Get real time statistics as sandbox attachment

        :param context:
        :return:
        """
        logger = get_logger_with_thread_id(context)
        logger.info('Get Statistics command started')

        with ErrorHandlingContext(logger):
            cs_api = get_api(context)
            reservation_id = context.reservation.reservation_id
            resource_config = TrafficGeneratorControllerResource.create_from_chassis_resource(
                context=context,
                shell_name=self.SHELL_NAME,
                shell_type=self.SHELL_TYPE,
                cs_api=cs_api)

            quali_api_client = create_quali_api_instance(context, logger)
            quali_api_client.login()

            test_runner = TeraVMResultsRunner(
                resource_config=resource_config,
                cs_api=cs_api,
                cli=self._cli,
                quali_api_client=quali_api_client,
                reservation_id=reservation_id,
                logger=logger)

            response = test_runner.get_results()
            logger.info('Get results command ended')

            return response
示例#15
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')
示例#16
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
示例#17
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')
示例#18
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
    def health_check(self, context):
        """Performs device health check

        :param ResourceCommandContext context: ResourceCommandContext object with all Resource Attributes inside
        :return: Success or Error message
        :rtype: str
        """
        logger = get_logger_with_thread_id(context)
        logger.info('Health Check command started')

        with ErrorHandlingContext(logger):
            api = get_api(context)

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

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

            state_operations = CgsStateRunner(logger=logger,
                                              api=api,
                                              resource_config=resource_config,
                                              cli_handler=cli_handler)

            result = state_operations.health_check()
            logger.info('Health Check command ended with result: {}'.format(result))

            return result
示例#20
0
    def connect_child_resources(self, context):
        """

        :type context: cloudshell.shell.core.driver_context.ResourceCommandContext
        :rtype: str
        """
        logger = get_logger_with_thread_id(context)
        logger.info("Connect child resources command started")

        with ErrorHandlingContext(logger):
            resource_name = context.resource.fullname
            reservation_id = context.reservation.reservation_id
            connectors = context.connectors
            api = get_api(context)

            connect_operation = ConnectChildResourcesRunner(logger=logger,
                                                            cs_api=api)

            ports = connect_operation.get_ports(resource_name=resource_name,
                                                port_model=MODEL_PORT)

            return connect_operation.connect_child_resources(connectors=connectors,
                                                             ports=ports,
                                                             resource_name=resource_name,
                                                             reservation_id=reservation_id)
示例#21
0
    def orchestration_save(self, context, mode, custom_params):
        """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
        """

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

        resource_config = create_firewall_resource_from_context(
            self.SHELL_NAME, self.SUPPORTED_OS, context)
        cli_handler = CliHandler(self._cli, resource_config, logger, api)

        configuration_operations = ConfigurationRunner(logger, resource_config,
                                                       api, cli_handler)
        logger.info('Orchestration save started')
        response = configuration_operations.orchestration_save(
            mode, custom_params)
        logger.info('Orchestration save completed')
        return response
示例#22
0
    def orchestration_restore(self, context, saved_artifact_info,
                              custom_params):
        """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 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)
        api = get_api(context)

        resource_config = create_firewall_resource_from_context(
            self.SHELL_NAME, self.SUPPORTED_OS, context)
        cli_handler = CliHandler(self._cli, resource_config, logger, api)

        configuration_operations = ConfigurationRunner(logger, resource_config,
                                                       api, cli_handler)
        logger.info('Orchestration restore started')
        configuration_operations.orchestration_restore(saved_artifact_info,
                                                       custom_params)

        logger.info('Orchestration restore completed')
示例#23
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)
        api = get_api(context)

        resource_config = create_firewall_resource_from_context(
            self.SHELL_NAME, self.SUPPORTED_OS, context)
        cli_handler = CliHandler(self._cli, resource_config, logger, api)

        configuration_type = configuration_type or 'running'

        configuration_operations = ConfigurationRunner(logger, resource_config,
                                                       api, cli_handler)
        logger.info('Save started')
        response = configuration_operations.save(folder_path,
                                                 configuration_type)
        logger.info('Save completed')
        return response
示例#24
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)
        api = get_api(context)

        resource_config = create_firewall_resource_from_context(
            self.SHELL_NAME, self.SUPPORTED_OS, context)
        cli_handler = CliHandler(self._cli, resource_config, logger, api)

        configuration_type = configuration_type or 'running'
        restore_method = restore_method or 'override'

        configuration_operations = ConfigurationRunner(logger, resource_config,
                                                       api, cli_handler)
        logger.info('Restore started')
        configuration_operations.restore(path, configuration_type,
                                         restore_method)
        logger.info('Restore completed')
    def cleanup_reservation(self, context):
        """Stop traffic and delete test group

        :param context: the context the command runs on
        :type context: cloudshell.shell.core.driver_context.ResourceRemoteCommandContext
        """
        logger = get_logger_with_thread_id(context)
        logger.info('Cleanup reservation command started')

        with ErrorHandlingContext(logger):
            cs_api = get_api(context)
            resource_config = TrafficGeneratorControllerResource.create_from_chassis_resource(
                context=context,
                shell_name=self.SHELL_NAME,
                shell_type=self.SHELL_TYPE,
                cs_api=cs_api)

            cleanup_runner = TeraVMCleanupRunner(
                resource_config=resource_config,
                cs_api=cs_api,
                cli=self._cli,
                logger=logger)

            response = cleanup_runner.cleanup_reservation()
            logger.info('Cleanup reservation command ended')

            return response
示例#26
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
        """

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

        logger.info("CONTEXT: {}".format(context))
        logger.info("SHELL_NAME: {}".format(self.SHELL_NAME))
        logger.info("SUPPORTED_OS: {}".format(self.SUPPORTED_OS))

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

        logger.info("RESOURCE_CONFIG: {}".format(resource_config.__dict__))

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

        state_operations = StateRunner(logger, api, resource_config,
                                       cli_handler)

        return state_operations.health_check()
示例#27
0
    def load_firmware(self,
                      context,
                      path,
                      features_to_install="",
                      vrf_management_name=None):
        """Upload and updates firmware on the resource

        :param ResourceCommandContext context: ResourceCommandContext object with all Resource Attributes inside
        :param path: full path to firmware file, i.e. tftp://10.10.10.1/firmware.tar
        :param features_to_install:
        :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 vrf_management_name:
            vrf_management_name = resource_config.vrf_management_name

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

        logger.info('Start Load Firmware')
        firmware_operations = FirmwareRunner(
            cli_handler=cli_handler,
            logger=logger,
            features_to_install=features_to_install)
        response = firmware_operations.load_firmware(
            path=path, vrf_management_name=vrf_management_name)
        logger.info('Finish Load Firmware: {}'.format(response))
        return response
    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

        configuration_operations = ConfigurationRunner(cli=self._cli,
                                                       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')
    def load_firmware(self, context, cancellation_context, path, vrf_management_name):
        """Upload and updates firmware on the resource

        :param ResourceCommandContext context: The context object for the command with resource and reservation info
        :param str path: path to tftp server where firmware file is stored
        :param str vrf_management_name: Optional. Virtual routing and Forwarding management name
        """
        logger = get_logger_with_thread_id(context)
        logger.info('Load firmware command started')

        with ErrorHandlingContext(logger):
            api = get_api(context)
            resource_config = create_load_balancing_resource_from_context(shell_name=self.SHELL_NAME,
                                                                          supported_os=self.SUPPORTED_OS,
                                                                          context=context)

            vrf_management_name = vrf_management_name or resource_config.vrf_management_name

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

            firmware_operations = CgsFirmwareRunner(cli_handler=cli_handler, logger=logger)
            response = firmware_operations.load_firmware(path=path, vrf_management_name=vrf_management_name)
            logger.info('Load firmware command ended with response: {}'.format(response))
    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

        configuration_operations = ConfigurationRunner(cli=self._cli,
                                                       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
示例#31
0
    def remove_aci_resources(self, context):
        """

        :param context:
        :return:
        """
        logger = get_logger_with_thread_id(context)
        logger.info("Create ACI Resources command started")

        with ErrorHandlingContext(logger):
            resource_config = CiscoACIControllerResourse.from_context(
                context=context,
                shell_type=self.SHELL_TYPE,
                shell_name=self.SHELL_NAME)
            cs_api = get_api(context)
            password = cs_api.DecryptPassword(resource_config.password).Value
            reservation_id = context.reservation.reservation_id

            aci_api_client = CiscoACIControllerHTTPClient(
                logger=logger,
                address=resource_config.address,
                user=resource_config.user,
                password=password,
                scheme=resource_config.scheme,
                port=resource_config.port)

            aci_resources_runner = CiscoACIResourcesRunner(
                aci_api_client=aci_api_client,
                resource_config=resource_config,
                reservation_id=reservation_id,
                logger=logger)

            aci_resources_runner.remove_resources()
示例#32
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
示例#33
0
    def ApplyConnectivityChanges(self, context, request):
        """
        Create vlan and add or remove it to/from network interface

        :param ResourceCommandContext context: ResourceCommandContext object with all Resource Attributes inside
        :param str request: request json
        :return:
        """

        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)
        connectivity_operations = ConnectivityRunner(logger=logger,
                                                     cli_handler=cli_handler)
        logger.info(
            'Start applying connectivity changes, request is: {0}'.format(
                str(request)))
        result = connectivity_operations.apply_connectivity_changes(
            request=request)
        logger.info(
            'Finished applying connectivity changes, response is: {0}'.format(
                str(result)))
        logger.info('Apply Connectivity changes completed')
        return result
    def get_inventory(self, context):
        """ Return device structure with all standard attributes

        :type context: cloudshell.shell.core.driver_context.AutoLoadCommandContext
        :rtype: cloudshell.shell.core.driver_context.AutoLoadDetails
        """

        logger = get_logger_with_thread_id(context)
        logger.info("Autoload started")

        with ErrorHandlingContext(logger):
            resource_config = TrafficGeneratorChassisResource.from_context(context=context,
                                                                           shell_name=self.SHELL_NAME)

            session_pool_size = int(resource_config.sessions_concurrency_limit)
            self._cli = get_cli(session_pool_size)
            api = get_api(context)

            autoload_runner = TRexAutoloadRunner(api=api,
                                                 cli=self._cli,
                                                 resource_config=resource_config,
                                                 logger=logger)

            response = autoload_runner.discover()
            logger.info("Autoload completed")

            return response
示例#35
0
    def health_check(self, context):
        """Performs device health check

        :param ResourceCommandContext context: ResourceCommandContext object with all Resource Attributes inside
        :return: Success or Error message
        :rtype: str
        """

        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)

        state_operations = StateRunner(logger=logger, api=api, resource_config=resource_config, cli_handler=cli_handler)
        return state_operations.health_check()
示例#36
0
    def shutdown(self, context):
        """ Shutdown device

        :param ResourceCommandContext context: ResourceCommandContext object with all Resource Attributes inside
        :return:
        """

        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)
        state_operations = StateRunner(logger=logger, api=api, resource_config=resource_config, cli_handler=cli_handler)

        return state_operations.shutdown()
示例#37
0
    def run_custom_command(self, context, custom_command):
        """Send custom command

        :param ResourceCommandContext context: ResourceCommandContext object with all Resource Attributes inside
        :return: result
        :rtype: str
        """

        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)
        send_command_operations = CommandRunner(logger=logger, cli_handler=cli_handler)

        response = send_command_operations.run_custom_command(custom_command=parse_custom_commands(custom_command))

        return response
示例#38
0
    def update_firmware(self, context, remote_host, file_path):
        """Upload and updates firmware on the resource

        :param ResourceCommandContext context: ResourceCommandContext object with all Resource Attributes inside
        :param remote_host: full path to firmware file, i.e. tftp://10.10.10.1/firmware.tar
        :param file_path: 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)

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

        logger.info('Start Load Firmware')
        firmware_operations = FirmwareRunner(cli_handler=cli_handler, logger=logger)
        response = firmware_operations.load_firmware(path=remote_host,
                                                     vrf_management_name=resource_config.vrf_management_name)
        logger.info('Finish Load Firmware: {}'.format(response))
示例#39
0
    def ApplyConnectivityChanges(self, context, request):
        """
        Create vlan and add or remove it to/from network interface

        :param ResourceCommandContext context: ResourceCommandContext object with all Resource Attributes inside
        :param str request: request json
        :return:
        """

        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)
        connectivity_operations = ConnectivityRunner(logger=logger, cli_handler=cli_handler)
        logger.info('Start applying connectivity changes, request is: {0}'.format(str(request)))
        result = connectivity_operations.apply_connectivity_changes(request=request)
        logger.info('Finished applying connectivity changes, response is: {0}'.format(str(result)))
        logger.info('Apply Connectivity changes completed')
        return result
示例#40
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')