copr-hv: fix VMs IPv6 allocation

The bug was that we tried to allocate addresses like "*cafe:c1001" (one
additional number).  This is now fixed, and since we are allowed to use
c1, c2, c3, .. let's give each hypervisor a fixed block of 64 addresses,
and don't be afraid to overflow there with new hypervisors.
This commit is contained in:
Pavel Raiskup 2021-07-12 14:13:59 +02:00
parent a37980bb0b
commit 96629a900d

View file

@ -381,22 +381,25 @@ def get_fedora_ipv6_address(pool_id, id_in_pool, dev=False):
Statically assign IPv6 + Gateway based on id_in_pool.
"""
gateway = "2620:52:3:1:ffff:ffff:ffff:fffe"
base = "2620:52:3:1:dead:beef:cafe:c1"
base = "2620:52:3:1:dead:beef:cafe:c"
# The initial 256 addresses (:c0XX) is reserved for hypervisor machines
# itself.
start = 0x100
# each hypervisor has block of 64 IPs
block = 64
offset = 0
# 01 => 0, 02 => 1, ...
hv_id, _, _ = get_hv_identification_from_pool_id(pool_id)
# we have block of 256 ipv6 addresses for builder, and 4 hypervisors
block = int(256 / 4)
# give 48 IPs to each hv (32 prod, some dev), currently 4*48=192 ips
offset = hv_id * block
if not dev:
# give the dev only 8 addresses
# give the first 8 addresses to Copr dev instance
offset += 8
addr_number = offset + int(id_in_pool)
addr_number = hex(addr_number).replace("0x", "")
addr_number = start + offset + int(id_in_pool)
addr_number = "{0:#05x}".format(addr_number).replace("0x", "")
return base + addr_number, gateway