1from nomad.api.base import Requester 2 3 4class Operator(Requester): 5 6 """ 7 The Operator endpoint provides cluster-level tools for 8 Nomad operators, such as interacting with the Raft subsystem. 9 10 https://www.nomadproject.io/docs/http/operator.html 11 """ 12 13 ENDPOINT = "operator" 14 15 def __init__(self, **kwargs): 16 super(Operator, self).__init__(**kwargs) 17 18 def __str__(self): 19 return "{0}".format(self.__dict__) 20 21 def __repr__(self): 22 return "{0}".format(self.__dict__) 23 24 def __getattr__(self, item): 25 raise AttributeError 26 27 def get_configuration(self, stale=False): 28 """ Query the status of a client node registered with Nomad. 29 30 https://www.nomadproject.io/docs/http/operator.html 31 32 returns: dict 33 optional arguments: 34 - stale, (defaults to False), Specifies if the cluster should respond without an active leader. 35 This is specified as a querystring parameter. 36 raises: 37 - nomad.api.exceptions.BaseNomadException 38 - nomad.api.exceptions.URLNotFoundNomadException 39 """ 40 41 params = {"stale": stale} 42 return self.request("raft", "configuration", params=params, method="get").json() 43 44 def delete_peer(self, peer_address, stale=False): 45 """ Remove the Nomad server with given address from the Raft configuration. 46 The return code signifies success or failure. 47 48 https://www.nomadproject.io/docs/http/operator.html 49 50 arguments: 51 - peer_address, The address specifies the server to remove and is given as an IP:port 52 optional arguments: 53 - stale, (defaults to False), Specifies if the cluster should respond without an active leader. 54 This is specified as a querystring parameter. 55 returns: Boolean 56 raises: 57 - nomad.api.exceptions.BaseNomadException 58 - nomad.api.exceptions.URLNotFoundNomadException 59 """ 60 61 params = {"address": peer_address, "stale": stale} 62 return self.request("raft", "peer", params=params, method="delete").ok 63