Skip to content

Commit

Permalink
refactor(rest): improve inspect api
Browse files Browse the repository at this point in the history
Add the correct cpus, memory, devices

Signed-off-by: Black-Hole1 <[email protected]>
  • Loading branch information
BlackHole1 committed Dec 26, 2023
1 parent 7572104 commit 65f2918
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cmd/vfkit/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func runVFKit(vmConfig *config.VirtualMachine, opts *cmdline.Options) error {

// Do not enable the rests server if user sets scheme to None
if opts.RestfulURI != cmdline.DefaultRestfulURI {
restVM := restvf.NewVzVirtualMachine(vm, vzVMConfig)
restVM := restvf.NewVzVirtualMachine(vm, vzVMConfig, vmConfig)
srv, err := rest.NewServer(restVM, restVM, opts.RestfulURI)
if err != nil {
return err
Expand Down
18 changes: 10 additions & 8 deletions pkg/rest/vf/vm_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,30 @@ import (
"net/http"

"github.com/Code-Hex/vz/v3"
"github.com/crc-org/vfkit/pkg/config"
"github.com/crc-org/vfkit/pkg/rest/define"
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
)

type VzVirtualMachine struct {
VzVM *vz.VirtualMachine
config *vz.VirtualMachineConfiguration
VzVM *vz.VirtualMachine
config *vz.VirtualMachineConfiguration
vmConfig *config.VirtualMachine
}

func NewVzVirtualMachine(vm *vz.VirtualMachine, config *vz.VirtualMachineConfiguration) *VzVirtualMachine {
return &VzVirtualMachine{config: config, VzVM: vm}
func NewVzVirtualMachine(vm *vz.VirtualMachine, config *vz.VirtualMachineConfiguration, vmConfig *config.VirtualMachine) *VzVirtualMachine {
return &VzVirtualMachine{config: config, VzVM: vm, vmConfig: vmConfig}
}

// inspect returns information about the virtual machine like hw resources
// and devices
func (vm *VzVirtualMachine) Inspect(c *gin.Context) {
ii := define.InspectResponse{
// TODO complete me
CPUs: 1,
Memory: 2048,
//Devices: vm.Devices,
CPUs: vm.vmConfig.Vcpus,
Memory: vm.vmConfig.MemoryBytes,
// TODO: add devices (VirtioDevice type needs to be improved) @Black-Hole1
//Devices: vm.vmConfig.Devices,
}
c.JSON(http.StatusOK, ii)
}
Expand Down

0 comments on commit 65f2918

Please sign in to comment.