From b02fc3f42c65d8833451e41b550f7588c9de2cc2 Mon Sep 17 00:00:00 2001 From: Disassembler Date: Sat, 5 Oct 2019 22:26:07 +0200 Subject: [PATCH] Handle leases for containers with already leased IPs --- usr/lib/python3.6/lxcmgr/lxcmgr.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/usr/lib/python3.6/lxcmgr/lxcmgr.py b/usr/lib/python3.6/lxcmgr/lxcmgr.py index d237d0b..1939921 100644 --- a/usr/lib/python3.6/lxcmgr/lxcmgr.py +++ b/usr/lib/python3.6/lxcmgr/lxcmgr.py @@ -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)