mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-30 12:44:39 +00:00
qemu: Add netdev options to the Device structure
With the NetDev and MACAddress strings, we can now create networking device drivers. We also add a unit test for netdev Device creation. Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
parent
4780e2371f
commit
eda8607cc6
22
qemu.go
22
qemu.go
@ -45,8 +45,8 @@ type Machine struct {
|
|||||||
|
|
||||||
// Device describes a device to be created by qemu.
|
// Device describes a device to be created by qemu.
|
||||||
type Device struct {
|
type Device struct {
|
||||||
// Type is the qemu device type
|
// Driver is the qemu device driver
|
||||||
Type string
|
Driver string
|
||||||
|
|
||||||
// ID is the user defined device ID.
|
// ID is the user defined device ID.
|
||||||
ID string
|
ID string
|
||||||
@ -57,12 +57,18 @@ type Device struct {
|
|||||||
// FSDev is the device filesystem identifier.
|
// FSDev is the device filesystem identifier.
|
||||||
FSDev string
|
FSDev string
|
||||||
|
|
||||||
|
// NetDev is the networking device identifier.
|
||||||
|
NetDev string
|
||||||
|
|
||||||
// MountTag is the device filesystem mount point tag.
|
// MountTag is the device filesystem mount point tag.
|
||||||
// It is only relevant when combined with FSDev.
|
// It is only relevant when combined with FSDev.
|
||||||
MountTag string
|
MountTag string
|
||||||
|
|
||||||
// CharDev is the device character device identifier.
|
// CharDev is the device character device identifier.
|
||||||
CharDev string
|
CharDev string
|
||||||
|
|
||||||
|
// MACAddress is the networking device interface MAC address.
|
||||||
|
MACAddress string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Object is a qemu object representation.
|
// Object is a qemu object representation.
|
||||||
@ -321,10 +327,10 @@ func appendQMPSocket(params []string, config Config) []string {
|
|||||||
|
|
||||||
func appendDevices(params []string, config Config) []string {
|
func appendDevices(params []string, config Config) []string {
|
||||||
for _, d := range config.Devices {
|
for _, d := range config.Devices {
|
||||||
if d.Type != "" {
|
if d.Driver != "" {
|
||||||
var deviceParams []string
|
var deviceParams []string
|
||||||
|
|
||||||
deviceParams = append(deviceParams, fmt.Sprintf("%s", d.Type))
|
deviceParams = append(deviceParams, fmt.Sprintf("%s", d.Driver))
|
||||||
|
|
||||||
if d.ID != "" {
|
if d.ID != "" {
|
||||||
deviceParams = append(deviceParams, fmt.Sprintf(",id=%s", d.ID))
|
deviceParams = append(deviceParams, fmt.Sprintf(",id=%s", d.ID))
|
||||||
@ -346,6 +352,14 @@ func appendDevices(params []string, config Config) []string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if d.NetDev != "" {
|
||||||
|
deviceParams = append(deviceParams, fmt.Sprintf(",netdev=%s", d.NetDev))
|
||||||
|
|
||||||
|
if d.MACAddress != "" {
|
||||||
|
deviceParams = append(deviceParams, fmt.Sprintf(",mac=%s", d.MACAddress))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
params = append(params, "-device")
|
params = append(params, "-device")
|
||||||
params = append(params, strings.Join(deviceParams, ""))
|
params = append(params, strings.Join(deviceParams, ""))
|
||||||
}
|
}
|
||||||
|
16
qemu_test.go
16
qemu_test.go
@ -117,7 +117,7 @@ var deviceNVDIMMString = "-device nvdimm,id=nv0,memdev=mem0"
|
|||||||
|
|
||||||
func TestAppendDeviceNVDIMM(t *testing.T) {
|
func TestAppendDeviceNVDIMM(t *testing.T) {
|
||||||
device := Device{
|
device := Device{
|
||||||
Type: "nvdimm",
|
Driver: "nvdimm",
|
||||||
ID: "nv0",
|
ID: "nv0",
|
||||||
MemDev: "mem0",
|
MemDev: "mem0",
|
||||||
}
|
}
|
||||||
@ -129,7 +129,7 @@ var deviceFSString = "-device virtio-9p-pci,fsdev=workload9p,mount_tag=rootfs"
|
|||||||
|
|
||||||
func TestAppendDeviceFS(t *testing.T) {
|
func TestAppendDeviceFS(t *testing.T) {
|
||||||
device := Device{
|
device := Device{
|
||||||
Type: "virtio-9p-pci",
|
Driver: "virtio-9p-pci",
|
||||||
FSDev: "workload9p",
|
FSDev: "workload9p",
|
||||||
MountTag: "rootfs",
|
MountTag: "rootfs",
|
||||||
}
|
}
|
||||||
@ -137,6 +137,18 @@ func TestAppendDeviceFS(t *testing.T) {
|
|||||||
testAppend(device, deviceFSString, t)
|
testAppend(device, deviceFSString, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var deviceNetworkString = "-device virtio-net-pci,netdev=eth0,mac=01:02:de:ad:be:ef"
|
||||||
|
|
||||||
|
func TestAppendDeviceNetwork(t *testing.T) {
|
||||||
|
device := Device{
|
||||||
|
Driver: "virtio-net-pci",
|
||||||
|
NetDev: "eth0",
|
||||||
|
MACAddress: "01:02:de:ad:be:ef",
|
||||||
|
}
|
||||||
|
|
||||||
|
testAppend(device, deviceNetworkString, t)
|
||||||
|
}
|
||||||
|
|
||||||
func TestAppendEmptyDevice(t *testing.T) {
|
func TestAppendEmptyDevice(t *testing.T) {
|
||||||
device := Device{}
|
device := Device{}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user