Skip to content

Commit

Permalink
add dependabot
Browse files Browse the repository at this point in the history
  • Loading branch information
ezrizhu committed Sep 8, 2023
1 parent 4225cf8 commit bbc0b7c
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 6 deletions.
22 changes: 18 additions & 4 deletions internal/controllers/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
11 changes: 11 additions & 0 deletions internal/controllers/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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) {
Expand Down
10 changes: 10 additions & 0 deletions internal/server/routes/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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")
Expand Down
9 changes: 7 additions & 2 deletions internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit bbc0b7c

Please sign in to comment.