Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions nomad/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def __init__(self, **kwargs):
self.stream_logs = stream_logs(**kwargs)
self.gc_allocation = gc_allocation(**kwargs)
self.gc_all_allocations = gc_all_allocations(**kwargs)
self.metadata = metadata(**kwargs)

def __str__(self):
return f"{self.__dict__}"
Expand Down Expand Up @@ -370,3 +371,48 @@ def garbage_collect(self, node_id=None):
- nomad.api.exceptions.BaseNomadException
"""
self.request(params={"node_id": node_id}, method="get")


class metadata(Requester):
"""
The /client/metadata endpoint is used to read and update dynamic Node metadata.

https://developer.hashicorp.com/nomad/api-docs/client#read-dynamic-node-metadata
"""

ENDPOINT = "client/metadata"

def __init__(self, **kwargs):
super().__init__(**kwargs)

def read_metadata(self, node_id: str):
"""Query Node metadata on a specific Client agent.

https://developer.hashicorp.com/nomad/api-docs/client#read-dynamic-node-metadata

arguments:
- node_id: (str) required
returns: dict
raises:
- nomad.api.exceptions.BaseNomadException
- nomad.api.exceptions.URLNotFoundNomadException
"""
params = {"node_id": node_id}
return self.request(params=params, method="get").json()

def update_metadata(self, node_id: str, meta: dict):
"""Update dynamic Node metadata on a specific Client agent.

https://developer.hashicorp.com/nomad/api-docs/client#update-dynamic-node-metadata

arguments:
- node_id: (str) required
- meta: (dict) required. Specifies the Node metadata keys to update.
returns: dict
raises:
- nomad.api.exceptions.BaseNomadException
- nomad.api.exceptions.URLNotFoundNomadException
"""
params = {"node_id": node_id}
payload = {"Meta": meta}
return self.request(json=payload, params=params, method="post").json()
Loading