Better error handling in nomad variable bootstrap
This commit is contained in:
parent
f11fad30a5
commit
69c8322d50
@ -10,7 +10,7 @@ NOMAD_ADDR = getenv("NOMAD_ADDR", "http://127.0.0.1:4646")
|
|||||||
NOMAD_TOKEN = getenv("NOMAD_TOKEN")
|
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 = {}
|
headers = {}
|
||||||
if NOMAD_TOKEN:
|
if NOMAD_TOKEN:
|
||||||
headers["X-Nomad-Token"] = 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)
|
print(result.text)
|
||||||
result.raise_for_status()
|
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}",
|
return nomad_req("PUT", f"var/{path}",
|
||||||
json={
|
json={
|
||||||
"Path": path,
|
"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}")
|
return nomad_req("DELETE", f"var/{path}")
|
||||||
|
|
||||||
|
|
||||||
@ -80,7 +80,12 @@ def write_nomad():
|
|||||||
response = delete_var(path)
|
response = delete_var(path)
|
||||||
else:
|
else:
|
||||||
response = write_var(path, items)
|
response = write_var(path, items)
|
||||||
print(response)
|
|
||||||
|
try:
|
||||||
|
response.raise_for_status()
|
||||||
|
except:
|
||||||
|
print(response.text)
|
||||||
|
raise
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
Loading…
Reference in New Issue
Block a user