def execute_snmp(self): i = [1, 2, 3, 4, 5] interfaces = [] for ii in i: status = self.snmp.get("1.3.6.1.4.1.35419.20.1.10%s.0" % ii) if status == 0: admin_status = False oper_status = False else: admin_status = True oper_status = True iface = { "type": "physical", "name": ii, "admin_status": admin_status, "oper_status": oper_status, "snmp_ifindex": ii, "subinterfaces": [{ "name": ii, "admin_status": admin_status, "oper_status": oper_status, "snmp_ifindex": ii, }], } interfaces += [iface] ip = self.snmp.get("1.3.6.1.4.1.35419.1.1.3.0") m = self.snmp.get("1.3.6.1.4.1.35419.1.1.4.0") mask = str(IPv4.netmask_to_len(m)) ip = ip + "/" + mask ip_list = [ip] iface = { "type": "physical", "name": "eth0", "admin_status": True, "oper_status": True, "mac": self.snmp.get("1.3.6.1.4.1.35419.1.1.6.0"), "snmp_ifindex": 10, "subinterfaces": [{ "name": "eth0", "admin_status": True, "oper_status": True, "mac": self.snmp.get("1.3.6.1.4.1.35419.1.1.6.0"), "ipv4_addresses": ip_list, "snmp_ifindex": 10, "enabled_afi": ["BRIDGE", "IPv4"], }], } interfaces += [iface] return [{"interfaces": interfaces}]
def execute(self): res = self.http.get( "/cgi-bin/configManager.cgi?action=getConfig&name=Network") # "getInterfaces" r = [] if res: res = self.profile.parse_equal_output(res) name = res["table.Network.DefaultInterface"] iface = { "name": name, "type": "physical", "admin_status": True, "oper_status": True, "mtu": res["table.Network.%s.MTU" % name], "mac": res["table.Network.%s.PhysicalAddress" % name], } ip_address = "%s/%s" % ( res["table.Network.%s.IPAddress" % name], IPv4.netmask_to_len(res["table.Network.%s.SubnetMask" % name]), ) sub = { "name": name, "admin_status": True, "oper_status": True, "mac": res["table.Network.%s.PhysicalAddress" % name], "enabled_afi": ["IPv4"], "ipv4_addresses": [ip_address], } iface["subinterfaces"] = [sub] r += [iface] return [{"interfaces": r}]
def execute(self): data = self.profile.var_data(self, "/setup_get.cgi") ip = data["ip"].encode("UTF8") mask = IPv4.netmask_to_len(data["mask"].encode("UTF8")) iface = { "name": "Fa1", "admin_status": True, "oper_status": True, "type": "physical", "description": data["location"].encode("UTF8"), "mac": data["mac"].encode("UTF8"), "subinterfaces": [{ "name": "Fa1", "admin_status": True, "oper_status": True, "type": "physical", "description": data["hostname"].encode("UTF8"), "mac": data["mac"].encode("UTF8"), "enabled_afi": ["IPv4"], "ipv4_addresses": ["%s/%s" % (ip, mask)], }], } return [{"interfaces": [iface]}]
def execute(self): sw = self.scripts.get_switchport() ports = self.scripts.get_interface_status() mv = self.rx_mv.search(self.cli("show vlan", cached=True)) if mv: mv = int(mv.group("mv")) else: mv = 1 interfaces = [] for p in ports: ifname = p['interface'] i = { "name": ifname, "type": "physical", "oper_status": p['status'], "enabled_protocols": [], "subinterfaces": [{ "name": ifname, "oper_status": p['status'], # "ifindex": 1, "enabled_afi": ['BRIDGE'] }] } for p1 in sw: if p1['interface'] == ifname: i['subinterfaces'][0]['tagged_vlans'] = p1['tagged'] if 'untagged' in p1: i['subinterfaces'][0]['untagged_vlan'] = p1['untagged'] interfaces += [i] match = self.rx_swi.search(self.cli("show switch")) if match: i = { "name": "System", "type": "SVI", "oper_status": True, "admin_status": True, "enabled_protocols": [], "subinterfaces": [{ "name": "System", "oper_status": True, "admin_status": True, "mac": match.group("mac"), "vlan_ids": [mv], "enabled_afi": ['IPv4'] }] } addr = match.group("ip") mask = match.group("mask") ip_address = "%s/%s" % (addr, IPv4.netmask_to_len(mask)) i['subinterfaces'][0]["ipv4_addresses"] = [ip_address] interfaces += [i] return [{"interfaces": interfaces}]
def execute(self): interfaces = [] v = self.cli("ethstat") for match in self.rx_eth.finditer(v): iface = { "name": match.group("name"), "type": "physical", "enabled_protocols": [], "subinterfaces": [ {"name": match.group("name"), "enabled_afi": ["BRIDGE"], "tagged_vlans": []} ], } interfaces += [iface] for v in self.scripts.get_vlans(): vlan_id = v["vlan_id"] c = self.cli("vlan %s -s" % vlan_id) match = self.rx_vlan.search(c) if match: for port in match.group("ports").split(","): for i in interfaces: if port == i["name"]: i["subinterfaces"][0]["tagged_vlans"] += [vlan_id] break else: match = self.rx_vlan2.search(c) for uport in match.group("uport").split(","): for i in interfaces: if uport and uport == i["name"]: i["subinterfaces"][0]["untagged_vlan"] = vlan_id for tports in match.group("tports").split(","): for i in interfaces: if tports == i["name"]: i["subinterfaces"][0]["tagged_vlans"] += [vlan_id] break v = self.cli("ipconfig") match = self.rx_ip.search(v) ip_address = match.group("ip_address") ip_subnet = match.group("ip_subnet") ip_address = "%s/%s" % (ip_address, IPv4.netmask_to_len(ip_subnet)) iface = { "name": "MGMT", "type": "SVI", "admin_status": True, "oper_status": True, "mac": match.group("mac"), "enabled_protocols": [], "subinterfaces": [ { "name": "MGMT", "admin_status": True, "oper_status": True, "mac": match.group("mac"), "enabled_afi": ["IPv4"], "ipv4_addresses": [ip_address], "vlan_ids": [int(match.group("vlan_id"))], } ], } interfaces += [iface] return [{"interfaces": interfaces}]
def execute(self): r = [] ns = { "isapi": "http://www.isapi.org/ver20/XMLSchema", "std-cgi": "http://www.std-cgi.com/ver20/XMLSchema", "hikvision": "http://www.hikvision.com/ver20/XMLSchema", } v = self.http.get("/ISAPI/System/Network/interfaces", use_basic=True) v = v.replace("\n", "") if "std-cgi" in v: ns["ns"] = ns["std-cgi"] elif "www.hikvision.com" in v: ns["ns"] = ns["hikvision"] else: ns["ns"] = ns["isapi"] root = ElementTree.fromstring(v) # mac = self.scripts.get_chassis_id()[0]["first_chassis_mac"] for o in root: o_id = o.find("{%s}id" % ns["ns"]).text name = "eth%s" % o_id iface = {"name": name, "type": "physical", "admin_status": True, "oper_status": True} sub = {"name": name, "admin_status": True, "oper_status": True, "enabled_afi": []} try: v = self.http.get("/ISAPI/System/Network/interfaces/%s/Link" % o_id, use_basic=True) v = v.replace("\n", "") v = ElementTree.fromstring(v) mac = v.find("{%s}MACAddress" % ns["ns"]).text except HTTPError: mac = self.scripts.get_chassis_id()[0]["first_chassis_mac"] if mac: sub["mac"] = mac iface["mac"] = mac ip = o.find("{%s}IPAddress" % ns["ns"]) # for ip in ip_addresses: afi = ip.find("{%s}ipVersion" % ns["ns"]).text if afi == "v4": if "IPv4" not in sub["enabled_afi"]: sub["enabled_afi"] += ["IPv4"] ip_address = "%s/%s" % ( ip.find("{%s}ipAddress" % ns["ns"]).text, IPv4.netmask_to_len(ip.find("{%s}subnetMask" % ns["ns"]).text), ) if "ipv4_addresses" in sub: sub["ipv4_addresses"] += [ip_address] else: sub["ipv4_addresses"] = [ip_address] if afi == "v6": if "IPv6" not in sub["enabled_afi"]: sub["enabled_afi"] += ["IPv6"] ip_address = IPv6( ip.find("{%s}ipAddress" % ns["ns"]).text, netmask=ip.find("ns:subnetMask", ns).text, ).prefix iface["subinterfaces"] = [sub] r += [iface] return [{"interfaces": r}]
def get_l3_interfaces(self): v = self.cli("IFSHOW") interfaces = {} ifname = None for block in self.rx_l3_iface_splitter.split(v)[1:]: if not block: continue match = self.rx_iface_name.match(block) if match: ifname = match.group("ifname") if match.group("unit_num"): ifname += match.group("unit_num") iftype = self.profile.get_interface_type(ifname) interfaces[ifname] = { "name": ifname, "type": iftype, "admin_status": True, "oper_status": True, "subinterfaces": [{ "name": ifname, "admin_status": True, "oper_status": True }], } continue match = self.rx_iface_mac.search(block) if match and match.group("mac") != "00:00:00:00:00:00": interfaces[ifname]["mac"] = match.group("mac") match = self.rx_iface_mtu.search(block) if match: interfaces[ifname]["mtu"] = match.group("mtu") match = self.rx_iface_ifindex.search(block) if match: interfaces[ifname]["ifindex"] = match.group("ifindex") l3_addresses = [] for l3 in self.rx_iface_l3_address1.finditer(block): # format inet 224.0.0.1 mask 240.0.0.0 address = l3.group("address") netmask = str(IPv4.netmask_to_len(l3.group("netmask"))) l3_addresses += ["%s/%s" % (address, netmask)] for l3 in self.rx_iface_l3_address2.finditer(block): # format Internet address: 192.168.20.1 # Broadcast address: 192.168.20.255 # Netmask 0xffffff00 Subnetmask 0xffffff00 address = l3.group("address") netmask = format(int(l3.group("netmask"), 16), "b").count("1") l3_addresses += ["%s/%s" % (address, netmask)] if l3_addresses: interfaces[ifname]["subinterfaces"][0][ "ipv4_addresses"] = l3_addresses interfaces[ifname]["subinterfaces"][0]["enabled_afi"] = [ "IPv4" ] return interfaces
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", "enabled_afi": ["BRIDGE"], "vlan_ids": match.group("vlan_id"), "ipv4_addresses": [ip_address], "enabled_afi": ["IPv4"], "mac": mac }] } interfaces += [iface] return [{"interfaces": interfaces}]
def execute(self): conf_interfaces = {} interfaces = [] v = self.cli("show running-config interface", cached=True) for match in self.rx_conf_iface.finditer(v): conf_interfaces[match.group("iface")] = match.group("cfg") v = self.cli("show interface", cached=True) for match in self.rx_iface.finditer(v): ifname = match.group("iface") iface = { "name": ifname, "type": self.profile.get_interface_type(ifname), "oper_status": match.group("oper") == "up", "admin_status": match.group("admin") == "up", "subinterfaces": [{ "name": ifname, "oper_status": match.group("oper") == "up", "admin_status": match.group("admin") == "up", "enabled_afi": [] }] } if match.group("mac"): iface["mac"] = match.group("mac") iface["subinterfaces"][0]["mac"] = match.group("mac") if match.group("mtu"): iface["subinterfaces"][0]["mtu"] = int(match.group("mtu")) if match.group("ip_addr"): ip = match.group("ip_addr") netmask = str(IPv4.netmask_to_len(match.group("ip_mask"))) ip = ip + '/' + netmask ip_list = [ip] iface["subinterfaces"][0]["ipv4_addresses"] = ip_list iface["subinterfaces"][0]["enabled_afi"] += ["IPv4"] if match.group("ipv6_addr"): ip = match.group("ipv6_addr") netmask = match.group("ipv6_mask") ip = IPv6(ip, netmask=match.group("ipv6_mask")).prefix ip_list = [ip] iface["subinterfaces"][0]["ipv6_addresses"] = ip_list iface["subinterfaces"][0]["enabled_afi"] += ["IPv6"] else: iface["subinterfaces"][0]["enabled_afi"] += ["BRIDGE"] if match.group("pvid"): iface["subinterfaces"][0]["untagged_vlan"] = \ int(match.group("pvid")) if conf_interfaces.get(ifname): cfg = conf_interfaces[ifname] for match in self.rx_trunk.finditer(cfg): if iface["subinterfaces"][0].get("tagged_vlans"): iface["subinterfaces"][0]["tagged_vlans"] += \ [int(match.group("vlan_id"))] else: iface["subinterfaces"][0]["tagged_vlans"] = \ [int(match.group("vlan_id"))] interfaces += [iface] return [{"interfaces": interfaces}]
def execute(self): ifaces = [] tagged = [] untag = "" v = self.cli("show interface brief") for match in self.rx_int1.finditer(v): ifname = self.profile.convert_interface_name(match.group("ifname")) typ = match.group('type') iftype = self.types[typ] i = { "name": ifname, "type": iftype, "admin_status": "up" in match.group('status'), "oper_status": "up" in match.group('status'), "description": match.group('desc'), "enabled_protocols": [], "subinterfaces": [{ "name": ifname, "admin_status": "up" in match.group('status'), "oper_status": "up" in match.group('status'), "description": match.group('desc'), "tagged_vlans": tagged, "untagged_vlan": untag, }] } if ifname.startswith('GigaEthernet'): cmd1 = "show lldp interface %s" % ifname cmd2 = self.cli(cmd1) for match1 in self.rx_lldp.finditer(cmd2): if match1.group('lldp_rx') == "enabled" \ or match1.groups('lldp_tx') == "enabled": i["enabled_protocols"] = ["LLDP"] ifaces += [i] match = self.rx_svi.search(self.cli("sh ip interface")) if match: vlan = match.group('ifname') vlan = vlan[4:] i = { "name": match.group('ifname'), "type": "SVI", "oper_status": True, "admin_status": True, "enabled_protocols": [], "subinterfaces": [{ "name": match.group('ifname'), "oper_status": True, "admin_status": True, "vlan_ids": [int(vlan)], "enabled_afi": ['IPv4'] }] } addr = match.group("ip") mask = match.group("mask") ip_address = "%s/%s" % (addr, IPv4.netmask_to_len(mask)) i['subinterfaces'][0]["ipv4_addresses"] = [ip_address] ifaces += [i] return [{"interfaces": ifaces}]
def execute(self): interfaces = [] v = self.cli("show lldp local config") for port in self.rx_port.finditer(v): port_no = port.group("port") c = self.cli("show interface port-list %s switchport" % port_no) match = self.rx_vlan.search(c) iface = { "name": "P%s" % port_no, "type": "physical" } sub = { "name": "P%s" % port_no, "enabled_afi": ["BRIDGE"], } if match.group("op_mode") in ["trunk", "hybrid"]: sub["untagged_vlan"] = int(match.group("trunk_native_vlan")) sub["tagged_vlans"] = ranges_to_list(match.group("op_vlans")) else: sub["untagged_vlan"] = int(match.group("access_vlan")) iface["subinterfaces"] = [sub] interfaces += [iface] mac = self.scripts.get_chassis_id()[0]["first_chassis_mac"] v = self.cli("show interface ip") for match in self.rx_ip_iface.finditer(v): ifname = match.group("iface") i = { "name": "ip%s" % ifname, "type": "SVI", "mac": mac, "enabled_protocols": [], "subinterfaces": [{ "name": "ip%s" % ifname, "mac": mac, "enabled_afi": ['IPv4'] }] } addr = match.group("ip") mask = match.group("mask") ip_address = "%s/%s" % (addr, IPv4.netmask_to_len(mask)) i['subinterfaces'][0]["ipv4_addresses"] = [ip_address] interfaces += [i] v = self.cli("show interface ip vlan") for match in self.rx_vlans_ip.finditer(v): vlan_id = match.group("vlan_id") if vlan_id == "none": continue ifname = "ip%s" % match.group("iface") for i in interfaces: if i["name"] == ifname: i["subinterfaces"][0]["vlan_ids"] = vlan_id break return [{"interfaces": interfaces}]
def execute_cli(self): interfaces = [] for l in self.cli("context ip router ifconfig").split("\n\n"): match = self.rx_iface.search(l) if not match: continue ifname = match.group("ifname") mac = match.group("mac") match = self.rx_flags.search(l) oper_status = "RUNNING" in match.group("flags") admin_status = "UP " in match.group("flags") mtu = match.group("mtu") if ifname.startswith("brv"): iftype = "physical" # Must be IRB if ifname.startswith("hbr"): iftype = "physical" # Must be IRB iftype = "physical" iface = { "name": ifname, "type": iftype, "admin_status": admin_status, "oper_status": oper_status, "mac": mac, "subinterfaces": [], } sub = { "name": ifname, "admin_status": admin_status, "oper_status": oper_status, "mac": mac, "mtu": mtu, } match = self.rx_ip.search(l) if match: ip_address = match.group("ip") ip_subnet = match.group("mask") ip_address = "%s/%s" % (ip_address, IPv4.netmask_to_len(ip_subnet)) sub["ipv4_addresses"] = [ip_address] sub["enabled_afi"] = ["IPv4"] # found = False if "." in ifname: parent, vlan = ifname.split(".") sub["vlan_ids"] = [vlan] for i in interfaces: if i["name"] == parent: i["subinterfaces"] += [sub] # found = True break continue iface["subinterfaces"] += [sub] interfaces += [iface] return [{"interfaces": interfaces}]
def execute_cli(self): interfaces = [] v = self.cli("ifconfig", cached=True) for line in v.split("\n\n"): match = self.rx_sh_int.search(line) if match: ifname = match.group("ifname") sub = { "name": ifname, "mtu": match.group("mtu"), "admin_status": True, "oper_status": True, "enabled_afi": ["BRIDGE"], } if match.group("ip"): ip_address = match.group("ip") ip_subnet = match.group("mask") ip_address = "%s/%s" % (ip_address, IPv4.netmask_to_len(ip_subnet)) sub["enabled_afi"] += ["IPv4"] sub["ipv4_addresses"] = [ip_address] if match.group("ip6"): ip6_address = match.group("ip6") sub["enabled_afi"] += ["IPv6"] sub["ipv6_addresses"] = [ip6_address] if "." in ifname: parent, vlan = ifname.split(".") sub["vlan_ids"] = int(vlan) found = False for i in interfaces: if i["name"] == parent: i["subinterfaces"] += [sub] found = True break if found: continue iface = { "type": self.profile.get_interface_type(ifname), "name": ifname, "mtu": match.group("mtu"), "admin_status": True, "oper_status": True, "subinterfaces": [], } if match.group("mac"): mac = match.group("mac") iface["mac"] = mac iface["subinterfaces"] = [sub] interfaces += [iface] return [{"interfaces": interfaces}]
def execute(self): interfaces = [] for iface in self.cli("show interface").split("Network device "): match = self.rx_iface.search(iface) if not match: continue ifname = match.group("ifname") admin_status = "Up" in match.group("flags") oper_status = "Running" in match.group("flags") if "Loopback" in match.group("flags"): iftype = "loopback" else: iftype = "SVI" i = { "name": ifname, "type": iftype, "admin_status": admin_status, "oper_status": oper_status, "subinterfaces": [{ "name": ifname, "admin_status": admin_status, "oper_status": oper_status }], } match = self.rx_mac.search(iface) if match: i["mac"] = match.group("mac") i["subinterfaces"][0]["mac"] = match.group("mac") match = self.rx_vlan.search(iface) if match: i["subinterfaces"][0]["vlan_ids"] = match.group("vlan_id") match = self.rx_ip.search(iface) if match: ip_address = match.group("ip") ip_subnet = match.group("mask") ip_address = "%s/%s" % (ip_address, IPv4.netmask_to_len(ip_subnet)) i["subinterfaces"][0]["ipv4_addresses"] = [ip_address] i["subinterfaces"][0]["enabled_afi"] = ["IPv4"] interfaces += [i] return [{"interfaces": interfaces}]
def execute(self): interfaces = [] with self.profile.shell(self): v = self.cli("ifconfig", cached=True) for line in v.split("\n\n"): match = self.rx_sh_int.search(line) if match: ifname = match.group("ifname") itype = match.group("itype") iface = { "type": self.get_interface_type(itype), "name": ifname, "admin_status": True, "oper_status": True, "subinterfaces": [ { "name": ifname, "mtu": match.group("mtu"), "admin_status": True, "oper_status": True, "enabled_afi": ["BRIDGE"], } ], } if match.group("ip"): ip_address = match.group("ip") ip_subnet = match.group("mask") ip_address = "%s/%s" % (ip_address, IPv4.netmask_to_len(ip_subnet)) ip_list = [ip_address] enabled_afi = [] ip_interfaces = "ipv4_addresses" enabled_afi += ["IPv4"] iface["subinterfaces"][0]["enabled_afi"] = enabled_afi iface["subinterfaces"][0][ip_interfaces] = ip_list if match.group("mac"): mac = match.group("mac") iface["mac"] = mac interfaces += [iface] return [{"interfaces": interfaces}]
def execute(self): interfaces = [] for match in self.rx_iface.finditer(self.cli("ifconfig")): ifname = match.group("ifname") iface = { "name": ifname, "type": "physical", "admin_status": "RUNNING " in match.group("flags"), "oper_status": "UP " in match.group("flags"), "mac": match.group("mac"), "subinterfaces": [], } sub = { "name": ifname, "admin_status": "RUNNING " in match.group("flags"), "oper_status": "UP " in match.group("flags"), "mtu": match.group("mtu"), "mac": match.group("mac"), } if match.group("ip"): ip = match.group("ip") mask = match.group("mask") ip_address = "%s/%s" % (ip, IPv4.netmask_to_len(mask)) sub["enabled_afi"] = ["IPv4"] sub["ipv4_addresses"] = [ip_address] found = False if "." in ifname: i1, i2 = ifname.split(".") for i in interfaces: if i["name"] == i1: i["subinterfaces"] += [sub] found = True break if not found: iface["subinterfaces"] += [sub] interfaces += [iface] return [{"interfaces": interfaces}]
def execute(self): # Get portchannels portchannel_members = {} portchannel_interface = [] for pc in self.scripts.get_portchannel(): i = pc["interface"] t = pc["type"] == "L" portchannel_interface += [i] for m in pc["members"]: portchannel_members[m] = (i, t) lldp = [] try: c = self.cli("show lldp") except self.CLISyntaxError: c = "" lldp_enable = self.rx_lldp_gs.search(c) is not None if lldp_enable: try: c = self.cli("show lldp ports") except self.CLISyntaxError: raise self.NotSupportedError() for match in self.rx_lldp.finditer(c): lldp += [match.group("ipif")] descriptions = {} d = self.cli("show ports descr all") for s in d.split("\n"): match = self.rx_descrs.search(s) if match: descriptions[match.group("port")] = match.group("description") vlans = [] c = self.cli("show vlan") for match in self.rx_vlan.finditer(c): members = self.expand_interface_range( self.profile.open_brackets(match.group("member_ports"))) tagged_ports = [] untagged_ports = self.expand_interface_range( self.profile.open_brackets(match.group("untagged_ports"))) for p in members: if p not in untagged_ports: tagged_ports += [p] vlans += [{ "vlan_id": int(match.group("vlan_id")), "vlan_name": match.group("vlan_name"), "vlan_type": match.group("vlan_type"), "tagged_ports": tagged_ports, "untagged_ports": untagged_ports, }] interfaces = [] c = self.cli("show ports all") for match in self.rx_ports.finditer(c): ifname = match.group("port") i = { "name": ifname, "type": "physical", "admin_status": match.group("admin_state") == "Enabled", "oper_status": match.group("status") is None, "enabled_protocols": [], "subinterfaces": [{ "name": ifname, "admin_status": match.group("admin_state") == "Enabled", "oper_status": match.group("status") is None, # "ifindex": 1, "enabled_afi": ["BRIDGE"], }], } desc = descriptions.get(ifname, "") if desc != "" and desc != "null": i.update({"description": desc}) i["subinterfaces"][0].update({"description": desc}) tagged_vlans = [] for v in vlans: if ifname in v["tagged_ports"]: tagged_vlans += [v["vlan_id"]] if ifname in v["untagged_ports"]: i["subinterfaces"][0]["untagged_vlan"] = v["vlan_id"] if len(tagged_vlans) != 0: i["subinterfaces"][0]["tagged_vlans"] = tagged_vlans if lldp_enable and ifname in lldp: i["enabled_protocols"] += ["LLDP"] # Portchannel member if ifname in portchannel_members: ai, is_lacp = portchannel_members[ifname] i["aggregated_interface"] = ai i["enabled_protocols"] += ["LACP"] i["subinterfaces"][0].update({"enabled_afi": []}) # Portchannel interface if ifname in portchannel_interface: i["type"] = "aggregated" interfaces += [i] mac = self.scripts.get_chassis_id()[0]["first_chassis_mac"] ipif = self.cli("show ipif") for match in self.rx_ipif.finditer(ipif): admin_status = match.group("admin_state") == "Enabled" o_status = match.group("oper_status") oper_status = self.rx_link_up.match(o_status) is not None i = { "name": "System", "type": "SVI", "admin_status": admin_status, "oper_status": oper_status, "subinterfaces": [{ "name": "System", "admin_status": admin_status, "oper_status": oper_status, "enabled_afi": ["IPv4"], }], } ip_address = match.group("ip_address") ip_subnet = match.group("ip_subnet") ip_address = "%s/%s" % (ip_address, IPv4.netmask_to_len(ip_subnet)) i["subinterfaces"][0]["ipv4_addresses"] = [ip_address] vlan_name = match.group("vlan_name") for v in vlans: if vlan_name == v["vlan_name"]: i["subinterfaces"][0]["vlan_ids"] = [v["vlan_id"]] break i["subinterfaces"][0]["mac"] = mac interfaces += [i] return [{"interfaces": interfaces}]
def execute(self): interfaces = [] self.cli("SELGRP Status") for etherswitch in ["1", "2"]: c = self.cli("GET ethernet%s/" % etherswitch) match = self.rx_eth_iface.search(c) ifname = match.group("ifname").replace("\"", "") # ifname = "port" + ifname[-1] iface = { "name": ifname, "oper_status": match.group("oper_status") == "up", "type": "physical", # "description": match.group("ifname").replace("\"", ""), "snmp_ifindex": match.group("snmp_ifindex"), "subinterfaces": [{ "name": ifname, "oper_status": match.group("oper_status") == "up", "enabled_afi": ["BRIDGE"], "mtu": match.group("mtu"), "tagged_vlans": [] }] } interfaces += [iface] c = self.cli( "GET ethernet%s/" % etherswitch, command_submit="\x09" ) self.cli("") for i in self.rx_hw_port.finditer(c): v = self.cli( "GET ethernet%s/%s/" % (etherswitch, i.group("port")) ) match = self.rx_eth_iface.search(v) ifname = match.group("ifname").replace("\"", "") ifname = "port" + ifname[-1] iface = { "name": ifname, "oper_status": match.group("oper_status") == "up", "type": "physical", "description": match.group("ifname").replace("\"", ""), "snmp_ifindex": match.group("snmp_ifindex"), "subinterfaces": [{ "name": ifname, "oper_status": match.group("oper_status") == "up", "enabled_afi": ["BRIDGE"], "mtu": match.group("mtu"), "tagged_vlans": [] }] } interfaces += [iface] c = self.cli("GET ethernet%s/vtuTable[]/" % etherswitch) for match in self.rx_vlan.finditer(c): vlan_id = match.group("vlan_id") for match1 in self.rx_vlan_port.finditer(match.group("ports")): vtype = match1.group("type") if vtype == "--": continue port = "port" + match1.group("port") for i in interfaces: if port == i["name"]: if vtype == "untag": i["subinterfaces"][0][ "untagged_vlan" ] = vlan_id else: i["subinterfaces"][0][ "tagged_vlans" ] += [vlan_id] break c = self.cli("GET ip/router/interfaces[]/") for match in self.rx_ip_iface.finditer(c): ip = match.group("ip_address") mask = IPv4.netmask_to_len(match.group("ip_mask")) ifname = match.group("descr").replace("\"", "") sub = { "name": ifname, # "admin_status": True, "oper_status": match.group("oper_status") == "up", "enabled_afi": ["IPv4"], "ipv4_addresses": ["%s/%s" % (ip, mask)] } found = False if ifname.startswith("eth"): ifname1 = ifname[:4] for i in interfaces: if i["name"] == ifname1: sub["enabled_afi"] = ["BRIDGE", "IPv4"] i["subinterfaces"][0].update(sub) found = True break if found: continue iface = { "name": ifname, # "admin_status": True, "oper_status": match.group("oper_status") == "up", "type": self.IF_TYPES[match.group("iftype")], "subinterfaces": [sub] } interfaces += [iface] c = self.cli("GET bridge/bridgeGroup/macAddress") match = self.rx_mac.search(c) mac = match.group("mac") for i in interfaces: if i["name"] == "bridge": i["mac"] = mac i["subinterfaces"][0]["mac"] = mac break return [{"interfaces": interfaces}]
def execute(self): interfaces = [] # Get LLDP interfaces lldp = [] c = self.cli("show lldp", ignore_errors=True) if self.rx_lldp_en.search(c): ll = self.rx_lldp.search(c) lldp = ll.group("local_if").split() v = self.cli("show interface", cached=True) for match in self.rx_sh_int.finditer(v): name = match.group("interface") ifname = match.group("ifname") a_stat = match.group("admin_status").lower() == "up" o_stat = match.group("oper_status").lower() == "up" other = match.group("other") match1 = self.rx_hw.search(other) iface = { "type": self.HW_TYPES[match1.group("hw_type")], "name": name, "admin_status": a_stat, "oper_status": o_stat } sub = {"name": name, "admin_status": a_stat, "oper_status": o_stat} # LLDP protocol if name in lldp: iface["enabled_protocols"] = ["LLDP"] if iface["type"] == "physical": sub["enabled_afi"] = ["BRIDGE"] if match1.group("mac"): iface["mac"] = match1.group("mac") sub["mac"] = match1.group("mac") match1 = self.rx_alias.search(ifname) if match1 and match1.group("alias") != "(null),": iface["description"] = match1.group("alias") sub["description"] = match1.group("alias") match1 = self.rx_index.search(other) if match1: iface["snmp_ifindex"] = match1.group("ifindex") sub["snmp_ifindex"] = match1.group("ifindex") else: if match.group("snmp_ifindex"): iface["snmp_ifindex"] = match.group("snmp_ifindex") sub["snmp_ifindex"] = match.group("snmp_ifindex") match1 = self.rx_mtu.search(other) if match1: sub["mtu"] = match1.group("mtu") match1 = self.rx_pvid.search(other) if match1: sub["untagged_vlan"] = match1.group("pvid") if name.startswith("Vlan"): sub["vlan_ids"] = [int(name[4:])] match1 = self.rx_ip.search(other) if match1: if "NULL" in match1.group("ip"): continue ip_address = "%s/%s" % (match1.group("ip"), IPv4.netmask_to_len( match1.group("mask"))) sub["ipv4_addresses"] = [ip_address] sub["enabled_afi"] = ["IPv4"] iface["subinterfaces"] = [sub] interfaces += [iface] v = self.cli("show switchport interface") for match in self.rx_vlan.finditer(v): ifname = match.group("ifname") untagged_vlan = match.group("untagged_vlan") for i in interfaces: if ifname == i["name"]: i["subinterfaces"][0]["untagged_vlan"] = untagged_vlan if match.group("tagged_vlans"): tagged_vlans = match.group("tagged_vlans").replace( ";", ",") i["subinterfaces"][0]["tagged_vlans"] = \ self.expand_rangelist(tagged_vlans) break return [{"interfaces": interfaces}]
def execute(self): rip = [] try: c = self.cli("show ip rip int | inc ^Interface") except self.CLISyntaxError: c = "" c = c.strip("\n") for ii in c.split("\n"): ii = ii.lower() if ii.find("ve") > 0: ii = ii.replace("ve ", "ve") else: ii = ii.replace("Eth ", "") if ii != "": ii = ii.split(" ")[1] rip += [ii] ospf = [] try: c = self.cli("sh ip ospf int | inc ospf enabled") except self.CLISyntaxError: c = "" c = c.strip("\n") for ii in c.split("\n"): ii = ii.lower().split(",")[0] if ii.startswith("ve "): ii = ii.replace("ve ", "ve") ii = ii.split(" ")[0] elif ii.startswith("v"): ii = ii.replace("v", "ve") ii = ii.split(" ")[0] elif ii.startswith("loop"): ii = ii.replace("loopback ", "lb") ii = ii.split(" ")[0] elif ii.startswith("lb"): ii = ii ii = ii.split(" ")[0] elif ii.startswith("tn"): ii = ii ii = ii.split(" ")[0] elif ii != "": ii = ii.split(" ")[1] self.logger.debug(ii) ospf += [ii.strip()] pim = [] try: c = self.cli("sh ip pim int | inc ^Int") except self.CLISyntaxError: c = "" if c != "": for ii in c.split("\n"): ii = ii.split(" ")[1] if ii.startswith("v"): ii = ii.replace("v", "ve") else: ii = ii.replace("e", "") pim += [ii] dvmrp = [] try: c = self.cli("sh ip dvmrp int | inc ^Int") except self.CLISyntaxError: c = "" if c != "": c = c.strip("\n") for ii in c.split("\n"): ii = ii.split(" ")[1] if ii.startswith("v"): ii = ii.replace("v", "ve") else: ii = ii.replace("e", "") dvmrp += [ii] stp = [] try: c = self.cli("show span | inc /") except self.CLISyntaxError: c = "" c = c.strip("\n") for ii in c.split("\n"): ii = ii.split(" ")[0] gvrp = [] try: c = self.cli("show gvrp") except self.CLISyntaxError: c = "" igmp = [] try: c = self.cli("sh ip igmp int | exc group:") except self.CLISyntaxError: c = "" c = c.strip("\n") for ii in c.split("\n"): ii = ii.strip() ii = ii.split(" ")[0] ii = ii.strip(":") if ii.startswith("v"): ii = ii.replace("v", "ve") else: ii = ii.replace("e", "") if not ii.startswith("IGMP"): igmp += [ii] interfaces = [] shrunvlan = self.cli("sh running-config vlan | excl tag-type") tagged = {} untagged = {} for v in shrunvlan.split("!"): self.logger.debug("\nPROCESSING:" + v + "\n") match = self.rx_vlan_list.findall(v) if match: tag = 1 for m in match: self.logger.debug(" m[0]:" + m[0] + "\n") if not m[0]: tag = 0 continue if m[0].split()[0] == "vlan": vlan = int(m[0].split()[1]) continue elif m[0][:3] == "ve ": ifc = "".join(m[0].split()) if ifc in untagged: untagged[ifc].append(vlan) else: untagged[ifc] = vlan continue elif not m[0].split()[0] == "ethe": continue elif not m[1]: ifc = m[0].split()[1] if tag == 1: if ifc in tagged: tagged[ifc].append(vlan) else: tagged[ifc] = [vlan] else: untagged[ifc] = vlan else: first = m[0].split()[1].split("/")[1] last = m[1].split()[1].split("/")[1] for n in range(int(first), int(last) + 1): ifc = m[0].split()[1].split("/")[0] + "/" + repr(n) if tag == 1: if ifc in tagged: tagged[ifc].append(vlan) else: tagged[ifc] = [vlan] else: untagged[ifc] = vlan # deal with VPLS and VLL vlans shmplsconf = self.cli("sh mpls config | excl vp|vll") for v in shmplsconf.split("!"): match = self.rx_vlan_list.findall(v) if match: tag = 1 for m in match: if not m[0]: tag = 0 continue if m[0].split()[0] == "vlan": vlan = int(m[0].split()[1]) continue elif m[0][:3] == "ve ": ifc = "".join(m[0].split()) if ifc in untagged: untagged[ifc].append(vlan) else: untagged[ifc] = vlan continue elif not m[0].split()[0] == "ethe": continue elif not m[1]: ifc = m[0].split()[1] if tag == 1: if ifc in tagged: tagged[ifc].append(vlan) else: tagged[ifc] = [vlan] else: untagged[ifc] = vlan else: first = m[0].split()[1].split("/")[1] last = m[1].split()[1].split("/")[1] for n in range(int(first), int(last) + 1): ifc = m[0].split()[1].split("/")[0] + "/" + repr(n) if tag == 1: if ifc in tagged: tagged[ifc].append(vlan) else: tagged[ifc] = [vlan] else: untagged[ifc] = vlan c = self.cli("sh int br | excl Port") c = c.strip("\n") for ii in c.split("\n"): if not ii.startswith("Port"): self.logger.debug("\nPROCESSING LINE: " + ii + "\n") ii = ii.lower() ii = ii.replace("disabled", " disabled ") ii = ii.replace("disabn", " disabled n") ii = ii.replace("up", " up ") ii = ii.replace(" ", " ") port = ii.split() if len(port) > 1: ifname = port[0] ift = "" self.logger.debug("INT :" + ifname + "\n") if ifname.find("/") > 0: ift = "physical" self.logger.debug("FOUND PHYSICAL\n") if ifname.find("e") > 0: ift = "SVI" self.logger.debug("FOUND VIRTUAL\n") if ifname.find("b") > 0: ift = "loopback" self.logger.debug("FOUND LOOPBACK\n") if ifname.find("g") > 0: ift = "management" self.logger.debug("FOUND MANAGEMENT\n") if ifname.find("n") > 0: ift = "tunnel" i = { "name": ifname, "type": ift, "admin_status": port[1] == "up", "oper_status": port[1] == "up", "enabled_protocols": [], "subinterfaces": [{ "name": ifname, "admin_status": port[1] == "up", "oper_status": port[1] == "up", }], } if ift == "SVI": i["subinterfaces"][0].update( {"vlan_ids": [untagged[ifname]]}) ipa = self.cli("show run int %s | inc ip addr" % ifname) ipal = ipa.splitlines() ip_address = [] for line in ipal: line = line.strip() self.logger.debug("ip.split len:" + str(len(line.split()))) if len(line.split()) > 3: ip_address.append( "%s/%s" % (line.split()[2], IPv4.netmask_to_len(line.split()[3]))) else: ip_address.append(line.split()[2]) i["subinterfaces"][0].update({"enabled_afi": ["IPv4"]}) i["subinterfaces"][0].update( {"ipv4_addresses": ip_address}) if len(port) > 9: desc = port[9] else: desc = "" i["subinterfaces"][0].update({"description": desc}) if ift == "physical": i["subinterfaces"][0].update({"is_bridge": True}) if ifname in tagged: i["subinterfaces"][0].update( {"tagged_vlans": tagged[ifname]}) if ifname in untagged: i["subinterfaces"][0].update( {"untagged_vlan": untagged[ifname]}) l2protos = [] l3protos = [] if ifname in stp: l2protos += ["STP"] if ifname in gvrp: l2protos += ["GVRP"] i.update({"enabled_protocols": l2protos}) if ifname in rip: l3protos += ["RIP"] if ifname in ospf: l3protos += ["OSPF"] if ifname in pim: l3protos += ["PIM"] if ifname in dvmrp: l3protos += ["DVMRP"] if ifname in igmp: l3protos += ["IGMP"] i["subinterfaces"][0].update( {"enabled_protocols": l3protos}) interfaces += [i] return [{"interfaces": interfaces}]
def execute_cli(self, **kwargs): interfaces = {} wres = self.get_radio_detail() c = self.cli("get interface all detail") for block in c.split("\n\n"): value = self.profile.table_parser(block) if "name" not in value: self.logger.info("Ignoring unknown interface: '%s", value) continue ip_address = None ifname = value["name"] interfaces[ifname] = { "type": self.profile.get_interface_type(ifname), "name": ifname, "subinterfaces": [], } if value["mac"] and value["mac"] != "00:00:00:00:00:00": interfaces[ifname]["mac"] = value["mac"] if "eth" in ifname: interfaces[ifname]["subinterfaces"] += [ {"name": ifname, "mac": value["mac"], "enabled_afi": ["BRIDGE"]} ] # static-ip or "ip" field may use if value.get("static-ip"): ip_address = "%s/%s" % ( value["static-ip"], IPv4.netmask_to_len(value.get("static-mask") or "255.255.255.255"), ) elif value.get("ip") in value: ip_address = "%s/%s" % ( value["ip"], IPv4.netmask_to_len(value.get("mask") or "255.255.255.255"), ) if ip_address: interfaces[ifname]["subinterfaces"] += [ {"name": ifname, "enabled_afi": ["IPv4"], "ipv4_addresses": [ip_address]} ] if value["mac"] != "00:00:00:00:00:00": interfaces[ifname]["subinterfaces"][-1]["mac"] = value["mac"] if value.get("bss") and value.get("ssid"): # For some reason creating SSID as interfaces otherwise sub. interfaces.pop(ifname) ssid = value["ssid"].replace(" ", "").replace("Managed", "") if ssid.startswith("2a2d"): # 2a2d - hex string ssid = ssid.decode("hex") r = self.get_bss_detail(value["bss"]) bss_ifname = "%s.%s" % (ifname, ssid) if r: radio = wres[r["radio"]] interfaces[bss_ifname] = { "type": "physical", "name": bss_ifname, "mac": value["mac"], "description": self.BSS_DESCRIPTION_TEMPLATE % ( "Enable" if r["ignore-broadcast-ssid"] == "off" else "Disable", radio["ieee_mode"], radio["channel"], radio["freq"], radio["channelbandwidth"], ), "subinterfaces": [ { "name": "%s.%s" % (ifname, ssid), "mac": value["mac"], "enabled_afi": ["BRIDGE"], } ], } return [{"interfaces": list(six.itervalues(interfaces))}]
def execute(self): interfaces = [] v = self.cli("show interface ethernet all configuration") for match in self.rx_eth.finditer(v): iface = { "name": match.group('port'), "type": "physical", "subinterfaces": [{ "name": match.group('port'), "enabled_afi": ["BRIDGE"], }] } if int(match.group('vlan_id')) > 0: iface["subinterfaces"][0]["untagged_vlan"] = int( match.group('vlan_id')) if "admin_status" in match.groupdict(): iface["admin_status"] = match.group("admin_status") == "up" iface["subinterfaces"][0]["admin_status"] = \ match.group("admin_status") == "up" interfaces += [iface] v = self.cli("show interface dsl all configuration") for p in v.split("\n DSL Port "): match = self.rx_dsl.search(p) if not match: continue iface = { "name": match.group("port"), "type": "physical", "subinterfaces": [] } if match.group("admin_status"): iface["admin_status"] = match.group( "admin_status") == "enabled" if match.group("name") and match.group("name").strip(): iface["description"] = match.group("name").strip() for match in self.rx_dsl_vpi_vci.finditer(p): sub = match.groupdict() sub["name"] = "%s/%s" % (iface["name"], sub["name"]) sub["admin_status"] = iface["admin_status"] sub["enabled_afi"] = ["BRIDGE", "ATM"] if sub["vlan_ids"]: sub["vlan_ids"] = [ int(x) for x in sub["vlan_ids"].split(", ") if int(x) > 0 ] iface["subinterfaces"] += [sub] interfaces += [iface] v = self.cli("show management inband") for match in self.rx_inband.finditer(v): iface = { "name": "mgmt_i" + match.group('ifnum'), "admin_status": match.group("admin_status") == "enable", "type": "SVI", "mac": match.group("mac"), "subinterfaces": [{ "name": "mgmt_i" + match.group('ifnum'), "admin_status": match.group("admin_status") == "enable", "mac": match.group("mac") }] } if match.group("ip") != "0.0.0.0": ip = match.group("ip") mask = match.group("mask") ip_address = "%s/%s" % (ip, IPv4.netmask_to_len(mask)) iface["subinterfaces"][0]["ipv4_addresses"] = [ip_address] iface["subinterfaces"][0]["enabled_afi"] = ["IPv4"] if match.group("vlan_id") != "0": iface["subinterfaces"][0]["vlan_ids"] = \ [match.group("vlan_id")] interfaces += [iface] match = self.rx_inband2.search(v) if match: iface = { "name": "mgmt_i", "type": "SVI", "mac": match.group("mac"), "subinterfaces": [{ "name": "mgmt_i", "mac": match.group("mac") }] } if match.group("ip") != "0.0.0.0": ip = match.group("ip") mask = match.group("mask") ip_address = "%s/%s" % (ip, IPv4.netmask_to_len(mask)) iface["subinterfaces"][0]["ipv4_addresses"] = [ip_address] iface["subinterfaces"][0]["enabled_afi"] = ["IPv4"] interfaces += [iface] v = self.cli("show management out-of-band") match = self.rx_outband.search(v) iface = { "name": "mgmt_o", "type": "SVI", "mac": match.group("mac"), "subinterfaces": [{ "name": "mgmt_o", "mac": match.group("mac") }] } if "admin_status" in match.groupdict(): iface["admin_status"] = match.group("admin_status") == "enable" iface["subinterfaces"][0]["admin_status"] = \ match.group("admin_status") == "enable" if match.group("ip") != "0.0.0.0": ip = match.group("ip") mask = match.group("mask") ip_address = "%s/%s" % (ip, IPv4.netmask_to_len(mask)) iface["subinterfaces"][0]["ipv4_addresses"] = [ip_address] iface["subinterfaces"][0]["enabled_afi"] = ["IPv4"] interfaces += [iface] v = self.cli("show vlan configuration all") for match in self.rx_vlan.finditer(v): vlan_id = match.group("vlan_id") if int(vlan_id) < 1: continue tagged = match.group("tagged").strip() if tagged: tagged = tagged.split(", ") for i in interfaces: sub = i["subinterfaces"][0] if sub["name"] not in tagged: continue if "tagged_vlans" in sub: sub["tagged_vlans"] += [vlan_id] else: sub["tagged_vlans"] = [vlan_id] untagged = match.group("untagged").strip() if untagged: untagged = untagged.split(", ") for i in interfaces: sub = i["subinterfaces"][0] if sub["name"] not in untagged: continue sub["untagged_vlan"] = vlan_id return [{"interfaces": interfaces}]
def execute(self): interfaces = [] v = self.cli("get interface stats") for match in self.rx_stats.finditer(v): i = { "name": match.group("name"), "type": self.IF_TYPES[match.group("type")], "admin_status": match.group("admin_status") == "Up", "oper_status": match.group("oper_status") == "Up", "enabled_protocols": [], "subinterfaces": [{ "name": match.group("name"), "admin_status": match.group("admin_status") == "Up", "oper_status": match.group("oper_status") == "Up", # "ifindex": 1, "enabled_afi": ["BRIDGE"], }], } if match.group("mtu") != "0": i["subinterfaces"][0]["mtu"] = match.group("mtu") if match.group("mac") != "00:00:00:00:00:00": i["mac"] = match.group("mac") i["subinterfaces"][0]["mac"] = match.group("mac") if match.group("descr").strip() != "": descr = match.group("descr").strip() i["description"] = descr i["subinterfaces"][0]["description"] = descr if match.group("type") == "ATM": i["subinterfaces"][0]["enabled_afi"] += ["ATM"] interfaces += [i] v = self.cli("get ethernet intf") for match in self.rx_eth.finditer(v): ifname = match.group("name") ip = match.group("ip") mask = match.group("mask") if ip == "0.0.0.0": continue ip_address = "%s/%s" % (ip, IPv4.netmask_to_len(mask)) for i in interfaces: if i["name"] == ifname: i["subinterfaces"][0]["ipv4_addresses"] = [ip_address] i["subinterfaces"][0]["enabled_afi"] += ["IPv4"] if match.group("vlan_id") != "-": i["subinterfaces"][0]["vlan_ids"] = [ match.group("vlan_id") ] break port_ids = {} v = self.cli("get bridge port intf") for match in self.rx_port_id.finditer(v): port_ids[match.group("id")] = match.group("name") v = self.cli("get vlan curr info") for match in self.rx_vlan.finditer(v): vlan_id = match.group("vlan_id") ports = match.group("ports").strip() if ports == "None": continue untagged = match.group("untagged").strip() bridge_ids = ports.split() for port_id in bridge_ids: if port_ids.get(port_id) == "": continue ifname = port_ids.get(port_id) for i in interfaces: if i["name"] == ifname: if (port_id == untagged) and (untagged != "None"): i["subinterfaces"][0]["untagged_vlan"] = vlan_id else: if "tagged_vlans" in i["subinterfaces"][0]: i["subinterfaces"][0]["tagged_vlans"] += [ vlan_id ] else: i["subinterfaces"][0]["tagged_vlans"] = [ vlan_id ] break return [{"interfaces": interfaces}]
def execute_cli(self): interfaces = [] v = self.cli("show interface port") for match in self.rx_port.finditer(v): i = { "name": match.group("port"), "type": "physical", "admin_status": match.group("admin_status") == "enable", "oper_status": match.group("admin_status") == "up", "snmp_ifindex": int(match.group("port")), "subinterfaces": [{ "name": match.group("port"), "admin_status": match.group("admin_status") == "enable", "oper_status": match.group("admin_status") == "up", "enabled_afi": ["BRIDGE"], }], } interfaces += [i] v = self.cli("show interface port switchport") for match in self.rx_vlan.finditer(v): port = match.group("port") for iface in interfaces: if iface["name"] == port: sub = iface["subinterfaces"][0] if match.group("op_mode") in ["trunk", "hybrid"]: sub["untagged_vlan"] = int( match.group("trunk_native_vlan")) sub["tagged_vlans"] = ranges_to_list( match.group("op_vlans")) else: sub["untagged_vlan"] = int(match.group("access_vlan")) break v = self.cli("show interface port description") for match in self.rx_descr.finditer(v): port = match.group("port") descr = match.group("descr").strip() if not descr: continue for iface in interfaces: if iface["name"] == port: iface["description"] = descr iface["subinterfaces"][0]["description"] = descr break mac = self.scripts.get_chassis_id()[0]["first_chassis_mac"] v = self.cli("show interface ip") for match in self.rx_ip_iface.finditer(v): ifname = str(int(match.group("iface")) - 1) addr = match.group("ip") mask = match.group("mask") ip_address = "%s/%s" % (addr, IPv4.netmask_to_len(mask)) i = { "name": "IP%s" % ifname, "type": "SVI", "mac": mac, "enabled_protocols": [], "subinterfaces": [{ "name": "ip%s" % ifname, "mac": mac, "enabled_afi": ["IPv4"], "ipv4_addresses": [ip_address], "vlan_ids": [match.group("vlan_id")], }], } interfaces += [i] return [{"interfaces": interfaces}]
def execute_cli(self): ifaces = [] v = self.cli("show switch port") for match in self.rx_port.finditer(v): port = match.group("port") i = { "name": port, "type": "physical", "admin_status": True, "oper_status": match.group("oper_status") == "Up", "snmp_ifindex": int(port), # Found in AT-8024 "subinterfaces": [{ "name": port, "admin_status": True, "oper_status": match.group("oper_status") == "Up", "enabled_afi": ["BRIDGE"], "untagged_vlan": match.group("pvid") }] } descr = match.group("descr").strip() if descr: i["description"] = descr i["subinterfaces"][0]["description"] = descr ifaces += [i] v = self.cli("show vlan", cached=True) for match in self.profile.rx_vlan.finditer(v): tagged = match.group("tagged").strip() if tagged == "None": continue vlan_id = int(match.group("vlan_id")) tagged = self.expand_rangelist(tagged) for ifname in tagged: for iface in ifaces: if iface["name"] == str(ifname): sub = iface["subinterfaces"][0] if "tagged_vlans" in sub: sub["tagged_vlans"] += [vlan_id] else: sub["tagged_vlans"] = [vlan_id] break v = self.cli("show ip interface") match = self.rx_ip.search(v) ip_address = "%s/%s" % (match.group("ip"), IPv4.netmask_to_len(match.group("mask"))) i = { "name": "mgmt", "type": "SVI", "admin_status": True, "oper_status": True, "subinterfaces": [{ "name": "mgmt", "admin_status": True, "oper_status": True, "ipv4_addresses": [ip_address], "enabled_afi": ["IPv4"] }] } ifaces += [i] return [{"interfaces": ifaces}]
def execute(self): c = self.scripts.get_config() interfaces = [] snmp_ifindex = 1 # Dirty hack. I can anot found another way for match in self.rx_port.finditer(self.cli("show port all")): ifname = match.group("port") try: v = self.cli("show port description %s" % ifname) match1 = self.rx_descr.search(v) snmp_ifindex = int(match1.group("ifindex")) mac = match1.group("mac") descr = match1.group("descr").strip() except self.CLISyntaxError: mac = "" descr = "" iface = { "name": ifname, "type": "physical", "admin_status": match.group("admin_status") == "Enable", "oper_status": match.group("oper_status") == "Up", "enabled_protocols": [], "snmp_ifindex": snmp_ifindex, "subinterfaces": [{ "name": ifname, "admin_status": match.group("admin_status") == "Enable", "oper_status": match.group("oper_status") == "Up", "enabled_afi": ["BRIDGE"], "enabled_protocols": [] }] } if mac: iface["mac"] = mac iface["subinterfaces"][0]["mac"] = mac if descr: iface["description"] = descr iface["subinterfaces"][0]["description"] = descr for match1 in self.rx_vlan.finditer(c): if match1.group("port") == ifname: if match1.group("pvid"): iface["subinterfaces"][0]["untagged_vlan"] = \ match1.group("pvid") if match1.group("tagged"): iface["subinterfaces"][0]["tagged_vlans"] = \ self.expand_rangelist(match1.group("tagged")) if match1.group("igmp"): iface["subinterfaces"][0]["enabled_protocols"] += \ ["IGMP"] interfaces += [iface] snmp_ifindex += 1 match = self.rx_ip.search(self.cli("show network")) ip_address = match.group("ip_address") ip_subnet = match.group("ip_subnet") ip_address = "%s/%s" % (ip_address, IPv4.netmask_to_len(ip_subnet)) iface = { "name": "0/0", "type": "SVI", "admin_status": True, "oper_status": True, "enabled_protocols": [], "subinterfaces": [{ "name": "0/0", "admin_status": True, "oper_status": True, "enabled_afi": ['IPv4'], "ipv4_addresses": [ip_address], "vlan_ids": [int(match.group("vlan_id"))] }] } if match.group("ipv6_address"): iface["subinterfaces"][0]["ipv6_addresses"] = \ [match.group("ipv6_address")] iface["subinterfaces"][0]["enabled_afi"] += ["IPv6"] if match.group("ip_address1") \ and match.group("ip_address1") != "0.0.0.0": ip_address = match.group("ip_address1") ip_subnet = match.group("ip_subnet1") ip_address = "%s/%s" % (ip_address, IPv4.netmask_to_len(ip_subnet)) iface["subinterfaces"][0]["ipv4_addresses"] += [ip_address] if match.group("vlan_id1"): iface["subinterfaces"][0]["vlan_ids"] += \ [int(match.group("vlan_id1"))] interfaces += [iface] return [{"interfaces": interfaces}]
def execute_cli(self): if self.is_iscom2624g: return self.execute_iscom2624g() lldp_ifaces = self.get_lldp_config() interfaces = {} if not self.is_rotek: v = self.cli("show interface port description") for line in v.splitlines()[2:-1]: ifname = int(line[:8]) interfaces[ifname] = { "name": ifname, "type": "physical", "snmp_ifindex": int(line[:8]), "subinterfaces": [], } if str(line[8:]) != "-": interfaces[ifname]["description"] = str(line[8:]) if ifname in lldp_ifaces: interfaces[ifname]["enabled_protocols"] = ["LLDP"] for port in self.get_iface_statuses(): if port["name"] in interfaces: interfaces[port["name"]].update(port) else: interfaces[port["name"]] = port vlans = self.get_switchport_cli() for ifname in interfaces: port = interfaces[ifname] name = str(port["name"]) port["subinterfaces"] = [ { "name": name, "enabled_afi": ["BRIDGE"], "admin_status": port["admin_status"], "oper_status": port["oper_status"], "tagged_vlans": [], } ] if name in vlans: port["subinterfaces"][0]["untagged_vlan"] = int(vlans[name]["untagged_vlan"]) if "n/a" not in vlans[name]["op_trunk_allowed_vlan"]: port["subinterfaces"][0]["tagged_vlans"] = ranges_to_list( vlans[name]["op_trunk_allowed_vlan"] ) if "description" in port: port["subinterfaces"][0]["description"] = port["description"] if not interfaces: v = self.cli("show interface description") for match in self.rx_descr.finditer(v): i = { "name": match.group("port"), "type": "physical", "description": match.group("descr").strip(), "enabled_protocols": [], "subinterfaces": [ {"name": match.group("port"), "description": match.group("descr").strip()} ], } interfaces[i["name"]] = i v = self.cli("show vlan detail") for match in self.rx_vlan2.finditer(v): vlan_id = int(match.group("vlan_id")) ports = ranges_to_list(match.group("ports")) if match.group("untagged"): untagged = ranges_to_list(match.group("untagged")) else: untagged = [] for p in ports: p_name = "port%s" % p if p_name in interfaces: if p not in untagged: if "tagged_vlans" in interfaces[p_name]["subinterfaces"][0]: interfaces[p_name]["subinterfaces"][0]["tagged_vlans"] += [vlan_id] else: interfaces[p_name]["subinterfaces"][0]["tagged_vlans"] = [vlan_id] else: interfaces[p_name]["subinterfaces"][0]["untagged_vlan"] = vlan_id ifdescr = self.get_iface_ip_description() v = self.scripts.get_chassis_id() mac = v[0]["first_chassis_mac"] # XXX: This is a dirty hack !!! # I do not know, how get ip interface MAC address if not self.is_rotek: try: v = self.cli("show interface ip") except self.CLISyntaxError: v = self.cli("show interface ip 0") for match in self.rx_iface.finditer(v): ifname = match.group("iface") i = { "name": "ip%s" % ifname, "type": "SVI", "oper_status": match.group("oper_status") == "active", "admin_status": match.group("oper_status") == "active", "mac": mac, "enabled_protocols": [], "subinterfaces": [ { "name": "ip%s" % ifname, "oper_status": match.group("oper_status") == "active", "admin_status": match.group("oper_status") == "active", "mac": mac, "vlan_ids": [int(match.group("vid"))], "enabled_afi": ["IPv4"], } ], } addr = match.group("ip") mask = match.group("mask") ip_address = "%s/%s" % (addr, IPv4.netmask_to_len(mask)) i["subinterfaces"][0]["ipv4_addresses"] = [ip_address] if ifname in ifdescr: i["description"] = ifdescr[ifname]["description"] i["subinterfaces"][0]["description"] = ifdescr[ifname]["description"] interfaces[i["name"]] = i try: v = self.cli("show ip interface brief") except self.CLISyntaxError: return [{"interfaces": list(interfaces.values())}] for match in self.rx_iface2.finditer(v): ifname = match.group("iface") i = { "name": "ip%s" % ifname, "type": "SVI", "mac": mac, "enabled_protocols": [], "subinterfaces": [{"name": "ip%s" % ifname, "mac": mac, "enabled_afi": ["IPv4"]}], } addr = match.group("ip") mask = match.group("mask") ip_address = "%s/%s" % (addr, IPv4.netmask_to_len(mask)) i["subinterfaces"][0]["ipv4_addresses"] = [ip_address] interfaces[i["name"]] = i if not self.is_rotek: v = self.cli("show interface ip vlan") for match in self.rx_vlans_ip.finditer(v): vlan_id = match.group("vlan_id") if vlan_id == "none": continue ifname = "ip%s" % match.group("iface") for iname in interfaces: if iname == ifname: interfaces[ifname]["subinterfaces"][0]["vlan_ids"] = vlan_id break return [{"interfaces": list(interfaces.values())}]
def execute(self): interfaces = [] v = self.cli("show interface") iface_procc = set() sub_map = {} for match in self.rx_port.finditer(v): ifname = match.group('port') if ifname not in iface_procc: i = { "name": ifname, "type": "physical", "admin_status": match.group('admin_status') == "Yes", "oper_status": match.group('oper_status') == "Yes", "subinterfaces": [] } iface_procc.add(ifname) elif match.group("vpi") and match.group("vci"): vpi = match.group("vpi") vci = match.group("vci") for ii in interfaces: if ii["name"] == ifname: ii["subinterfaces"] += [{ "name": "%s:%s_%s" % (ifname, vpi, vci), "admin_status": match.group('admin_status') == "Yes", "oper_status": match.group('oper_status') == "Yes", "enabled_afi": ["BRIDGE", "ATM"], "vpi": vpi, "vci": vci }] sub_map["%s:%s_%s" % (ifname, vpi, vci)] = ii["subinterfaces"][-1] continue if match.group("vpi") and match.group("vci"): vpi = match.group("vpi") vci = match.group("vci") i["subinterfaces"] += [{ "name": "%s:%s_%s" % (ifname, vpi, vci), "admin_status": match.group('admin_status') == "Yes", "oper_status": match.group('oper_status') == "Yes", "enabled_afi": ["BRIDGE", "ATM"], "vpi": vpi, "vci": vci }] sub_map["%s:%s_%s" % (ifname, vpi, vci)] = i["subinterfaces"][-1] else: i["subinterfaces"] += [{ "name": ifname, "admin_status": match.group('admin_status') == "Yes", "oper_status": match.group('oper_status') == "Yes", "enabled_afi": ["BRIDGE"] }] sub_map[ifname] = i["subinterfaces"][-1] interfaces += [i] for match in self.rx_ip.finditer(v): ifname = match.group('port') for i in interfaces: if i["name"] == ifname: addr = match.group("ip") mask = match.group("mask") ip_address = "%s/%s" % (addr, IPv4.netmask_to_len(mask)) i['type'] = "SVI" i['mac'] = match.group("mac") i['subinterfaces'][0]['mac'] = match.group("mac") i['subinterfaces'][0]["ipv4_addresses"] = [ip_address] i['subinterfaces'][0]["enabled_afi"] = ['IPv4'] v = self.cli("show vlan detail") for match in self.rx_vlan.finditer(v): ifname = match.group('port') # for i in interfaces: # if i['subinterfaces'][0]["name"] == ifname: if ifname in sub_map: if "tagged" in sub_map[ifname]: sub_map[ifname]["tagged"] += [match.group("vlan_id")] else: sub_map[ifname]["tagged"] = [match.group("vlan_id")] for match in self.rx_vlan1.finditer(v): ifname = match.group('port') # for i in interfaces: # if i['subinterfaces'][0]["name"] == ifname: if ifname in sub_map: if match.group("mode") == "trunk": sub_map[ifname]["untagged"] = match.group("vlan_id") else: sub_map[ifname]["vlan_ids"] = [match.group("vlan_id")] return [{"interfaces": interfaces}]
def execute_cli(self): if self.is_iscom2624g: return self.execute_iscom2624g() lldp_ifaces = [] v = self.cli("show lldp local config") match = self.rx_lldp.search(v) if match: lldp_ifaces = self.expand_rangelist(match.group("ports")) ifaces = [] v = self.cli("show interface port description") for line in v.splitlines()[2:-1]: i = { "name": int(line[:8]), "type": "physical", "snmp_ifindex": int(line[:8]), "subinterfaces": [], } if str(line[8:]) != "-": i["description"] = str(line[8:]) if i["name"] in lldp_ifaces: i["enabled_protocols"] = ["LLDP"] ifaces.append(i) statuses = [] v = self.cli("show interface port") for line in v.splitlines()[5:]: i = { "name": int(line[:6]), "admin_status": "enable" in line[7:14], "oper_status": "up" in line[14:29], } statuses.append(i) vlans = [] v = self.cli("show interface port switchport") for section in v.split("Port"): if not section: continue vlans.append(self.parse_vlans(section)) d = defaultdict(dict) for l in (statuses, ifaces): for elem in l: d[elem["name"]].update(elem) l3 = list(six.itervalues(d)) for port in l3: name = port["name"] port["subinterfaces"] = [{ "name": str(name), "enabled_afi": ["BRIDGE"], "admin_status": port["admin_status"], "oper_status": port["oper_status"], "tagged_vlans": [], "untagged_vlan": [ int(vlan["untagged_vlan"]) for vlan in vlans if int(vlan["name"]) == name ][0], }] if "description" in port: port["subinterfaces"][0]["description"] = port["description"] tvl = [ vlan["op_trunk_allowed_vlan"] for vlan in vlans if int(vlan["name"]) == name ][0] if "n/a" not in tvl: port["subinterfaces"][0]["tagged_vlans"] = ranges_to_list(tvl) if_descr = [] v = self.cli("show interface ip description") for line in v.splitlines()[2:-1]: i = {"name": int(line[:9]), "description": str(line[9:])} if_descr.append(i) if not l3: v = self.cli("show interface description") for match in self.rx_descr.finditer(v): i = { "name": match.group("port"), "type": "physical", "description": match.group("descr").strip(), "enabled_protocols": [], "subinterfaces": [{ "name": match.group("port"), "description": match.group("descr").strip() }], } l3 += [i] v = self.cli("show vlan detail") for match in self.rx_vlan2.finditer(v): vlan_id = int(match.group("vlan_id")) ports = ranges_to_list(match.group("ports")) if match.group("untagged"): untagged = ranges_to_list(match.group("untagged")) else: untagged = [] for i in l3: for p in ports: if i["name"] == "port%s" % p: if p not in untagged: if "tagged_vlans" in i["subinterfaces"][0]: i["subinterfaces"][0]["tagged_vlans"] += [ vlan_id ] else: i["subinterfaces"][0]["tagged_vlans"] = [ vlan_id ] else: i["subinterfaces"][0][ "untagged_vlan"] = vlan_id v = self.profile.get_version(self) mac = v["mac"] # XXX: This is a dirty hack !!! # I do not know, how get ip interface MAC address try: v = self.cli("show interface ip") except self.CLISyntaxError: v = self.cli("show interface ip 0") for match in self.rx_iface.finditer(v): ifname = match.group("iface") i = { "name": "ip%s" % ifname, "type": "SVI", "oper_status": match.group("oper_status") == "active", "admin_status": match.group("oper_status") == "active", "mac": mac, "enabled_protocols": [], "subinterfaces": [{ "name": "ip%s" % ifname, "oper_status": match.group("oper_status") == "active", "admin_status": match.group("oper_status") == "active", "mac": mac, "vlan_ids": [int(match.group("vid"))], "enabled_afi": ["IPv4"], }], } addr = match.group("ip") mask = match.group("mask") ip_address = "%s/%s" % (addr, IPv4.netmask_to_len(mask)) i["subinterfaces"][0]["ipv4_addresses"] = [ip_address] for q in if_descr: if str(q["name"]).strip() == ifname: i["description"] = q["description"] i["subinterfaces"][0]["description"] = q["description"] l3 += [i] try: v = self.cli("show ip interface brief") except self.CLISyntaxError: return [{"interfaces": l3}] for match in self.rx_iface2.finditer(v): ifname = match.group("iface") i = { "name": "ip%s" % ifname, "type": "SVI", "mac": mac, "enabled_protocols": [], "subinterfaces": [{ "name": "ip%s" % ifname, "mac": mac, "enabled_afi": ["IPv4"] }], } addr = match.group("ip") mask = match.group("mask") ip_address = "%s/%s" % (addr, IPv4.netmask_to_len(mask)) i["subinterfaces"][0]["ipv4_addresses"] = [ip_address] l3 += [i] v = self.cli("show interface ip vlan") for match in self.rx_vlans_ip.finditer(v): vlan_id = match.group("vlan_id") if vlan_id == "none": continue ifname = "ip%s" % match.group("iface") for i in l3: if i["name"] == ifname: i["subinterfaces"][0]["vlan_ids"] = vlan_id break return [{"interfaces": l3}]
def execute(self): interfaces = [] c = self.profile.get_dict(self) for i in range(0, 4): # for future models mac = c.get("root.Network.eth%d.MACAddress" % i) if mac is not None: iface = { "name": "eth%d" % i, "type": "physical", "admin_status": True, "oper_status": True, "mac": mac, } sub = { "name": "eth%d" % i, "admin_status": True, "oper_status": True, "mac": mac, "enabled_afi": [], } ip = c.get("root.Network.eth%d.IPAddress" % i) mask = c.get("root.Network.eth%d.SubnetMask" % i) if ip and ip != "0.0.0.0" and mask and mask != "0.0.0.0": ip_address = "%s/%s" % (ip, IPv4.netmask_to_len(mask)) sub["ipv4_addresses"] = [ip_address] sub["enabled_afi"] += ["IPv4"] ipv6 = c.get("root.Network.eth%d.IPv6.IPAddresses" % i) if ipv6: sub["ipv6_addresses"] = [ipv6] sub["enabled_afi"] += ["IPv6"] iface["subinterfaces"] = [sub] interfaces += [iface] """ root.Input.NbrOfInputs=1 root.Input.I0.Name=Input 1 root.Input.I0.Trig=closed """ o = c.get("root.Input.NbrOfInputs") if is_int(o) and int(o) > 0: for i in range(0, int(o)): ifname = c.get("root.Input.I%d.Name" % i) iface = { "name": ifname, "type": "dry", "admin_status": True, "oper_status": True, "subinterfaces": [{ "name": ifname, "admin_status": True, "oper_status": True }], } p = c.get("root.Input.I%d.Trig" % i) if p == "closed": iface["enabled_protocols"] = ["DRY_NO"] else: iface["enabled_protocols"] = ["DRY_NC"] interfaces += [iface] """ root.Output.NbrOfOutputs=1 root.Output.O0.Name=Output 1 root.Output.O0.Active=closed root.Output.O0.Button=none root.Output.O0.PulseTime=0 """ o = c.get("root.Output.NbrOfOutputs") if is_int(o) and int(o) > 0: for i in range(0, int(o)): ifname = c.get("root.Output.O%d.Name" % i) iface = { "name": ifname, "type": "dry", "admin_status": True, "oper_status": True, "subinterfaces": [{ "name": ifname, "admin_status": True, "oper_status": True }], } p = c.get("root.Output.O%d.Active" % i) if p == "closed": iface["enabled_protocols"] = ["DRY_NO"] else: iface["enabled_protocols"] = ["DRY_NC"] interfaces += [iface] return [{"interfaces": interfaces}]