Example #1
0
def _set_network_ip_config(ip_config):
    """Set IP configuration on Vdsm controlled OVS network"""
    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)
Example #2
0
def _set_default_route(gateway, family, dev=None):
    try:
        ipwrapper.routeAdd(['default', 'via', gateway], family=family, dev=dev)
    except ipwrapper.IPRoute2Error:  # there already is a default route
        logging.warning(
            'Existing default route will be removed so a new one can be set.')
        ipwrapper.routeDel('default', family=family)
        ipwrapper.routeAdd(['default', 'via', gateway], family=family, dev=dev)
Example #3
0
def _set_default_route(gateway, family, dev=None):
    try:
        ipwrapper.routeAdd(['default', 'via', gateway], family=family, dev=dev)
    except ipwrapper.IPRoute2Error:  # there already is a default route
        logging.warning(
            'Existing default route will be removed so a new one can be set.')
        ipwrapper.routeDel('default', family=family)
        ipwrapper.routeAdd(['default', 'via', gateway], family=family, dev=dev)
Example #4
0
def add(iface, ipv4, ipv6):
    if ipv4.address:
        ipwrapper.addrAdd(iface, ipv4.address, ipv4.netmask)
        if ipv4.gateway and ipv4.defaultRoute:
            ipwrapper.routeAdd(['default', 'via', ipv4.gateway])
    if ipv6:
        _add_ipv6_address(iface, ipv6)
    elif ipv6_supported():
        sysctl.disable_ipv6(iface)
Example #5
0
def add(iface, ipv4, ipv6):
    if ipv4.address:
        ipwrapper.addrAdd(iface, ipv4.address, ipv4.netmask)
        if ipv4.gateway and ipv4.defaultRoute:
            ipwrapper.routeAdd(['default', 'via', ipv4.gateway])
    if ipv6:
        _add_ipv6_address(iface, ipv6)
    elif ipv6_supported():
        sysctl.disable_ipv6(iface)
Example #6
0
def _add_ipv6_address(iface, ipv6):
    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)
    if ipv6.ipv6autoconf is not None:
        with open('/proc/sys/net/ipv6/conf/%s/autoconf' % iface,
                  'w') as ipv6_autoconf:
            ipv6_autoconf.write('1' if ipv6.ipv6autoconf else '0')
Example #7
0
def _add_ipv6_address(iface, ipv6):
    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)
    if ipv6.ipv6autoconf is not None:
        with open('/proc/sys/net/ipv6/conf/%s/autoconf' % iface,
                  'w') as ipv6_autoconf:
            ipv6_autoconf.write('1' if ipv6.ipv6autoconf else '0')
Example #8
0
 def _setIpConfig(self, iface):
     ipv4 = iface.ipv4
     ipv6 = iface.ipv6
     if ipv4.address or ipv6.address:
         self.removeIpConfig(iface)
     if ipv4.address:
         ipwrapper.addrAdd(iface.name, ipv4.address,
                           ipv4.netmask)
         if ipv4.gateway and ipv4.defaultRoute:
             ipwrapper.routeAdd(['default', 'via', ipv4.gateway])
     if ipv6.address:
         ipv6addr, ipv6netmask = ipv6.address.split('/')
         ipwrapper.addrAdd(iface.name, ipv6addr, ipv6netmask, family=6)
         if ipv6.gateway:
             ipwrapper.routeAdd(['default', 'via', ipv6.gateway],
                                dev=iface.name, family=6)
     if ipv6.ipv6autoconf is not None:
         with open('/proc/sys/net/ipv6/conf/%s/autoconf' % iface.name,
                   'w') as ipv6_autoconf:
             ipv6_autoconf.write('1' if ipv6.ipv6autoconf else '0')
Example #9
0
    def configureSourceRoute(routes, rules, device):
        for route in routes:
            routeAdd(route)

        for rule in rules:
            ruleAdd(rule)
Example #10
0
 def add(route_data):
     r = route_data
     with _translate_iproute2_exception(IPRouteAddError, route_data):
         routeAdd(Route(r.to, r.via, r.src, r.device, r.table), r.family)
Example #11
0
 def add(route_data):
     r = route_data
     with _translate_iproute2_exception(IPRouteAddError, route_data):
         routeAdd(Route(r.to, r.via, r.src, r.device, r.table), r.family)