summaryrefslogtreecommitdiff
path: root/src/helpers
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/helpers
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/helpers')
-rwxr-xr-xsrc/helpers/commands-pipe.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/helpers/commands-pipe.py b/src/helpers/commands-pipe.py
new file mode 100755
index 000000000..3ffc64545
--- /dev/null
+++ b/src/helpers/commands-pipe.py
@@ -0,0 +1,30 @@
+#!/usr/bin/python3
+
+import sys
+import re
+
+from signal import signal, SIGPIPE, SIG_DFL
+from vyos.configtree import ConfigTree
+
+signal(SIGPIPE,SIG_DFL)
+
+
+config_string = sys.stdin.read().strip()
+
+if not config_string:
+ sys.exit(0)
+
+# When used in conf mode pipe, the config given to the script is likely incomplete
+# and breaks the "all top level nodes are neither tag nor leaf"
+# invariant, so we wrap it into a fake node.
+# Since nodes don't normally start with an underscore,
+# __root__ is hygienic enough.
+config_string = "__root__ {{ {0} \n }}".format(config_string)
+
+config_re = re.compile("(set|comment)\s+__root__\s+(.*)")
+
+config = ConfigTree(config_string)
+commands = config.to_commands()
+commands = config_re.sub("\\1 \\2", commands)
+
+print(commands)