get_version.py 1.59 KB
Newer Older
Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
1
2
3
4
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------
# Qtech.QOS.get_version
# ---------------------------------------------------------------------
5
# Copyright (C) 2007-2019 The NOC Project
Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
6
7
8
9
10
# See LICENSE for details
# ---------------------------------------------------------------------

# Python modules
import re
11

Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# NOC modules
from noc.core.script.base import BaseScript
from noc.sa.interfaces.igetversion import IGetVersion


class Script(BaseScript):
    name = "Qtech.QOS.get_version"
    interface = IGetVersion
    cache = True

    rx_ver = re.compile(
        r"^Product Name: (?P<platform>\S+)\s*\n"
        r"^Hardware Version: (?P<hardware>\S+)\s*\n"
        r"^Bootstrap Version: (?P<bootprom>\S+)\s*\n"
        r"^Software Version: QOS_(?P<version>\S+)\s*\n"
        r"^PCB Version: .+\n"
28
        r"(^FPGA Version: .+\n)?"
Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
29
30
        r"^CPLD Version: .+\n"
        r"^QOS Version: .+\n"
31
        r"(^BOM Version: .+\n)?"
Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
32
33
34
35
        r"^Compiled .+\n"
        r"^\s*\n"
        r"^System MacAddress: (?P<mac>\S+)\s*\n"
        r"^Serial number: (?P<serial>\S+)\s*\n",
36
        re.MULTILINE,
Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
37
38
39
40
41
42
43
44
45
46
47
48
    )

    def execute(self):
        ver = self.cli("show version", cached=True)
        match = self.rx_ver.search(ver)
        return {
            "vendor": "Qtech",
            "platform": match.group("platform"),
            "version": match.group("version"),
            "attributes": {
                "Boot PROM": match.group("bootprom"),
                "HW version": match.group("hardware"),
49
50
                "Serial Number": match.group("serial"),
            },
Dmitry Lukhtionov's avatar
Dmitry Lukhtionov committed
51
        }