summaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@baturin.org>2018-06-05 20:20:30 +0200
committerDaniil Baturin <daniil@baturin.org>2018-06-05 20:20:30 +0200
commit9aec42029aff0d81c9f27a6d6df6eae401446c76 (patch)
treec0fc8650237e54da7fefc22d22f8113b796b30d0 /src/utils
parent28db29e42fca939f8157041cbedc52378ce3622e (diff)
downloadvyos-1x-9aec42029aff0d81c9f27a6d6df6eae401446c76.tar.gz
vyos-1x-9aec42029aff0d81c9f27a6d6df6eae401446c76.zip
T684: add bindings for the commands formatter and scripts for converting configs to commands.
Diffstat (limited to 'src/utils')
-rwxr-xr-xsrc/utils/vyos-config-to-commands29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/utils/vyos-config-to-commands b/src/utils/vyos-config-to-commands
new file mode 100755
index 000000000..8b50f7c5d
--- /dev/null
+++ b/src/utils/vyos-config-to-commands
@@ -0,0 +1,29 @@
+#!/usr/bin/python3
+
+import sys
+
+from signal import signal, SIGPIPE, SIG_DFL
+from vyos.configtree import ConfigTree
+
+signal(SIGPIPE,SIG_DFL)
+
+config_string = None
+if (len(sys.argv) == 1):
+ # If no argument given, act as a pipe
+ config_string = sys.stdin.read()
+else:
+ file_name = sys.argv[1]
+ try:
+ with open(file_name, 'r') as f:
+ config_string = f.read()
+ except OSError as e:
+ print("Could not read config file {0}: {1}".format(file_name, e), file=sys.stderr)
+
+try:
+ config = ConfigTree(config_string)
+ commands = config.to_commands()
+except ValueError as e:
+ print("Could not parse the config file: {0}".format(e), file=sys.stderr)
+ sys.exit(1)
+
+print(commands)