Esempio n. 1
0
 def __init__(self, device):
     """Initialize the XR 64 bit Driver object."""
     super(Driver, self).__init__(device)
     self.calvados_re = pattern_manager.pattern(self.platform, 'calvados')
     self.calvados_connect_re = pattern_manager.pattern(
         self.platform, 'calvados_connect')
     self.calvados_term_length = pattern_manager.pattern(
         self.platform, 'calvados_term_length')
Esempio n. 2
0
 def after_connect(self):
     """Execute after connect."""
     # TODO: check if this works.
     show_users = self.device.send("show users", timeout=120)
     result = re.search(pattern_manager.pattern(self.platform, 'connected_locally'), show_users)
     if result:
         logger.debug('Locally connected to Calvados. Exiting.')
         self.device.send('exit')
         return True
     return False
Esempio n. 3
0
 def after_connect(self):
     """Execute after connect."""
     # TODO: check if this works.
     show_users = self.device.send("show users", timeout=120)
     result = re.search(
         pattern_manager.pattern(self.platform, 'connected_locally'),
         show_users)
     if result:
         self.log('Locally connected to Calvados. Exiting.')
         self.device.send('exit')
         return True
     return False
Esempio n. 4
0
    def make_dynamic_prompt(self, prompt):
        """Extend prompt with flexible mode handling regexp."""
        patterns = [pattern_manager.pattern(
            self.platform, pattern_name, compiled=False) for pattern_name in self.target_prompt_components]

        patterns_re = "|".join(patterns).format(prompt=re.escape(prompt))

        try:
            prompt_re = re.compile(patterns_re)
        except re.error as e:  # pylint: disable=invalid-name
            raise RuntimeError("Pattern compile error: {} ({}:{})".format(e.message, self.platform, patterns_re))

        logger.debug("Dynamic prompt: '{}'".format(prompt_re.pattern))
        return prompt_re
Esempio n. 5
0
 def base_prompt(self, prompt):
     """Extract the base prompt pattern."""
     if prompt is None:
         return None
     if not self.device.is_target:
         return prompt
     pattern = pattern_manager.pattern(self.platform, "prompt_dynamic", compiled=False)
     pattern = pattern.format(prompt="(?P<prompt>.*?)")
     result = re.search(pattern, prompt)
     if result:
         base = result.group("prompt") + "#"
         logger.debug("base prompt: {}".format(base))
         return base
     else:
         logger.error("Unable to extract the base prompt")
         return prompt
Esempio n. 6
0
    def make_dynamic_prompt(self, prompt):
        """Extend prompt with flexible mode handling regexp."""
        patterns = [
            "[\r\n]" + pattern_manager.pattern(
                self.platform, pattern_name, compiled=False)
            for pattern_name in self.target_prompt_components
        ]

        hostname = self.update_hostname(prompt)
        # patterns_re = "|".join(patterns).format(prompt=re.escape(prompt[:-1]))
        patterns_re = "|".join(patterns).format(hostname=re.escape(hostname))

        try:
            prompt_re = re.compile(patterns_re, re.MULTILINE)
        except re.error as e:  # pylint: disable=invalid-name
            raise RuntimeError("Pattern compile error: {} ({}:{})".format(
                e.message, self.platform, patterns_re))

        self.log("Platform: {} -> Dynamic prompt: '{}'".format(
            self.platform, repr(prompt_re.pattern)))
        return prompt_re
Esempio n. 7
0
 def __init__(self, device):
     """Initialize the XR 64 bit Driver object."""
     super(Driver, self).__init__(device)
     self.calvados_re = pattern_manager.pattern(self.platform, 'calvados')
     self.calvados_connect_re = pattern_manager.pattern(self.platform, 'calvados_connect')
     self.calvados_term_length = pattern_manager.pattern(self.platform, 'calvados_term_length')
Esempio n. 8
0
    def __init__(self, device):
        """Initialize the Driver object."""
        self.device = device

        # FIXME: Do something with this, it's insane
        self.prompt_re = pattern_manager.pattern(self.platform, 'prompt')
        self.syntax_error_re = pattern_manager.pattern(self.platform,
                                                       'syntax_error')
        self.connection_closed_re = pattern_manager.pattern(
            self.platform, 'connection_closed')
        self.press_return_re = pattern_manager.pattern(self.platform,
                                                       'press_return')
        self.more_re = pattern_manager.pattern(self.platform, 'more')
        self.rommon_re = pattern_manager.pattern(self.platform, 'rommon')
        self.buffer_overflow_re = pattern_manager.pattern(
            self.platform, 'buffer_overflow')

        self.username_re = pattern_manager.pattern(self.platform, 'username')
        self.password_re = pattern_manager.pattern(self.platform, 'password')
        self.authentication_error_re = pattern_manager.pattern(
            self.platform, 'authentication_error')
        self.unable_to_connect_re = pattern_manager.pattern(
            self.platform, 'unable_to_connect')
        self.timeout_re = pattern_manager.pattern(self.platform, 'timeout')
        self.standby_re = pattern_manager.pattern(self.platform, 'standby')

        self.pid2platform_re = pattern_manager.pattern(self.platform,
                                                       'pid2platform')
        self.platform_re = pattern_manager.pattern(self.platform,
                                                   'platform',
                                                   compiled=False)
        self.version_re = pattern_manager.pattern(self.platform,
                                                  'version',
                                                  compiled=False)
        self.vty_re = pattern_manager.pattern(self.platform, 'vty')
        self.console_re = pattern_manager.pattern(self.platform, 'console')

        self.plane = 'sdr'

        self.log = device.chain.connection.log
        self.platform_string = ""
        self.raw_family = None
Esempio n. 9
0
    def __init__(self, device):
        """Initialize the Driver object."""
        self.device = device

        # FIXME: Do something with this, it's insane
        self.prompt_re = pattern_manager.pattern(self.platform, 'prompt')
        self.syntax_error_re = pattern_manager.pattern(self.platform, 'syntax_error')
        self.connection_closed_re = pattern_manager.pattern(self.platform, 'connection_closed')
        self.press_return_re = pattern_manager.pattern(self.platform, 'press_return')
        self.more_re = pattern_manager.pattern(self.platform, 'more')
        self.rommon_re = pattern_manager.pattern(self.platform, 'rommon')
        self.buffer_overflow_re = pattern_manager.pattern(self.platform, 'buffer_overflow')

        self.username_re = pattern_manager.pattern(self.platform, 'username')
        self.password_re = pattern_manager.pattern(self.platform, 'password')
        self.authentication_error_re = pattern_manager.pattern(self.platform, 'authentication_error')
        self.unable_to_connect_re = pattern_manager.pattern(self.platform, 'unable_to_connect')
        self.timeout_re = pattern_manager.pattern(self.platform, 'timeout')
        self.standby_re = pattern_manager.pattern(self.platform, 'standby')

        self.pid2platform_re = pattern_manager.pattern(self.platform, 'pid2platform')
        self.platform_re = pattern_manager.pattern(self.platform, 'platform', compiled=False)
        self.version_re = pattern_manager.pattern(self.platform, 'version', compiled=False)
        self.vty_re = pattern_manager.pattern(self.platform, 'vty')
        self.console_re = pattern_manager.pattern(self.platform, 'console')