Example #1
0
 def test_add_ipv4_address_with_gateway(self):
     ip = address.IPv4(address=IPV4_ADDRESS, netmask=IPV4_NETMASK,
                       gateway=IPV4_GATEWAY, defaultRoute=True)
     with dummy_device() as nic:
         with preserve_default_route():
             address.add(nic, ipv4=ip, ipv6=None)
             self.assertTrue(routes.is_default_route(IPV4_GATEWAY))
Example #2
0
    def test_add_ipv6_gateway_given_existing_ipv4_and_ipv6_gateways(
            self, nic0, ipv4_address, ipv6_address):
        with preserve_default_route():
            address.add(nic0, ipv4=ipv4_address, ipv6=None)
            address.add(nic0, ipv4=None, ipv6=ipv6_address)

            address.add(nic0, ipv4=None, ipv6=ipv6_address)
            assert routes.is_default_route(IPV4_GATEWAY, routes.get_routes())
            assert routes.is_ipv6_default_route(IPV6_GATEWAY)
Example #3
0
 def test_add_ipv4_address_with_gateway(self):
     ip = address.IPv4(address=IPV4_A_ADDRESS,
                       netmask=IPV4_NETMASK,
                       gateway=IPV4_GATEWAY,
                       defaultRoute=True)
     with dummy_device() as nic:
         with preserve_default_route():
             address.add(nic, ipv4=ip, ipv6=None)
             self.assertTrue(routes.is_default_route(IPV4_GATEWAY))
Example #4
0
 def test_add_ipv4_and_ipv6_address_with_gateways(self):
     ipv4 = address.IPv4(address=IPV4_ADDRESS, netmask=IPV4_NETMASK,
                         gateway=IPV4_GATEWAY, defaultRoute=True)
     ipv6 = address.IPv6(address=IPV6_ADDRESS, gateway=IPV6_GATEWAY,
                         defaultRoute=True)
     with dummy_device() as nic:
         with preserve_default_route():
             address.add(nic, ipv4=ipv4, ipv6=ipv6)
             addr, netmask, _, ipv6addresses = address.addrs_info(nic)
             self.assertTrue(routes.is_default_route(IPV4_GATEWAY))
             self.assertTrue(routes.is_ipv6_default_route(IPV6_GATEWAY))
Example #5
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}
Example #6
0
    def test_add_ipv6_gateway_given_existing_ipv4_and_ipv6_gateways(self):
        ipv4 = address.IPv4(address=IPV4_ADDRESS, netmask=IPV4_NETMASK,
                            gateway=IPV4_GATEWAY, defaultRoute=True)
        ipv6 = address.IPv6(address=IPV6_ADDRESS, gateway=IPV6_GATEWAY,
                            defaultRoute=True)
        with dummy_device() as nic:
            with preserve_default_route():
                address.add(nic, ipv4=ipv4, ipv6=None)
                address.add(nic, ipv4=None, ipv6=ipv6)

                address.add(nic, ipv4=None, ipv6=ipv6)
                self.assertTrue(routes.is_default_route(IPV4_GATEWAY))
                self.assertTrue(routes.is_ipv6_default_route(IPV6_GATEWAY))
Example #7
0
File: info.py Project: 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}
Example #8
0
 def test_add_ipv4_and_ipv6_address_with_gateways(self):
     ipv4 = address.IPv4(address=IPV4_A_ADDRESS,
                         netmask=IPV4_NETMASK,
                         gateway=IPV4_GATEWAY,
                         defaultRoute=True)
     ipv6 = address.IPv6(address=IPV6_A_WITH_PREFIXLEN,
                         gateway=IPV6_GATEWAY,
                         defaultRoute=True)
     with dummy_device() as nic:
         with preserve_default_route():
             address.add(nic, ipv4=ipv4, ipv6=ipv6)
             addr, netmask, _, ipv6addresses = address.addrs_info(nic)
             self.assertTrue(routes.is_default_route(IPV4_GATEWAY))
             self.assertTrue(routes.is_ipv6_default_route(IPV6_GATEWAY))
Example #9
0
def preserve_default_route():
    ipv4_dg_data = routes.getDefaultGateway()
    ipv4_gateway = ipv4_dg_data.via if ipv4_dg_data else None
    ipv4_device = ipv4_dg_data.device if ipv4_dg_data else None

    ipv6_dg_data = routes.ipv6_default_gateway()
    ipv6_gateway = ipv6_dg_data.via if ipv6_dg_data else None
    ipv6_device = ipv6_dg_data.device if ipv6_dg_data else None

    try:
        yield
    finally:
        if ipv4_gateway and not routes.is_default_route(ipv4_gateway):
            address.set_default_route(ipv4_gateway, family=4, dev=ipv4_device)
        if ipv6_gateway and not routes.is_ipv6_default_route(ipv6_gateway):
            address.set_default_route(ipv6_gateway, family=6, dev=ipv6_device)
Example #10
0
    def test_add_ipv6_gateway_given_existing_ipv4_and_ipv6_gateways(self):
        ipv4 = address.IPv4(address=IPV4_ADDRESS,
                            netmask=IPV4_NETMASK,
                            gateway=IPV4_GATEWAY,
                            defaultRoute=True)
        ipv6 = address.IPv6(address=IPV6_ADDRESS,
                            gateway=IPV6_GATEWAY,
                            defaultRoute=True)
        with dummy_device() as nic:
            with preserve_default_route():
                address.add(nic, ipv4=ipv4, ipv6=None)
                address.add(nic, ipv4=None, ipv6=ipv6)

                address.add(nic, ipv4=None, ipv6=ipv6)
                self.assertTrue(routes.is_default_route(IPV4_GATEWAY))
                self.assertTrue(routes.is_ipv6_default_route(IPV6_GATEWAY))
Example #11
0
def preserve_default_route():
    ipv4_dg_data = routes.getDefaultGateway()
    ipv4_gateway = ipv4_dg_data.via if ipv4_dg_data else None
    ipv4_device = ipv4_dg_data.device if ipv4_dg_data else None

    ipv6_dg_data = routes.ipv6_default_gateway()
    ipv6_gateway = ipv6_dg_data.via if ipv6_dg_data else None
    ipv6_device = ipv6_dg_data.device if ipv6_dg_data else None

    try:
        yield
    finally:
        if ipv4_gateway and not routes.is_default_route(ipv4_gateway):
            address.set_default_route(ipv4_gateway, family=4, dev=ipv4_device)
        if ipv6_gateway and not routes.is_ipv6_default_route(ipv6_gateway):
            address.set_default_route(ipv6_gateway, family=6, dev=ipv6_device)
Example #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)}
Example #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,
        'ipv4defaultroute': netinfo_routes.is_default_route(gateway)
    }
Example #14
0
 def test_add_ipv4_and_ipv6_address_with_gateways(self, nic0, ipv4_address,
                                                  ipv6_address):
     with preserve_default_route():
         address.add(nic0, ipv4=ipv4_address, ipv6=ipv6_address)
         assert routes.is_default_route(IPV4_GATEWAY, routes.get_routes())
         assert routes.is_ipv6_default_route(IPV6_GATEWAY)
Example #15
0
def _translate_default_route(net_attr):
    is_default_route = net_attr.get('ipv4defaultroute')
    if is_default_route is None:
        return routes.is_default_route(net_attr['gateway'])
    else:
        return is_default_route
Example #16
0
def _translate_default_route(net_attr):
    is_default_route = net_attr.get('ipv4defaultroute')
    if is_default_route is None:
        return routes.is_default_route(net_attr['gateway'])
    else:
        return is_default_route