Esempio n. 1
0
    def test_ip_info(self, nic0):
        nic0_interface = Interface.from_existing_dev_name(nic0)
        with waitfor.waitfor_ipv4_addr(nic0, address=IPV4_ADDR1_CIDR):
            nic0_interface.add_ip(IPV4_ADDR1, IPV4_PREFIX_LENGTH,
                                  IpFamily.IPv4)
        with waitfor.waitfor_ipv4_addr(nic0, address=IPV4_ADDR2_CIDR):
            nic0_interface.add_ip(IPV4_ADDR2, IPV4_PREFIX_LENGTH,
                                  IpFamily.IPv4)
        with waitfor.waitfor_ipv6_addr(nic0, address=IPV6_ADDR_CIDR):
            nic0_interface.add_ip(IPV6_ADDR, IPV6_PREFIX_LENGTH, IpFamily.IPv6)

        # 32 bit addresses are reported slashless by netlink
        with waitfor.waitfor_ipv4_addr(nic0, address=IPV4_ADDR3):
            nic0_interface.add_ip(IPV4_ADDR3, 32, IpFamily.IPv4)

        assert addresses.getIpInfo(nic0) == (
            IPV4_ADDR1,
            IPV4_NETMASK,
            [IPV4_ADDR1_CIDR, IPV4_ADDR2_CIDR, IPV4_ADDR3_CIDR],
            [IPV6_ADDR_CIDR],
        )
        assert addresses.getIpInfo(nic0, ipv4_gateway=IPV4_GATEWAY1) == (
            IPV4_ADDR1,
            IPV4_NETMASK,
            [IPV4_ADDR1_CIDR, IPV4_ADDR2_CIDR, IPV4_ADDR3_CIDR],
            [IPV6_ADDR_CIDR],
        )
        assert addresses.getIpInfo(nic0, ipv4_gateway=IPV4_GATEWAY2) == (
            IPV4_ADDR2,
            IPV4_NETMASK,
            [IPV4_ADDR1_CIDR, IPV4_ADDR2_CIDR, IPV4_ADDR3_CIDR],
            [IPV6_ADDR_CIDR],
        )
Esempio n. 2
0
    def test_ip_info(self, nic0):
        with waitfor.waitfor_ipv4_addr(nic0, address=IPV4_ADDR1_CIDR):
            ipwrapper.addrAdd(nic0, IPV4_ADDR1, IPV4_PREFIX_LENGTH)
        with waitfor.waitfor_ipv4_addr(nic0, address=IPV4_ADDR2_CIDR):
            ipwrapper.addrAdd(nic0, IPV4_ADDR2, IPV4_PREFIX_LENGTH)
        with waitfor.waitfor_ipv6_addr(nic0, address=IPV6_ADDR_CIDR):
            ipwrapper.addrAdd(nic0, IPV6_ADDR, IPV6_PREFIX_LENGTH, family=6)

        # 32 bit addresses are reported slashless by netlink
        with waitfor.waitfor_ipv4_addr(nic0, address=IPV4_ADDR3):
            ipwrapper.addrAdd(nic0, IPV4_ADDR3, 32)

        assert addresses.getIpInfo(nic0) == (
            IPV4_ADDR1,
            IPV4_NETMASK,
            [IPV4_ADDR1_CIDR, IPV4_ADDR2_CIDR, IPV4_ADDR3_CIDR],
            [IPV6_ADDR_CIDR],
        )
        assert addresses.getIpInfo(nic0, ipv4_gateway=IPV4_GATEWAY1) == (
            IPV4_ADDR1,
            IPV4_NETMASK,
            [IPV4_ADDR1_CIDR, IPV4_ADDR2_CIDR, IPV4_ADDR3_CIDR],
            [IPV6_ADDR_CIDR],
        )
        assert addresses.getIpInfo(nic0, ipv4_gateway=IPV4_GATEWAY2) == (
            IPV4_ADDR2,
            IPV4_NETMASK,
            [IPV4_ADDR1_CIDR, IPV4_ADDR2_CIDR, IPV4_ADDR3_CIDR],
            [IPV6_ADDR_CIDR],
        )
Esempio n. 3
0
    def test_ip_info(self):
        IPV4_ADDR1 = '192.168.99.2'
        IPV4_GATEWAY1 = '192.168.99.1'
        IPV4_ADDR2 = '192.168.199.2'
        IPV4_GATEWAY2 = '192.168.199.1'
        IPV4_ADDR3 = '192.168.200.2'
        IPV4_NETMASK = '255.255.255.0'
        IPV4_PREFIX_LENGTH = 24
        IPV6_ADDR = '2607:f0d0:1002:51::4'
        IPV6_PREFIX_LENGTH = 64

        IPV4_ADDR1_CIDR = self._cidr_form(IPV4_ADDR1, IPV4_PREFIX_LENGTH)
        IPV4_ADDR2_CIDR = self._cidr_form(IPV4_ADDR2, IPV4_PREFIX_LENGTH)
        IPV4_ADDR3_CIDR = self._cidr_form(IPV4_ADDR3, 32)
        IPV6_ADDR_CIDR = self._cidr_form(IPV6_ADDR, IPV6_PREFIX_LENGTH)

        with dummy_device() as device:
            with waitfor.waitfor_ipv4_addr(device, address=IPV4_ADDR1_CIDR):
                ipwrapper.addrAdd(device, IPV4_ADDR1, IPV4_PREFIX_LENGTH)
            with waitfor.waitfor_ipv4_addr(device, address=IPV4_ADDR2_CIDR):
                ipwrapper.addrAdd(device, IPV4_ADDR2, IPV4_PREFIX_LENGTH)
            with waitfor.waitfor_ipv6_addr(device, address=IPV6_ADDR_CIDR):
                ipwrapper.addrAdd(device,
                                  IPV6_ADDR,
                                  IPV6_PREFIX_LENGTH,
                                  family=6)

            # 32 bit addresses are reported slashless by netlink
            with waitfor.waitfor_ipv4_addr(device, address=IPV4_ADDR3):
                ipwrapper.addrAdd(device, IPV4_ADDR3, 32)

            self.assertEqual(
                addresses.getIpInfo(device),
                (
                    IPV4_ADDR1,
                    IPV4_NETMASK,
                    [IPV4_ADDR1_CIDR, IPV4_ADDR2_CIDR, IPV4_ADDR3_CIDR],
                    [IPV6_ADDR_CIDR],
                ),
            )
            self.assertEqual(
                addresses.getIpInfo(device, ipv4_gateway=IPV4_GATEWAY1),
                (
                    IPV4_ADDR1,
                    IPV4_NETMASK,
                    [IPV4_ADDR1_CIDR, IPV4_ADDR2_CIDR, IPV4_ADDR3_CIDR],
                    [IPV6_ADDR_CIDR],
                ),
            )
            self.assertEqual(
                addresses.getIpInfo(device, ipv4_gateway=IPV4_GATEWAY2),
                (
                    IPV4_ADDR2,
                    IPV4_NETMASK,
                    [IPV4_ADDR1_CIDR, IPV4_ADDR2_CIDR, IPV4_ADDR3_CIDR],
                    [IPV6_ADDR_CIDR],
                ),
            )
Esempio n. 4
0
 def test_netinfo_ignoring_link_scope_ip(self):
     v4_link = {
         'family': 'inet',
         'address': '169.254.0.0/16',
         'scope': 'link',
         'prefixlen': 16,
         'flags': ['permanent']
     }
     v4_global = {
         'family': 'inet',
         'address': '192.0.2.2/24',
         'scope': 'global',
         'prefixlen': 24,
         'flags': ['permanent']
     }
     v6_link = {
         'family': 'inet6',
         'address': 'fe80::5054:ff:fea3:f9f3/64',
         'scope': 'link',
         'prefixlen': 64,
         'flags': ['permanent']
     }
     v6_global = {
         'family': 'inet6',
         'address': 'ee80::5054:ff:fea3:f9f3/64',
         'scope': 'global',
         'prefixlen': 64,
         'flags': ['permanent']
     }
     ipaddrs = {'eth0': (v4_link, v4_global, v6_link, v6_global)}
     ipv4addr, ipv4netmask, ipv4addrs, ipv6addrs = \
         addresses.getIpInfo('eth0', ipaddrs=ipaddrs)
     self.assertEqual(ipv4addrs, ['192.0.2.2/24'])
     self.assertEqual(ipv6addrs, ['ee80::5054:ff:fea3:f9f3/64'])
Esempio n. 5
0
    def test_ip_info(self):
        IPV4_ADDR1 = '192.168.99.2'
        IPV4_GATEWAY1 = '192.168.99.1'
        IPV4_ADDR2 = '192.168.199.2'
        IPV4_GATEWAY2 = '192.168.199.1'
        IPV4_ADDR3 = '192.168.200.2'
        IPV4_NETMASK = '255.255.255.0'
        IPV4_PREFIX_LENGTH = 24
        IPV6_ADDR = '2607:f0d0:1002:51::4'
        IPV6_PREFIX_LENGTH = 64

        IPV4_ADDR1_CIDR = self._cidr_form(IPV4_ADDR1, IPV4_PREFIX_LENGTH)
        IPV4_ADDR2_CIDR = self._cidr_form(IPV4_ADDR2, IPV4_PREFIX_LENGTH)
        IPV4_ADDR3_CIDR = self._cidr_form(IPV4_ADDR3, 32)
        IPV6_ADDR_CIDR = self._cidr_form(IPV6_ADDR, IPV6_PREFIX_LENGTH)

        with dummy_device() as device:
            with waitfor.waitfor_ipv4_addr(device, address=IPV4_ADDR1_CIDR):
                ipwrapper.addrAdd(device, IPV4_ADDR1, IPV4_PREFIX_LENGTH)
            with waitfor.waitfor_ipv4_addr(device, address=IPV4_ADDR2_CIDR):
                ipwrapper.addrAdd(device, IPV4_ADDR2, IPV4_PREFIX_LENGTH)
            with waitfor.waitfor_ipv6_addr(device, address=IPV6_ADDR_CIDR):
                ipwrapper.addrAdd(
                    device, IPV6_ADDR, IPV6_PREFIX_LENGTH, family=6)

            # 32 bit addresses are reported slashless by netlink
            with waitfor.waitfor_ipv4_addr(device, address=IPV4_ADDR3):
                ipwrapper.addrAdd(device, IPV4_ADDR3, 32)

            self.assertEqual(
                addresses.getIpInfo(device),
                (IPV4_ADDR1, IPV4_NETMASK,
                 [IPV4_ADDR1_CIDR, IPV4_ADDR2_CIDR, IPV4_ADDR3_CIDR],
                 [IPV6_ADDR_CIDR]))
            self.assertEqual(
                addresses.getIpInfo(device, ipv4_gateway=IPV4_GATEWAY1),
                (IPV4_ADDR1, IPV4_NETMASK,
                 [IPV4_ADDR1_CIDR, IPV4_ADDR2_CIDR, IPV4_ADDR3_CIDR],
                 [IPV6_ADDR_CIDR]))
            self.assertEqual(
                addresses.getIpInfo(device, ipv4_gateway=IPV4_GATEWAY2),
                (IPV4_ADDR2, IPV4_NETMASK,
                 [IPV4_ADDR1_CIDR, IPV4_ADDR2_CIDR, IPV4_ADDR3_CIDR],
                 [IPV6_ADDR_CIDR]))
Esempio n. 6
0
def _get_iface_info(iface, addresses, routes):
    ipv4gateway = get_gateway(routes, iface, family=4)
    ipv4addr, ipv4netmask, ipv4addrs, ipv6addrs = getIpInfo(
        iface, addresses, ipv4gateway)
    is_dhcpv4, is_dhcpv6 = dhcp_status(iface, addresses)

    return {'mtu': getMtu(iface), 'addr': ipv4addr, 'ipv4addrs': ipv4addrs,
            'gateway': ipv4gateway, 'netmask': ipv4netmask,
            'dhcpv4': is_dhcpv4, 'ipv6addrs': ipv6addrs,
            'ipv6gateway': get_gateway(routes, iface, family=6),
            'ipv6autoconf': is_ipv6_local_auto(iface), 'dhcpv6': is_dhcpv6}
Esempio n. 7
0
File: info.py Progetto: nirs/vdsm
def _get_iface_info(iface, addresses, routes):
    ipv4gateway = get_gateway(routes, iface, family=4)
    ipv4addr, ipv4netmask, ipv4addrs, ipv6addrs = getIpInfo(
        iface, addresses, ipv4gateway)
    is_dhcpv4 = dhclient.is_active(iface, family=4)
    is_dhcpv6 = dhclient.is_active(iface, family=6)
    mtu = iflink(iface).mtu()
    return {'mtu': mtu, 'addr': ipv4addr, 'ipv4addrs': ipv4addrs,
            'gateway': ipv4gateway, 'netmask': ipv4netmask,
            'ipv4defaultroute': is_default_route(ipv4gateway, routes),
            'dhcpv4': is_dhcpv4, 'ipv6addrs': ipv6addrs,
            'ipv6gateway': get_gateway(routes, iface, family=6),
            'ipv6autoconf': is_ipv6_local_auto(iface), 'dhcpv6': is_dhcpv6}
Esempio n. 8
0
def _get_iface_info(iface, addresses, routes):
    ipv4gateway = get_gateway(routes, iface, family=4)
    ipv4addr, ipv4netmask, ipv4addrs, ipv6addrs = getIpInfo(
        iface, addresses, ipv4gateway)
    is_dhcpv4 = dhclient.is_active(iface, family=4)
    is_dhcpv6 = dhclient.is_active(iface, family=6)

    return {'mtu': get_mtu(iface), 'addr': ipv4addr, 'ipv4addrs': ipv4addrs,
            'gateway': ipv4gateway, 'netmask': ipv4netmask,
            'ipv4defaultroute': is_default_route(ipv4gateway),
            'dhcpv4': is_dhcpv4, 'ipv6addrs': ipv6addrs,
            'ipv6gateway': get_gateway(routes, iface, family=6),
            'ipv6autoconf': is_ipv6_local_auto(iface), 'dhcpv6': is_dhcpv6}
Esempio n. 9
0
 def test_netinfo_ignoring_link_scope_ip(self):
     v4_link = {'family': 'inet', 'address': '169.254.0.0/16',
                'scope': 'link', 'prefixlen': 16, 'flags': ['permanent']}
     v4_global = {'family': 'inet', 'address': '192.0.2.2/24',
                  'scope': 'global', 'prefixlen': 24,
                  'flags': ['permanent']}
     v6_link = {'family': 'inet6', 'address': 'fe80::5054:ff:fea3:f9f3/64',
                'scope': 'link', 'prefixlen': 64, 'flags': ['permanent']}
     v6_global = {'family': 'inet6',
                  'address': 'ee80::5054:ff:fea3:f9f3/64',
                  'scope': 'global', 'prefixlen': 64,
                  'flags': ['permanent']}
     ipaddrs = {'eth0': (v4_link, v4_global, v6_link, v6_global)}
     ipv4addr, ipv4netmask, ipv4addrs, ipv6addrs = \
         addresses.getIpInfo('eth0', ipaddrs=ipaddrs)
     self.assertEqual(ipv4addrs, ['192.0.2.2/24'])
     self.assertEqual(ipv6addrs, ['ee80::5054:ff:fea3:f9f3/64'])
Esempio n. 10
0
def _get_iface_info(iface, addresses, routes):
    ipv4gateway = get_gateway(routes, iface, family=4)
    ipv4addr, ipv4netmask, ipv4addrs, ipv6addrs = getIpInfo(
        iface, addresses, ipv4gateway)
    is_dhcpv4, is_dhcpv6 = dhcp_status(iface, addresses)

    return {
        'mtu': getMtu(iface),
        'addr': ipv4addr,
        'ipv4addrs': ipv4addrs,
        'gateway': ipv4gateway,
        'netmask': ipv4netmask,
        'dhcpv4': is_dhcpv4,
        'ipv6addrs': ipv6addrs,
        'ipv6gateway': get_gateway(routes, iface, family=6),
        'ipv6autoconf': is_ipv6_local_auto(iface),
        'dhcpv6': is_dhcpv6
    }
Esempio n. 11
0
def _get_net_info(interface, routes):
    mtu = mtus.getMtu(interface)
    ipaddrs = addresses.getIpAddrs()
    addr, netmask, ipv4addrs, ipv6addrs = addresses.getIpInfo(interface,
                                                              ipaddrs)
    dhcpv4, dhcpv6 = dhcp.dhcp_status(interface, ipaddrs)
    gateway = netinfo_routes.get_gateway(routes, interface)
    ipv6gateway = netinfo_routes.get_gateway(routes, interface, family=6)

    return {
        'mtu': str(mtu),
        'addr': addr,
        'gateway': gateway,
        'netmask': netmask,
        'dhcpv4': dhcpv4,
        'ipv4addrs': ipv4addrs,
        'ipv6addrs': ipv6addrs,
        'ipv6autoconf': addresses.is_ipv6_local_auto(interface),
        'ipv6gateway': ipv6gateway,
        'dhcpv6': dhcpv6}
Esempio n. 12
0
def _get_net_info(interface, routes):
    mtu = mtus.getMtu(interface)
    ipaddrs = addresses.getIpAddrs()
    addr, netmask, ipv4addrs, ipv6addrs = addresses.getIpInfo(interface,
                                                              ipaddrs)
    dhcpv4 = dhclient.is_active(interface, family=4)
    dhcpv6 = dhclient.is_active(interface, family=6)
    gateway = netinfo_routes.get_gateway(routes, interface)
    ipv6gateway = netinfo_routes.get_gateway(routes, interface, family=6)

    return {
        'mtu': str(mtu),
        'addr': addr,
        'gateway': gateway,
        'netmask': netmask,
        'dhcpv4': dhcpv4,
        'ipv4addrs': ipv4addrs,
        'ipv6addrs': ipv6addrs,
        'ipv6autoconf': addresses.is_ipv6_local_auto(interface),
        'ipv6gateway': ipv6gateway,
        'dhcpv6': dhcpv6,
        'ipv4defaultroute': netinfo_routes.is_default_route(gateway)}
Esempio n. 13
0
def _get_net_info(interface, routes):
    mtu = mtus.getMtu(interface)
    ipaddrs = addresses.getIpAddrs()
    addr, netmask, ipv4addrs, ipv6addrs = addresses.getIpInfo(
        interface, ipaddrs)
    dhcpv4 = dhclient.is_active(interface, family=4)
    dhcpv6 = dhclient.is_active(interface, family=6)
    gateway = netinfo_routes.get_gateway(routes, interface)
    ipv6gateway = netinfo_routes.get_gateway(routes, interface, family=6)

    return {
        'mtu': str(mtu),
        'addr': addr,
        'gateway': gateway,
        'netmask': netmask,
        'dhcpv4': dhcpv4,
        'ipv4addrs': ipv4addrs,
        'ipv6addrs': ipv6addrs,
        'ipv6autoconf': addresses.is_ipv6_local_auto(interface),
        'ipv6gateway': ipv6gateway,
        'dhcpv6': dhcpv6
    }
Esempio n. 14
0
def addrs_info(dev, ipaddrs=None, ipv4_gateway=None):
    return addresses.getIpInfo(dev, ipaddrs, ipv4_gateway)
Esempio n. 15
0
 def get_ip_info(*a, **kw):
     """filter away ipv6 link local addresses that may or may not exist
     on the device depending on OS configuration"""
     ipv4addr, ipv4netmask, ipv4addrs, ipv6addrs = \
         addresses.getIpInfo(*a, **kw)
     return ipv4addr, ipv4netmask, ipv4addrs, ipv6addrs
Esempio n. 16
0
def addrs_info(dev, ipaddrs=None, ipv4_gateway=None):
    return addresses.getIpInfo(dev, ipaddrs, ipv4_gateway)
Esempio n. 17
0
 def get_ip_info(*a, **kw):
     """filter away ipv6 link local addresses that may or may not exist
     on the device depending on OS configuration"""
     ipv4addr, ipv4netmask, ipv4addrs, ipv6addrs = \
         addresses.getIpInfo(*a, **kw)
     return ipv4addr, ipv4netmask, ipv4addrs, ipv6addrs