diff options
-rw-r--r-- | pyproject.toml | 8 | ||||
-rwxr-xr-x | src/cli/hashi_env.py (renamed from packages/robloxenv/robloxenv.py) | 1 | ||||
-rwxr-xr-x | src/cli/nomad_allocs.py | 51 |
3 files changed, 57 insertions, 3 deletions
diff --git a/pyproject.toml b/pyproject.toml index 0c944c3..4400828 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -65,8 +65,10 @@ combine-as-imports = true known-first-party = ["rbx_nomad"] [project.scripts] +hashi_env = "cli.hash_env:cli" +int2ip = "cli.ipconverter:int2ip" +ip2int = "cli.ipconverter:ip2int" +nomad_allocs = "cli.nomad_allocs:cli" pizza = "cli.pizza:main" -slocalc = "cli.slocalc:cli" seqstat = "cli.seqstat:cli" -ip2int = "cli.ipconverter:ip2int" -int2ip = "cli.ipconverter:int2ip" +slocalc = "cli.slocalc:cli" diff --git a/packages/robloxenv/robloxenv.py b/src/cli/hashi_env.py index 79f9428..aeac5ef 100755 --- a/packages/robloxenv/robloxenv.py +++ b/src/cli/hashi_env.py @@ -21,6 +21,7 @@ creds_cache = os.path.join(os.getenv("HOME") or "", ".local/state/rbxenv") valid_dcs = ["ash1", "chi1"] valid_edges = [ + "bom1", "ams1", "atl1", "dwf1", diff --git a/src/cli/nomad_allocs.py b/src/cli/nomad_allocs.py new file mode 100755 index 0000000..f2369bb --- /dev/null +++ b/src/cli/nomad_allocs.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python3 + +import sys + +import click +import requests + + +@click.command() +@click.argument("job") +@click.option("--dc", default="bom1", help="Name of the data center") +@click.option("--token", help="Token for Nomad") +def cli(job, dc, token): + if token is None: + print("you need to pass a valid token") + sys.exit(1) + + headers = {"Authorization": f"Bearer {token}"} + url = f"https://{dc}-nomad.simulprod.com/v1/job/{job}/allocations" + try: + resp = requests.get(url, headers=headers) + resp.raise_for_status + except Exception as e: + print("return {}".format(str(e))) + + running_tasks = [] + terminated_tasks = [] + for task in resp.json(): + task_name = list(task["TaskStates"].keys())[0] + if task["TaskStates"][task_name]["State"] == "running": + running_tasks.append( + f"https://{dc}-nomad.simulprod.com/ui/allocations/{task['ID']}/{task_name}/logs" + ) + else: + terminated_tasks.append( + f"https://{dc}-nomad.simulprod.com/ui/allocations/{task['ID']}/{task_name}/logs" + ) + + if len(running_tasks) > 0: + print("running tasks") + for t in running_tasks: + print(f"→ {t}") + + if len(terminated_tasks) > 0: + print("terminated tasks") + for t in terminated_tasks: + print(f"→ {t}") + + +if __name__ == "__main__": + cli() |