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

Skip to content

Commit d0556f6

Browse files
committed
Support stopping an allocation
1 parent c758391 commit d0556f6

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ def test_get_allocation(nomad_setup):
1919
assert isinstance(nomad_setup.allocation.get_allocation(id), dict) == True
2020

2121

22+
def test_stop_allocation(nomad_setup):
23+
id = nomad_setup.job.get_allocations("example")[0]["ID"]
24+
assert isinstance(nomad_setup.allocation.stop_allocation(id), dict) == True
25+
26+
2227
def test_dunder_getitem_exist(nomad_setup):
2328
id = nomad_setup.job.get_allocations("example")[0]["ID"]
2429
a = nomad_setup.allocation[id]

0 commit comments

Comments
 (0)