-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from jrxFive/add_operator_endpoint
add operator endpoint and job/summary and job/plan for #27
- Loading branch information
Showing
9 changed files
with
166 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
|
||
class Operator(object): | ||
|
||
""" | ||
The Operator endpoint provides cluster-level tools for | ||
Nomad operators, such as interacting with the Raft subsystem. | ||
https://www.nomadproject.io/docs/http/operator.html | ||
""" | ||
|
||
ENDPOINT = "operator" | ||
|
||
def __init__(self, requester): | ||
self._requester = requester | ||
|
||
def __str__(self): | ||
return "{0}".format(self.__dict__) | ||
|
||
def __repr__(self): | ||
return "{0}".format(self.__dict__) | ||
|
||
def __getattr__(self, item): | ||
raise AttributeError | ||
|
||
def _get(self, *args, **kwargs): | ||
try: | ||
url = self._requester._endpointBuilder(Operator.ENDPOINT, *args) | ||
response = self._requester.get(url, | ||
params=kwargs.get("params",None)) | ||
|
||
return response.json() | ||
except: | ||
raise | ||
|
||
def _delete(self, *args, **kwargs): | ||
try: | ||
url = self._requester._endpointBuilder(Operator.ENDPOINT, *args) | ||
response = self._requester.delete(url, | ||
params=kwargs.get("params", None)) | ||
|
||
return response.ok | ||
except: | ||
raise | ||
|
||
def get_configuration(self, stale=False): | ||
""" Query the status of a client node registered with Nomad. | ||
https://www.nomadproject.io/docs/http/operator.html | ||
returns: dict | ||
raises: | ||
- nomad.api.exceptions.BaseNomadException | ||
- nomad.api.exceptions.URLNotFoundNomadException | ||
""" | ||
|
||
params = {"stale": stale} | ||
return self._get("raft", "configuration", params=params) | ||
|
||
def delete_peer(self, peer_address): | ||
""" Remove the Nomad server with given address from the Raft configuration. | ||
The return code signifies success or failure. | ||
https://www.nomadproject.io/docs/http/operator.html | ||
arguments: | ||
- peer_address, The address specifies the server to remove and is given as an IP:port | ||
returns: Ok status | ||
raises: | ||
- nomad.api.exceptions.BaseNomadException | ||
- nomad.api.exceptions.URLNotFoundNomadException | ||
""" | ||
|
||
params = {"address": peer_address} | ||
return self._delete("raft", "peer", params=params) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import pytest | ||
import tests.common as common | ||
import nomad | ||
import json | ||
import os | ||
import mock | ||
from nomad.api import exceptions | ||
|
||
|
||
@pytest.fixture | ||
def nomad_setup(): | ||
n = nomad.Nomad(host=common.IP, port=common.NOMAD_PORT) | ||
return n | ||
|
||
# integration tests requires nomad Vagrant VM or Binary running | ||
@pytest.mark.skipif(tuple(int(i) for i in os.environ.get("NOMAD_VERSION").split(".")) < (0, 5, 5), reason="Not supported in version") | ||
def test_get_configuration_default(nomad_setup): | ||
assert isinstance(nomad_setup.operator.get_configuration(), dict) | ||
|
||
@pytest.mark.skipif(tuple(int(i) for i in os.environ.get("NOMAD_VERSION").split(".")) < (0, 5, 5), reason="Not supported in version") | ||
def test_get_configuration_stale(nomad_setup): | ||
assert isinstance(nomad_setup.operator.get_configuration(stale=True), dict) | ||
|
||
@pytest.mark.skipif(tuple(int(i) for i in os.environ.get("NOMAD_VERSION").split(".")) < (0, 5, 5), reason="Not supported in version") | ||
def test_delete_peer(nomad_setup): | ||
with pytest.raises(exceptions.URLNotFoundNomadException): | ||
nomad_setup.operator.delete_peer("192.168.10.133:4646") | ||
|
||
def test_dunder_str(nomad_setup): | ||
assert isinstance(str(nomad_setup.operator), str) | ||
|
||
def test_dunder_repr(nomad_setup): | ||
assert isinstance(repr(nomad_setup.operator), str) | ||
|
||
def test_dunder_getattr(nomad_setup): | ||
with pytest.raises(AttributeError): | ||
d = nomad_setup.operator.does_not_exist |