get_inventory.py 3.05 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------
# Zhone.Bitstorm.get_inventory
# ---------------------------------------------------------------------
# Copyright (C) 2007-2019 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------

# Python modules
import re

# NOC modules
from noc.core.script.base import BaseScript
from noc.sa.interfaces.igetinventory import IGetInventory


class Script(BaseScript):
    name = "Zhone.Bitstorm.get_inventory"
    interface = IGetInventory

    rx_card = re.compile(
        r"^(?P<part_no>\S+ [Cc]ard)\s*\n"
        r"(^HW Rev\s+(?P<revision>\S+)\s*\n)?"
        r"(^PLD Rev\s+\S+\s*\n)?"
        r"(^Serial Number(?P<serial>\S+)\s*\n)?",
        re.MULTILINE,
    )

    PLATFORMS = {
        "4214-A1-520": "24p ReachDSL, T1 MLPPP, No Splitters",
        "4214-A1-522": "24p ReachDSL, E1 MLPPP, No Splitters",
        "4214-A1-530": "24p ReachDSL, T1 MLPPP, w/Internal Splitters",
        "4214-A1-531": "24p ReachDSL, E1 MLPPP, w/Internal 600ohm Splitters",
        "4214-A1-532": "24p ReachDSL, E1 MLPPP, w/Internal Splitters",
        "4219-A2-520": "24p ReachDSL, GigE Uplink, No Splitters",
        "4219-A2-530": "24p ReachDSL, GigE Uplink, w/Internal Splitters",
        "4219-A2-531": "24p ReachDSL, GigE Uplink, w/Internal 600 ohm Splitters",
        "4224-A1-520": "24p ADSL2+, T1 MLPPP Uplink, No Splitters",
        "4224-A1-522": "24p ADSL2+, E1 MLPPP Uplink, No Splitters",
        "4224-A1-530": "24p ADSL2+, T1 MLPPP Uplink, w/Internal Splitters",
        "4224-A1-531": "24p ADSL2+, E1 MLPPP Uplink, w/Internal 600ohm Splitters",
        "4224-A1-532": "24p ADSL2+, E1 MLPPP Uplink, w/Internal Splitters",
        "4229-A3-520": "24p ADSL2+, GigE Uplink, No Splitters",
        "4229-A3-530": "24p ADSL2+, GigE Uplink, w/Internal Splitters",
        "4229-A3-531": "24p ADSL2+, GigE Uplink, w/Internal 600 ohm Splitters",
        "4234-A1-522": "24p ADSL2+, E1 MLPPP Uplink, No Splitters",
        "4234-A1-532": "24p ADSL2+, E1 MLPPP Uplink, w/Internal ISDN Splitter",
        "4239-A3-520": "24p ADSL2+ Annex B, GigE Uplink, No Splitters",
        "4239-A3-532": "24p ADSL2+ Annex B, GigE Uplink, w/Internal ISDN Splitters",
    }

    def execute_cli(self):
        v = self.scripts.get_version()
        r = {"type": "CHASSIS", "vendor": "ZHONE", "part_no": [v["platform"]]}
        if "attributes" in v and "Serial Number" in v["attributes"]:
            r["serial"] = v["attributes"]["Serial Number"]
        if self.PLATFORMS.get(v["platform"]):
            r["description"] = self.PLATFORMS.get(v["platform"])
        res = [r]
        v = self.cli("show system information", cached=True)
        for match in self.rx_card.finditer(v):
            r = {"type": "CARD", "vendor": "ZHONE", "part_no": [match.group("part_no")]}
            if match.group("revision"):
                r["revision"] = match.group("revision")
            if match.group("serial"):
                r["serial"] = match.group("serial")
            res += [r]
        return res