@@ -30,35 +30,16 @@ def random_cidr_addresses_by_family(net_seed: int, host_address: int) -> list[st
3030 Returns:
3131 List of CIDR strings (e.g. ["192.168.1.1/24", "fd00::1/64"]).
3232 """
33- return [
34- f"{ ip } /64" if ipaddress .ip_address (ip ).version == 6 else f"{ ip } /24"
35- for ip in random_ip_addresses_by_family (net_seed = net_seed , host_address = host_address )
36- ]
37-
38-
39- def random_ip_addresses_by_family (
40- net_seed : int ,
41- host_address : int ,
42- ) -> list [str ]:
43- """Generate IP addresses for each IP family supported by the cluster network stack.
44-
45- Args:
46- net_seed: Seed index for selecting the random network portion of the address.
47- host_address: Host portion of the address, used to place VMs on the same subnet.
48-
49- Returns:
50- List of IP address strings, one per IP family supported by the cluster.
51- """
52- ips = []
33+ addresses = []
5334 if ipv4_supported_cluster ():
54- ips .append (random_ipv4_address (net_seed = net_seed , host_address = host_address ))
35+ addresses .append (random_ipv4_address (net_seed = net_seed , host_address = host_address ))
5536 if ipv6_supported_cluster ():
56- ips .append (random_ipv6_address (net_seed = net_seed , host_address = host_address ))
57- return ips
37+ addresses .append (random_ipv6_address (net_seed = net_seed , host_address = host_address ))
38+ return addresses
5839
5940
6041def random_ipv4_address (net_seed : int , host_address : int ) -> str :
61- """Construct a random IPv4 address using a cached list of random third octets.
42+ """Construct a random IPv4 CIDR address using a cached list of random third octets.
6243
6344 Uses a pre-defined network address, a cached random third octet and the given
6445 host address to generate deterministic yet randomized IPv4 addresses.
@@ -68,10 +49,10 @@ def random_ipv4_address(net_seed: int, host_address: int) -> str:
6849 host_address (int): The last (fourth) octet of the IPv4 address.
6950
7051 Returns:
71- str: A string representing a randomized IPv4 address.
52+ str: A CIDR string representing a randomized IPv4 address.
7253 """
7354 third_octets = _random_octets (count = _MAX_NUM_OF_RANDOM_OCTETS_PER_SESSION )
74- return f"{ _IPV4_ADDRESS_SUBNET_PREFIX_VMI } .{ third_octets [net_seed ]} .{ host_address } "
55+ return f"{ _IPV4_ADDRESS_SUBNET_PREFIX_VMI } .{ third_octets [net_seed ]} .{ host_address } /24 "
7556
7657
7758@cache
@@ -91,7 +72,7 @@ def _random_octets(count: int) -> list[int]:
9172
9273
9374def random_ipv6_address (net_seed : int , host_address : int ) -> str :
94- """Construct a random IPv6 address using a cached list of random seventh hextets.
75+ """Construct a random IPv6 CIDR address using a cached list of random seventh hextets.
9576
9677 Uses a pre-defined network prefix, a cached random seventh hextet and the given
9778 host address to generate deterministic yet randomized IPv6 addresses.
@@ -101,10 +82,10 @@ def random_ipv6_address(net_seed: int, host_address: int) -> str:
10182 host_address (int): The last (eighth) hextet of the IPv6 address.
10283
10384 Returns:
104- str: A string representing a randomized IPv6 address.
85+ str: A CIDR string representing a randomized IPv6 address.
10586 """
10687 seventh_hextets = _random_hextets (count = _MAX_NUM_OF_RANDOM_HEXTETS_PER_SESSION )
107- return f"{ _IPV6_ADDRESS_SUBNET_PREFIX_VMI } ::{ seventh_hextets [net_seed ]:x} :{ host_address :x} "
88+ return f"{ _IPV6_ADDRESS_SUBNET_PREFIX_VMI } ::{ seventh_hextets [net_seed ]:x} :{ host_address :x} /64 "
10889
10990
11091@cache
0 commit comments