Add support for QEMU, and add test code.
Signed-off-by: Thomas Hipp <thipp(a)suse.de>
---
Changes since v1:
- support multiple Args and Envs
---
domain.go | 50 +++++++++++++++++++++++++++++++++-----------------
domain_test.go | 28 ++++++++++++++++++++++++++++
2 files changed, 61 insertions(+), 17 deletions(-)
diff --git a/domain.go b/domain.go
index b9b0f77..8c1fa76 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 {
+ Args []DomainQEMUCommandlineArg `xml:"qemu arg"`
+ Envs []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..0aa5938 100644
--- a/domain_test.go
+++ b/domain_test.go
@@ -1141,6 +1141,34 @@ var domainTestData = []struct {
`</domain>`,
},
},
+ {
+ Object: &Domain{
+ Type: "qemu",
+ Name: "test",
+ XMLNS_QEMU: "http://libvirt.org/schemas/domain/qemu/1.0",
+ 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 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>`,
+ ` <arg xmlns="qemu" value="-oldarg"></arg>`,
+ ` <env xmlns="qemu" name="QEMU_ENV"
value="VAL"></env>`,
+ ` <env xmlns="qemu" name="QEMU_VAR"
value="VAR"></env>`,
+ ` </commandline>`,
+ `</domain>`,
+ },
+ },
/* Tests for sub-documents that can be hotplugged */
{
--
2.13.2