modify some file
This commit is contained in:
@@ -84,6 +84,10 @@ func handleCreateVM(cfg config.Config, svc Services) http.HandlerFunc {
|
||||
writeJSON(w, http.StatusBadRequest, map[string]string{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
if err := validators.CheckStoragePoolsVM(spec.Disks, cfg); err != nil {
|
||||
writeJSON(w, http.StatusBadRequest, map[string]string{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
if err := svc.Store.SaveVM(spec); err != nil {
|
||||
writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
|
||||
return
|
||||
@@ -203,6 +207,10 @@ func handleCreateCT(cfg config.Config, svc Services) http.HandlerFunc {
|
||||
writeJSON(w, http.StatusBadRequest, map[string]string{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
if err := validators.CheckStoragePoolsCT(spec, cfg); err != nil {
|
||||
writeJSON(w, http.StatusBadRequest, map[string]string{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
if err := svc.Store.SaveCT(spec); err != nil {
|
||||
writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
|
||||
return
|
||||
@@ -410,3 +418,14 @@ func authMiddleware(token string) func(http.Handler) http.Handler {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func validateVM(spec libvirt.VMSpec, cfg config.Config) error {
|
||||
if spec.CPU <= 0 {
|
||||
return errors.New("cpu must be > 0")
|
||||
}
|
||||
if spec.MemoryMB <= 0 {
|
||||
return errors.New("memory_mb must be > 0")
|
||||
}
|
||||
// storage pools validated elsewhere
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user