[libvirt] [PATCH go-xml v2] Add support for QEMU

Thomas Hipp posted 1 patch 6 years, 9 months ago
Failed in applying to current master (apply log)
There is a newer version of this series
domain.go      | 50 +++++++++++++++++++++++++++++++++-----------------
domain_test.go | 28 ++++++++++++++++++++++++++++
2 files changed, 61 insertions(+), 17 deletions(-)
[libvirt] [PATCH go-xml v2] Add support for QEMU
Posted by Thomas Hipp 6 years, 9 months ago
Add support for QEMU, and add test code.

Signed-off-by: Thomas Hipp <thipp@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

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH go-xml v2] Add support for QEMU
Posted by Daniel P. Berrange 6 years, 9 months ago
On Mon, Jul 10, 2017 at 11:15:14AM +0200, Thomas Hipp wrote:
> Add support for QEMU, and add test code.
> 
> Signed-off-by: Thomas Hipp <thipp@suse.de>

> +		Expected: []string{
> +			`<domain xmlns:_xmlns="xmlns" _xmlns:qemu="http://libvirt.org/schemas/domain/qemu/1.0" type="qemu">`,

This is very wrong -  'xmlns:_xmlns="xmlns"' is just bizarre, and
you can't have an '_' on the xmlns declaration.

> +			`  <name>test</name>`,
> +			`  <commandline xmlns="qemu">`,

This is wrong too - if you want to reference the name of a previously
declared namespace you need "qemu:commandline". What you're doing
here is declaring a new default namespace with a uri of '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>`,

The following ought to work

   <commandline xmlns="http://libvirt.org/schemas/domain/qemu/1.0">
       <arg xmlns="qemu" value="-newarg"></arg>
       <env xmlns="qemu" name="QEMU_ENV" value="VAL"></env>
   </commandline>

...but libvirt rejects it for reasons I don't understand :-( It seems we
really must have

   <qemu:commandline xmlns:qemu="http://libvirt.org/schemas/domain/qemu/1.0">
       <qemu:arg xmlns="qemu" value="-newarg"></arg>
       <qemu:env xmlns="qemu" name="QEMU_ENV" value="VAL"></env>
   </qemu:commandline>

but I don't see how to generate this in Go XML

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH go-xml v2] Add support for QEMU
Posted by Daniel P. Berrange 6 years, 9 months ago
On Mon, Jul 10, 2017 at 11:15:14AM +0200, Thomas Hipp wrote:
> Add support for QEMU, and add test code.
> 
> Signed-off-by: Thomas Hipp <thipp@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 {

Add

      XMLName xml.Name  `xml:"http://libvirt.org/schemas/domain/qemu/1.0 commandline"`

> +	Args []DomainQEMUCommandlineArg `xml:"qemu arg"`

And change to `xml:"arg"`

> +	Envs []DomainQEMUCommandlineEnv `xml:"qemu env"`

And change to `xml:"arg"`

> +}



> +
>  // 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 {

...snip...

> +	QEMUCommandline *DomainQEMUCommandline `xml:"qemu commandline"`

And change to `xml:"commandline"`

>  }

Then, I think it will generate valid XML that works with libvirt

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

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