This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

lava_scheduler_app: api: Add put_into_online_mode

Add the put_into_online_mode endpoint to the API to put a given device
in online mode with the given reason and skip health check if asked.

To access this endpoint, you have to be authenticated as a user with
sufficient permission (the same as the one used in the web interface:
superuser, device owner or 'can change device' permission).

Skipping health check is optional.

Change-Id: I8b6ffb3b2da00d3ce8940ddb96793726e981a35d
Signed-off-by: Quentin Schulz <quentin.schulz@free-electrons.com>
  • Loading branch information...
QSchulz authored and Linaro Code Review committed Apr 18, 2016
1 parent 5033972 commit 2091ac9c3f9305f5a4e083d156c04d1f098ac2fa
Showing with 49 additions and 0 deletions.
  1. +49 −0 lava_scheduler_app/api.py
View
@@ -320,6 +320,55 @@ def all_device_types(self):
return all_device_types
def put_into_online_mode(self, hostname, reason, skip_health_check=False):
"""
Name
----
`put_into_online_mode` (`hostname`, `reason`, `skip_health_check`)
Description
-----------
Put the given device into online mode with the given reason ans skip health
check if asked.
Arguments
---------
`hostname`: string
Name of the device to put into online mode.
`reason`: string
The reason given to justify putting the device into online mode.
`skip_health_check`: boolean
Skip health check when putting the board into online mode. If
omitted, health check is not skipped by default.
Return value
------------
None. The user should be authenticated with a username and token and has
sufficient permission.
"""
self._authenticate()
if not hostname:
raise xmlrpclib.Fault(
400, "Bad request: Hostname was not specified."
)
if not reason:
raise xmlrpclib.Fault(
400, "Bad request: Reason was not specified."
)
try:
device = Device.objects.get(hostname=hostname)
except Device.DoesNotExist:
raise xmlrpclib.Fault(
404, "Device '%s' was not found." % hostname
)
if device.can_admin(self.user):
device.put_into_online_mode(self.user, reason, skip_health_check)
else:
raise xmlrpclib.Fault(
403, "Permission denied for user to put %s into online mode." % hostname
)
def pending_jobs_by_device_type(self):
"""
Name

0 comments on commit 2091ac9

Please sign in to comment.