vm query works
Some checks failed
CI / Lint (push) Waiting to run
CI / Test (push) Waiting to run
CI / End-to-End (push) Waiting to run
CI / Publish Docker (push) Blocked by required conditions
continuous-integration/drone/push Build is failing

This commit is contained in:
2024-09-12 16:02:01 +10:00
parent 6b285e55b8
commit c46117d084
6 changed files with 122 additions and 3 deletions

View File

@@ -9,6 +9,7 @@ import (
"net/http"
"time"
queries "vctp/db/queries"
"vctp/internal/vcenter"
models "vctp/server/models"
)
@@ -27,7 +28,6 @@ func (h *Handler) VmCreate(w http.ResponseWriter, r *http.Request) {
// Decode the JSON body into vmModel struct
var vm models.CloudEventReceived
//if err := json.NewDecoder(r.Body).Decode(&vm); err != nil {
if err := json.Unmarshal(reqBody, &vm); err != nil {
h.Logger.Error("unable to decode json", "error", err)
http.Error(w, "Invalid JSON body", http.StatusBadRequest)
@@ -48,6 +48,17 @@ func (h *Handler) VmCreate(w http.ResponseWriter, r *http.Request) {
unixTimestamp = eventTime.Unix()
}
// TODO - initiate govmomi query of source vcenter to discover related data
vc := vcenter.New(h.Logger)
vc.Login(vm.CloudEvent.Source)
vmObject, err := vc.FindVMByName(vm.CloudEvent.Data.VM.Name)
if err != nil {
h.Logger.Error("Can't locate vm in vCenter", "vmName", vm.CloudEvent.Data.VM.Name, "error", err)
} else {
h.Logger.Debug("found VM", "object", vmObject)
}
vc.Logout()
// Create an instance of CreateInventoryParams
params := queries.CreateInventoryParams{
Name: vm.CloudEvent.Data.VM.Name,