Ejemplo n.º 1
0
 def parse_chassis(cls, data):
     objects = []
     parts = data.split("\n\n")
     # Chassis section
     _, ctable = parts[0].split("\n", 1)
     n = 0
     for part_no, description in parse_table(ctable):
         objects += [{
             "type": "CHASSIS",
             "number": str(n),
             "vendor": "ARISTA",
             "serial": None,
             "description": description,
             "part_no": part_no,
             "revision": None,
             "builtin": False,
         }]
         n += 1
     # Serial/revision section
     n = 0
     for rev, serial, mfg_data in parse_table(parts[1]):
         objects[n]["revision"] = rev
         objects[n]["serial"] = serial
         n += 1
     return objects
Ejemplo n.º 2
0
 def execute(self):
     interfaces = []
     lldp = self.get_lldp()
     ctp = self.get_ctp()
     for i in parse_table(self.cli("show interface  switchport")):
         iface = {
             "name":
             i[0],
             "type":
             "physical",
             "enabled_protocols": [],
             "subinterfaces": [{
                 "name": i[0],
                 "enabled_afi": ["BRIDGE"],
                 "untagged_vlan": i[1]
             }],
         }
         if i[0] in lldp:
             iface["enabled_protocols"] += ["LLDP"]
         if i[0] in ctp:
             iface["enabled_protocols"] += ["CTP"]
         interfaces += [iface]
     for v in parse_table(self.cli("show vlan"), max_width=80):
         if not is_int(v[0]):
             continue
         vlan_id = v[0]
         ports = self.expand_rangelist(v[2])
         for i in interfaces:
             if i["subinterfaces"][0]["untagged_vlan"] == vlan_id:
                 continue
             if int(i["name"]) in ports:
                 if "tagged_vlans" in i["subinterfaces"][0]:
                     i["subinterfaces"][0]["tagged_vlans"] += [vlan_id]
                 else:
                     i["subinterfaces"][0]["tagged_vlans"] = [vlan_id]
     mac = self.scripts.get_chassis_id()[0]["first_chassis_mac"]
     match = self.rx_ipif.search(self.cli("show ip interface"))
     ip = match.group("ip")
     mask = match.group("mask")
     ip_address = "%s/%s" % (ip, IPv4.netmask_to_len(mask))
     iface = {
         "name":
         "mgmt",
         "type":
         "SVI",
         "mac":
         mac,
         "subinterfaces": [{
             "name": "mgmt",
             "vlan_ids": match.group("vlan_id"),
             "ipv4_addresses": [ip_address],
             "enabled_afi": ["IPv4"],
             "mac": mac,
         }],
     }
     interfaces += [iface]
     return [{"interfaces": interfaces}]
Ejemplo n.º 3
0
 def execute_cli(self):
     try:
         v = self.cli("sh mod")
     except self.CLISyntaxError:
         v = self.scripts.get_version()
         return [{"type": "CHASSIS", "vendor": "HP", "part_no": v["platform"]}]
     match = self.rx_chassis.search(v)
     r = [
         {
             "type": "CHASSIS",
             "vendor": "HP",
             "part_no": match.group("part_no"),
             "serial": match.group("serial"),
         }
     ]
     match = self.rx_mng.search(v)
     r += [
         {
             "type": "MODULE",
             "vendor": "HP",
             "part_no": match.group("part_no"),
             "serial": match.group("serial"),
         }
     ]
     t = parse_table(v, allow_wrap=True)
     for i in t:
         match = self.rx_linecard.search(i[1])
         r += [
             {
                 "type": "LINECARD",
                 "number": i[0],
                 "vendor": "HP",
                 "part_no": match.group("part_no"),
                 "serial": i[2],
                 "revision": i[5],
                 "description": i[1],
             }
         ]
     v = self.cli("show system power-supply")
     t = parse_table(v, allow_wrap=True)
     for i in t:
         r += [
             {
                 "type": "PSU",
                 "number": i[0],
                 "vendor": "HP",
                 "part_no": i[1],
                 "description": "%s / %s Watt" % (i[3], i[4]),
             }
         ]
     return r
Ejemplo n.º 4
0
 def execute_cli(self):
     r = []
     try:
         s = self.cli("show etherchannel summary")
     except self.CLISyntaxError:
         # Some ASR100X do not have this command
         # raise self.NotSupportedError
         return []
     for i in parse_table(s, allow_wrap=True, max_width=120):
         iface = {"interface": self.extract_iface(i[1]), "members": []}
         if (len(i) == 4) and (i[2] == "LACP"):
             iface["type"] = "L"
         else:
             iface["type"] = "S"
         for ifname in i[len(i) - 1].split():
             # Found on some ASR100X
             #
             # Group  Port-channel  Protocol    Ports
             # ------+-------------+-----------+-----------------------------------------------
             # 1       Po1(RD)
             # 55      Po55(RU)                LACP     Gi1/1/0(bndl) Gi1/1/1(bndl)
             if ifname == "ACP":
                 iface["type"] = "L"
                 continue
             iface["members"] += [self.extract_iface(ifname)]
         r += [iface]
     return r
Ejemplo n.º 5
0
 def execute(self):
     v = self.cli("show system information", cached=True)
     platform = "Unknown"
     version = ""
     if "Paradyne DSLAM" in v or "Zhone DSLAM" in v:
         match = self.rx_ver2.match(v)
         if match:
             platform = match.group("description")
             platform = platform.split(";")[1].split(":")[1].strip()
         v = self.cli("show system status", cached=True)
         v = parse_table(v)
         for l in v:
             # if "Slot A (SCP)" in l[0]:
             if "SCP" in l[0] or "MCP" in l[0]:
                 version = l[1]
     else:
         match = self.re_search(self.rx_ver, v)
         version = match.group("version")
         # v = self.cli("slots", cached=True)
         # match = self.re_search(self.rx_platform, v)
         platform = match.group("platform")
     r = {"vendor": "Zhone", "version": version, "platform": platform}
     if "serial" in match.groupdict():
         r["attributes"] = {}
         r["attributes"]["Serial Number"] = match.group("serial")
     return r
Ejemplo n.º 6
0
 def execute_cli(self, **kwargs):
     res = [{
         "type": "CHASSIS",
         "vendor": "ELTEX",
         "part_no": "MA4000",
     }]
     for i in [1, 2]:
         v = self.cli("show system information %d" % i, cached=True)
         match = self.rx_serial.search(v)
         if match:
             r = {
                 "type": "SUP",
                 "number": i,
                 "vendor": "ELTEX",
                 "serial": match.group("serial"),
                 "part_no": "PP4X",
             }
             res += [r]
     v = self.cli("show shelf")
     for i in parse_table(v):
         if i[2] == "none":
             continue
         c = self.cli("show slot %s information" % i[0])
         match = self.rx_slot.search(c)
         r = {
             "type": "LINECARD",
             "number": i[0],
             "vendor": "ELTEX",
             "serial": i[4],
             "part_no": match.group("part_no"),
             "revision": match.group("revision"),
         }
         res += [r]
         sfp = []
         c = self.cli("show interface gpon-port %s/all state" % i[0])
         match = self.rx_gpon_port.search(c)
         if not match:
             continue
         items = self.rx_sep.split(match.group(1))
         for i in range(64):  # Maximum value
             try:
                 sfp += [{"number": items[i].strip(), "type": "XCVR"}]
             except IndexError:
                 break
         sfp_count = i
         match = self.rx_gpon_vendor.search(c)
         items = self.rx_sep.split(match.group(1))
         for i in range(sfp_count):
             sfp[i]["vendor"] = items[i].strip()
         match = self.rx_gpon_part_no.search(c)
         items = self.rx_sep.split(match.group(1))
         for i in range(sfp_count):
             sfp[i]["part_no"] = items[i].strip()
         match = self.rx_gpon_rev.search(c)
         items = self.rx_sep.split(match.group(1))
         for i in range(sfp_count):
             sfp[i]["revision"] = items[i].strip()
         for i in range(sfp_count):
             res += [sfp[i]]
     return res
Ejemplo n.º 7
0
    def execute(self, interface=None):
        if self.is_ne_platform:
            return self.execute_ne(interface=interface)
        if self.is_ar:
            return self.execute_ar(interface=interface)
        cmd = "display transceiver diagnosis interface"
        if interface is not None:
            cmd += " %s" % interface
        try:
            c = self.cli(cmd)
        except self.CLISyntaxError:
            return []

        r = []
        for block in c.split("\n\n"):
            match = self.rx_port.search(block)
            if match:
                iface = {"interface": match.group("port")}
                t = parse_table(block)
                for i in t:
                    if i[0] == "TxPower(dBm)":
                        iface["optical_tx_dbm"] = i[1]
                    if i[0] == "RxPower(dBm)":
                        iface["optical_rx_dbm"] = i[1]
                    if i[0] == "Current(mA)":
                        iface["current_ma"] = i[1]
                    if i[0] == "Temp.(C)":
                        iface["temp_c"] = i[1]
                    if i[0] == "Voltage(V)":
                        iface["voltage_v"] = i[1]
                if t:
                    r += [iface]
        return r
Ejemplo n.º 8
0
 def execute(self):
     r = []
     for i in parse_table(self.cli("show lldp remote-device all")):
         if not i[1]:
             continue
         c = self.cli("show lldp remote-device detail %s" % i[0])
         iface = {"local_interface": i[0], "neighbors": []}
         for match in self.rx_detail.finditer(c):
             cap = 0
             for c in match.group("caps").split(","):
                 c = c.strip()
                 if c:
                     cap |= self.CAPS_MAP[c]
             n = {
                 "remote_chassis_id": match.group("chassis_id").strip(),
                 "remote_chassis_id_subtype": self.CHASSIS_SUBTYPE[
                     match.group("chassis_id_subtype").strip()
                 ],
                 "remote_port": match.group("port_id").strip(),
                 "remote_port_subtype": self.PORT_SUBTYPE[
                     match.group("port_id_subtype").strip()
                 ],
                 "remote_capabilities": cap,
             }
             if match.group("system_name").strip():
                 n["remote_system_name"] = match.group("system_name").strip()
             if match.group("system_description").strip():
                 n["remote_system_description"] = match.group("system_description").strip()
             if match.group("port_description").strip():
                 n["remote_port_description"] = match.group("port_description").strip()
             iface["neighbors"] += [n]
         r += [iface]
     return r
Ejemplo n.º 9
0
 def execute(self, interface=None):
     r = []
     for i in parse_table(self.cli("show arp")):
         if interface is not None and interface != i[2]:
             continue
         r += [{"ip": i[0], "mac": i[1], "interface": i[2]}]
     return r
Ejemplo n.º 10
0
 def execute(self, interface=None):
     r = []
     for i in parse_table(self.cli("show ip arp"), expand_columns=True):
         if interface is not None and interface != i[3]:
             continue
         r += [{"ip": i[0], "mac": i[1], "interface": i[3]}]
     return r
Ejemplo n.º 11
0
 def get_ports_attrs(self, cli_stp, sep):
     """
     Get port attributes (Link type and edge status)
     :param cli_stp:
     :return: hash of port -> {link_type: , edge, role, status}
     """
     ports = {}  # instance -> port -> attributes
     instance_id = 0
     for instance in cli_stp.split(sep):
         match = self.rx_ins.search(instance)
         if match:
             instance_id = int(match.group("instance"))
         ports[instance_id] = {}
         for I in parse_table(instance):
             # On  MES-3124F version 2.5.48.5[aa39f5d3] found strange line:
             # \r\n                            0                                               \r\n
             if not I[0]:
                 continue
             interface = I[0]
             priority = I[2].split(".")[0]
             ports[instance_id][interface] = {
                 "status": I[1].lower() == "enabled",
                 "priority": priority,
                 "port_id": I[2],
                 "cost": I[3],
                 "state": self.PORT_STATE[I[4].lower()],
                 "role": self.PORT_ROLE[I[5].lower()],
                 "point_to_point": "p2p" in I[7].lower().split(" "),
             }
     return ports
Ejemplo n.º 12
0
    def execute_cli(self, **kwargs):
        v = self.scripts.get_version()
        res = [{
            "type": "CHASSIS",
            "vendor": "ELTEX",
            "part_no": v["platform"],
            "serial": v["attributes"]["Serial Number"],
        }]

        try:
            v = self.cli("show fiber-ports optical-transceiver-info all")
            for i in parse_table(v):
                r = {
                    "type": "XCVR",
                    "number": i[0].split("/")[-1],
                    "vendor": i[2],
                    "serial": i[5],
                    "part_no": i[6],
                }
                if i[2] == "OEM":
                    if i[9] == "1000LX":
                        r["part_no"] = "NoName | Transceiver | 1G | SFP LX"
                    elif i[9] == "10GBase-LR":
                        r["part_no"] = "NoName | Transceiver | 10G | SFP+ LR"
                    else:
                        raise self.NotSupportedError()
                if i[8]:
                    r["revision"] = i[8]
                res += [r]
        except self.CLISyntaxError:
            pass

        return res
Ejemplo n.º 13
0
    def execute(self):
        tagged = defaultdict(list)
        # untagged = defaultdict(list)
        va = self.cli("adsl pvc show")
        vl = self.cli("switch vlan show *")
        r = []

        for line in parse_table(va):
            r += [{
                "interface": line[0],
                "untagged": line[3],
                "tagged": [],
                "members": []
            }]
        for match in self.rx_vlan.finditer(vl):
            up = 0
            if match.group("vstatus") == "enabled":
                for i in match.group("uplinkmask"):
                    up += 1
                    if i == "T":
                        tagged[up] += [match.group("vid")]
                    # if i == "U":
                    # untagged[up]+=[match.group("vid")]
        for i in range(up):
            r += [{
                "interface": "enet" + str(i + 1),
                "802.1Q Enabled": True,
                # "untagged": untagged[i+1],
                "tagged": tagged[i + 1],
                "members": [],
            }]
        return r
Ejemplo n.º 14
0
 def execute(self, vrf=None):
     r = []
     c = self.cli("show ipv6 neighbors", cached=True)
     for ifname, ip, mac, state, age in parse_table(c):
         if "." in ifname:
             ifname, vlan_id = ifname.split(".")
         found = False
         for i in r:
             if (ifname == i["interface"]) and (ip == i["ip"]):
                 found = True
                 break
         if found:
             continue
         if mac == "--":
             r += [{
                 "ip": ip,
                 "interface": ifname,
                 "state": self.s_map[state]
             }]
         else:
             r += [{
                 "ip": ip,
                 "mac": mac,
                 "interface": ifname,
                 "state": self.s_map[state]
             }]
     return r
Ejemplo n.º 15
0
 def execute_cli(self):
     r = []
     v = self.cli("show vlan brief", cached=True)
     t = parse_table(v, allow_wrap=True)
     for i in t:
         r += [{"vlan_id": int(i[0]), "name": i[1]}]
     return r
Ejemplo n.º 16
0
 def has_stack(self):
     """
     Check stack members
     :return:
     """
     r = self.cli("show version", cached=True)
     return [e[0] for e in parse_table(r)]
Ejemplo n.º 17
0
 def get_ip_interfaces(self):
     r = {}
     v = self.cli("show ip interface brief")
     v = parse_table(v)
     for row in v:
         ifname = row[0]
         iftype = self.profile.get_interface_type(ifname)
         r[ifname] = {
             "name":
             ifname,
             "type":
             iftype,
             "admin_status":
             row[3] == "UP",
             "description":
             ifname,
             "oper_status":
             row[3] == "UP",
             "subinterfaces": [{
                 "name": ifname,
                 "ipv4_addresses": [row[1]],
                 "enabled_afi": ["IPv4"],
                 "vlan_ids": [int(ifname.split()[-1])],
             }],
         }
     return r
Ejemplo n.º 18
0
 def execute(self, interface=None, vlan=None, mac=None):
     r = []
     c = self.cli("show mac-address-table")
     for i in parse_table(c, max_width=80):
         mtype = i[0].lower()
         vlan_id = i[1]
         if (vlan is not None) and (vlan != vlan_id):
             continue
         mmac = i[2]
         if (mac is not None) and (mac != mmac):
             continue
         port = i[3]
         if "None" in port:
             continue
         ports = self.expand_rangelist(port.replace(",CPU", ""))
         r += [{
             "vlan_id": vlan_id,
             "mac": mmac,
             "interfaces": ports,
             "type": {
                 "dynami": "D",
                 "static": "S"
             }[mtype],
         }]
     return r
Ejemplo n.º 19
0
 def get_ifindexes(self):
     r = {}
     v = self.cli("show snmp mib ifmib ifIndex")
     v = parse_table(v, max_width=200)
     for row in v:
         r[row[2]] = row[0]
     return r
Ejemplo n.º 20
0
 def execute(self, interface=None):
     r = []
     if interface is None:
         interface = "all"
     c = self.cli("show sfp front-port %s" % interface)
     t = parse_table(c, allow_wrap=True)
     for i in t:
         port = " ".join(i[0].split())
         if not port.startswith("front-port"):
             continue
         temp_c = i[1]
         if temp_c in ["N/A", "N/S"]:
             temp_c = None
         voltage_v = i[2]
         if voltage_v in ["N/A", "N/S"]:
             voltage_v = None
         current_ma = i[3]
         if current_ma in ["N/A", "N/S"]:
             current_ma = None
         optical_rx_dbm = i[4]
         if optical_rx_dbm in ["N/A", "N/S"]:
             optical_rx_dbm = None
         optical_tx_dbm = i[5]
         if optical_tx_dbm in ["N/A", "N/S"]:
             optical_tx_dbm = None
         r += [{
             "interface": port,
             "temp_c": temp_c,
             "voltage_v": voltage_v,
             "current_ma": current_ma,
             "optical_rx_dbm": optical_rx_dbm,
             "optical_tx_dbm": optical_tx_dbm,
         }]
     return r
Ejemplo n.º 21
0
    def execute(self):
        match = self.rx_mac.search(self.cli("show system", cached=True))
        if match:
            return {
                "first_chassis_mac": match.group("mac"),
                "last_chassis_mac": match.group("mac")
            }

        macs = []
        try:
            v = self.cli("show stack", cached=True)
            for i in parse_table(v, footer="Topology is "):
                for m in macs:
                    if m == i[1]:
                        break
                else:
                    macs += [i[1]]
        except self.CLISyntaxError:
            pass

        if macs:
            macs.sort()
            return [{
                "first_chassis_mac": f,
                "last_chassis_mac": t
            } for f, t in self.macs_to_ranges(macs)]
Ejemplo n.º 22
0
 def execute(self):
     r = []
     for v in parse_table(self.cli("show vlan", cached=True), max_width=80):
         if not is_int(v[0]):
             continue
         r += [{"vlan_id": v[0], "name": v[1]}]
     return r
Ejemplo n.º 23
0
    def execute_cli(self, **kwargs):
        v = self.scripts.get_version()
        res = [{
            "type": "CHASSIS",
            "vendor": "ELTEX",
            "part_no": v["platform"],
            "serial": v["attributes"]["Serial Number"],
        }]

        v = self.cli("show shelf")
        for i in parse_table(v):
            if i[2] == "none":
                continue
            c = self.cli("show slot %s information" % i[0])
            match = self.rx_slot.search(c)
            r = {
                "type": "LINECARD",
                "number": i[0],
                "vendor": "ELTEX",
                "serial": i[4],
                "part_no": match.group("part_no"),
                "revision": match.group("revision"),
            }
            res += [r]

        return res
Ejemplo n.º 24
0
 def execute_cli(self):
     interfaces = []
     v = self.cli("show interfaces")
     for match in self.rx_iface.finditer(v):
         ifname = match.group("ifname")
         admin_status = match.group("admin_status") == "up"
         oper_status = match.group("oper_status") == "up"
         iface = {
             "name": ifname,
             "type": self.profile.get_interface_type(ifname),
             "admin_status": admin_status,
             "oper_status": oper_status,
         }
         sub = {
             "name": ifname,
             "admin_status": admin_status,
             "oper_status": oper_status
         }
         if iface["type"] == "physical":
             sub["enable_afi"] = ["BRIDGE"]
             if ifname.startswith("Gi"):
                 sw_ifname = "gigabitethernet %s" % ifname[2:]
             elif ifname.startswith("Fa"):
                 sw_ifname = "fastethernet %s" % ifname[2:]
             elif ifname.startswith("Ex"):
                 sw_ifname = "extreme-ethernet %s" % ifname[2:]
             c = self.cli("show interfaces switchport %s" % sw_ifname)
             for i in parse_table(c):
                 vlan_id = i[0]
                 if i[2] == "Untagged":
                     sub["untagged_vlan"] = vlan_id
                 else:
                     if "tagged_vlans" in sub:
                         sub["tagged_vlans"] += [vlan_id]
                     else:
                         sub["tagged_vlans"] = [vlan_id]
         if iface["name"].startswith("vlan"):
             sub["vlan_ids"] = iface["name"][4:]
         if match.group("mac"):
             mac = match.group("mac").strip()
             iface["mac"] = mac
             sub["mac"] = mac
         if match.group("descr"):
             descr = match.group("descr").strip()
             iface["description"] = descr
             sub["description"] = descr
         iface["subinterfaces"] = [sub]
         interfaces += [iface]
     v = self.cli("show ip interface")
     for match in self.rx_ip_iface.finditer(v):
         ifname = match.group("ifname")
         for i in interfaces:
             if i["name"] == ifname:
                 i["subinterfaces"][0]["enabled_afi"] = ["IPv4"]
                 i["subinterfaces"][0]["ipv4_addresses"] = [
                     match.group("ip")
                 ]
                 break
     return [{"interfaces": interfaces}]
Ejemplo n.º 25
0
 def has_lldp_cli(self):
     """
     Check box has lldp enabled on Eltex
     """
     for i in parse_table(self.cli("show lldp interface all")):
         if i[2] == "Enabled" or i[3] == "Enabled":
             return True
     return False
Ejemplo n.º 26
0
 def has_stack(self):
     """
     Check stack members
     :return:
     """
     v = self.cli("show module")
     v = parse_table(v.replace("\n\n", "\n"))
     return [l[0].split("-")[1] for l in v if "NI-" in l[0]]
Ejemplo n.º 27
0
    def execute_cli(self):
        r = []
        t = parse_table(self.cli("show lldp neighbor"), allow_wrap=True)
        for i in t:
            c = self.cli("show lldp neighbor %s" % i[0])
            match = self.rx_neighbor.search(c)
            chassis_id = match.group("chassis_id")
            if is_ipv4(chassis_id) or is_ipv6(chassis_id):
                chassis_id_subtype = LLDP_CHASSIS_SUBTYPE_NETWORK_ADDRESS
            elif is_mac(chassis_id):
                chassis_id_subtype = LLDP_CHASSIS_SUBTYPE_MAC
            else:
                chassis_id_subtype = LLDP_CHASSIS_SUBTYPE_LOCAL
            port_id = match.group("port_id")
            if is_ipv4(port_id) or is_ipv6(port_id):
                port_id_subtype = LLDP_PORT_SUBTYPE_NETWORK_ADDRESS
            elif is_mac(port_id):
                port_id_subtype = LLDP_PORT_SUBTYPE_MAC
            else:
                port_id_subtype = LLDP_PORT_SUBTYPE_LOCAL
            neighbor = {
                "remote_chassis_id": chassis_id,
                "remote_chassis_id_subtype": chassis_id_subtype,
                "remote_port": port_id,
                "remote_port_subtype": port_id_subtype,
            }
            if match.group("port_descr"):
                port_descr = match.group("port_descr").strip()
                if port_descr:
                    neighbor["remote_port_description"] = port_descr
            if match.group("system_name"):
                system_name = match.group("system_name").strip()
                if system_name:
                    neighbor["remote_system_name"] = system_name
            if match.group("system_descr"):
                system_descr = match.group("system_descr").strip()
                if system_descr:
                    neighbor["remote_system_description"] = system_descr
            caps = 0
            match = self.rx_caps.search(c)
            if match:
                caps = lldp_caps_to_bits(
                    match.group("caps").strip().split(","),
                    {
                        "other": LLDP_CAP_OTHER,
                        "repeater": LLDP_CAP_REPEATER,
                        "bridge": LLDP_CAP_BRIDGE,
                        "access point": LLDP_CAP_WLAN_ACCESS_POINT,
                        "router": LLDP_CAP_ROUTER,
                        "telephone": LLDP_CAP_TELEPHONE,
                        "cable device": LLDP_CAP_DOCSIS_CABLE_DEVICE,
                        "station only": LLDP_CAP_STATION_ONLY,
                    },
                )
            neighbor["remote_capabilities"] = caps

            r += [{"local_interface": i[0], "neighbors": [neighbor]}]
        return r
Ejemplo n.º 28
0
 def execute(self):
     r = []
     try:
         v = self.cli("show lldp neighbors")
         # This is strange behavior, but it helps us
         v = self.blank_line.sub("", v)
     except self.CLISyntaxError:
         raise self.NotSupportedError()
     t = parse_table(v, allow_wrap=True, allow_extend=True)
     for i in t:
         chassis_id = i[1]
         if is_ipv4(chassis_id) or is_ipv6(chassis_id):
             chassis_id_subtype = 5
         elif is_mac(chassis_id):
             chassis_id_subtype = 4
         else:
             chassis_id_subtype = 7
         port_id = i[2]
         if is_ipv4(port_id) or is_ipv6(port_id):
             port_id_subtype = 4
         elif is_mac(port_id):
             port_id_subtype = 3
         else:
             port_id_subtype = 7
         caps = 0
         for c in i[4].split(","):
             c = c.strip()
             if c:
                 caps |= {
                     "O": 1,
                     "P": 2,
                     "B": 4,
                     "W": 8,
                     "R": 16,
                     "T": 32,
                     "C": 64,
                     "S": 128
                 }[c]
         neighbor = {
             "remote_chassis_id": chassis_id,
             "remote_chassis_id_subtype": chassis_id_subtype,
             "remote_port": port_id,
             "remote_port_subtype": port_id_subtype,
             "remote_capabilities": caps,
         }
         if i[3]:
             neighbor["remote_system_name"] = i[3]
         s = self.cli("show lldp neighbors ethernet %s" % i[0])
         match = self.rx_sysdescr.search(s)
         if match:
             neighbor["remote_system_description"] = match.group(
                 "descr").strip()
         match = self.rx_portdescr.search(s)
         if match:
             neighbor["remote_port_description"] = match.group(
                 "descr").strip()
         r += [{"local_interface": i[0], "neighbors": [neighbor]}]
     return r
Ejemplo n.º 29
0
    def execute_cli(self, **kwargs):
        res = []
        ports = []

        try:
            v = self.cli("show fiber-ports optical-transceiver")
            for i in parse_table(v, footer=r"Temp\s+- Internally measured transceiver temperature"):
                if i[1] in ["OK", "N/S"] or is_int(i[1]):
                    ports += [i[0]]
        except self.CLISyntaxError:
            pass

        if self.has_capability("Stack | Members"):
            has_unit_command = True
            for unit in self.capabilities["Stack | Member Ids"].split(" | "):
                try:
                    plat = self.cli("show system unit %s" % unit, cached=True)
                except self.CLISyntaxError:
                    # Found on MES1124M SW version 1.1.46
                    # Left for compatibility with other models
                    if unit == "1":
                        plat = self.cli("show system", cached=True)
                        has_unit_command = False
                    else:
                        raise self.NotSupportedError()
                if not self.is_has_image:
                    if has_unit_command:
                        ver = self.cli("show version unit %s" % unit, cached=True)
                    else:
                        ver = self.cli("show version", cached=True)
                else:
                    ver = ""
                if has_unit_command:
                    ser = self.cli("show system id unit %s" % unit, cached=True)
                else:
                    ser = self.cli("show system", cached=True)
                r = self.get_chassis(plat, ver, ser)
                platform = r["part_no"][0]
                res += [r]
                for match in self.rx_pwr.finditer(plat):
                    res += [self.get_pwr(match.group("type"), match.group("pwr_type"), platform)]
                for p in ports:
                    if p.startswith("gi") or p.startswith("te"):
                        if unit == p[2]:
                            res += [self.get_trans(p)]
        else:
            plat = self.cli("show system", cached=True)
            ver = self.cli("show version", cached=True)
            ser = self.cli("show system id", cached=True)
            r = self.get_chassis(plat, ver, ser)
            platform = r["part_no"][0]
            res = [r]
            for match in self.rx_pwr.finditer(plat):
                res += [self.get_pwr(match.group("type"), match.group("pwr_type"), platform)]
            for p in ports:
                res += [self.get_trans(p)]

        return res
Ejemplo n.º 30
0
 def has_stack(self):
     """
     Check stack members
     :return:
     """
     r = self.cli("show version", cached=True)
     s = [e[0] for e in parse_table(r)]
     if not s:  # MES3324
         r = self.cli("show system", cached=True)
         if "Unit" not in r:  # MES3108F
             return []
         s = [
             e[0] for e in parse_table(
                 r, footer=r"^Unit\s*(?:Main Power|Fans Status)")
         ]
         while s[-1] == "":
             del s[-1]
     return s