Commit 0588d597 authored by Xavier Thompson's avatar Xavier Thompson

slapformat: WIP: Add checkFormat

parent c44a9e73
...@@ -37,6 +37,7 @@ import pwd ...@@ -37,6 +37,7 @@ import pwd
import grp import grp
import subprocess import subprocess
import sys import sys
import time
from collections import defaultdict from collections import defaultdict
from netifaces import AF_INET, AF_INET6 from netifaces import AF_INET, AF_INET6
...@@ -53,6 +54,8 @@ def do_format(conf): ...@@ -53,6 +54,8 @@ def do_format(conf):
computer.checkConf() computer.checkConf()
# format # format
computer.format() computer.format()
# check formatting
computer.checkFormat()
# collect some environmental data # collect some environmental data
computer.update() computer.update()
# send to master # send to master
...@@ -269,6 +272,11 @@ class Computer(object): ...@@ -269,6 +272,11 @@ class Computer(object):
for p in self.partitions: for p in self.partitions:
p.format(self.interface) p.format(self.interface)
def checkFormat(self):
time.sleep(2)
for p in self.partitions:
p.checkFormat(self.interface)
def update(self): def update(self):
pass pass
...@@ -358,6 +366,27 @@ class Interface(object): ...@@ -358,6 +366,27 @@ class Interface(object):
if not address in (q['addr'].split('%')[0] for q in ifaddresses): if not address in (q['addr'].split('%')[0] for q in ifaddresses):
call(['ip', 'addr', 'add', str(ip), 'dev', interface]) call(['ip', 'addr', 'add', str(ip), 'dev', interface])
def checkAddress(self, ip, reason, interface=None):
interface = interface or getattr(self, 'ipv%d_interface' % ip.version)
flag = str(-ip.version)
_, result = call(['ip', flag, 'addr', 'show', interface])
address = str(ip.ip)
for line in result.splitlines():
if address in line:
for state in ('tentative', 'dadfailed'):
if state in line:
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
)
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
)
class Partition(object): class Partition(object):
reference : str reference : str
...@@ -406,6 +435,12 @@ class Partition(object): ...@@ -406,6 +435,12 @@ class Partition(object):
for ip in self.ipv6_list: for ip in self.ipv6_list:
interface.addAddress(ip, self.reference) interface.addAddress(ip, self.reference)
def checkFormat(self, interface):
for ip in self.ipv4_list:
interface.checkAddress(ip, self.reference)
for ip in self.ipv6_list:
interface.checkAddress(ip, self.reference)
def createPath(self): def createPath(self):
if not os.path.exists(self.path): if not os.path.exists(self.path):
os.mkdir(self.path) os.mkdir(self.path)
......
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