From 5ef633d47485ad98d9fbe85737b83572fd219c2a Mon Sep 17 00:00:00 2001 From: Wei Zhou Date: Mon, 16 Aug 2021 11:38:52 +0200 Subject: [PATCH 1/3] vr: reload dnsmasq when start vms --- systemvm/debian/opt/cloud/bin/cs/CsDhcp.py | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/systemvm/debian/opt/cloud/bin/cs/CsDhcp.py b/systemvm/debian/opt/cloud/bin/cs/CsDhcp.py index 91b95c6c676a..666a6886a02a 100755 --- a/systemvm/debian/opt/cloud/bin/cs/CsDhcp.py +++ b/systemvm/debian/opt/cloud/bin/cs/CsDhcp.py @@ -37,12 +37,12 @@ def process(self): self.changed = [] self.devinfo = CsHelper.get_device_info() self.preseed() - self.cloud = CsFile(DHCP_HOSTS) + self.dhcp_hosts = CsFile(DHCP_HOSTS) self.dhcp_opts = CsFile(DHCP_OPTS) self.conf = CsFile(CLOUD_CONF) self.dhcp_leases = CsFile(LEASES) - self.cloud.repopulate() + self.dhcp_hosts.repopulate() self.dhcp_opts.repopulate() for item in self.dbag: @@ -58,17 +58,11 @@ def process(self): if self.conf.commit(): restart_dnsmasq = True - if self.cloud.commit(): - restart_dnsmasq = True - - if self.dhcp_leases.commit(): - restart_dnsmasq = True - + self.dhcp_hosts.commit() + self.dhcp_leases.commit() self.dhcp_opts.commit() - if restart_dnsmasq: - self.delete_leases() - + self.delete_leases() self.write_hosts() if not self.cl.is_redundant() or self.cl.is_master(): @@ -189,7 +183,7 @@ def add(self, entry): lease = 'infinite' if entry['default_entry']: - self.cloud.add("%s,%s,%s,%s" % (entry['mac_address'], + self.dhcp_hosts.add("%s,%s,%s,%s" % (entry['mac_address'], entry['ipv4_address'], entry['host_name'], lease)) @@ -198,7 +192,7 @@ def add(self, entry): entry['host_name'])) else: tag = entry['ipv4_address'].replace(".", "_") - self.cloud.add("%s,set:%s,%s,%s,%s" % (entry['mac_address'], + self.dhcp_hosts.add("%s,set:%s,%s,%s,%s" % (entry['mac_address'], tag, entry['ipv4_address'], entry['host_name'], From 737f50d133c918f1f61580c1c23ebf37b12a3799 Mon Sep 17 00:00:00 2001 From: Wei Zhou Date: Tue, 17 Aug 2021 09:12:02 +0200 Subject: [PATCH 2/3] vr: fix pycodestyle check error --- systemvm/debian/opt/cloud/bin/cs/CsDhcp.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/systemvm/debian/opt/cloud/bin/cs/CsDhcp.py b/systemvm/debian/opt/cloud/bin/cs/CsDhcp.py index 666a6886a02a..70f274d5c4d1 100755 --- a/systemvm/debian/opt/cloud/bin/cs/CsDhcp.py +++ b/systemvm/debian/opt/cloud/bin/cs/CsDhcp.py @@ -184,19 +184,19 @@ def add(self, entry): if entry['default_entry']: self.dhcp_hosts.add("%s,%s,%s,%s" % (entry['mac_address'], - entry['ipv4_address'], - entry['host_name'], - lease)) + entry['ipv4_address'], + entry['host_name'], + lease)) self.dhcp_leases.search(entry['mac_address'], "0 %s %s %s *" % (entry['mac_address'], entry['ipv4_address'], entry['host_name'])) else: tag = entry['ipv4_address'].replace(".", "_") self.dhcp_hosts.add("%s,set:%s,%s,%s,%s" % (entry['mac_address'], - tag, - entry['ipv4_address'], - entry['host_name'], - lease)) + tag, + entry['ipv4_address'], + entry['host_name'], + lease)) self.dhcp_opts.add("%s,%s" % (tag, 3)) self.dhcp_opts.add("%s,%s" % (tag, 6)) self.dhcp_opts.add("%s,%s" % (tag, 15)) From 6787235569b9a24ee9b6c55694c0a7dcfd92d68b Mon Sep 17 00:00:00 2001 From: Wei Zhou Date: Thu, 19 Aug 2021 09:58:49 +0200 Subject: [PATCH 3/3] vr: delete leases only when needed --- systemvm/debian/opt/cloud/bin/cs/CsDhcp.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/systemvm/debian/opt/cloud/bin/cs/CsDhcp.py b/systemvm/debian/opt/cloud/bin/cs/CsDhcp.py index 70f274d5c4d1..487d247b744b 100755 --- a/systemvm/debian/opt/cloud/bin/cs/CsDhcp.py +++ b/systemvm/debian/opt/cloud/bin/cs/CsDhcp.py @@ -54,15 +54,22 @@ def process(self): self.configure_server() restart_dnsmasq = False + need_delete_leases = False if self.conf.commit(): restart_dnsmasq = True + need_delete_leases = True + + if self.dhcp_hosts.commit(): + need_delete_leases = True + + if self.dhcp_leases.commit(): + need_delete_leases = True - self.dhcp_hosts.commit() - self.dhcp_leases.commit() self.dhcp_opts.commit() - self.delete_leases() + if need_delete_leases: + self.delete_leases() self.write_hosts() if not self.cl.is_redundant() or self.cl.is_master():