mirror of
https://github.com/cirruslabs/orchard.git
synced 2026-10-22 06:18:16 +02:00
Events Entity (#28)
* Generic Events We can try to use these generic events for script execution and storing of the output logs in events with `log` kind. * Lint issues * Cleanup events upon VM deletion * Basic integration test * Run an actual VM in tests * Apply suggestions from code review Co-authored-by: Nikolay Edigaryev <edigaryev@gmail.com> * Use POST * Make newEventKey private * Append events in batches * Lint issues * Private `scopePrefix` --------- Co-authored-by: Nikolay Edigaryev <edigaryev@gmail.com>
This commit is contained in:
co-authored by
Nikolay Edigaryev
parent
165662bb0a
commit
0582108ea6
@@ -122,10 +122,65 @@ func (controller *Controller) deleteVM(ctx *gin.Context) responder.Responder {
|
||||
name := ctx.Param("name")
|
||||
|
||||
return controller.storeUpdate(func(txn storepkg.Transaction) responder.Responder {
|
||||
if err := txn.DeleteVM(name); err != nil {
|
||||
vm, err := txn.GetVM(name)
|
||||
if err != nil {
|
||||
return responder.Error(err)
|
||||
}
|
||||
err = txn.DeleteVM(name)
|
||||
if err != nil {
|
||||
return responder.Error(err)
|
||||
}
|
||||
err = txn.DeleteEvents("vms", vm.UID)
|
||||
if err != nil {
|
||||
return responder.Error(err)
|
||||
}
|
||||
|
||||
return responder.Code(http.StatusOK)
|
||||
})
|
||||
}
|
||||
func (controller *Controller) appendVMEvents(ctx *gin.Context) responder.Responder {
|
||||
if !controller.authorize(ctx, v1.ServiceAccountRoleComputeWrite) {
|
||||
return responder.Code(http.StatusUnauthorized)
|
||||
}
|
||||
|
||||
var events []v1.Event
|
||||
|
||||
if err := ctx.ShouldBindJSON(&events); err != nil {
|
||||
return responder.Code(http.StatusBadRequest)
|
||||
}
|
||||
|
||||
name := ctx.Param("name")
|
||||
|
||||
return controller.storeUpdate(func(txn storepkg.Transaction) responder.Responder {
|
||||
vm, err := txn.GetVM(name)
|
||||
if err != nil {
|
||||
return responder.Error(err)
|
||||
}
|
||||
if err := txn.AppendEvents(events, "vms", vm.UID); err != nil {
|
||||
return responder.Error(err)
|
||||
}
|
||||
|
||||
return responder.Code(http.StatusOK)
|
||||
})
|
||||
}
|
||||
|
||||
func (controller *Controller) listVMEvents(ctx *gin.Context) responder.Responder {
|
||||
if !controller.authorize(ctx, v1.ServiceAccountRoleComputeRead) {
|
||||
return responder.Code(http.StatusUnauthorized)
|
||||
}
|
||||
|
||||
name := ctx.Param("name")
|
||||
|
||||
return controller.storeView(func(txn storepkg.Transaction) responder.Responder {
|
||||
vm, err := txn.GetVM(name)
|
||||
if err != nil {
|
||||
return responder.Error(err)
|
||||
}
|
||||
events, err := txn.ListEvents("vms", vm.UID)
|
||||
if err != nil {
|
||||
return responder.Error(err)
|
||||
}
|
||||
|
||||
return responder.JSON(http.StatusOK, events)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user