profile.py 2.09 KB
Newer Older
Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
1
2
3
4
# ---------------------------------------------------------------------
# Vendor: NAG
# OS:     SNR
# ---------------------------------------------------------------------
Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
5
# Copyright (C) 2007-2022 The NOC Project
Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
6
7
# See LICENSE for details
# ---------------------------------------------------------------------
8

9
10
11
# Python modules
import re

Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
12
# NOC modules
Dmitry Volodin's avatar
Dmitry Volodin committed
13
from noc.core.profile.base import BaseProfile
14
15


Dmitry Volodin's avatar
Dmitry Volodin committed
16
class Profile(BaseProfile):
17
    name = "NAG.SNR"
Charlie Root's avatar
Charlie Root committed
18
    pattern_more = [
19
20
        (rb"^ --More-- ", b"\n"),
        (rb"^Confirm to overwrite current startup-config configuration \[Y/N\]:", b"y\n"),
Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
21
        (rb"^\.\.\.\.press ENTER to next line, Q to quit, other key to next page\.\.\.\.", b" "),
Charlie Root's avatar
Charlie Root committed
22
    ]
Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
23
    pattern_syntax_error = rb"% (?:Unrecognized|Incomplete) command, and error detected at"
24
25
26
    username_submit = b"\r"
    password_submit = b"\r"
    command_submit = b"\r"
27
    # command_disable_pager = "terminal length 200"
28
    command_super = b"enable"
29
    command_exit = "exit"
30
    config_tokenizer = "indent"
Dmitry Volodin's avatar
Dmitry Volodin committed
31
    config_tokenizer_settings = {"line_comment": "!"}
Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
32

33
34
35
36
37
38
39
40
41
42
    rx_pager = re.compile(r"0 for no pausing")

    def setup_session(self, script):
        # For old models
        script.cli("terminal length 200", ignore_errors=True)
        # For new models
        c = script.cli("terminal length ?", command_submit=b"", ignore_errors=True)
        match = self.rx_pager.search(c)
        if match:
            script.cli("\x01\x0bterminal length 0", ignore_errors=True)
Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
43
44
        elif "% Unrecognized command" in c:  # Return to normal prompt
            script.cli("", ignore_errors=True)
45

Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
46
47
    INTERFACE_TYPES = {
        "Ethe": "physical",  # Ethernet
Dmitry Lukhtionov's avatar
Fix    
Dmitry Lukhtionov committed
48
        "Vlan": "SVI",  # Vlan
Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
49
        "syst": "SVI",  # system
Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
50
        "Port": "aggregated",  # Port-Channel
Dmitry Lukhtionov's avatar
Fix    
Dmitry Lukhtionov committed
51
        "Vsf-": "aggregated",  # Vsf-Port
Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
52
53
54
55
56
57
58
59
        "vpls": "unknown",  # vpls_dev
        "l2ov": "tunnel",  # l2overgre
    }

    @classmethod
    def get_interface_type(cls, name):
        if name == "Ethernet0":
            return "management"
Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
60
61
        if name.startswith("e0/"):
            return "physical"
Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
62
        return cls.INTERFACE_TYPES.get(name[:4])