Beispiel #1
0
    def removeBond(self, bonding):
        if not self.owned_device(bonding.name):
            IfcfgAcquire.acquire_device(bonding.name)
        to_be_removed = self._ifaceDownAndCleanup(bonding)
        if to_be_removed:
            self.configApplier.removeBonding(bonding.name)
            if bonding.on_removal_just_detach_from_network:
                # Recreate the bond with ip and master info cleared
                bonding.ipv4 = address.IPv4()
                bonding.ipv6 = address.IPv6()
                bonding.master = None
                bonding.configure()
            else:
                for slave in bonding.slaves:
                    slave.remove()
                self.runningConfig.removeBonding(bonding.name)
        else:
            vlans = link_vlan.get_vlans_on_base_device(bonding.name)
            set_mtu = self._setNewMtu(bonding, vlans)
            # Since we are not taking the device up again, ifcfg will not be
            # read at this point and we need to set the live mtu value.
            # Note that ip link set dev bondX mtu Y sets Y on all its links
            if set_mtu is not None:
                ipwrapper.linkSet(bonding.name, ['mtu', str(set_mtu)])

            # If the bond was bridged, we must remove BRIDGE parameter from its
            # ifcfg configuration file.
            if bonding.bridge:
                self.configApplier.dropBridgeParameter(bonding.name)

            bond_used_by_net = self.net_info.getNetworkForIface(bonding.name)
            bond_info = self.net_info.bondings[bonding.name]
            if not bond_used_by_net and (bond_info['ipv4addrs']
                                         or bond_info['ipv6addrs']):
                ipwrapper.addrFlush(bonding.name)
Beispiel #2
0
    def removeBond(self, bonding):
        if not self.owned_device(bonding.name):
            IfcfgAcquire.acquire_device(bonding.name)
        to_be_removed = self._ifaceDownAndCleanup(bonding)
        if to_be_removed:
            self.configApplier.removeBonding(bonding.name)
            if bonding.on_removal_just_detach_from_network:
                # Recreate the bond with ip and master info cleared
                bonding.ipv4 = address.IPv4()
                bonding.ipv6 = address.IPv6()
                bonding.master = None
                bonding.configure()
            else:
                for slave in bonding.slaves:
                    slave.remove()
                self.runningConfig.removeBonding(bonding.name)
        else:
            vlans = link_vlan.get_vlans_on_base_device(bonding.name)
            set_mtu = self._setNewMtu(bonding, vlans)
            # Since we are not taking the device up again, ifcfg will not be
            # read at this point and we need to set the live mtu value.
            # Note that ip link set dev bondX mtu Y sets Y on all its links
            if set_mtu is not None:
                ipwrapper.linkSet(bonding.name, ['mtu', str(set_mtu)])

            # If the bond was bridged, we must remove BRIDGE parameter from its
            # ifcfg configuration file.
            if bonding.bridge:
                self.configApplier.dropBridgeParameter(bonding.name)

            bond_used_by_net = self.net_info.getNetworkForIface(bonding.name)
            bond_info = self.net_info.bondings[bonding.name]
            if (not bond_used_by_net and
                    (bond_info['ipv4addrs'] or bond_info['ipv6addrs'])):
                ipwrapper.addrFlush(bonding.name)
Beispiel #3
0
def kill_dhclient(device_name, family=4):
    for pid in pgrep('dhclient'):
        try:
            with open('/proc/%s/cmdline' % pid) as cmdline:
                args = cmdline.read().strip('\0').split('\0')
        except IOError as ioe:
            if ioe.errno == errno.ENOENT:  # exited before we read cmdline
                continue
        if args[-1] != device_name:  # dhclient of another device
            continue
        tokens = iter(args)
        pid_file = '/var/run/dhclient.pid'  # Default client pid location
        running_family = 4
        for token in tokens:
            if token == '-pf':
                pid_file = next(tokens)
            elif token == '--no-pid':
                pid_file = None
            elif token == '-6':
                running_family = 6

        if running_family != family:
            continue
        logging.info('Stopping dhclient -%s before running our own on %s',
                     family, device_name)
        kill_and_rm_pid(pid, pid_file)

    #  In order to be able to configure the device with dhclient again. It is
    #  necessary that dhclient does not find it configured with any IP address
    #  (except 0.0.0.0 which is fine, or IPv6 link-local address needed for
    #   DHCPv6).
    ipwrapper.addrFlush(device_name, family)
Beispiel #4
0
def kill_dhclient(device_name, family=4):
    for pid in pgrep('dhclient'):
        try:
            with open('/proc/%s/cmdline' % pid) as cmdline:
                args = cmdline.read().strip('\0').split('\0')
        except IOError as ioe:
            if ioe.errno == errno.ENOENT:  # exited before we read cmdline
                continue
        if args[-1] != device_name:  # dhclient of another device
            continue
        tokens = iter(args)
        pid_file = '/var/run/dhclient.pid'  # Default client pid location
        running_family = 4
        for token in tokens:
            if token == '-pf':
                pid_file = next(tokens)
            elif token == '--no-pid':
                pid_file = None
            elif token == '-6':
                running_family = 6

        if running_family != family:
            continue
        logging.info('Stopping dhclient -%s before running our own on %s',
                     family, device_name)
        kill_and_rm_pid(pid, pid_file)

    #  In order to be able to configure the device with dhclient again. It is
    #  necessary that dhclient does not find it configured with any IP address
    #  (except 0.0.0.0 which is fine, or IPv6 link-local address needed for
    #   DHCPv6).
    ipwrapper.addrFlush(device_name, family)
Beispiel #5
0
    def test_routes_device_to(self, ip_addr, ip_netmask, nic0):
        addr_in_net = ipaddress.ip_address(ip_addr) + 1
        ip_version = addr_in_net.version

        ipwrapper.addrAdd(nic0, ip_addr, ip_netmask, family=ip_version)
        try:
            ipwrapper.linkSet(nic0, ['up'])
            assert routes.getRouteDeviceTo(str(addr_in_net)) == nic0
        finally:
            ipwrapper.addrFlush(nic0, ip_version)
Beispiel #6
0
def _remove_network_ip_config(ip_config):
    """Remove IP configuration from Vdsm controlled OVS network"""
    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)
Beispiel #7
0
    def testGetRouteDeviceTo(self):
        with dummyIf(1) as nics:
            nic, = nics

            addrAdd(nic, IP_ADDRESS, IP_CIDR)
            try:
                linkSet(nic, ['up'])
                self.assertEqual(getRouteDeviceTo(IP_ADDRESS_IN_NETWORK), nic)
            finally:
                addrFlush(nic)

            sysctl.disable_ipv6(nic, False)
            addrAdd(nic, IPv6_ADDRESS, IPv6_CIDR, family=6)
            try:
                linkSet(nic, ['up'])
                self.assertEqual(getRouteDeviceTo(IPv6_ADDRESS_IN_NETWORK),
                                 nic)
            finally:
                addrFlush(nic)
Beispiel #8
0
def flush(iface, family='both'):
    ipwrapper.addrFlush(iface, family)
Beispiel #9
0
 def removeIpConfig(self, iface):
     ipwrapper.addrFlush(iface.name)
Beispiel #10
0
def flush(iface, family='both'):
    ipwrapper.addrFlush(iface, family)