Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
verktoy
kindnavsync
Commits
02ea3080
Commit
02ea3080
authored
Nov 20, 2019
by
Morten Brekkevold
Browse files
Add new API endpoints for NAV 5.0
parent
20754f7f
Changes
1
Hide whitespace changes
Inline
Side-by-side
kindnavsync/navapi.py
View file @
02ea3080
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment