def _set_ip_config(iface, ipv4, ipv6, port, blockingdhcp):
    net_dev = NetDevice(iface, iproute2, ipv4=ipv4, ipv6=ipv6,
                        blockingdhcp=blockingdhcp)
    DynamicSourceRoute.addInterfaceTracking(net_dev)
    ipwrapper.linkSet(iface, ['down'])
    if ipv4.address:
        ipwrapper.addrAdd(iface, ipv4.address, ipv4.netmask)
    if ipv4.gateway and ipv4.defaultRoute:
        ipwrapper.routeAdd(['default', 'via', ipv4.gateway])
    if ipv6.address or ipv6.ipv6autoconf or ipv6.dhcpv6:
        sysctl.disable_ipv6(iface, disable=False)
    else:
        sysctl.disable_ipv6(iface)
    if ipv6.address:
        ipv6addr, ipv6netmask = ipv6.address.split('/')
        ipwrapper.addrAdd(iface, ipv6addr, ipv6netmask, family=6)
        if ipv6.gateway:
            ipwrapper.routeAdd(['default', 'via', ipv6.gateway], dev=iface,
                               family=6)
    ipwrapper.linkSet(port, ['up'])
    ipwrapper.linkSet(iface, ['up'])
    if ipv4.bootproto == 'dhcp':
        _run_dhclient(iface, blockingdhcp, ipv4.defaultRoute, 4)
    if ipv6.dhcpv6:
        _run_dhclient(iface, blockingdhcp, ipv6.defaultRoute, 6)
    iproute2._addSourceRoute(net_dev)
def _set_ip_config(ip_config):
    iface = ip_config.top_dev
    ipv4 = ip_config.ipv4
    ipv6 = ip_config.ipv6
    port = ip_config.port
    blocking_dhcp = ip_config.blocking_dhcp

    net_dev = NetDevice(iface, iproute2, ipv4=ipv4, ipv6=ipv6, blockingdhcp=blocking_dhcp)
    DynamicSourceRoute.addInterfaceTracking(net_dev)
    ipwrapper.linkSet(iface, ["down"])
    if ipv4.address:
        ipwrapper.addrAdd(iface, ipv4.address, ipv4.netmask)
    if ipv4.gateway and ipv4.defaultRoute:
        ipwrapper.routeAdd(["default", "via", ipv4.gateway])
    if ipv6.address or ipv6.ipv6autoconf or ipv6.dhcpv6:
        sysctl.disable_ipv6(iface, disable=False)
    else:
        sysctl.disable_ipv6(iface)
    if ipv6.address:
        ipv6addr, ipv6netmask = ipv6.address.split("/")
        ipwrapper.addrAdd(iface, ipv6addr, ipv6netmask, family=6)
        if ipv6.gateway:
            ipwrapper.routeAdd(["default", "via", ipv6.gateway], dev=iface, family=6)
    ipwrapper.linkSet(port, ["up"])
    ipwrapper.linkSet(iface, ["up"])
    if ipv4.bootproto == "dhcp":
        _run_dhclient(iface, blocking_dhcp, ipv4.defaultRoute, 4)
    if ipv6.dhcpv6:
        _run_dhclient(iface, blocking_dhcp, ipv6.defaultRoute, 6)
    iproute2._addSourceRoute(net_dev)
def _remove_ip_config(iface, ipv4, ipv6):
    net_dev = NetDevice(iface, iproute2, ipv4=ipv4, ipv6=ipv6)
    DynamicSourceRoute.addInterfaceTracking(net_dev)
    DhcpClient(iface).shutdown()
    iproute2._removeSourceRoute(net_dev, DynamicSourceRoute)
    if ipv4.address or ipv6.address:
        with suppress(ipwrapper.IPRoute2Error):  # device does not exist
            ipwrapper.addrFlush(iface)
def _remove_ip_config(ip_config):
    iface = ip_config.top_dev
    ipv4 = ip_config.ipv4
    ipv6 = ip_config.ipv6

    net_dev = NetDevice(iface, iproute2, ipv4=ipv4, ipv6=ipv6)
    DynamicSourceRoute.addInterfaceTracking(net_dev)
    DhcpClient(iface).shutdown()
    iproute2._removeSourceRoute(net_dev, DynamicSourceRoute)
    if ipv4.address or ipv6.address:
        with suppress(ipwrapper.IPRoute2Error):  # device does not exist
            ipwrapper.addrFlush(iface)
def _set_ip_config(ip_config):
    iface = ip_config.top_dev
    ipv4 = ip_config.ipv4
    ipv6 = ip_config.ipv6
    port = ip_config.port
    blocking_dhcp = ip_config.blocking_dhcp

    net_dev = NetDevice(iface,
                        iproute2,
                        ipv4=ipv4,
                        ipv6=ipv6,
                        blockingdhcp=blocking_dhcp)
    DynamicSourceRoute.addInterfaceTracking(net_dev)
    ipwrapper.linkSet(iface, ['down'])
    if ipv4.address:
        ipwrapper.addrAdd(iface, ipv4.address, ipv4.netmask)
    if ipv4.gateway and ipv4.defaultRoute:
        ipwrapper.routeAdd(['default', 'via', ipv4.gateway])
    if ipv6.address or ipv6.ipv6autoconf or ipv6.dhcpv6:
        sysctl.disable_ipv6(iface, disable=False)
    else:
        sysctl.disable_ipv6(iface)
    if ipv6.address:
        ipv6addr, ipv6netmask = ipv6.address.split('/')
        ipwrapper.addrAdd(iface, ipv6addr, ipv6netmask, family=6)
        if ipv6.gateway:
            ipwrapper.routeAdd(['default', 'via', ipv6.gateway],
                               dev=iface,
                               family=6)
    ipwrapper.linkSet(port, ['up'])
    ipwrapper.linkSet(iface, ['up'])
    if ipv4.bootproto == 'dhcp':
        _run_dhclient(iface, blocking_dhcp, ipv4.defaultRoute, 4)
    if ipv6.dhcpv6:
        _run_dhclient(iface, blocking_dhcp, ipv6.defaultRoute, 6)
    iproute2._addSourceRoute(net_dev)