diff mbox

[Branch,~linaro-validation/lava-scheduler/trunk] Rev 179: add a "retire" admin action

Message ID 20120617235709.28292.78297.launchpad@ackee.canonical.com
State Accepted
Headers show

Commit Message

Michael-Doyle Hudson June 17, 2012, 11:57 p.m. UTC
------------------------------------------------------------
revno: 179
committer: Michael Hudson-Doyle <michael.hudson@linaro.org>
branch nick: trunk
timestamp: Mon 2012-06-18 11:55:10 +1200
message:
  add a "retire" admin action
modified:
  lava_scheduler_app/admin.py


--
lp:lava-scheduler
https://code.launchpad.net/~linaro-validation/lava-scheduler/trunk

You are subscribed to branch lp:lava-scheduler.
To unsubscribe from this branch go to https://code.launchpad.net/~linaro-validation/lava-scheduler/trunk/+edit-subscription
diff mbox

Patch

=== modified file 'lava_scheduler_app/admin.py'
--- lava_scheduler_app/admin.py	2012-03-13 00:21:57 +0000
+++ lava_scheduler_app/admin.py	2012-06-17 23:55:10 +0000
@@ -18,6 +18,17 @@ 
             device.put_into_online_mode(request.user, "admin action")
 online_action.short_description = "take online"
 
+def retire_action(modeladmin, request, queryset):
+    for device in queryset:
+        if device.can_admin(request.user):
+            new_status = device.RETIRED
+            DeviceStateTransition.objects.create(
+                created_by=request.user, device=device, old_state=device.status,
+                new_state=new_status, message="retiring", job=None).save()
+            device.status = new_status
+            device.save()
+retire_action.short_description = "retire"
+
 def health_unknown(modeladmin, request, queryset):
     for device in queryset.filter(health_status=Device.HEALTH_PASS):
         device.health_status = Device.HEALTH_UNKNOWN
@@ -25,7 +36,7 @@ 
 health_unknown.short_description = "set health_status to unknown"
 
 class DeviceAdmin(admin.ModelAdmin):
-    actions = [online_action, offline_action, health_unknown]
+    actions = [online_action, offline_action, health_unknown, retire_action]
     list_filter = ['device_type', 'status']
 
 admin.site.register(Device, DeviceAdmin)