def bridgemem_details(self): """ :return: list vlans or bridge names of various stp states MODIFY """ if not self.iface.is_bridgemem(): return None # check if port is in STP _str = '' _stpstate = self.iface.stp.state # get the list of states by grabbing all the keys if self.iface.vlan_filtering: _vlanlist = self.iface.vlan_list _header = [_("all vlans on l2 port")] _table = [[', '.join(linux_common.create_range('', _vlanlist))]] _str += tabulate(_table, _header, numalign='left') + self.new_line() _header = [_("untagged vlans")] _table = [[', '.join(self.iface.native_vlan)]] _str += tabulate(_table, _header, numalign='left') + self.new_line() for _state, _bridgelist in _stpstate.items(): if _bridgelist: _header = [_("vlans in %s state") % (inflection.titleize(_state))] # if vlan aware and bridgelist is not empty, then assume # all vlans have that stp state if self.iface.vlan_filtering: _table = [[', '.join(linux_common.create_range( '', _vlanlist))]] else: _table = [self._pretty_vlanlist(_bridgelist)] _str += tabulate(_table, _header, numalign='left') + self.new_line() return _str
def in_clag(self): """ :return: print clag status """ if self.iface.clag_enable == '0': return _('clag inactive') elif self.iface.clag_enable == '1': return _('clag active') else: return _('clag not supported')
def trunk_summary_vlan_aware(self): """ :return list of vlan trunk info for vlan aware bridge """ _strlist = [] _strlist.append(_('vlans') + ': ' + ','.join( linux_common.create_range('', self.iface.vlan_list))) _strlist.append(_('native') + ': ' + ','.join( linux_common.create_range('', self.iface.native_vlan))) return _strlist
def print_counters(self): """ :return: cli output of netshow counters """ _header = ['', _('port'), _('speed'), _('mode'), '', _('ucast'), _('mcast'), _('bcast'), _('errors')] _table = [] for _piface in self.ifacelist.values(): if not _piface.iface.counters.rx: return "This is probably Cumulus VX, or ethtool -S doesn't work for this user. " \ "Cannot produce valid counters yet" _rx_counters = _piface.iface.counters.rx _tx_counters = _piface.iface.counters.tx _table.append([_piface.linkstate, _piface.name, _piface.speed, _piface.port_category, _('rx'), _rx_counters.get('unicast'), _rx_counters.get('multicast'), _rx_counters.get('broadcast'), _rx_counters.get('errors')]) _table.append(['', '', '', '', _('tx'), _tx_counters.get('unicast'), _tx_counters.get('multicast'), _tx_counters.get('broadcast'), _tx_counters.get('errors')]) return legend_wrapped_cli_output(tabulate(_table, _header, floatfmt='.0f'))
def port_category(self): """ :return: port type. Via interface discovery determine classify port \ type """ if self.iface.is_mgmt(): return _('mgmt') elif self.iface.is_svi(): return _('svi/l3') else: return super(PrintIface, self).port_category
def stp_mode(self): stp_mode = self.iface.stp.mode if stp_mode == 0: _str = _('802.1d / per vlan instance') elif stp_mode == 1: _str = _('802.1d / single instance') elif stp_mode == 2: _str = _('RSTP / per vlan instance') elif stp_mode == 3: _str = _('RSTP / single instance') return _str
def lacp_bypass(self): """ :return print lacp bypass status """ _lacp = self.iface.lacp if _lacp: if _lacp.bypass == '1': return _('lacp_bypass_active') elif _lacp.bypass == '0': return _('lacp_bypass_inactive') return _('lacp bypass not supported')
def stp_mode(self): stp_mode = self.iface.stp.mode if stp_mode == 0: _str = _("802.1d / per vlan instance") elif stp_mode == 1: _str = _("802.1d / single instance") elif stp_mode == 2: _str = _("RSTP / per vlan instance") elif stp_mode == 3: _str = _("RSTP / single instance") return _str
def root_port(self): ":return: root port in the form of a list" if self.iface.stp: _stproot = self.iface.stp.root_port if _stproot != 'none': return [str(_stproot)] return [_('root_switch')]
def alternate_ports(self): if self.iface.stp: portlist = self.iface.stp.member_state.get('alternate') portnames = [x.name for x in portlist] if portlist: return linux_common.group_ports(portnames) return [_('none')]
def alternate_ports(self): if self.iface.stp: portlist = self.iface.stp.member_state.get("alternate") portnames = [x.name for x in portlist] if portlist: return linux_common.group_ports(portnames) return [_("none")]
def counters_summary(self): """ if counters are available print a summary of the counters. """ _counters = self.iface.counters if not _counters: return '' _counters_all = _counters.all _header = [_('counters'), _('tx'), _('rx')] _table = [] for _countername in ['errors', 'unicast', 'broadcast', 'multicast']: _table.append([_(_countername), _counters_all.get('tx').get(_countername), _counters_all.get('rx').get(_countername)]) # keep return in the right place please! return tabulate(_table, _header) + self.new_line()
def connector_type(self): """ :return: prints out string for connector type """ if not hasattr(self.iface, 'connector_type'): return None _connector = self.iface.connector_type if _connector == 4: return _('4x10g') elif _connector == 3: return _('qsfp') elif _connector == 2: return _('sfp') elif _connector == 1: return _('rj45')
def root_port(self): ":return: root port in the form of a list" if self.iface.stp: _stproot = self.iface.stp.root_port if _stproot != "none": return [str(_stproot)] return [_("root_switch")]
def access_summary_vlan_aware(self): """ :return: list of access summar port info """ _strlist = [] _strlist.append(_('native') + ': ' + ','.join(self.iface.vlan_list)) return _strlist
def clag_summary(self): """ :return: clag summary details for 'netshow interface' for all ints """ if self.iface.clag_enable == '1': return _('in_clag') return ''
def bondmem_details(self): """ print out table with bond member summary info for netshow interface [ifacename] for bond interface """ _header = [ '', _('port'), _('speed'), _('tx'), _('rx'), _('err'), _('link_failures') ] _table = [] _bondmembers = self.iface.members.values() if len(_bondmembers) == 0: return _('no_bond_members_found') for _bondmem in _bondmembers: _printbondmem = PrintBondMember(_bondmem) _table.append([ _printbondmem.linkstate, "%s(%s)" % (_printbondmem.name, self.abbrev_bondstate(_bondmem)), _printbondmem.speed, _bondmem.counters.total_tx, _bondmem.counters.total_rx, _bondmem.counters.total_err, _bondmem.linkfailures ]) return tabulate(_table, _header, floatfmt='.0f') + self.new_line()
def counters_summary(self): """ print summary of cumulus counters Returns: table of unicast, broadcast, multicast and error tx/rx counters if executed on cumulus VM/non Cumulus but Linux platform, this returns nothing """ _counters = self.iface.counters if not _counters or not _counters.tx: return '' _counters_all = _counters.all _header = [_('counters'), _('tx'), _('rx')] _table = [] for _countername in ['errors', 'unicast', 'broadcast', 'multicast']: _table.append([_(_countername), _counters_all.get('tx').get(_countername), _counters_all.get('rx').get(_countername)]) # keep return in the right place please! return tabulate(_table, _header) + self.new_line()
def cli_output(self): """ :return: print out system info on a cumulus switch """ _pd = self.system.platform_info # If platform detect does not work. # TODO make this better.... if not _pd: return linux_system.ShowSystem.cli_output(self) chip = _pd.get('chipset') cpu = _pd.get('processor') _str = '' _str = "\n%s %s\n" % (_pd.get('manufacturer'), _pd.get('model')) _str += "%s %s %s\n" % (self.system.os_name, _('version'), self.system.version) _str += "%s: %s\n\n" % (_('build'), self.system.os_build) _str += "%s: %s %s %s\n\n" % (_('chipset'), chip.get('manufacturer'), chip.get('family'), chip.get('model')) _str += "%s: %s\n\n" % (_('port config'), _pd.get('ports')) _str += "%s: (%s) %s %s %s %s\n\n" % (_('cpu'), self.system.arch, cpu.get('manufacturer'), cpu.get('family'), cpu.get('model'), cpu.get('speed')) _str += "%s: %s\n" % (_('uptime'), self.uptime) return _str
def stp_details(self): """ :return: stp details for the bridge interface """ _header = ["", ""] _table = [] _table.append([_("stp_mode") + ":", self.stp_mode()]) _table.append([_("root_port") + ":", ", ".join(self.root_port())]) _table.append([_("ports_in_designated_role") + ":", ", ".join(self.designated_ports())]) _table.append([_("ports_in_alternate_role") + ":", ", ".join(self.alternate_ports())]) _table.append([_("root_priority") + ":", self.iface.stp.root_priority]) _table.append([_("bridge_priority") + ":", self.iface.stp.bridge_priority]) _table.append([_("last_tcn") + ":", self.last_tcn_field()]) if self.iface.vlan_filtering: _table.append([_("bridge_type"), _("vlan_aware_bridge")]) else: _table.append(self.vlan_id_field().split()) return tabulate(_table, _header) + self.new_line()
def bond_details(self): """ print out table with bond details for netshow interface [ifacename] """ _header = [_('bond_details'), ''] _table = [] _table.append([_('bond_mode') + ':', self.mode]) _table.append([_('load_balancing') + ':', self.hash_policy]) _table.append([_('minimum_links') + ':', self.iface.min_links]) if self.in_clag: _table.append([_('in_clag') + ':', self.in_clag()]) _lacp_info = self.iface.lacp if _lacp_info: _table.append([_('lacp_sys_priority') + ':', self.iface.lacp.sys_priority]) _table.append([_('lacp_rate') + ':', self.lacp_rate()]) _table.append([_('lacp_bypass') + ':', self.lacp_bypass()]) return tabulate(_table, _header) + self.new_line()
def stp_details(self): """ :return: stp details for the bridge interface """ _header = ['', ''] _table = [] _table.append([_('stp_mode') + ':', self.stp_mode()]) _table.append([_('root_port') + ':', ', '.join(self.root_port())]) _table.append([_('ports_in_designated_role') + ':', ', '.join(self.designated_ports())]) _table.append([_('ports_in_alternate_role') + ':', ', '.join(self.alternate_ports())]) _table.append([_('root_priority') + ':', self.iface.stp.root_priority]) _table.append([_('bridge_priority') + ':', self.iface.stp.bridge_priority]) _table.append([_('last_tcn') + ':', self.last_tcn_field()]) if self.iface.vlan_filtering: _table.append([_('bridge_type'), _('vlan_aware_bridge')]) else: _table.append(self.vlan_id_field().split()) return tabulate(_table, _header) + self.new_line()
def print_single_iface(self): """ :return: netshow terminal output or JSON of a single iface """ feature_cache = self.cache.Cache() feature_cache.run() _printiface = self.print_iface.iface(self.single_iface, feature_cache) if not _printiface: return _('interface_does_not_exist') if self.use_json: return json.dumps(_printiface, cls=NetEncoder, indent=4) else: return legend_wrapped_cli_output(_printiface.cli_output(), self.show_legend)
def bond_details(self): """ print out table with bond details for netshow interface [ifacename] """ _header = [_('bond_details'), ''] _table = [] _table.append([_('bond_mode') + ':', self.mode]) _table.append([_('load_balancing') + ':', self.hash_policy]) _table.append([_('minimum_links') + ':', self.iface.min_links]) if self.in_clag: _table.append([_('in_clag') + ':', self.in_clag()]) _lacp_info = self.iface.lacp if _lacp_info: _table.append( [_('lacp_sys_priority') + ':', self.iface.lacp.sys_priority]) _table.append([_('lacp_rate') + ':', self.lacp_rate()]) _table.append([_('lacp_bypass') + ':', self.lacp_bypass()]) return tabulate(_table, _header) + self.new_line()
def print_counters(self): """ :return: cli output of netshow counters """ _header = ['', _('port'), _('speed'), _('mode'), '', _('ucast'), _('mcast'), _('bcast'), _('errors')] _table = [] for _piface in self.ifacelist.values(): _rx_counters = _piface.iface.counters.rx _tx_counters = _piface.iface.counters.tx _table.append([_piface.linkstate, _piface.name, _piface.speed, _piface.port_category, _('rx'), _rx_counters.get('unicast'), _rx_counters.get('multicast'), _rx_counters.get('broadcast'), _rx_counters.get('errors')]) _table.append(['', '', '', '', _('tx'), _tx_counters.get('unicast'), _tx_counters.get('multicast'), _tx_counters.get('broadcast'), _tx_counters.get('errors')]) return legend_wrapped_cli_output(tabulate(_table, _header, floatfmt='.0f'))
def print_counters(self): """ :return: cli output of netshow counters """ _header = [ '', _('port'), _('speed'), _('mode'), '', _('ucast'), _('mcast'), _('bcast'), _('errors') ] _table = [] for _piface in self.ifacelist.values(): _rx_counters = _piface.iface.counters.rx _tx_counters = _piface.iface.counters.tx _table.append([ _piface.linkstate, _piface.name, _piface.speed, _piface.port_category, _('rx'), _rx_counters.get('unicast'), _rx_counters.get('multicast'), _rx_counters.get('broadcast'), _rx_counters.get('errors') ]) _table.append([ '', '', '', '', _('tx'), _tx_counters.get('unicast'), _tx_counters.get('multicast'), _tx_counters.get('broadcast'), _tx_counters.get('errors') ]) return legend_wrapped_cli_output( tabulate(_table, _header, floatfmt='.0f'))
def bondmem_details(self): """ print out table with bond member summary info for netshow interface [ifacename] for bond interface """ _header = ['', _('port'), _('speed'), _('tx'), _('rx'), _('err'), _('link_failures')] _table = [] _bondmembers = self.iface.members.values() if len(_bondmembers) == 0: return _('no_bond_members_found') for _bondmem in _bondmembers: _printbondmem = PrintBondMember(_bondmem) _table.append([_printbondmem.linkstate, "%s(%s)" % (_printbondmem.name, self.abbrev_bondstate(_bondmem)), _printbondmem.speed, _bondmem.counters.total_tx, _bondmem.counters.total_rx, _bondmem.counters.total_err, _bondmem.linkfailures]) return tabulate(_table, _header, floatfmt='.0f') + self.new_line()
def bondmem_details(self): """ :return: string with output shown when netshow interfaces is issued on a \ bond member """ _header = [_('bond_details'), ''] _master = self.iface.master _printbond = PrintBond(_master) _table = [] _table.append([_('master_bond') + ':', _master.name]) _table.append([_('state_in_bond') + ':', self.state_in_bond]) _table.append([_('link_failures') + ':', self.iface.linkfailures]) _table.append( [_('bond_members') + ':', ', '.join(_master.members.keys())]) _table.append([_('bond_mode') + ':', _printbond.mode]) _table.append([_('load_balancing') + ':', _printbond.hash_policy]) _table.append([_('minimum_links') + ':', _master.min_links]) _lacp_info = self.iface.master.lacp if _lacp_info: _table.append( [_('lacp_sys_priority') + ':', _master.lacp.sys_priority]) _table.append([_('lacp_rate') + ':', _printbond.lacp_rate()]) _table.append([_('lacp_bypass') + ':', _printbond.lacp_bypass()]) return tabulate(_table, _header)
def is_vlan_aware_bridge(self): if self.iface.vlan_filtering: return _("vlan_aware_bridge") return ""
def bondmem_details(self): """ :return: string with output shown when netshow interfaces is issued on a \ bond member """ _header = [_('bond_details'), ''] _master = self.iface.master _printbond = PrintBond(_master) _table = [] _table.append([_('master_bond') + ':', _master.name]) _table.append([_('state_in_bond') + ':', self.state_in_bond]) _table.append([_('link_failures') + ':', self.iface.linkfailures]) _table.append([_('bond_members') + ':', ', '.join(_master.members.keys())]) _table.append([_('bond_mode') + ':', _printbond.mode]) _table.append([_('load_balancing') + ':', _printbond.hash_policy]) _table.append([_('minimum_links') + ':', _master.min_links]) _lacp_info = self.iface.master.lacp if _lacp_info: _table.append([_('lacp_sys_priority') + ':', _master.lacp.sys_priority]) _table.append([_('lacp_rate') + ':', _printbond.lacp_rate()]) _table.append([_('lacp_bypass') + ':', _printbond.lacp_bypass()]) return tabulate(_table, _header)
def is_vlan_aware_bridge(self): if self.iface.vlan_filtering: return _('vlan_aware_bridge') return ''