Skip to content

Commit

Permalink
feat(config): add AddDevices function
Browse files Browse the repository at this point in the history
In most cases, there might be more than one device. Adding the AddDevices method helps reduce the amount of code.

Signed-off-by: Black-Hole1 <[email protected]>
  • Loading branch information
BlackHole1 committed Dec 27, 2023
1 parent 71179cc commit 73eaa96
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
5 changes: 5 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ func (vm *VirtualMachine) AddDevice(dev VirtioDevice) {
vm.Devices = append(vm.Devices, dev)
}

// AddDevices adds a list of devices to vm.
func (vm *VirtualMachine) AddDevices(dev ...VirtioDevice) {
vm.Devices = append(vm.Devices, dev...)
}

func (vm *VirtualMachine) AddTimeSyncFromCmdLine(cmdlineOpts string) error {
if cmdlineOpts == "" {
return nil
Expand Down
10 changes: 4 additions & 6 deletions pkg/config/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,12 @@ var jsonTests = map[string]jsonTest{
dev = VirtioVsockNew(1234, "/virtiovsock", false)
vm.AddDevice(dev)
// virtio-fs
dev = VirtioFsNew("/virtiofs", "tag")
vm.AddDevice(dev)
fs := VirtioFsNew("/virtiofs", "tag")
// USB mass storage
dev = USBMassStorageNew("/usbmassstorage")
vm.AddDevice(dev)
usb := USBMassStorageNew("/usbmassstorage")
// rosetta
dev = RosettaShareNew("vz-rosetta")
vm.AddDevice(dev)
rosetta := RosettaShareNew("vz-rosetta")
vm.AddDevices(fs, usb, rosetta)

return vm
},
Expand Down

0 comments on commit 73eaa96

Please sign in to comment.