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: set_mtu = self._setNewMtu(bonding, vlans.vlan_devs_for_iface(bonding.name)) # 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)
def _get_ipv6_model(attrs): addr = attrs.get('ipv6addr') gateway = attrs.get('ipv6gateway') default_route = attrs.get('defaultRoute') autoconf = attrs.get('ipv6autoconf') dhcp = attrs.get('dhcpv6') return address.IPv6(addr, gateway, default_route, autoconf, dhcp)
def test_add_ipv4_and_ipv6_address(self, nic0): ipv4 = address.IPv4(address=IPV4_A_ADDRESS, netmask=IPV4_NETMASK) ipv6 = address.IPv6(address=IPV6_A_WITH_PREFIXLEN) address.add(nic0, ipv4=ipv4, ipv6=ipv6) addr, netmask, _, ipv6addresses = address.addrs_info(nic0) assert IPV4_A_ADDRESS == addr assert IPV4_NETMASK == netmask assert IPV6_A_WITH_PREFIXLEN == ipv6addresses[0]
def test_add_ipv6_address_with_gateway(self): ip = 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=None, ipv6=ip) self.assertTrue(routes.is_ipv6_default_route(IPV6_GATEWAY))
def test_add_ipv4_and_ipv6_address(self): ipv4 = address.IPv4(address=IPV4_A_ADDRESS, netmask=IPV4_NETMASK) ipv6 = address.IPv6(address=IPV6_A_WITH_PREFIXLEN) with dummy_device() as nic: address.add(nic, ipv4=ipv4, ipv6=ipv6) addr, netmask, _, ipv6addresses = address.addrs_info(nic) self.assertEqual(IPV4_A_ADDRESS, addr) self.assertEqual(IPV4_NETMASK, netmask) self.assertEqual(IPV6_A_WITH_PREFIXLEN, ipv6addresses[0])
def _set_dhcp_config(iface, attrs): blocking_dhcp = attrs.get('blockingdhcp', False) duid_source = attrs.get('bonding') or attrs.get('nic') ipv4 = address.IPv4(*_ipv4_conf_params(attrs)) if ipv4.bootproto == 'dhcp': dhclient.run(iface, 4, ipv4.defaultRoute, duid_source, blocking_dhcp) ipv6 = address.IPv6(*_ipv6_conf_params(attrs)) if ipv6.dhcpv6: dhclient.run(iface, 6, ipv6.defaultRoute, duid_source, blocking_dhcp)
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))
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))
def removeBond(self, bonding): 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() if self.unifiedPersistence: self.runningConfig.removeBonding(bonding.name) else: set_mtu = self._setNewMtu(bonding, vlans.vlan_devs_for_iface(bonding.name)) # 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)])
def _set_static_ip_config(iface, attrs): address.flush(iface) ipv4 = address.IPv4(*_ipv4_conf_params(attrs)) ipv6 = address.IPv6(*_ipv6_conf_params(attrs)) address.add(iface, ipv4, ipv6)
def test_add_ipv6_address(self, nic0): ip = address.IPv6(address=IPV6_A_WITH_PREFIXLEN) address.add(nic0, ipv4=None, ipv6=ip) _, _, _, ipv6addresses = address.addrs_info(nic0) assert IPV6_A_WITH_PREFIXLEN == ipv6addresses[0]
def ipv6_address(): return address.IPv6(address=IPV6_A_WITH_PREFIXLEN, gateway=IPV6_GATEWAY, defaultRoute=True)
def test_add_ipv6_address(self): ip = address.IPv6(address=IPV6_A_WITH_PREFIXLEN) with dummy_device() as nic: address.add(nic, ipv4=None, ipv6=ip) _, _, _, ipv6addresses = address.addrs_info(nic) self.assertEqual(IPV6_A_WITH_PREFIXLEN, ipv6addresses[0])
def test_ipv6_clean_init(self): ip = address.IPv6() self._assert_ip_clean_init(ip) self.assertEqual(None, ip.ipv6autoconf) self.assertEqual(None, ip.dhcpv6)
def test_ipv6_clean_init(self): ip = address.IPv6() assert not ip self._assert_ip_clean_init(ip) assert ip.ipv6autoconf is None assert ip.dhcpv6 is None