diff --git a/systemvm/patches/debian/config/opt/cloud/bin/CsDhcp.py b/systemvm/patches/debian/config/opt/cloud/bin/CsDhcp.py index 3dbec384f80..1a54caf7f6b 100644 --- a/systemvm/patches/debian/config/opt/cloud/bin/CsDhcp.py +++ b/systemvm/patches/debian/config/opt/cloud/bin/CsDhcp.py @@ -39,6 +39,7 @@ class CsDhcp(object): dnsmasqb4.parse_hosts() dnsmasqb4.parse_dnsmasq() if not dnsmasq.compare_hosts(dnsmasqb4): + logging.info("Updating hosts file") dnsmasq.write_hosts() else: logging.debug("Hosts file is up to date") @@ -94,8 +95,8 @@ class CsDnsMasq(object): return def configure_server(self): - self.updated = self.updated or CsHelper.addifmissing(CLOUD_CONF, "dhcp-hostsfile=/etc/dhcphosts.txt") - self.updated = self.updated or CsHelper.addifmissing(DNSMASQ_CONF, "dhcp-optsfile=%s:" % DHCP_OPTS) + self.updated = self.updated | CsHelper.addifmissing(CLOUD_CONF, "dhcp-hostsfile=/etc/dhcphosts.txt") + self.updated = self.updated | CsHelper.addifmissing(DNSMASQ_CONF, "dhcp-optsfile=%s:" % DHCP_OPTS) for i in self.devinfo: if not i['dnsmasq']: continue @@ -103,12 +104,12 @@ class CsDnsMasq(object): ip = i['ip'].split('/')[0] line = "dhcp-range=interface:%s,set:interface-%s,%s,static" \ % (device, device, ip) - self.updated = self.updated or CsHelper.addifmissing(CLOUD_CONF, line) + self.updated = self.updated | CsHelper.addifmissing(CLOUD_CONF, line) # Next add the domain # if this is a guest network get it there otherwise use the value in resolv.conf gn = CsGuestNetwork(device) line = "dhcp-option=tag:interface-%s,15,%s" % (device,gn.get_domain()) - self.updated = self.updated or CsHelper.addifmissing(CLOUD_CONF, line) + self.updated = self.updated | CsHelper.addifmissing(CLOUD_CONF, line) if self.updated: if self.first_host: CsHelper.service("dnsmasq", "restart") diff --git a/systemvm/patches/debian/config/opt/cloud/bin/CsHelper.py b/systemvm/patches/debian/config/opt/cloud/bin/CsHelper.py index 10efe678efe..269585b092e 100644 --- a/systemvm/patches/debian/config/opt/cloud/bin/CsHelper.py +++ b/systemvm/patches/debian/config/opt/cloud/bin/CsHelper.py @@ -12,10 +12,12 @@ from pprint import pprint def updatefile(filename, val, mode): """ add val to file """ - for line in open(filename): - if line.strip().lstrip("0") == val: + handle = open(filename, 'r') + for line in handle.read(): + if line.strip().lstrip() == val: return # set the value + handle.close() handle = open(filename, mode) handle.write(val) handle.close()