crc-org / vfkit

Apache License 2.0
119 stars 23 forks source link

Report list of devices in the REST API #99

Closed cfergeau closed 6 months ago

cfergeau commented 6 months ago

The aim of this PR was to add the list of devices to the /inspect endpoint with their parameters. This supersedes https://github.com/crc-org/vfkit/pull/73

My initial goal was to only add tests for this code. Along the way I found 2 related issues (memory byte/MiB confusion, and too long unix socket paths) which I fixed, and I also realized the code from #73 could be made simpler: config.VirtualMachine already can be serialized to/from json, so we don't need any new code.

openshift-ci[bot] commented 6 months ago

@BlackHole1: changing LGTM is restricted to collaborators

In response to [this](https://github.com/crc-org/vfkit/pull/99#pullrequestreview-1891887712): >LGTM Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.
cfergeau commented 6 months ago

This can be tested by starting vfkit with --restful-uri unix:///Users/teuf/dev/vfkit/rest.sock and then running curl --unix-socket /Users/teuf/dev/vfkit/rest.sock http://unused/vm/inspect

praveenkumar commented 6 months ago

Tested with following and works as expected

✗ ./out/vfkit \
    --cpus 2 --memory 2048 \
    --bootloader efi,variable-store=efi-variable-store,create \
    --device virtio-blk,path=vfkit-test-image.raw \
>   --restful-uri unix:///Users/prkumar/dev/vfkit/rest.sock
INFO[0000] &{2 2048    {[efi variable-store=efi-variable-store create] true}  [virtio-blk,path=vfkit-test-image.raw] unix:///Users/prkumar/dev/vfkit/rest.sock  false} 
INFO[0000] boot parameters: &{EFIVariableStorePath:efi-variable-store CreateVariableStore:true} 
INFO[0000]                                              
INFO[0000] virtual machine parameters:                  
INFO[0000]  vCPUs: 2                                    
INFO[0000]  memory: 2048 MiB                            
INFO[0000]                                              
INFO[0000] Adding virtio-blk device (imagePath: vfkit-test-image.raw) 
INFO[0000] virtual machine is running                   
INFO[0000] waiting for VM to stop    

and api response

✗ curl --unix-socket /Users/prkumar/dev/vfkit/rest.sock http://unused/vm/inspect | jq .
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   236  100   236    0     0   524k      0 --:--:-- --:--:-- --:--:--  230k
{
  "vcpus": 2,
  "memoryBytes": 2147483648,
  "bootloader": {
    "kind": "efiBootloader",
    "efiVariableStorePath": "efi-variable-store",
    "createVariableStore": true
  },
  "devices": [
    {
      "kind": "virtioblk",
      "devName": "virtio-blk",
      "imagePath": "vfkit-test-image.raw"
    }
  ]
}

/lgtm

praveenkumar commented 6 months ago

/approve /lgtm

openshift-ci[bot] commented 6 months ago

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: BlackHole1, praveenkumar Once this PR has been reviewed and has the lgtm label, please ask for approval from cfergeau. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files: - **[OWNERS](https://github.com/crc-org/vfkit/blob/main/OWNERS)** Approvers can indicate their approval by writing `/approve` in a comment Approvers can cancel approval by writing `/approve cancel` in a comment