Advertisement
Izya12

NetXpert/get_version.py

Apr 28th, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.82 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. # ---------------------------------------------------------------------
  3. # Nateks.flexgain.get_version
  4. # ---------------------------------------------------------------------
  5. # Copyright (C) 2007-2016 The NOC Project
  6. # See LICENSE for details
  7. # ---------------------------------------------------------------------
  8. """
  9. """
  10. # Python modules
  11. import re
  12. # NOC modules
  13. from noc.core.script.base import BaseScript
  14. from noc.sa.interfaces.igetversion import IGetVersion
  15.  
  16.  
  17. class Script(BaseScript):
  18.  
  19.     name = "Nateks.NetXpert.get_version"
  20.     cache = True
  21.     interface = IGetVersion
  22.  
  23.     rx_ver = re.compile(
  24.         r".*Series Software, Version (?P<version>[\S\s]*)\, RELEASE SOFTWARE",
  25.         re.MULTILINE | re.DOTALL | re.IGNORECASE)
  26.     rx_boot = re.compile(
  27.         r".*ROM: System Bootstrap, Version (?P<bootrom>\d+\.\d+\.\d+).*",
  28.         re.MULTILINE | re.DOTALL | re.IGNORECASE)
  29.     rx_sn = re.compile(
  30.         r"Serial num:(?P<sn>[^ ,]+),.*\n",
  31.         re.MULTILINE | re.DOTALL | re.IGNORECASE)
  32.     rx_plat = re.compile(
  33.         r"Nateks (?P<platform>.*) RISC",
  34.         re.MULTILINE | re.DOTALL | re.IGNORECASE)
  35.  
  36.     def execute(self):
  37.         v = self.cli("show version", cached=True)
  38.         match = self.rx_ver.search(v)
  39.         version = match.group("version")
  40.         match = self.rx_boot.search(v)
  41.         bootrom = match.group("bootrom")
  42.         match = self.rx_sn.search(v)
  43.         sn = match.group("sn")
  44.         match = self.rx_plat.search(v)
  45.         platform = match.group("platform")
  46.  
  47.         return {
  48.             "vendor": "Nateks",
  49.             "platform": match.group("platform"),
  50.             "version": match.group("version"),
  51.             "attributes": {
  52.                 "Boot PROM": match.group("bootrom"),
  53.                 "SN": match.group("sn"),
  54.             }
  55.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement