diff --git a/pkg/config/json.go b/pkg/config/json.go index 580785cb..1452e3b6 100644 --- a/pkg/config/json.go +++ b/pkg/config/json.go @@ -16,14 +16,15 @@ const ( linuxBootloader vmComponentKind = "linuxBootloader" // VirtIO device kinds - vfNet vmComponentKind = "virtionet" - vfVsock vmComponentKind = "virtiosock" - vfBlk vmComponentKind = "virtioblk" - vfFs vmComponentKind = "virtiofs" - vfRng vmComponentKind = "virtiorng" - vfSerial vmComponentKind = "virtioserial" - vfGpu vmComponentKind = "virtiogpu" - vfInput vmComponentKind = "virtioinput" + vfNet vmComponentKind = "virtionet" + vfVsock vmComponentKind = "virtiosock" + vfBlk vmComponentKind = "virtioblk" + vfFs vmComponentKind = "virtiofs" + vfRng vmComponentKind = "virtiorng" + vfSerial vmComponentKind = "virtioserial" + vfGpu vmComponentKind = "virtiogpu" + vfInput vmComponentKind = "virtioinput" + usbMassStorage vmComponentKind = "usbmassstorage" ) type jsonKind struct { @@ -123,6 +124,10 @@ func unmarshalDevice(rawMsg json.RawMessage) (VirtioDevice, error) { var newDevice VirtioInput err = json.Unmarshal(rawMsg, &newDevice) dev = &newDevice + case usbMassStorage: + var newDevice USBMassStorage + err = json.Unmarshal(rawMsg, &newDevice) + dev = &newDevice default: return nil, fmt.Errorf("unknown 'kind' field: '%s'", kind) } @@ -287,3 +292,14 @@ func (dev *VirtioInput) MarshalJSON() ([]byte, error) { VirtioInput: *dev, }) } + +func (dev *USBMassStorage) MarshalJSON() ([]byte, error) { + type devWithKind struct { + jsonKind + USBMassStorage + } + return json.Marshal(devWithKind{ + jsonKind: kind(usbMassStorage), + USBMassStorage: *dev, + }) +} diff --git a/pkg/config/json_test.go b/pkg/config/json_test.go index a0cface1..ad9cb213 100644 --- a/pkg/config/json_test.go +++ b/pkg/config/json_test.go @@ -102,15 +102,14 @@ var jsonTests = map[string]jsonTest{ err = vm.AddDevice(dev) require.NoError(t, err) // USB mass storage - //dev, err = USBMassStorageNew("/usbmassstorage") - //require.NoError(t, err) - //err = vm.AddDevice(dev) - //require.NoError(t, err) + dev, err = USBMassStorageNew("/usbmassstorage") + require.NoError(t, err) + err = vm.AddDevice(dev) + require.NoError(t, err) return vm }, - //expectedJSON: `{"vcpus":3,"memoryBytes":4000000000,"bootloader":{"kind":"linuxBootloader","VmlinuzPath":"/vmlinuz","KernelCmdLine":"/initrd","InitrdPath":"console=hvc0"},"devices":[{"kind":"virtioserial","LogFile":"/virtioserial","UsesStdio":false},{"inputType":"keyboard"},{"usesGUI":false,"height":800,"width":600},{"kind":"virtionet","Nat":true,"MacAddress":"ABEiM0RV","Socket":null,"UnixSocketPath":""},{"kind":"virtiorng"},{"kind":"virtioblk","DevName":"virtio-blk","ImagePath":"/virtioblk","ReadOnly":false,"DeviceIdentifier":""},{"kind":"virtiosock","Port":1234,"SocketURL":"/virtiovsock","Listen":false},{"kind":"virtiofs","SharedDir":"/virtiofs","MountTag":"tag"},{"DevName":"usb-mass-storage","ImagePath":"/usbmassstorage","ReadOnly":false}]}`, - expectedJSON: `{"vcpus":3,"memoryBytes":4000000000,"bootloader":{"kind":"linuxBootloader","VmlinuzPath":"/vmlinuz","KernelCmdLine":"/initrd","InitrdPath":"console=hvc0"},"devices":[{"kind":"virtioserial","LogFile":"/virtioserial","UsesStdio":false},{"kind":"virtioinput","inputType":"keyboard"},{"kind":"virtiogpu","usesGUI":false,"height":800,"width":600},{"kind":"virtionet","Nat":true,"MacAddress":"ABEiM0RV","Socket":null,"UnixSocketPath":""},{"kind":"virtiorng"},{"kind":"virtioblk","DevName":"virtio-blk","ImagePath":"/virtioblk","ReadOnly":false,"DeviceIdentifier":""},{"kind":"virtiosock","Port":1234,"SocketURL":"/virtiovsock","Listen":false},{"kind":"virtiofs","SharedDir":"/virtiofs","MountTag":"tag"}]}`, + expectedJSON: `{"vcpus":3,"memoryBytes":4000000000,"bootloader":{"kind":"linuxBootloader","VmlinuzPath":"/vmlinuz","KernelCmdLine":"/initrd","InitrdPath":"console=hvc0"},"devices":[{"kind":"virtioserial","LogFile":"/virtioserial","UsesStdio":false},{"kind":"virtioinput","inputType":"keyboard"},{"kind":"virtiogpu","usesGUI":false,"height":800,"width":600},{"kind":"virtionet","Nat":true,"MacAddress":"ABEiM0RV","Socket":null,"UnixSocketPath":""},{"kind":"virtiorng"},{"kind":"virtioblk","DevName":"virtio-blk","ImagePath":"/virtioblk","ReadOnly":false,"DeviceIdentifier":""},{"kind":"virtiosock","Port":1234,"SocketURL":"/virtiovsock","Listen":false},{"kind":"virtiofs","SharedDir":"/virtiofs","MountTag":"tag"},{"kind":"usbmassstorage","DevName":"usb-mass-storage","ImagePath":"/usbmassstorage","ReadOnly":false}]}`, }, }