Skip to content

Commit a3f26fd

Browse files
authored
Merge pull request #111 from jrnk/master
Support stopping an allocation
2 parents c758391 + 1cf9840 commit a3f26fd

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

docs/api/allocation.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,19 @@ allocation = my_nomad.allocation.get_allocation('32c54571-fb79-97d2-ee38-16673ba
1515
1616
print (allocation)
1717
```
18+
19+
### Stop an allocation
20+
21+
This endpoint stops and reschedules a specific allocation.
22+
23+
https://www.nomadproject.io/api-docs/allocations/#stop-allocation
24+
25+
Example of stopping an allocation
26+
27+
```
28+
import nomad
29+
30+
my_nomad = nomad.Nomad(host='192.168.33.10')
31+
32+
my_nomad.allocation.stop_allocation('32c54571-fb79-97d2-ee38-16673bab692c')
33+
```

nomad/api/allocation.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,15 @@ def get_allocation(self, id):
5555
- nomad.api.exceptions.URLNotFoundNomadException
5656
"""
5757
return self.request(id, method="get").json()
58+
59+
def stop_allocation(self, id):
60+
""" Stop a specific allocation.
61+
62+
https://www.nomadproject.io/api-docs/allocations/#stop-allocation
63+
64+
returns: dict
65+
raises:
66+
- nomad.api.exceptions.BaseNomadException
67+
- nomad.api.exceptions.URLNotFoundNomadException
68+
"""
69+
return self.request(id, "stop", method="post").json()

tests/test_allocation.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import uuid
44
import responses
55
import tests.common as common
6+
import os
67

78

89
# integration tests requires nomad Vagrant VM or Binary running
@@ -19,6 +20,12 @@ def test_get_allocation(nomad_setup):
1920
assert isinstance(nomad_setup.allocation.get_allocation(id), dict) == True
2021

2122

23+
@pytest.mark.skipif(tuple(int(i) for i in os.environ.get("NOMAD_VERSION").split(".")) < (0, 9, 2), reason="Nomad alloc stop not supported")
24+
def test_stop_allocation(nomad_setup):
25+
id = nomad_setup.job.get_allocations("example")[0]["ID"]
26+
assert isinstance(nomad_setup.allocation.stop_allocation(id), dict) == True
27+
28+
2229
def test_dunder_getitem_exist(nomad_setup):
2330
id = nomad_setup.job.get_allocations("example")[0]["ID"]
2431
a = nomad_setup.allocation[id]

0 commit comments

Comments
 (0)