diff options
author | Daniil Baturin <daniil@baturin.org> | 2018-06-29 12:31:09 +0200 |
---|---|---|
committer | Daniil Baturin <daniil@baturin.org> | 2018-06-29 12:31:09 +0200 |
commit | 10e28b3e0a795a588b17305e87a1b2fc0875dbe2 (patch) | |
tree | 5103a7b3dcda3669f92326af8ce25373f97c2c29 /src/utils | |
parent | 2cdbb5ac6ff9c1a17d4b2bdd0e1d9f9a6d54088d (diff) | |
download | vyos-1x-10e28b3e0a795a588b17305e87a1b2fc0875dbe2.tar.gz vyos-1x-10e28b3e0a795a588b17305e87a1b2fc0875dbe2.zip |
T723: add a prototype of an initial setup script.
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/initial-setup | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/utils/initial-setup b/src/utils/initial-setup new file mode 100644 index 000000000..37fc45751 --- /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() ) |