Skip to content

Commit 16e4de0

Browse files
vr: reload dnsmasq when start vms (#5319)
* vr: reload dnsmasq when start vms * vr: fix pycodestyle check error * vr: delete leases only when needed
1 parent f822547 commit 16e4de0

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

systemvm/debian/opt/cloud/bin/cs/CsDhcp.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ def process(self):
3737
self.changed = []
3838
self.devinfo = CsHelper.get_device_info()
3939
self.preseed()
40-
self.cloud = CsFile(DHCP_HOSTS)
40+
self.dhcp_hosts = CsFile(DHCP_HOSTS)
4141
self.dhcp_opts = CsFile(DHCP_OPTS)
4242
self.conf = CsFile(CLOUD_CONF)
4343
self.dhcp_leases = CsFile(LEASES)
4444

45-
self.cloud.repopulate()
45+
self.dhcp_hosts.repopulate()
4646
self.dhcp_opts.repopulate()
4747

4848
for item in self.dbag:
@@ -54,21 +54,22 @@ def process(self):
5454
self.configure_server()
5555

5656
restart_dnsmasq = False
57+
need_delete_leases = False
5758

5859
if self.conf.commit():
5960
restart_dnsmasq = True
61+
need_delete_leases = True
6062

61-
if self.cloud.commit():
62-
restart_dnsmasq = True
63+
if self.dhcp_hosts.commit():
64+
need_delete_leases = True
6365

6466
if self.dhcp_leases.commit():
65-
restart_dnsmasq = True
67+
need_delete_leases = True
6668

6769
self.dhcp_opts.commit()
6870

69-
if restart_dnsmasq:
71+
if need_delete_leases:
7072
self.delete_leases()
71-
7273
self.write_hosts()
7374

7475
if not self.cl.is_redundant() or self.cl.is_master():
@@ -189,20 +190,20 @@ def add(self, entry):
189190
lease = 'infinite'
190191

191192
if entry['default_entry']:
192-
self.cloud.add("%s,%s,%s,%s" % (entry['mac_address'],
193-
entry['ipv4_address'],
194-
entry['host_name'],
195-
lease))
193+
self.dhcp_hosts.add("%s,%s,%s,%s" % (entry['mac_address'],
194+
entry['ipv4_address'],
195+
entry['host_name'],
196+
lease))
196197
self.dhcp_leases.search(entry['mac_address'], "0 %s %s %s *" % (entry['mac_address'],
197198
entry['ipv4_address'],
198199
entry['host_name']))
199200
else:
200201
tag = entry['ipv4_address'].replace(".", "_")
201-
self.cloud.add("%s,set:%s,%s,%s,%s" % (entry['mac_address'],
202-
tag,
203-
entry['ipv4_address'],
204-
entry['host_name'],
205-
lease))
202+
self.dhcp_hosts.add("%s,set:%s,%s,%s,%s" % (entry['mac_address'],
203+
tag,
204+
entry['ipv4_address'],
205+
entry['host_name'],
206+
lease))
206207
self.dhcp_opts.add("%s,%s" % (tag, 3))
207208
self.dhcp_opts.add("%s,%s" % (tag, 6))
208209
self.dhcp_opts.add("%s,%s" % (tag, 15))

0 commit comments

Comments
 (0)