Commit 0a1df161 authored by Mark Schouten's avatar Mark Schouten
Browse files

Implement vaddresses, so we don't alter vrrp-assigned addresses

parent aea579ce
......@@ -5,6 +5,8 @@ An array of interfaces, where each interface has the following options:
A description we can read via snmpd
- addresses:
An array of addresses in the syntax address/prefixlen
- vaddresses:
An optional array of addresses that can be assigned on this interface, e.g. via VRRP. ypconfig will not add or remove these addresses
- adminstate:
The state of the interface, may be ```UP``` or ```DOWN```, defaults to ```UP```
- mtu:
......
......@@ -7,6 +7,6 @@ Standards-Version: 3.9.1
Package: ypconfig
Architecture: all
Pre-Depends: python-support python3-pip
Pre-Depends: python-support, python3-pip
Description: ypconfig, talk to Netlink from Python
ypconfig is able to configure your servers network interfaces from a Yaml file, and rollback if something goes wrong.
......@@ -106,7 +106,7 @@ def Validate(document):
raise ValueError("Invalid value for lacp_rate")
def Interface(iface, iname):
known_fields = [ 'description', 'name', 'addresses', 'adminstate', 'mtu', 'ratelimit', 'slaves', 'type', 'vlanid', 'parent', 'bond-mode', 'miimon', 'lacp_rate' ]
known_fields = [ 'vaddresses', 'description', 'name', 'addresses', 'adminstate', 'mtu', 'ratelimit', 'slaves', 'type', 'vlanid', 'parent', 'bond-mode', 'miimon', 'lacp_rate' ]
for f in iface.keys():
if f not in known_fields:
raise ValueError("Invalid field in config for interface %s: %s" % (iname, f))
......@@ -123,6 +123,22 @@ def Validate(document):
except KeyError:
ret['description'] = ret['name']
try:
if iface['vaddresses']:
if type(iface['vaddresses']) != list:
raise ValueError("vaddresses should be an array")
for address in iface['vaddresses']:
try:
ret['vaddresses']
except KeyError:
ret['vaddresses'] = []
ret['vaddresses'].append(IP(address))
ret['vaddresses'].sort()
except ValueError as e:
raise e
except (KeyError, TypeError):
pass
try:
if iface['addresses']:
if type(iface['addresses']) != list:
......
......@@ -123,6 +123,17 @@ def Commit(cur, new):
else:
c[v] = None
if v == 'addresses':
vaddresses = []
try:
vaddresses += n['vaddresses']
except KeyError:
pass
try:
vaddresses += c['vaddresses']
except KeyError:
pass
try:
if n[v] != c[v]:
if v == 'adminstate':
......@@ -132,10 +143,13 @@ def Commit(cur, new):
elif v == 'description':
Ifalias(iface, n[v])
elif v == 'addresses':
for addr in set(n[v]).difference(set(c[v])):
Addaddr(iface, addr)
if addr not in vaddresses:
Addaddr(iface, addr)
for addr in set(c[v]).difference(set(n[v])):
Deladdr(iface, addr)
if addr not in vaddresses:
Deladdr(iface, addr)
elif v == 'slaves':
for slave in set(n[v]).difference(set(c[v])):
Addslave(iface, slave)
......
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