コード例 #1
0
    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
コード例 #2
0
    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)
コード例 #3
0
 def test_read_ipaddr(self, mock_cache_info):
     """ test reading IP address """
     # no cache provided.
     mock_cache_info.return_value = {
         'eth2': {
             'ipv4': ['192.168.1.1/24'],
             'ipv6': ['10:1:1::1/128']
         }
     }
     self.iface = linux_iface.Iface('eth2')
     _ipaddr = self.iface.ip_address
     assert_equals(_ipaddr.ipv4, ['192.168.1.1/24'])
     new_cache = linux_cache.Cache()
     new_cache.run()
     new_cache.ip_address = {'eth2': {'ipv4': ['10.1.1.1/24']}}
     self.iface = linux_iface.Iface('eth2', new_cache)
     assert_equals(self.iface.ip_address.ipv4, ['10.1.1.1/24'])
コード例 #4
0
 def test_run_ip_address(self, mock_ip_cache):
     """ get ipv6 and ipv4 info """
     # using feature cache
     _output = io.open('tests/test_netshowlib/ip_addr_show.txt').read()
     output = io.StringIO(_output)
     mock_ip_cache.return_value = ip_address_mod.parse_ip_cache(output)
     _feature_cache = feature_cache.Cache()
     _feature_cache.run()
     ip_address = ip_address_mod.IpAddress('eth0', _feature_cache)
     ip_address.run()
     assert_equals(ip_address.ipv4, ['192.168.0.33/24'])
     assert_equals(ip_address.ipv6, [])
     # without feature cache
     ip_address = ip_address_mod.IpAddress('eth0')
     ip_address.run()
     assert_equals(ip_address.ipv4, ['192.168.0.33/24'])
     assert_equals(ip_address.ipv6, [])
コード例 #5
0
 def setup(self):
     self.cache = linux_cache.Cache()