Add support for QEMU, and add test code.

Signed-off-by: Thomas Hipp <th...@suse.de>
---
 domain.go      | 50 +++++++++++++++++++++++++++++++++-----------------
 domain_test.go | 20 ++++++++++++++++++++
 2 files changed, 53 insertions(+), 17 deletions(-)

diff --git a/domain.go b/domain.go
index b9b0f77..15fdb3a 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 {
+       Arg DomainQEMUCommandlineArg `xml:"qemu arg"`
+       Env DomainQEMUCommandlineEnv `xml:"qemu 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"`
+       XMLNS_QEMU      string                 `xml:"xmlns qemu,attr,omitempty"`
+       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 `xml:"qemu commandline"`
 }
 
 func (d *Domain) Unmarshal(doc string) error {
diff --git a/domain_test.go b/domain_test.go
index 47e5e26..7e683a9 100644
--- a/domain_test.go
+++ b/domain_test.go
@@ -1141,6 +1141,26 @@ var domainTestData = []struct {
                        `</domain>`,
                },
        },
+       {
+               Object: &Domain{
+                       Type:       "qemu",
+                       Name:       "test",
+                       XMLNS_QEMU: 
"http://libvirt.org/schemas/domain/qemu/1.0";,
+                       QEMUCommandline: &DomainQEMUCommandline{
+                               Arg: DomainQEMUCommandlineArg{Value: "-newarg"},
+                               Env: DomainQEMUCommandlineEnv{Name: "QEMU_ENV", 
Value: "VAL"},
+                       },
+               },
+               Expected: []string{
+                       `<domain xmlns:_xmlns="xmlns" 
_xmlns:qemu="http://libvirt.org/schemas/domain/qemu/1.0"; type="qemu">`,
+                       `  <name>test</name>`,
+                       `  <commandline xmlns="qemu">`,
+                       `    <arg xmlns="qemu" value="-newarg"></arg>`,
+                       `    <env xmlns="qemu" name="QEMU_ENV" 
value="VAL"></env>`,
+                       `  </commandline>`,
+                       `</domain>`,
+               },
+       },
 
        /* Tests for sub-documents that can be hotplugged */
        {
-- 
2.13.2

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

Reply via email to