Commit de034ddd authored by Mark Schouten's avatar Mark Schouten
Browse files

Validate configation before applying it and catch the errors. Also, catch...

Validate configation before applying it and catch the errors. Also, catch KeyboardInterrupts and rollback on them..
parent aa41502c
...@@ -71,21 +71,27 @@ if __name__ == '__main__': ...@@ -71,21 +71,27 @@ if __name__ == '__main__':
cfgfile = '_'.join(['ypconfig', 'backup', str(time())]) cfgfile = '_'.join(['ypconfig', 'backup', str(time())])
rollbackcfg = os.path.join('/tmp', cfgfile) rollbackcfg = os.path.join('/tmp', cfgfile)
Config.Set(rollbackcfg, cur) Config.Set(rollbackcfg, cur)
try:
new = Config.Validate(cfgdoc) new = Config.Validate(cfgdoc)
except ValueError as e:
print("Errors in configuration:\n - %s" % (e))
sys.exit(1)
try: try:
Netlink.Commit(cur, new) Netlink.Commit(cur, new)
except Exception as e: except Exception as e:
print("We had an error confirming this new configuration:") print("We had an error confirming this new configuration:\n - '%s" % (e))
print("%s" % (e))
print("\n\n")
print("Rolling back") print("Rolling back")
rollback(rollbackcfg) rollback(rollbackcfg)
if not args['--confirm']: if not args['--confirm']:
print("New configuration commited. Type 'confirm' to confirm, we will rollback in 60 seconds otherwise.") print("New configuration commited. Type 'confirm' to confirm, we will rollback in 60 seconds otherwise.")
try:
i, o, e = select.select( [sys.stdin], [], [], 60 ) i, o, e = select.select( [sys.stdin], [], [], 60 )
if i and sys.stdin.readline().strip() == 'confirm': if i and sys.stdin.readline().strip() == 'confirm':
sys.exit(0) sys.exit(0)
else: else:
rollback(rollbackcfg) rollback(rollbackcfg)
except KeyboardInterrupt:
rollback(rollbackcfg)
\ No newline at end of file
Supports Markdown
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