77from kubernetes .dynamic .resource import ResourceField
88from ocp_resources .virtual_machine_instance import VirtualMachineInstance
99
10+ from libs .net .cluster import ipv4_supported_cluster , ipv6_supported_cluster
1011from libs .net .ip import random_ipv4_address , random_ipv6_address
1112from libs .net .vmspec import lookup_iface_status , lookup_primary_network
1213from libs .vm .factory import base_vmspec , fedora_vm
@@ -26,8 +27,6 @@ def secondary_network_vm(
2627 name : str ,
2728 client : DynamicClient ,
2829 bridge_network_name : str ,
29- ipv4_supported_cluster : bool ,
30- ipv6_supported_cluster : bool ,
3130) -> BaseVirtualMachine :
3231 spec = base_vmspec ()
3332 spec .template .spec .domain .devices .interfaces = [ # type: ignore
@@ -42,24 +41,13 @@ def secondary_network_vm(
4241 ]
4342
4443 ethernets = {}
45- primary = primary_iface_cloud_init (
46- ipv4_supported_cluster = ipv4_supported_cluster ,
47- ipv6_supported_cluster = ipv6_supported_cluster ,
48- )
44+ primary = primary_iface_cloud_init ()
4945 if primary :
5046 ethernets ["eth1" ] = primary
5147
52- ethernets ["eth0" ] = secondary_iface_cloud_init (
53- ipv4_supported_cluster = ipv4_supported_cluster ,
54- ipv6_supported_cluster = ipv6_supported_cluster ,
55- host_address = 1 ,
56- )
48+ ethernets ["eth0" ] = secondary_iface_cloud_init (host_address = 1 )
5749
58- ethernets ["eth2" ] = secondary_iface_cloud_init (
59- ipv4_supported_cluster = ipv4_supported_cluster ,
60- ipv6_supported_cluster = ipv6_supported_cluster ,
61- host_address = 2 ,
62- )
50+ ethernets ["eth2" ] = secondary_iface_cloud_init (host_address = 2 )
6351
6452 userdata = cloudinit .UserData (users = [])
6553 disk , volume = cloudinitdisk_storage (
@@ -73,50 +61,33 @@ def secondary_network_vm(
7361 return fedora_vm (namespace = namespace , name = name , client = client , spec = spec )
7462
7563
76- def primary_iface_cloud_init (
77- ipv4_supported_cluster : bool ,
78- ipv6_supported_cluster : bool ,
79- ) -> cloudinit .EthernetDevice | None :
80- if not ipv6_supported_cluster :
64+ def primary_iface_cloud_init () -> cloudinit .EthernetDevice | None :
65+ if not ipv6_supported_cluster ():
8166 return None
8267 return cloudinit .EthernetDevice (
8368 addresses = ["fd10:0:2::2/120" ],
8469 gateway6 = "fd10:0:2::1" ,
85- dhcp4 = ipv4_supported_cluster ,
70+ dhcp4 = ipv4_supported_cluster () ,
8671 dhcp6 = False ,
8772 )
8873
8974
90- def secondary_iface_cloud_init (
91- ipv4_supported_cluster : bool ,
92- ipv6_supported_cluster : bool ,
93- host_address : int ,
94- ) -> cloudinit .EthernetDevice :
95- ips = secondary_iface_ips (
96- ipv4_supported_cluster = ipv4_supported_cluster ,
97- ipv6_supported_cluster = ipv6_supported_cluster ,
98- host_address = host_address ,
99- )
75+ def secondary_iface_cloud_init (host_address : int ) -> cloudinit .EthernetDevice :
76+ ips = secondary_iface_ips (host_address = host_address )
10077 addresses = [f"{ ip } /64" if ipaddress .ip_address (ip ).version == 6 else f"{ ip } /24" for ip in ips ]
10178 return cloudinit .EthernetDevice (addresses = addresses )
10279
10380
104- def secondary_iface_ips (
105- ipv4_supported_cluster : bool ,
106- ipv6_supported_cluster : bool ,
107- host_address : int ,
108- ) -> list [str ]:
81+ def secondary_iface_ips (host_address : int ) -> list [str ]:
10982 ips = []
110- if ipv4_supported_cluster :
83+ if ipv4_supported_cluster () :
11184 ips .append (random_ipv4_address (net_seed = 0 , host_address = host_address ))
112- if ipv6_supported_cluster :
85+ if ipv6_supported_cluster () :
11386 ips .append (random_ipv6_address (net_seed = 0 , host_address = host_address ))
11487 return ips
11588
11689
117- def wait_for_stable_ifaces (
118- vm : BaseVirtualMachine ,
119- ) -> None :
90+ def wait_for_stable_ifaces (vm : BaseVirtualMachine ) -> None :
12091 primary_network = lookup_primary_network (vm = vm )
12192
12293 secondary_iface_to_ips = {
0 commit comments