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

lava_scheduler_app: api: Add put_into_maintenance_mode

Add the put_into_maintenance_mode endpoint to the API to put a given
device in maintenance mode with the given reason and optionally the
mail address to optionally notify, if a job is currently running, when
it has finished.

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).

The mail address to notify is optional.

Change-Id: I6e5b8e7671f405a56286e0626e1e05e7efe2fbc6
Signed-off-by: Quentin Schulz <quentin.schulz@free-electrons.com>
  • Loading branch information...
QSchulz authored and codehelp committed Apr 18, 2016
1 parent 2091ac9 commit 6da3b4abf0c8a66f746f5a9264fc6ae4ad01f9fc
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_maintenance_mode(self, hostname, reason, notify=None):
+ """
+ Name
+ ----
+ `put_into_maintenance_mode` (`hostname`, `reason`, `notify`)
+
+ Description
+ -----------
+ Put the given device in maintenance mode with the given reason and optionally
+ notify the given mail address when the job has finished.
+
+ Arguments
+ ---------
+ `hostname`: string
+ Name of the device to put into maintenance mode.
+ `reason`: string
+ The reason given to justify putting the device into maintenance mode.
+ `notify`: string
+ Email address of the user to notify when the job has finished. Can be
+ omitted.
+
+ 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_maintenance_mode(self.user, reason, notify)
+ else:
+ raise xmlrpclib.Fault(
+ 403, "Permission denied for user to put %s into maintenance mode." % hostname
+ )
+
def put_into_online_mode(self, hostname, reason, skip_health_check=False):
"""
Name

0 comments on commit 6da3b4a

Please sign in to comment.