Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff -r 710121307405 sa/profiles/Cisco/IOS/get_inventory.py
- --- a/sa/profiles/Cisco/IOS/get_inventory.py Wed Dec 18 11:20:26 2013 +0400
- +++ b/sa/profiles/Cisco/IOS/get_inventory.py Mon Dec 30 11:18:30 2013 +0400
- @@ -20,42 +20,165 @@
- rx_item = re.compile(
- r"^NAME: \"(?P<name>[^\"]+)\", DESCR: \"(?P<descr>[^\"]+)\"\n"
- - r"PID:\s+(?P<pid>\S+)?\s*,\s+VID:\s+(?P<vid>\S+)?\s*, SN: (?P<serial>\S+)",
- + r"PID:\s+(?P<pid>\S+)?\s*,\s+VID:\s+(?P<vid>\S+[^\,]+)?\s*, SN: (?P<serial>\S+)",
- re.MULTILINE | re.DOTALL
- )
- + rx_csn = re.compile("[A-Z]{3}\w{4}\w{4}")
- rx_trans = re.compile("((?:100|1000|10G)BASE\S+)")
- + rx_int = re.compile("([a-z,A-Z]+(\d+\/)+\d+)")
- + rx_cvend = re.compile("(CISCO.(?P<ven>\S{3,15}))")
- + rx_trans_6k = re.compile(
- + r"\s*Vendor Name\s+(:|=)(\s+)?(?P<t_vendor>\S+[\S ]*)\n"
- + r"(\s*Vendor OUI\s+(:|=)(\s+)?[\S+ ]*(\s+)?\n)?"
- + r"\s*Vendor (PN|Part No.|Part Number)\s+(:|=)(\s+)?(?P<t_part_no>\S+[\S ]*)\n"
- + r"\s*Vendor (rev|Revision|Part Rev.)\s+(:|=)(\s+)?(?P<t_rev>\S+[\S ]*)?\n"
- + r"\s*Vendor (SN|Serial No.|Serial Number)\s+(:|=)(\s+)?(?P<t_sn>\S+)(\s+)?\n",
- + re.IGNORECASE | re.MULTILINE | re.DOTALL
- + )
- IGNORED_NAMES = set([
- "c7201"
- ])
- + IGNORED_SERIAL = set([
- + "H22L714"
- + ])
- +
- +
- def execute(self):
- objects = []
- v = self.cli("show inventory")
- for match in self.rx_item.finditer(v):
- + vendor = None
- if match.group("name") in self.IGNORED_NAMES:
- continue
- type, number, part_no = self.get_type(
- match.group("name"), match.group("pid"),
- match.group("descr"), len(objects)
- )
- + serial = match.group("serial") if match.group("serial") not in self.IGNORED_SERIAL else None
- + descr = match.group("descr")
- + vid = match.group("vid")
- + pid = match.group("pid")
- + # If not part_no for transceiver
- + if type == "XCVR":
- + if part_no == "N/A" or "GBIC" in pid:
- + # try idprom
- + try:
- + i = self.rx_int.search(match.group("name"))
- + if i:
- + vendor, serial, vid, pid = self.get_idprom(i.group(1), descr.upper())
- + except:
- + print "Unable to get idprom"
- + # fix gbic_pid noname xcvr
- + if pid == "GBIC_LX" and "Gigabit" in match.group("name"):
- + part_no = self.get_transceiver_pid("1000BASELX")
- + elif pid == "GBIC_ZX" and "Gigabit" in match.group("name"):
- + part_no = self.get_transceiver_pid("1000BASEZX")
- + elif pid == "GBIC_LH" and "Gigabit" in match.group("name"):
- + part_no = self.get_transceiver_pid("1000BASELH")
- + elif pid == "GBIC_T" and "Gigabit" in match.group("name"):
- + part_no = self.get_transceiver_pid("1000BASET")
- + else:
- + if self.rx_trans.search(pid):
- + part_no = self.get_transceiver_pid(pid)
- + else:
- + part_no = pid
- +
- if not part_no:
- print "!!! UNKNOWN: ", match.groupdict()
- continue
- else:
- - vendor = "CISCO" if "NoName" not in part_no else "NONAME"
- + if not vendor:
- + if "NoName" in part_no or "Unknown" in part_no:
- + vendor = "NONAME"
- + else:
- + vendor = "CISCO"
- objects += [{
- "type": type,
- "number": number,
- "vendor": vendor,
- - "serial": match.group("serial"),
- - "description": match.group("descr"),
- + "serial": serial,
- + "description": descr,
- "part_no": [part_no],
- - "revision": match.group("vid"),
- + "revision": vid,
- "builtin": False
- }]
- +
- + #if not transceiver in "sh inv" output - 6500 series gbic cards and sup
- + if ((type == "LINECARD" or type == "SUP") and
- + "RJ45" not in match.group("descr") and
- + ("WS-X64" in match.group("descr") or
- + "WS-X6K" in match.group("descr"))):
- + i = self.cli("show interface status module " + str(number))
- + for s in i.split("\n"):
- + if not s or "No Transceiver" in s or s.startswith("Port"):
- + continue
- + else:
- + t_num = s.split()[0].split("/")[-1]
- + t_vendor, t_sn, t_rev, pid = self.get_idprom(s.split()[0], s.split()[-1].upper())
- + objects += [{
- + "type": "XCVR",
- + "number": t_num,
- + "vendor": t_vendor,
- + "serial": t_sn,
- + "description": s.split()[-1] + " Transceiver",
- + "part_no": [pid],
- + "revision": t_rev,
- + "builtin": False
- + }]
- +
- return objects
- + def get_idprom(self, int, descr):
- + try:
- + t = self.cli("show idprom int " + int + " | i Vendor")
- + match = self.rx_trans_6k.search(t)
- + if match:
- + # Check Cisco-standart format SN
- + if self.rx_csn.search(match.group("t_sn")):
- + t_vendor = "CISCO"
- + v = self.rx_cvend.search(match.group("t_vendor").upper())
- + if v and "SYSTEMS" not in v.group("ven"):
- + t_vendor = v.group("ven")
- + else:
- + # China noname products with "CISCO-" or "OEM" vendor
- + if ("CISCO" in match.group("t_vendor").upper() or
- + "OEM" in match.group("t_vendor").upper()):
- + t_vendor = "NONAME"
- + else:
- + # Others vendors
- + t_vendor = match.group("t_vendor").upper().strip()
- +
- + # Ignored serial
- + t_sn = match.group("t_sn") if match.group("t_sn") not in self.IGNORED_SERIAL else None
- +
- + # Decode hex revision (need rewrite)
- + if match.group("t_rev"):
- +# if "0x" in match.group("t_rev"):
- +# t_rev = None
- +# else:
- + t_rev = match.group("t_rev").strip()
- + else:
- + t_rev = None
- + if self.rx_trans.search(match.group("t_part_no").upper().replace("-", "")):
- + pid = self.get_transceiver_pid(match.group("t_part_no"))
- + else:
- + if ("GBIC-LX" in match.group("t_part_no") and
- + "Gi" in int):
- + pid = self.get_transceiver_pid("1000BASELX")
- + else:
- + if "NONAME" in t_vendor and self.rx_trans.search(descr):
- + pid = self.get_transceiver_pid(descr)
- + else:
- + pid = match.group("t_part_no").strip()
- + return t_vendor, t_sn, t_rev, pid
- + else:
- + return None, None, None, None
- + except self.CLISyntaxError:
- + print "sh idprom command not supported"
- +
- +
- def get_type(self, name, pid, descr, lo):
- """
- Get type, number and part_no
- @@ -81,26 +204,34 @@
- else:
- number = None
- if pid in ("", "N/A", "Unspecified") or self.rx_trans.search(pid):
- - # Non-Cisco transceivers
- - pid = self.get_transceiver_pid(descr)
- - if not pid:
- - return None, None, None
- - else:
- - return "XCVR", number, pid
- + return "XCVR", number, "N/A"
- else:
- return "XCVR", number, pid
- - elif lo == 0 or pid.startswith("CISCO") or pid.startswith("WS-C"):
- + elif "FRU" in descr:
- + return None, None, None
- + elif (lo == 0 or pid.startswith("CISCO") or
- + (pid.startswith("WS-C") and "PS" not in name)):
- try:
- number = int(name)
- except ValueError:
- number = None
- return "CHASSIS", number, pid
- - elif name.startswith("module "):
- + elif name.startswith("module ") or pid.startswith("WS-X"):
- # Linecards or supervisors
- - if pid.startswith("RSP"):
- - return "SUP", name[7:], pid
- + try:
- + number = int(name)
- + except ValueError:
- + number = None
- + if pid.startswith("RSP") or "SUP" in pid:
- + if not number:
- + return "SUP", name[7:], pid
- + else:
- + return "SUP", str(number), pid
- else:
- - return "LINECARD", name[7:], pid
- + if not number:
- + return "LINECARD", name[7:], pid
- + else:
- + return "LINECARD", number, pid
- elif "-DFC" in pid or "-CFC" in pid:
- # DFC subcard
- return "DFC", None, pid
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement