Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 30f093d

Browse files
authored
Merge pull request jrxFive#85 from jrxFive/prefix_support
add prefixes option and tests
2 parents c3eb383 + 9aa69b8 commit 30f093d

File tree

11 files changed

+78
-15
lines changed

11 files changed

+78
-15
lines changed

nomad/api/allocations.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,17 @@ def __iter__(self):
3232
response = self.get_allocations()
3333
return iter(response)
3434

35-
def get_allocations(self):
35+
def get_allocations(self, prefix=None):
3636
""" Lists all the allocations.
3737
3838
https://www.nomadproject.io/docs/http/allocs.html
39-
39+
arguments:
40+
- prefix :(str) optional, specifies a string to filter allocations on based on an prefix.
41+
This is specified as a querystring parameter.
4042
returns: list
4143
raises:
4244
- nomad.api.exceptions.BaseNomadException
4345
- nomad.api.exceptions.URLNotFoundNomadException
4446
"""
45-
return self.request(method="get").json()
47+
params = {"prefix": prefix}
48+
return self.request(method="get", params=params).json()

nomad/api/evaluations.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,17 @@ def __iter__(self):
5757
evaluations = self.get_evaluations()
5858
return iter(evaluations)
5959

60-
def get_evaluations(self):
60+
def get_evaluations(self, prefix=None):
6161
""" Lists all the evaluations.
6262
6363
https://www.nomadproject.io/docs/http/evals.html
64-
64+
arguments:
65+
- prefix :(str) optional, specifies a string to filter evaluations on based on an prefix.
66+
This is specified as a querystring parameter.
6567
returns: list
6668
raises:
6769
- nomad.api.exceptions.BaseNomadException
6870
- nomad.api.exceptions.URLNotFoundNomadException
6971
"""
70-
return self.request(method="get").json()
72+
params = {"prefix": prefix}
73+
return self.request(method="get", params=params).json()

nomad/api/jobs.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,20 @@ def __iter__(self):
6363
jobs = self.get_jobs()
6464
return iter(jobs)
6565

66-
def get_jobs(self):
66+
def get_jobs(self, prefix=None):
6767
""" Lists all the jobs registered with Nomad.
6868
6969
https://www.nomadproject.io/docs/http/jobs.html
70-
70+
arguments:
71+
- prefix :(str) optional, specifies a string to filter jobs on based on an prefix.
72+
This is specified as a querystring parameter.
7173
returns: list
7274
raises:
7375
- nomad.api.exceptions.BaseNomadException
7476
- nomad.api.exceptions.URLNotFoundNomadException
7577
"""
76-
return self.request(method="get").json()
78+
params = {"prefix": prefix}
79+
return self.request(method="get", params=params).json()
7780

7881
def register_job(self, job):
7982
""" Register a job with Nomad.

nomad/api/namespaces.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,17 @@ def __iter__(self):
5757
namespaces = self.get_namespaces()
5858
return iter(namespaces)
5959

60-
def get_namespaces(self):
60+
def get_namespaces(self, prefix=None):
6161
""" Lists all the namespaces registered with Nomad.
6262
6363
https://www.nomadproject.io/docs/enterprise/namespaces/index.html
64-
64+
arguments:
65+
- prefix :(str) optional, specifies a string to filter namespaces on based on an prefix.
66+
This is specified as a querystring parameter.
6567
returns: list
6668
raises:
6769
- nomad.api.exceptions.BaseNomadException
6870
- nomad.api.exceptions.URLNotFoundNomadException
6971
"""
70-
return self.request(method="get").json()
72+
params = {"prefix": prefix}
73+
return self.request(method="get", params=params).json()

nomad/api/nodes.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,17 @@ def __iter__(self):
6161
nodes = self.get_nodes()
6262
return iter(nodes)
6363

64-
def get_nodes(self):
64+
def get_nodes(self, prefix=None):
6565
""" Lists all the client nodes registered with Nomad.
6666
6767
https://www.nomadproject.io/docs/http/nodes.html
68-
68+
arguments:
69+
- prefix :(str) optional, specifies a string to filter nodes on based on an prefix.
70+
This is specified as a querystring parameter.
6971
returns: list
7072
raises:
7173
- nomad.api.exceptions.BaseNomadException
7274
- nomad.api.exceptions.URLNotFoundNomadException
7375
"""
74-
return self.request(method="get").json()
76+
params = {"prefix": prefix}
77+
return self.request(method="get", params=params).json()

tests/test_allocations.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ def test_get_allocations(nomad_setup):
1717
assert isinstance(nomad_setup.allocations.get_allocations(), list) == True
1818

1919

20+
def test_get_allocations_prefix(nomad_setup):
21+
allocations = nomad_setup.allocations.get_allocations()
22+
prefix = allocations[0]["ID"][:4]
23+
nomad_setup.allocations.get_allocations(prefix=prefix)
24+
25+
2026
def test_dunder_str(nomad_setup):
2127
assert isinstance(str(nomad_setup.allocations), str)
2228

tests/test_deployments.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ def test_get_evaluation(nomad_setup):
1919
assert "example" == nomad_setup.deployments.get_deployments()[0]["JobID"]
2020

2121

22+
@pytest.mark.skipif(tuple(int(i) for i in os.environ.get("NOMAD_VERSION").split(".")) < (0, 6, 0), reason="Not supported in version")
23+
def test_get_deployments_prefix(nomad_setup):
24+
deployments = nomad_setup.deployments.get_deployments()
25+
prefix = deployments[0]["ID"][:4]
26+
nomad_setup.deployments.get_deployments(prefix=prefix)
27+
28+
2229
@pytest.mark.skipif(tuple(int(i) for i in os.environ.get("NOMAD_VERSION").split(".")) < (0, 6, 0), reason="Not supported in version")
2330
def test_dunder_getitem_exist(nomad_setup):
2431
jobID = nomad_setup.deployments.get_deployments()[0]["ID"]

tests/test_evaluations.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ def test_get_evaluations(nomad_setup):
1515
assert isinstance(nomad_setup.evaluations.get_evaluations(), list) == True
1616

1717

18+
def test_get_evaluations_prefix(nomad_setup):
19+
evaluations = nomad_setup.evaluations.get_evaluations()
20+
prefix = evaluations[0]["ID"][:4]
21+
nomad_setup.evaluations.get_evaluations(prefix=prefix)
22+
23+
1824
def test_dunder_getitem_exist(nomad_setup):
1925
evalID = nomad_setup.job.get_allocations("example")[0]["EvalID"]
2026
e = nomad_setup.evaluations[evalID]

tests/test_jobs.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ def test_get_jobs(nomad_setup):
1717
assert isinstance(nomad_setup.jobs.get_jobs(), list) == True
1818

1919

20+
def test_get_jobs_prefix(nomad_setup):
21+
nomad_setup.jobs.get_jobs(prefix="ex")
22+
23+
2024
@pytest.mark.skipif(tuple(int(i) for i in os.environ.get("NOMAD_VERSION").split(".")) < (0, 8, 3), reason="Not supported in version")
2125
def test_parse_job(nomad_setup):
2226
with open("example.nomad") as fh:

tests/test_namespaces.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,25 @@ def test_get_namespaces(nomad_setup):
3030
assert isinstance(nomad_setup.namespaces.get_namespaces(), list) == True
3131

3232

33+
@responses.activate
34+
def test_get_namespaces_prefix(nomad_setup):
35+
responses.add(
36+
responses.GET,
37+
"http://{ip}:{port}/v1/namespaces?prefix=api-".format(ip=common.IP, port=common.NOMAD_PORT),
38+
status=200,
39+
json=[
40+
{
41+
"CreateIndex": 31,
42+
"Description": "Production API Servers",
43+
"ModifyIndex": 31,
44+
"Name": "api-prod"
45+
},
46+
]
47+
)
48+
49+
assert isinstance(nomad_setup.namespaces.get_namespaces(prefix="api-"), list) == True
50+
51+
3352
@responses.activate
3453
def test_namespaces_iter(nomad_setup):
3554
responses.add(

0 commit comments

Comments
 (0)