diff --git a/internal/controllers/storage.go b/internal/controllers/storage.go index dcd594e..3b40b9d 100644 --- a/internal/controllers/storage.go +++ b/internal/controllers/storage.go @@ -8,10 +8,10 @@ import ( ) var ( - CloudImages = []string{} - Images = []string{} - Disks = []string{} - CloudInitPath = "" + CloudImages = []map[string]string{} + Images = []map[string]string{} + Disks = []map[string]string{} + CloudInitPath = []map[string]string{} ) func CheckStorage() error { @@ -72,3 +72,17 @@ func CheckStorage() error { return nil } + +func (hv *HV) ListDir(path string) ([]string, error) { + files, err := os.ReadDir(path) + if err != nil { + return nil, err + } + + var names []string + for _, file := range files { + names = append(names, file.Name()) + } + + return names, nil +} diff --git a/internal/controllers/vm.go b/internal/controllers/vm.go index 8744a6b..1900b1a 100644 --- a/internal/controllers/vm.go +++ b/internal/controllers/vm.go @@ -66,12 +66,14 @@ func (hv *HV) fetchVMSpecs(vm *models.VM) { vm.Mutex.Lock() defer vm.Mutex.Unlock() + // CPU cpuInt, err := strconv.Atoi(specs.Vcpu.Text) if err != nil { log.Error().Err(err).Msg("Failed to convert CPU count to int") } vm.CPU = cpuInt + // Memory mem, err := strconv.ParseInt(specs.Memory.Text, 10, 64) if err != nil { log.Error().Err(err).Msg("Failed to parse memory") @@ -87,6 +89,15 @@ func (hv *HV) fetchVMSpecs(vm *models.VM) { } vm.Memory = mem + + // USBs + //TODO + // Disks + //TODO + // Nics + //TODO + // Graphics + //TODO } func (hv *HV) GetVMState(vm *models.VM) (models.VMState, error) { diff --git a/internal/server/routes/storage.go b/internal/server/routes/storage.go index cbda77c..b88b619 100644 --- a/internal/server/routes/storage.go +++ b/internal/server/routes/storage.go @@ -6,6 +6,7 @@ import ( "github.com/BasedDevelopment/auto/internal/config" "github.com/BasedDevelopment/auto/internal/controllers" eUtil "github.com/BasedDevelopment/eve/pkg/util" + "github.com/go-chi/chi/v5" ) func GetStorages(w http.ResponseWriter, r *http.Request) { @@ -16,6 +17,15 @@ func GetStorages(w http.ResponseWriter, r *http.Request) { } func GetImages(w http.ResponseWriter, r *http.Request) { + storage := chi.URLParam(r, "storage") + // this will be a path, how will we represent this path in a url? + // OH IN THE CONFIG WE NAMED THE STORAGE, we will have to first convirt everything to storage name instead of path + if err := eUtil.WriteResponse(resp, w, http.StatusOK); err != nil { + eUtil.WriteError(w, r, err, http.StatusInternalServerError, "Failed to marshall/send response") + } +} + +func GetCloudImages(w http.ResponseWriter, r *http.Request) { resp := controllers.Images if err := eUtil.WriteResponse(resp, w, http.StatusOK); err != nil { eUtil.WriteError(w, r, err, http.StatusInternalServerError, "Failed to marshall/send response") diff --git a/internal/server/server.go b/internal/server/server.go index 2a350b4..fe16561 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -50,8 +50,13 @@ func Service() *chi.Mux { r.Get("/", routes.GetHV) r.Route("/storage", func(r chi.Router) { r.Get("/", routes.GetStorages) - r.Get("/image", routes.GetImages) - r.Get("/disk", routes.GetDisks) + r.Route("/{storage}", func(r chi.Router) { + // this is fine, have it read from config, and make sure it is also valid by checking the slices + // then have a route return the stuff in each storage + r.Get("/images", routes.GetImages) + r.Get("/cloud-images", routes.GetCloudImages) + r.Get("/disks", routes.GetDisks) + }) }) r.Route("/domains", func(r chi.Router) { r.Get("/", routes.GetDomains)