Better error handling in nomad variable bootstrap

This commit is contained in:
IamTheFij 2023-05-09 13:21:00 -07:00
parent f11fad30a5
commit 69c8322d50

View File

@ -10,7 +10,7 @@ NOMAD_ADDR = getenv("NOMAD_ADDR", "http://127.0.0.1:4646")
NOMAD_TOKEN = getenv("NOMAD_TOKEN")
def nomad_req(method: str, path: str, json: dict|None = None) -> dict:
def nomad_req(method: str, path: str, json: dict|None = None) -> requests.Response:
headers = {}
if NOMAD_TOKEN:
headers["X-Nomad-Token"] = NOMAD_TOKEN
@ -25,11 +25,11 @@ def nomad_req(method: str, path: str, json: dict|None = None) -> dict:
print(result.text)
result.raise_for_status()
return result.json()
return result
def write_var(path: str, items: dict[str, str | float | int]) -> dict:
def write_var(path: str, items: dict[str, str | float | int]) -> requests.Response:
return nomad_req("PUT", f"var/{path}",
json={
"Path": path,
@ -38,7 +38,7 @@ def write_var(path: str, items: dict[str, str | float | int]) -> dict:
)
def delete_var(path: str) -> dict:
def delete_var(path: str) -> requests.Response:
return nomad_req("DELETE", f"var/{path}")
@ -80,7 +80,12 @@ def write_nomad():
response = delete_var(path)
else:
response = write_var(path, items)
print(response)
try:
response.raise_for_status()
except:
print(response.text)
raise
def main():