[PATCH go-xml v3] Add support for QEMU

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add support for QEMU, and add test code.

Signed-off-by: Thomas Hipp <thipp@xxxxxxx>
---
Changes since v2:
  - set default ns in commandline subtree
  - remove ns prefix "qemu:"

---
 domain.go      | 50 +++++++++++++++++++++++++++++++++-----------------
 domain_test.go | 27 +++++++++++++++++++++++++++
 2 files changed, 60 insertions(+), 17 deletions(-)

diff --git a/domain.go b/domain.go
index b9b0f77..d5d358a 100644
--- a/domain.go
+++ b/domain.go
@@ -590,27 +590,43 @@ type DomainFeatureList struct {
 	SMM        *DomainFeatureState  `xml:"smm"`
 }
 
+type DomainQEMUCommandlineArg struct {
+	Value string `xml:"value,attr"`
+}
+
+type DomainQEMUCommandlineEnv struct {
+	Name  string `xml:"name,attr"`
+	Value string `xml:"value,attr,omitempty"`
+}
+
+type DomainQEMUCommandline struct {
+	XMLName xml.Name                   `xml:"http://libvirt.org/schemas/domain/qemu/1.0 commandline"`
+	Args    []DomainQEMUCommandlineArg `xml:"arg"`
+	Envs    []DomainQEMUCommandlineEnv `xml:"env"`
+}
+
 // NB, try to keep the order of fields in this struct
 // matching the order of XML elements that libvirt
 // will generate when dumping XML.
 type Domain struct {
-	XMLName       xml.Name           `xml:"domain"`
-	Type          string             `xml:"type,attr,omitempty"`
-	Name          string             `xml:"name"`
-	UUID          string             `xml:"uuid,omitempty"`
-	Memory        *DomainMemory      `xml:"memory"`
-	CurrentMemory *DomainMemory      `xml:"currentMemory"`
-	MaximumMemory *DomainMaxMemory   `xml:"maxMemory"`
-	VCPU          *DomainVCPU        `xml:"vcpu"`
-	Resource      *DomainResource    `xml:"resource"`
-	SysInfo       *DomainSysInfo     `xml:"sysinfo"`
-	OS            *DomainOS          `xml:"os"`
-	Features      *DomainFeatureList `xml:"features"`
-	CPU           *DomainCPU         `xml:"cpu"`
-	OnPoweroff    string             `xml:"on_poweroff,omitempty"`
-	OnReboot      string             `xml:"on_reboot,omitempty"`
-	OnCrash       string             `xml:"on_crash,omitempty"`
-	Devices       *DomainDeviceList  `xml:"devices"`
+	XMLName         xml.Name           `xml:"domain"`
+	Type            string             `xml:"type,attr,omitempty"`
+	Name            string             `xml:"name"`
+	UUID            string             `xml:"uuid,omitempty"`
+	Memory          *DomainMemory      `xml:"memory"`
+	CurrentMemory   *DomainMemory      `xml:"currentMemory"`
+	MaximumMemory   *DomainMaxMemory   `xml:"maxMemory"`
+	VCPU            *DomainVCPU        `xml:"vcpu"`
+	Resource        *DomainResource    `xml:"resource"`
+	SysInfo         *DomainSysInfo     `xml:"sysinfo"`
+	OS              *DomainOS          `xml:"os"`
+	Features        *DomainFeatureList `xml:"features"`
+	CPU             *DomainCPU         `xml:"cpu"`
+	OnPoweroff      string             `xml:"on_poweroff,omitempty"`
+	OnReboot        string             `xml:"on_reboot,omitempty"`
+	OnCrash         string             `xml:"on_crash,omitempty"`
+	Devices         *DomainDeviceList  `xml:"devices"`
+	QEMUCommandline *DomainQEMUCommandline
 }
 
 func (d *Domain) Unmarshal(doc string) error {
diff --git a/domain_test.go b/domain_test.go
index 47e5e26..f2d83fc 100644
--- a/domain_test.go
+++ b/domain_test.go
@@ -1141,6 +1141,33 @@ var domainTestData = []struct {
 			`</domain>`,
 		},
 	},
+	{
+		Object: &Domain{
+			Type: "qemu",
+			Name: "test",
+			QEMUCommandline: &DomainQEMUCommandline{
+				Args: []DomainQEMUCommandlineArg{
+					DomainQEMUCommandlineArg{Value: "-newarg"},
+					DomainQEMUCommandlineArg{Value: "-oldarg"},
+				},
+				Envs: []DomainQEMUCommandlineEnv{
+					DomainQEMUCommandlineEnv{Name: "QEMU_ENV", Value: "VAL"},
+					DomainQEMUCommandlineEnv{Name: "QEMU_VAR", Value: "VAR"},
+				},
+			},
+		},
+		Expected: []string{
+			`<domain type="qemu">`,
+			`  <name>test</name>`,
+			`  <commandline xmlns="http://libvirt.org/schemas/domain/qemu/1.0";>`,
+			`    <arg value="-newarg"></arg>`,
+			`    <arg value="-oldarg"></arg>`,
+			`    <env name="QEMU_ENV" value="VAL"></env>`,
+			`    <env name="QEMU_VAR" value="VAR"></env>`,
+			`  </commandline>`,
+			`</domain>`,
+		},
+	},
 
 	/* Tests for sub-documents that can be hotplugged */
 	{
-- 
2.13.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]
  Powered by Linux