Commit 8e3692b8 authored by Xavier Thompson's avatar Xavier Thompson

slapformat: WIP: Improve addAddress and checkAddress

parent 9051387e
......@@ -354,6 +354,7 @@ class Interface(object):
interface = interface or getattr(self, 'ipv%d_interface' % ip.version)
af = {4: AF_INET, 6: AF_INET6}[ip.version]
address = str(ip.ip)
netmask = str(ip.network.netmask)
for iface in netifaces.interfaces():
if iface != interface:
ifaddresses = netifaces.ifaddresses(iface).get(af, ())
......@@ -363,7 +364,15 @@ class Interface(object):
ip, reason, interface, iface
)
ifaddresses = netifaces.ifaddresses(interface).get(af, ())
if not address in (q['addr'].split('%')[0] for q in ifaddresses):
for q in ifaddresses:
if address == q['addr'].split('%')[0]:
if netmask not in q['netmask']:
self.conf.error(
"Address %s (%s) is already on %s but with another netmask %s",
ip, reason, interface, q['netmask']
)
break
else:
call(['ip', 'addr', 'add', str(ip), 'dev', interface])
def checkAddress(self, ip, reason, interface=None):
......@@ -378,13 +387,13 @@ class Interface(object):
call(['ip', 'addr', 'del', address, 'dev', interface])
self.conf.error(
"Address %s (%s) on %s was in state %s so was removed: %r",
address, reason, interface, state, line
ip, reason, interface, state, line
)
return
report = self.conf.warn if self.conf.dry_run else self.conf.error
report(
"Address %s (%s) is unexpectedly not present on %s",
address, reason, interface
ip, reason, interface
)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment