Esempio n. 1
0
    def parse(self, url, filename, command_processor):
        self.logger.info("Reading : %s/%s" % (url, filename))

        data = self.reader.read_tftp(url, filename).split("\n")

        command_processor.init(
            self.configuration, NoopTerminalController(),
            self.logger, NotPipingProcessor())

        for line in data:
            self.logger.debug("Processing : %s" % line)
            command_processor.process_command(line)
Esempio n. 2
0
    def launch(self, protocol, terminal_controller):
        self.last_connection_id += 1

        self.logger = logging.getLogger("fake_switches.arista.{}.{}.{}".format(
            self.switch_configuration.name, self.last_connection_id, protocol))

        processor = self.processor_stack(display_class=TerminalDisplay)

        processor.init(
            self.switch_configuration,
            LoggingTerminalController(self.logger, terminal_controller),
            self.logger, NotPipingProcessor())

        return AristaShellSession(processor)
Esempio n. 3
0
    def render_POST(self, request):
        content = json.loads(request.content.read().decode())
        self.logger.info("Request in: {}".format(content))

        driver = driver_for(content["params"]["format"])

        command_processor = self.processor_stack_factory(
            display_class=driver.display_class)
        command_processor.init(
            switch_configuration=self.switch_configuration,
            terminal_controller=BufferingTerminalController(),
            logger=self.logger,
            piping_processor=NotPipingProcessor())

        result = {
            "jsonrpc": content["jsonrpc"],
            "id": content["id"],
        }

        command_index = 1
        command_results = []
        try:
            for cmd in content["params"]["cmds"]:
                command_processor.process_command(cmd)
                command_results.append(driver.format_output(command_processor))
                command_index += 1
            result["result"] = command_results
        except CommandProcessorError as e:
            command_results.append(
                driver.format_errors([str(e)], base_obj=e.json_data))
            result["error"] = {
                "data":
                command_results,
                "message":
                "CLI command {index} of {count} '{cmd}' failed: {error}".
                format(index=command_index,
                       count=len(content["params"]["cmds"]),
                       cmd=content["params"]["cmds"][command_index - 1],
                       error=e.error),
                "code":
                e.code
            }

        return json.dumps(result).encode()
Esempio n. 4
0
    def parse(self, url, filename, command_processor_class):
        self.logger.info("Reading : %s/%s" % (url, filename))

        data = self.reader.read_tftp(url, filename).split("\n")

        command_processor = command_processor_class(self.configuration, lambda x: None, self.logger, NotPipingProcessor())

        for line in data:
            self.logger.debug("Processing : %s" % line)
            command_processor.process_command(line)