Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions docs/api/allocation.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,19 @@ allocation = my_nomad.allocation.get_allocation('32c54571-fb79-97d2-ee38-16673ba

print (allocation)
```

### Stop an allocation

This endpoint stops and reschedules a specific allocation.

https://www.nomadproject.io/api-docs/allocations/#stop-allocation

Example of stopping an allocation

```
import nomad

my_nomad = nomad.Nomad(host='192.168.33.10')

my_nomad.allocation.stop_allocation('32c54571-fb79-97d2-ee38-16673bab692c')
```
12 changes: 12 additions & 0 deletions nomad/api/allocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,15 @@ def get_allocation(self, id):
- nomad.api.exceptions.URLNotFoundNomadException
"""
return self.request(id, method="get").json()

def stop_allocation(self, id):
""" Stop a specific allocation.

https://www.nomadproject.io/api-docs/allocations/#stop-allocation

returns: dict
raises:
- nomad.api.exceptions.BaseNomadException
- nomad.api.exceptions.URLNotFoundNomadException
"""
return self.request(id, "stop", method="post").json()
7 changes: 7 additions & 0 deletions tests/test_allocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import uuid
import responses
import tests.common as common
import os


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


@pytest.mark.skipif(tuple(int(i) for i in os.environ.get("NOMAD_VERSION").split(".")) < (0, 9, 2), reason="Nomad alloc stop not supported")
def test_stop_allocation(nomad_setup):
id = nomad_setup.job.get_allocations("example")[0]["ID"]
assert isinstance(nomad_setup.allocation.stop_allocation(id), dict) == True


def test_dunder_getitem_exist(nomad_setup):
id = nomad_setup.job.get_allocations("example")[0]["ID"]
a = nomad_setup.allocation[id]
Expand Down