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
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ jobs:
env:
NOMAD_IP: '127.0.0.1'
NOMAD_PORT: '4646'
NOMAD_LATEST: '1.1.4'
NOMAD_LATEST: '1.1.18'

strategy:
fail-fast: false
matrix:
python-version: ['2.7', '3.7', '3.10']
nomad-version: ['1.0.0', '1.1.4']
nomad-version: ['1.0.0', '1.1.18']

steps:
- uses: actions/checkout@v2
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
.vagrant
.build
.venv

example.json
example.nomad
5 changes: 5 additions & 0 deletions nomad/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def __init__(self,
self._nodes = api.Nodes(**self.requester_settings)
self._operator = api.Operator(**self.requester_settings)
self._regions = api.Regions(**self.requester_settings)
self._scaling = api.Scaling(**self.requester_settings)
self._sentinel = api.Sentinel(**self.requester_settings)
self._status = api.Status(**self.requester_settings)
self._system = api.System(**self.requester_settings)
Expand Down Expand Up @@ -166,6 +167,10 @@ def deployment(self):
def regions(self):
return self._regions

@property
def scaling(self):
return self._scaling

@property
def status(self):
return self._status
Expand Down
1 change: 1 addition & 0 deletions nomad/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from nomad.api.nodes import Nodes
from nomad.api.operator import Operator
from nomad.api.regions import Regions
from nomad.api.scaling import Scaling
from nomad.api.sentinel import Sentinel
from nomad.api.status import Status
from nomad.api.system import System
Expand Down
68 changes: 68 additions & 0 deletions nomad/api/scaling.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import nomad.api.exceptions

from nomad.api.base import Requester


class Scaling(Requester):
"""
Endpoints are used to list and view scaling policies.

https://developer.hashicorp.com/nomad/api-docs/scaling-policies
"""
ENDPOINT = "scaling"

def __init__(self, **kwargs):
super(Scaling, self).__init__(**kwargs)

def __str__(self):
return "{0}".format(self.__dict__)

def __repr__(self):
return "{0}".format(self.__dict__)

def __getattr__(self, item):
raise AttributeError

def get_scaling_policies(self, job="", type=""):
"""
This endpoint returns the scaling policies from all jobs.

https://developer.hashicorp.com/nomad/api-docs/scaling-policies#list-scaling-policies

arguments:
- job
- type
returns: list of dicts
raises:
- nomad.api.exceptions.BaseNomadException
- nomad.api.exceptions.URLNotFoundNomadException
"""
type_of_scaling_policies = [
"horizontal",
"vertical_mem",
"vertical_cpu",
"",
] # we have only horizontal in OSS

if type not in type_of_scaling_policies:
raise nomad.api.exceptions.InvalidParameters("type is invalid "
"(expected values are {} but got {})".format(type_of_scaling_policies, type))

params = {"job": job, "type": type}

return self.request("policies", method="get", params=params).json()

def get_scaling_policy(self, id):
"""
This endpoint reads a specific scaling policy.

https://developer.hashicorp.com/nomad/api-docs/scaling-policies#read-scaling-policy

arguments:
- id
returns: list of dicts
raises:
- nomad.api.exceptions.BaseNomadException
- nomad.api.exceptions.URLNotFoundNomadException
"""
return self.request("policy/{}".format(id), method="get").json()
11 changes: 11 additions & 0 deletions tests/test_scaling.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import pytest

from nomad.api import exceptions

def test_scaling_list(nomad_setup):
result = nomad_setup.scaling.get_scaling_policies()
assert not result

def test_scaling_policy_not_exist(nomad_setup):
with pytest.raises(exceptions.URLNotFoundNomadException):
nomad_setup.scaling.get_scaling_policy("example")