crc-org / vfkit

Apache License 2.0
123 stars 24 forks source link

Surprising values returned for the restful "state" #174

Open afbjorklund opened 1 month ago

afbjorklund commented 1 month ago

https://github.com/crc-org/vfkit/blob/main/doc/usage.md#restful-service

Get VM state Used to obtain the state of the virtual machine that is being run by vfkit.

GET /vm/state Response: { "state": string, "canStart": bool, "canPause": bool, "canResume": bool, "canStop": bool, "canHardStop": bool

It doesn't show the possible values of "string", but it doesn't match the POST:

{
  "canHardStop": true,
  "canPause": true,
  "canResume": false,
  "canStart": false,
  "canStop": true,
  "state": "VirtualMachineStateRunning"
}

It should probably be documented? I think the values come straight from vz.

cfergeau commented 1 week ago

They are indeed coming from https://github.com/Code-Hex/vz/blob/c3198942b1b797ac424b673e06769f45bef0d275/virtualmachinestate_string.go#L22C1-L23C93

I agree it would make more sense to strip the VirtualMachineState, I don't think there are many users of this API right now (I'll have to check) so we can probably just do it. And yes, documenting the possible values would be useful, a list is available there: https://github.com/Code-Hex/vz/blob/c3198942b1b797ac424b673e06769f45bef0d275/virtualization.go#L25-L67

afbjorklund commented 1 week ago

I used both types of values (both "enum" and string), but it did raise some eyebrows during code review...

e.g. "running", "VirtualMachineStateRunning"

afbjorklund commented 1 week ago

Documenting them might be easiest