Skip to content

Commit

Permalink
get query for VM yaml object
Browse files Browse the repository at this point in the history
Signed-off-by: Vladik Romanovsky <[email protected]>
  • Loading branch information
vladikr committed Sep 28, 2023
1 parent ac75825 commit 2543b31
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
29 changes: 29 additions & 0 deletions pkg/backend/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -1219,6 +1219,35 @@ func (d *DatabaseInstance) genericGetPVCs(queryString string) (map[string]interf
return pvcsList, nil
}

func (d *DatabaseInstance) GetVMObject(vmUUID string) (*kubevirtv1.VirtualMachine, error) {
var content json.RawMessage

queryString := fmt.Sprintf("select content from vms where uuid = '%s'", vmUUID)

rows := d.db.QueryRow(queryString)
err := rows.Scan(&content)
if err != nil {
if err == sql.ErrNoRows {
log.Log.Println("can't find VMs with this uuid: ", vmUUID)
return nil, err
} else {
log.Log.Println("ERROR: ", err, " for uuid: ", vmUUID)
return nil, err
}
}

// Unmashal json
var vm kubevirtv1.VirtualMachine

err = json.Unmarshal(content, &vm)
if err != nil {
log.Log.Fatalln("failed to unmarshal json to vm object - ", err)
return nil, err
}

return &vm, nil
}

func (d *DatabaseInstance) GetVMIObject(vmiUUID string) (*kubevirtv1.VirtualMachineInstance, error) {
var content json.RawMessage

Expand Down
1 change: 0 additions & 1 deletion pkg/backend/db/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ type (
InvolvedVirtHandlers []Pod
}

>>>>>>> 2ae3f8b2 (allow storing VirtualMachine types in the database)
GenericQueryDetails struct {
UUID string
Name string
Expand Down
7 changes: 7 additions & 0 deletions pkg/backend/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,13 @@ func (c *app) getObjYaml(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
case "vm":
retObject, err = c.storeDB.GetVMObject(fmt.Sprintf("%s", UUID))
if err != nil {
log.Log.Println("failed to fetch vm params", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
case "vmi":
retObject, err = c.storeDB.GetVMIObject(fmt.Sprintf("%s", UUID))
if err != nil {
Expand Down

0 comments on commit 2543b31

Please sign in to comment.