def ifacelist(self): """ :return: hash of interface categories. each category containing a list of \ iface pointers to interfaces that belong in that category. For example ifacelist['bridge'] points to a list of bridge Ifaces. """ # ifacelist is already populated.. # to reset set ``self._ifacelist = None`` if len(self._ifacelist.get('all')) > 0: return self._ifacelist self._initialize_ifacelist() list_of_ports = sorted(linux_iface.portname_list()) feature_cache = linux_cache.Cache() feature_cache.run() for _portname in list_of_ports: _printiface = print_iface.iface(_portname, feature_cache) if self.show_up and _printiface.iface.linkstate < 2: continue # if iface is a l2 subint bridgemem, then ignore if _printiface.iface.is_subint() and \ isinstance(_printiface, print_bridge.PrintBridgeMember): continue self._ifacelist['all'][_portname] = _printiface # mutual exclusive bond/bridge/bondmem/bridgemem if isinstance(_printiface, print_bridge.PrintBridge): self._ifacelist['bridge'][_portname] = _printiface self._ifacelist['l2'][_portname] = _printiface elif isinstance(_printiface, print_bond.PrintBond): self._ifacelist['bond'][_portname] = _printiface elif isinstance(_printiface, print_bridge.PrintBridgeMember): self._ifacelist['l2'][_portname] = _printiface elif isinstance(_printiface, print_bond.PrintBondMember): self._ifacelist['bondmem'][_portname] = _printiface continue # mutual exclusive - l3/trunk/access if _printiface.iface.is_l3(): self._ifacelist['l3'][_portname] = _printiface elif _printiface.iface.is_trunk(): self._ifacelist['trunk'][_portname] = _printiface elif _printiface.iface.is_access(): self._ifacelist['access'][_portname] = _printiface return self._ifacelist
def print_single_iface(self): """ :return: netshow terminal output or JSON of a single iface """ feature_cache = linux_cache.Cache() feature_cache.run() _printiface = 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 _printiface.cli_output(show_legend=self.show_legend)