get_version.py 3.73 KB
Newer Older
Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
1
2
3
# ---------------------------------------------------------------------
# SKS.SKS.get_version
# ---------------------------------------------------------------------
4
# Copyright (C) 2007-2021 The NOC Project
Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
5
6
# See LICENSE for details
# ---------------------------------------------------------------------
7

Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
8
# Python modules
9
import re
Dmitry Volodin's avatar
Dmitry Volodin committed
10

Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
11
# NOC modules
12
13
from noc.core.script.base import BaseScript
from noc.sa.interfaces.igetversion import IGetVersion
kk's avatar
kk committed
14
from noc.core.text import parse_table
15
16
17
18
19


class Script(BaseScript):
    name = "SKS.SKS.get_version"
    interface = IGetVersion
Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
20
    cache = True
21
22
23
24

    rx_ver = re.compile(
        r"^\s*SW version\s+(?P<version>\S+).*\n"
        r"^\s*Boot version\s+(?P<bootprom>\S+).*\n"
Dmitry Volodin's avatar
Dmitry Volodin committed
25
26
27
28
29
        r"^\s*HW version\s+(?P<hardware>\S+).*\n",
        re.MULTILINE,
    )
    rx_platform = re.compile(r"^\s*System Description:\s+(?P<platform>.+)\n", re.MULTILINE)
    rx_serial = re.compile(r"^\s*Serial number : (?P<serial>\S+)")
30

Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
31
    rx_ver2 = re.compile(
32
33
        r"^(?P<platform>S(?:KS|WA)\-\S+) Series Software, Version (?P<version>\S+(?: Build \d+)?)",
        re.MULTILINE,
Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
34
35
36
37
    )
    rx_rs = re.compile(
        r"^ROM: System Bootstrap, Version (?P<bootprom>\S+),\s*"
        r"hardware version:\s*(?P<hardware>\S+)\s*\n"
Dmitry Volodin's avatar
Dmitry Volodin committed
38
39
40
        r"^Serial num:\s*(?P<serial>\w+),?",
        re.MULTILINE,
    )
Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
41

Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
42
    def execute_cli(self):
43
        v = self.cli("show version", cached=True)
Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
44
45
46
47
48
49
50
        match = self.rx_ver.search(v)
        if match:
            r = {
                "vendor": "SKS",
                "version": match.group("version"),
                "attributes": {
                    "Boot PROM": match.group("bootprom"),
Dmitry Volodin's avatar
Dmitry Volodin committed
51
52
                    "HW version": match.group("hardware"),
                },
Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
53
54
55
56
57
58
59
            }
            v = self.cli("show system", cached=True)
            match = self.rx_platform.search(v)
            platform = match.group("platform")
            if platform == "SKS 10G":
                platform = "SKS-16E1-IP-1U"
            elif platform.startswith("SKS"):
Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
60
                platform = "SKS-16E1-IP"
Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
61
62
            r["platform"] = platform
            v = self.cli("show system id", cached=True)
Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
63
            match = self.rx_serial.search(v)
64
65
            if match:
                r["attributes"]["Serial Number"] = match.group("serial")
Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
66
67
        else:
            match = self.rx_ver2.search(v)
Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
68
69
70
71
            if match:
                r = {
                    "vendor": "SKS",
                    "platform": match.group("platform"),
Dmitry Volodin's avatar
Dmitry Volodin committed
72
                    "version": match.group("version"),
Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
73
74
75
76
77
                }
                match = self.rx_rs.search(v)
                r["attributes"] = {
                    "Boot PROM": match.group("bootprom"),
                    "HW version": match.group("hardware"),
Dmitry Volodin's avatar
Dmitry Volodin committed
78
                    "Serial Number": match.group("serial"),
Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
79
80
81
82
83
84
85
                }
            else:
                t = parse_table(v)
                for i in t:
                    r = {
                        "vendor": "SKS",
                        "version": i[1],
Dmitry Volodin's avatar
Dmitry Volodin committed
86
                        "attributes": {"Boot PROM": i[2], "HW version": i[3]},
Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
87
88
89
90
91
92
93
94
95
96
                    }
                    break
                v = self.cli("show system", cached=True)
                t = parse_table(v)
                for i in t:
                    platform = i[1]
                    break
                if platform == "SKS 10G":
                    platform = "SKS-16E1-IP-1U"
                elif platform.startswith("SKS"):
Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
97
                    platform = "SKS-16E1-IP"
Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
98
99
100
101
102
103
104
105
                r["platform"] = platform
                v = self.cli("show system id", cached=True)
                t = parse_table(v)
                for i in t:
                    serial = i[1]
                    break
                r["attributes"]["Serial Number"] = serial

106
        return r