Commit 74426f04 authored by Mark Schouten's avatar Mark Schouten

If nothing changed, tell us and don't ask for confirmation

parent 942efee2
......@@ -85,16 +85,19 @@ def Commit(cur, new):
curif = set(cur.keys())
newif = set(new.keys())
changed = False
with IPDB(mode='implicit') as ip:
curif = set(cur.keys())
newif = set(new.keys())
# These interfaces should be deleted
for iface in curif.difference(newif):
changed = True
Delif(iface)
# These interfaces need to be created
for iface in newif.difference(curif):
changed = True
if new[iface]['type'] == 'vlan':
Addvlan(new[iface])
elif new[iface]['type'] == 'bond':
......@@ -134,6 +137,7 @@ def Commit(cur, new):
try:
if n[v] != c[v]:
changed = True
if v == 'adminstate':
Ifstate(iface, n[v])
elif v == 'mtu':
......@@ -167,6 +171,8 @@ def Commit(cur, new):
ip.commit()
ip.release()
return changed
def Delif(iface):
print("Removing interface %s" % (iface))
global ip
......
......@@ -78,13 +78,18 @@ if __name__ == '__main__':
print("Errors in configuration:\n - %s" % (e))
sys.exit(1)
changed = False
try:
Netlink.Commit(cur, new)
changed = Netlink.Commit(cur, new)
except Exception as e:
print("We had an error confirming this new configuration:\n - '%s" % (e))
print("Rolling back")
rollback(rollbackcfg)
if not changed:
print("Nothing changed")
sys.exit(0)
if not args['--confirm']:
print("New configuration commited. Type 'confirm' to confirm, we will rollback in 60 seconds otherwise.")
try:
......
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