Commit 02ea3080 authored by Morten Brekkevold's avatar Morten Brekkevold

Add new API endpoints for NAV 5.0

parent 20754f7f
......@@ -2,6 +2,7 @@
import functools
from simple_rest_client.api import API
from simple_rest_client.resource import Resource
from simple_rest_client.exceptions import NotFoundError, ClientError
......@@ -30,6 +31,10 @@ class NAVAPI(object):
)
self.api.add_resource(resource_name='netbox')
self.api.add_resource(resource_name='room')
self.api.add_resource(resource_name="version")
self.api.add_resource(
resource_name="management_profile", resource_class=ManagementProfileResource
)
def list_netboxes(self):
response = self.api.netbox.list(params={'page_size': 1000})
......@@ -56,6 +61,37 @@ class NAVAPI(object):
def post_room(self, room):
return self.api.room.create(body=room)
@functools.lru_cache(1)
def get_version(self):
try:
response = self.api.version.list()
except NotFoundError:
# This NAV version doesn't have the version endpoint
return 0, 0, 0
version = response.body.get("version")
return tuple(int(v) if v.isdigit() else v for v in version.split("."))
def list_management_profiles(self):
response = self.api.management_profile.list(params={"page_size": 1000})
return response.body["results"]
@_translate_notfounderror
def get_management_profile(self, profile_id):
return self.api.management_profile.retrieve(profile_id)
def post_management_profile(self, profile):
return self.api.management_profile.create(body=profile)
class ManagementProfileResource(Resource):
actions = {
"create": {"method": "POST", "url": "management-profile"},
"destroy": {"method": "DELETE", "url": "management-profile/{}"},
"list": {"method": "GET", "url": "management-profile"},
"partial_update": {"method": "PATCH", "url": "management-profile/{}"},
"retrieve": {"method": "GET", "url": "management-profile/{}"},
"update": {"method": "PUT", "url": "management-profile/{}"},
}
# Exception classes
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment