#!/usr/bin/env python3 from __future__ import annotations import subprocess as sub import re P_OPTIONS = """ Options: 0) Exit 1) Maak/Update klantomgeving(en) 2) Vernietig klantomgeving(en) 3) Recover klantomgeving(en) 4) List klantomgeving(en) h) Help """ RE_TEXT = re.compile(r"^\w+$") RE_NUM = re.compile(r"^\d+$") def _take_input(prompt: str, pattern: re.Pattern) -> str: while True: i = input(prompt) if pattern.match(i): return i def main() -> int: while True: print(P_OPTIONS) c = input("Input: ") if c == "h": continue if c == "0": break if c == "1": customer_name = _take_input("Customer name (example=opc): ", RE_TEXT) env_name = _take_input("Environment name (example=prod): ", RE_TEXT) amnt_nginx_web = _take_input( "Number of nginx webservers (example=1): ", RE_NUM) amnt_nginx_lb = _take_input( "Number of nginx loadbalancers (example=1): ", RE_NUM) amnt_psql = _take_input( "Number of postgres instances (example=1): ", RE_NUM) ip_format = _take_input( "Format of ip (example=192.168.56.{}, `{}` will be replaced with the correct octet at runtime): ", re.compile(r".+")) ip_int = _take_input( "Number to start formatting the IP from (example=10): ", RE_NUM) sub.call([ "python3", "cli.py", "create", customer_name, env_name, "--num-nginx-web", amnt_nginx_web, "--num-postgres", amnt_psql, "--num-nginx-lb", amnt_nginx_lb, "--ip-format", ip_format, "--ip-int", ip_int ]) if c == "2": customer_name = _take_input("Customer name (example=opc): ", RE_TEXT) env_name = _take_input("Environment name (example=prod): ", RE_TEXT) sub.call(["python3", "cli.py", "delete", customer_name, env_name]) if c == "3": customer_name = _take_input("Customer name (example=opc): ", RE_TEXT) env_name = _take_input("Environment name (example=prod): ", RE_TEXT) sub.call(["python3", "cli.py", "recover", customer_name, env_name]) if c == "4": customer_name = _take_input("Customer name (example=opc): ", RE_TEXT) sub.call(["python3", "cli.py", "list", customer_name]) return 0 if __name__ == "__main__": raise SystemExit(main())