updates
This commit is contained in:
21
server/handler/vmDelete.go
Normal file
21
server/handler/vmDelete.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// VmUpdate receives the CloudEvent for a VM modification or move
|
||||
func (h *Handler) VmDelete(w http.ResponseWriter, r *http.Request) {
|
||||
reqBody, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
fmt.Fprintf(w, "Invalid data received")
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
h.Logger.Debug("received delete request", "body", string(reqBody))
|
||||
w.WriteHeader(http.StatusOK)
|
||||
fmt.Fprintf(w, "Delete Request (%d): %v\n", len(reqBody), string(reqBody))
|
||||
}
|
21
server/handler/vmImport.go
Normal file
21
server/handler/vmImport.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// VmImport is used for bulk import of existing VMs
|
||||
func (h *Handler) VmImport(w http.ResponseWriter, r *http.Request) {
|
||||
reqBody, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
fmt.Fprintf(w, "Invalid data received")
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
h.Logger.Debug("received import request", "body", string(reqBody))
|
||||
w.WriteHeader(http.StatusOK)
|
||||
fmt.Fprintf(w, "Import Request (%d): %v\n", len(reqBody), string(reqBody))
|
||||
}
|
@@ -6,8 +6,8 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// VmUpdate receives the CloudEvent for a VM modification or move
|
||||
func (h *Handler) VmUpdate(w http.ResponseWriter, r *http.Request) {
|
||||
// VmModify receives the CloudEvent for a VM modification or move
|
||||
func (h *Handler) VmModify(w http.ResponseWriter, r *http.Request) {
|
||||
reqBody, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
fmt.Fprintf(w, "Invalid data received")
|
@@ -55,6 +55,10 @@ type CloudEventReceived struct {
|
||||
Value string `json:"Value"`
|
||||
} `json:"Vm"`
|
||||
} `json:"Vm"`
|
||||
ConfigSpec any `json:"configSpec"`
|
||||
ConfigChanges struct {
|
||||
Modified string `json:"modified"`
|
||||
} `json:"configChanges"`
|
||||
} `json:"data"`
|
||||
} `json:"cloudEvent"`
|
||||
}
|
||||
|
@@ -23,7 +23,9 @@ func New(logger *slog.Logger, database db.Database, buildTime string, sha1ver st
|
||||
mux.Handle("/assets/", middleware.CacheMiddleware(http.FileServer(http.FS(dist.AssetsDir))))
|
||||
mux.HandleFunc("/", h.Home)
|
||||
mux.HandleFunc("/api/event/vm/create", h.VmCreate)
|
||||
mux.HandleFunc("/api/event/vm/update", h.VmUpdate)
|
||||
mux.HandleFunc("/api/event/vm/modify", h.VmModify)
|
||||
mux.HandleFunc("/api/event/vm/delete", h.VmDelete)
|
||||
mux.HandleFunc("/api/import/vm", h.VmImport)
|
||||
|
||||
return middleware.NewLoggingMiddleware(logger, mux)
|
||||
}
|
||||
|
@@ -152,5 +152,5 @@ func (s *Server) GracefulShutdown() {
|
||||
// <-ctx.Done() if your application should wait for other services
|
||||
// to finalize based on context cancellation.
|
||||
s.logger.Info("shutting down")
|
||||
os.Exit(0)
|
||||
//os.Exit(0)
|
||||
}
|
||||
|
Reference in New Issue
Block a user