Handle leases for containers with already leased IPs
This commit is contained in:
parent
6045349f9c
commit
b02fc3f42c
@ -88,8 +88,12 @@ def update_hosts_lease(container, is_request):
|
||||
# Load all existing records
|
||||
with open(HOSTS_FILE, 'r') as f:
|
||||
leases = [l.strip().split(' ', 1) for l in f]
|
||||
# If this call is a request for lease, find the first unassigned IP
|
||||
# If this call is a request for lease, find if there isn't already existing lease for the container
|
||||
if is_request:
|
||||
already_leased = [l[0] for l in leases if l[1] == container]
|
||||
if already_leased:
|
||||
return already_leased[0]
|
||||
# Otherwise assign the first unassigned IP
|
||||
used_ips = [l[0] for l in leases]
|
||||
for i in range(2, 65278): # Reserve last /24 subnet for VPN
|
||||
ip = '172.17.{}.{}'. format(i // 256, i % 256)
|
||||
|
Loading…
Reference in New Issue
Block a user