summaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
authorUnicronNL <kim.sidney@gmail.com>2018-07-01 22:48:06 +0200
committerUnicronNL <kim.sidney@gmail.com>2018-07-01 22:48:06 +0200
commitaaff68c0d55dc32f8972b9bde3239bb0923de140 (patch)
tree3d1d5aa18bd8d100e32d6ee2a4012f49f990117b /src/utils
parentcf4738ddbff6858975ff5f2bb0d656453e563848 (diff)
downloadvyos-salt-minion-aaff68c0d55dc32f8972b9bde3239bb0923de140.tar.gz
vyos-salt-minion-aaff68c0d55dc32f8972b9bde3239bb0923de140.zip
add vyos 1.x
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/initial-setup40
-rwxr-xr-xsrc/utils/vyos-config-to-commands29
2 files changed, 69 insertions, 0 deletions
diff --git a/src/utils/initial-setup b/src/utils/initial-setup
new file mode 100644
index 0000000..37fc457
--- /dev/null
+++ b/src/utils/initial-setup
@@ -0,0 +1,40 @@
+#!/usr/bin/env python3
+
+import argparse
+
+import vyos.configtree
+
+
+parser = argparse.ArgumentParser()
+
+parser.add_argument("--ssh", help="Enable SSH", action="store_true")
+parser.add_argument("--ssh-port", help="SSH port", type=int, action="store", default=22)
+
+parser.add_argument("--intf-address", help="Set interface address", type=str, action="append")
+
+parser.add_argument("config_file", help="Configuration file to modify", type=str)
+
+args = parser.parse_args()
+
+# Load the config file
+with open(args.config_file, 'r') as f:
+ config_file = f.read()
+
+config = vyos.configtree.ConfigTree(config_file)
+
+
+# Interface names and addresses are comma-separated,
+# we need to split them
+intf_addrs = list(map(lambda s: s.split(","), args.intf_address))
+
+# Enable SSH, if requested
+if args.ssh:
+ config.set(["service", "ssh", "port"], value=str(args.ssh_port))
+
+# Assign addresses to interfaces
+if intf_addrs:
+ for a in intf_addrs:
+ config.set(["interfaces", "ethernet", a[0], "address"], value=a[1])
+ config.set_tag(["interfaces", "ethernet"])
+
+print( config.to_string() )
diff --git a/src/utils/vyos-config-to-commands b/src/utils/vyos-config-to-commands
new file mode 100755
index 0000000..8b50f7c
--- /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)