Implement scenario subcommand

This commit is contained in:
Quentin 2022-09-15 17:00:02 +02:00
parent cfd3e500fe
commit 62e4ed55a4
Signed by untrusted user: quentin
GPG key ID: E9602264D639FF68
2 changed files with 12 additions and 3 deletions

View file

@ -47,7 +47,7 @@ import garage_admin_sdk
(Not yet implemented) (Not yet implemented)
```bash ```bash
./mknet scenario ./scenarios/garage-s3lat ./topo/single-dc.yml ./mknet scenario ./topo/single-dc.yml ./scenarios/garage-s3lat
``` ```
## Manual usage ## Manual usage

13
mknet
View file

@ -349,22 +349,31 @@ def destroy():
net.ns.forget("unconfined") net.ns.forget("unconfined")
os.remove(".current_state.yml") os.remove(".current_state.yml")
def scenario(config, cmd):
create(config)
runall(cmd)
destroy()
if __name__ == "__main__": if __name__ == "__main__":
if len(sys.argv) < 2: if len(sys.argv) < 2:
progname = os.path.basename(sys.argv[0]) if len(sys.argv) > 0 else "mknet" progname = os.path.basename(sys.argv[0]) if len(sys.argv) > 0 else "mknet"
print(f"""Usage: print(f"""Usage:
{progname} create [config_path] # create a new network. config_path defailt to config.yml {progname} scenario <config_path> <cmd> [args...] # all in one simulation: create a network, run the command on all nodes, destroy the network
{progname} create [config_path] # create a new network. config_path defailt to topo/with-vdsl.yml
{progname} run-all <cmd> [args...] # run a command as each host. set the IP, NAME and ZONE environment variables {progname} run-all <cmd> [args...] # run a command as each host. set the IP, NAME and ZONE environment variables
{progname} run <name> [cmd [args...]] # run command in host named <name>. Use zonename:name if multiple zones hosts server with same name. If cmd is empty, run a shell {progname} run <name> [cmd [args...]] # run command in host named <name>. Use zonename:name if multiple zones hosts server with same name. If cmd is empty, run a shell
{progname} destroy # destroy the current environment""") {progname} destroy # destroy the current environment""")
exit() exit()
cmd = sys.argv[1] cmd = sys.argv[1]
if cmd == "create": if cmd == "create":
create(sys.argv[2] if len(sys.argv) > 2 else "config.yml") create(sys.argv[2] if len(sys.argv) > 2 else "topo/with-vdsl.yml")
elif cmd == "run": elif cmd == "run":
run(sys.argv[2], sys.argv[3:]) run(sys.argv[2], sys.argv[3:])
elif cmd == "run-all": elif cmd == "run-all":
runall(sys.argv[2:]) runall(sys.argv[2:])
elif cmd == "scenario":
scenario(sys.argv[2], sys.argv[3:])
elif cmd == "destroy": elif cmd == "destroy":
destroy() destroy()
else: else: