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 Jan 8, 2024
1 parent 71179cc commit a7c46b2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
7 changes: 6 additions & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,12 @@ func (vm *VirtualMachine) VirtioVsockDevices() []*VirtioVsock {
// AddDevice adds a dev to vm. This device can be created with one of the
// VirtioXXXNew methods.
func (vm *VirtualMachine) AddDevice(dev VirtioDevice) {
vm.Devices = append(vm.Devices, dev)
vm.AddDevices(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 {
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 a7c46b2

Please sign in to comment.