Advertisement
Guest User

get_lldp_neighbors.py

a guest
Apr 21st, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.10 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. # ---------------------------------------------------------------------
  3. # InfiNet.WANFlexX.get_lldp_neighbors
  4. # ---------------------------------------------------------------------
  5. # Copyright (C) 2007-2017 The NOC Project
  6. # See LICENSE for details
  7. # ---------------------------------------------------------------------
  8.  
  9. # Python modules
  10. import re
  11. # NOC modules
  12. from noc.core.script.base import BaseScript
  13. from noc.sa.interfaces.igetlldpneighbors import IGetLLDPNeighbors
  14. from noc.lib.validators import is_int, is_ipv4, is_ipv6, is_mac
  15. from noc.sa.interfaces.base import MACAddressParameter, IPv4Parameter
  16.  
  17.  
  18. class Script(BaseScript):
  19.     name = "InfiNet.WANFlexX.get_lldp_neighbors"
  20.     interface = IGetLLDPNeighbors
  21.  
  22.     rx_chassis_id = re.compile(
  23.         r"ChassisID:    \|\s*(?P<id>\S+)", re.MULTILINE | re.IGNORECASE)
  24.  
  25.     def execute(self):
  26.         v = self.cli("lldp report")
  27.  
  28.         match = self.rx_chassis_id.search(v)
  29.         if match:
  30.             lldp = match.group("id")
  31.             return lldp
  32.         else:
  33.             raise self.UnexpectedResultError()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement