Stupid stupd bug

a or b is of course not the same as a | b
This commit is contained in:
Ian Southam 2014-08-21 16:00:57 +02:00 committed by wilderrodrigues
parent c318bd6337
commit e6e47de6ff
2 changed files with 9 additions and 6 deletions

View File

@ -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")

View File

@ -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()