Netshow CLI / Netshow Library - Linux Provider Release 1.1.7+Git.18.C727438
Total Page:16
File Type:pdf, Size:1020Kb
Netshow CLI / Netshow Library - Linux Provider Release 1.1.7+git.18.c727438 Jun 20, 2017 Contents 1 Netshow Linux Provider 1 1.1 Linux Provider API...........................................1 1.1.1 Linux Provider API - Netshow Library.............................1 1.1.2 Linux Provider API - Netshow App.............................. 13 1.2 License.................................................. 19 1.3 Credits.................................................. 19 Python Module Index 21 i ii CHAPTER 1 Netshow Linux Provider The Netshow Linux Provider is a plugin for the Netshow, a linux troubleshooting toolkit This site contains the API for this provider. For more details on how Netshow works, see the Netshow App Intro and Netshow Library Intro Linux Provider API Linux Provider API - Netshow Library netshowlib.linux.bond module This module is responsible for finding properties related to bond interface and bond member interfaces class netshowlib.linux.bond.Bond(name, cache=None) Bases: netshowlib.linux.iface.Iface Linux Bond attributes •members: list of bond members/slaves. creates instances of BondMember •bond mode: options are –balance-rr ‘0’ –active-backup ‘1’ –balance-xor ‘2’ –balance-alb ‘3’ –802.3ad ‘4’ –balance-tlb ‘5’ –balance-alb ‘6’ •min_links: number of minimum links 1 Netshow CLI / Netshow Library - Linux Provider, Release 1.1.7+git.18.c727438 •hash_policy: load balancing algorithm. options are –layer2 ‘0’ –layer3+4 ‘1’ •lacp: pointer to Lacp instance for this bond •system_mac: Bond system mac. Packets egressing bond use this mac address. bridge_masters Returns list of bridges associated with this port and its subinterfaces. hash_policy Returns bond load balancing policy / xmit hash policy lacp Returns linux.lacp class instance if bond is in LACP mode members Returns list of bond members min_links Returns number of minimum links required to keep the bond active mode Returns bond mode integer. Not the name. See linux kernel driver docs for more details stp Returns KernelStpBridgeMember instance system_mac Returns bond system mac class netshowlib.linux.bond.BondMember(name, cache=None, master=None) Bases: netshowlib.linux.iface.Iface Linux Bond Member Attributes •master: pointer to Bond instance that this interface belongs to. This can be provided in the __init__ function •linkfailures: bond driver reports number of times bond member flaps •bondstate: returns whether bond member is active (1) or inactive(0) in a bond irrespective of its car- rier/linkstate status. What this means is that the link can be up, but not in the bond. Examples: import netshowlib.netshowlib as nn # bond member info should be normally obtained from # first calling the bond and then running the members # property. bond0= nn.bond.Bond('bond0') print len(bond0.members.keys()) >>2 # on the rare case you know the bond member but want to get # bond master information you can. 2 Chapter 1. Netshow Linux Provider Netshow CLI / Netshow Library - Linux Provider, Release 1.1.7+git.18.c727438 bondmem= nn.bond_member.BondMember('eth1') print bondmem.master >> Linux Bond Interface'bond0'. Member Count:1 bondstate Returns state of interface in the bond. can be 0(inactive) or 1(active) linkfailures number of mii transitions bond member reports while the bond is active this counter cannot be cleared. will reset when the bond is reinitialized via the ifdown/ifup process Returns number of mii transitions master Returns pointer to Bond instance that this interface belongs to netshowlib.linux.bridge module This module is responsible for finding properties related to linux bridge and bridge member interfaces class netshowlib.linux.bridge.Bridge(name, cache=None) Bases: netshowlib.linux.iface.Iface Linux Bridge interface attributes •tagged_members: list of tagged bridge members (part of a trunk) •untagged_members: list of untagged bridge members (access) •members: all bridge members •vlan_tag: vlan ID tag if applicable. empty string means no tag. •stp: pointer to KernelStpBridge instance. If set to None, then bridge has STP disabled. members Returns list of bridge port members stp Returns None if STP is disabled Returns KernelStpBridge instance if STP is enabled tagged_members Works for default/classic linux bridge driver Returns list of tagged bridge members. untagged_members Works for default/classic linux bridge driver Returns list of untagged bridge members vlan_tag For the classic/default bridge driver, if a tagged bridge member is provided then the function will use the tag as the vlan id Returns vlan ID if applicable. If multiple tags found, 1.1. Linux Provider API 3 Netshow CLI / Netshow Library - Linux Provider, Release 1.1.7+git.18.c727438 possibly indicating vlan translation, then all tags are printed as a list Empty array means no tag class netshowlib.linux.bridge.BridgeMember(name, cache=None) Bases: netshowlib.linux.iface.Iface Linux Bridge Member attributes •cache: feature cache •stp: pointer to KernelStpBridgeMember instance bridge_masters Returns list of bridges associated with this port and its subinterfaces. stp Returns instance of KernelStpBridgeMember class netshowlib.linux.bridge.KernelStpBridge(bridge) Bases: object Attributes for STP for a bridge •bridge: instance of Bridge •member_state: return hash of basic stp attributes of bridge members. Example iface= linux.bridge.Bridge('eth2') iface.stp.state >>{'stp_disabled':[list of bridge member instances] 'forwarding':[list of bridge member instances ] 'blocking':[list of bridge member instances ] 'intransition':[ list of bridge member instances ] 'disabled':[list of bridge member instances] 'root':[list of bridge member instances. should only be one] } •root_priority: root priority for the spanning tree domain •bridge_priority: bridge priority bridge_priority Returns return bridge priority number is_root() Returns True if bridge is STP root. member_state Returns dict of stp state of bridge members root_priority Returns return root priority number class netshowlib.linux.bridge.KernelStpBridgeMember(bridgemem, cache=None) Bases: object Attributes for Bridgemems using the Kernel STP •bridgemem: instance of BridgeMember •state: return hash of basic stp attributes of the port. Example 4 Chapter 1. Netshow Linux Provider Netshow CLI / Netshow Library - Linux Provider, Release 1.1.7+git.18.c727438 iface= linux.bridge.BridgeMember('eth2') iface.stp.state >>{'forwarding':[list of bridge instances ] 'blocking':[list of bridge instances ] 'intransition':[ list of bridge instances ] 'disabled':[list of bridge instances] 'root':[list of bridges instances with root ports ] 'stp_disabled':[ list of bridge instances where stp is disabled] } •cache: feature cache that is used state Returns dict of stp states with associated linux.bridge instances netshowlib.linux.bridge.update_stp_state(stp_hash, iface_to_add, iface_under_test) Updates stp state dict from BridgeMember and Bridge netshowlib.linux.cache module This module produces the cache info for Linux class netshowlib.linux.cache.Cache Bases: object This class produces the cache info for Linux networking such as ip addressing, lldp, QOS run(features=None) Parameters features – List of features to enable. If set to None cache from all features is obtained Returns returns Cache instance of appropriate OS type netshowlib.linux.common module Linux common module exception netshowlib.linux.common.ExecCommandException Bases: exceptions.Exception Exception when a exec command fails netshowlib.linux.common.check_bit(int_type, offset) copied from wiki.python.org if testBit is not zero, return checkBit as True netshowlib.linux.common.clear_bit(int_type, offset) Returns integer with the bit at ‘offset’ cleared netshowlib.linux.common.create_range(rkey, rgroup) Parameters rkey – if rey is swp, rgroup is “swp2, swp3, swp10” create a range list given a list of ports with a common pattern netshowlib.linux.common.create_sort_tuple(result) returns tuple value used for sorting. Example (‘bond’, ‘0’, ‘.’ , ‘1’) converts it to (‘bond’, 0, 0, 1) for the sort another example (‘vlan’, ‘10’, ‘-v’, ‘0’) converts to (‘vlan’, 10, 0, 0) for the sort. 1.1. Linux Provider API 5 Netshow CLI / Netshow Library - Linux Provider, Release 1.1.7+git.18.c727438 netshowlib.linux.common.dict_merge(list1, list2) merge two dicts by overriding content in first dict with content from 2nd dict. does not return a new merge dict. all merging takes place in the first dict. Parameters • list1 – original dict • list2 – dict to override original dict content netshowlib.linux.common.exec_command(cmd, cmdenv=None) execute a command netshowlib.linux.common.exec_commandl(cmdl, cmdenv=None) execute a command netshowlib.linux.common.generate_cidr_ip(addr) generate address in CIDR format Example: 10.1.1.1/24 instead of 10.1.1.1 mask 255.255.255.0 netshowlib.linux.common.group_iface(initial_list, group_func) groups iface values netshowlib.linux.common.group_ports(list_of_ports) create group list of ports given a list of ports. Example: ‘swp1, swp2, bond0, bond1, swp3.100, swp4.100’ becomes ‘swp1-2, swp3-4.100, bond0-1’ netshowlib.linux.common.grouping_func(xvar) group ports based on 2 criteria. If name is like so ‘bond0’, ‘swp22’, ‘br-vlan22’, ‘vlan33’, group it by name. So for example ‘bond0’, ‘bond1’, would be under the ‘bond’ group. 2nd criteria is by vlan number. If the ports are ‘swp1.100, swp2.100’ group it by ‘100’. So Dict entry would be ‘100’ -> ‘swp1.100’, ‘swp2.100’ netshowlib.linux.common.has_stats(ifacename) netshowlib.linux.common.munge_str(match0) sorting by string that is int, produces wrong sort..so