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)
def removeNic(self, nic, remove_even_if_used=False): if not self.owned_device(nic.name): IfcfgAcquire.acquire_device(nic.name) # If the nic is top device we should ifdown it even if it is # used by a VLAN. Otherwise we would keep its IP address. remove_even_if_used |= nic.master is None to_be_removed = self._ifaceDownAndCleanup(nic, remove_even_if_used) if to_be_removed: self.configApplier.removeNic(nic.name) if nic.name in nics.nics(): _exec_ifup(nic) else: logging.warning('host interface %s missing', nic.name) else: vlans = link_vlan.get_vlans_on_base_device(nic.name) set_mtu = self._setNewMtu(nic, 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 if set_mtu is not None: ipwrapper.linkSet(nic.name, ['mtu', str(set_mtu)]) # If the nic was bridged, we must remove BRIDGE parameter from its # ifcfg configuration file. if nic.bridge: self.configApplier.dropBridgeParameter(nic.name)
def test_list_vlans_on_base_device(self): with dummy_device() as nic: with vlan_device(nic, tag=999) as vlan_dev: self.assertEqual( [vlan_dev.devName], list(vlan.get_vlans_on_base_device(nic)), )
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)
def test_list_vlans_on_base_device(self): with dummy_device() as nic: with vlan_device(nic, tag=999) as vlan_dev: self.assertEqual([vlan_dev.devName], list(vlan.get_vlans_on_base_device(nic)))
def test_list_vlans_on_base_device(self, nic0, vlan999): base_device_vlans = list(vlan.get_vlans_on_base_device(nic0)) assert base_device_vlans == [vlan999.devName]