Commit 0ed0602d authored by Xavier Thompson's avatar Xavier Thompson

slapformat: WIP Add addresses to interface

parent 030c6f70
......@@ -331,6 +331,20 @@ class Interface(object):
if not 'dev lo' in result:
call(['ip', '-6', 'route', 'add', 'local', network, 'dev', 'lo'])
def addAddress(self, ip, interface=None):
interface = interface or getattr(self, 'ipv%d_interface' % ip.version)
af = {4: AF_INET, 6: AF_INET6}[ip.version]
for iface in netifaces.interfaces():
if iface != interface:
ifaddresses = netifaces.ifaddresses(iface).get(af, ())
if ip.ip in (q['addr'].split('%')[0] for q in ifaddresses):
self.conf.error(
"Cannot add address %s to %s as it already exists on %s",
ip, interface, iface
)
ifaddresses = netifaces.ifaddresses(interface).get(af, ())
if not ip.ip in (q['addr'].split('%')[0] for q in ifaddresses):
call(['ip', 'addr', 'add', str(ip), 'dev', interface])
class Partition(object):
......@@ -377,6 +391,10 @@ class Partition(object):
def format(self):
self.user.createUser()
self.createPath()
for ip in self.ipv4_list:
self.interface.addAddress(ip)
for ip in self.ipv6_list:
self.interface.addAddress(ip)
def createPath(self):
if not os.path.exists(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