profile.py 1.81 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"),
Charlie Root's avatar
Charlie Root committed
21
    ]
22
23
24
    username_submit = b"\r"
    password_submit = b"\r"
    command_submit = b"\r"
25
    # command_disable_pager = "terminal length 200"
26
    command_super = b"enable"
27
    command_exit = "exit"
28
    config_tokenizer = "indent"
Dmitry Volodin's avatar
Dmitry Volodin committed
29
    config_tokenizer_settings = {"line_comment": "!"}
Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
30

31
32
33
34
35
36
37
38
39
40
    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
41
42
        elif "% Unrecognized command" in c:  # Return to normal prompt
            script.cli("", ignore_errors=True)
43

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

    @classmethod
    def get_interface_type(cls, name):
        if name == "Ethernet0":
            return "management"
        return cls.INTERFACE_TYPES.get(name[:4])