[libvirt] [PATCH go-xml] Add support for Node Device with basic testing.

2017-06-07 Thread Vladik Romanovsky
---
 node_device.go  | 310 +++
 node_device_test.go | 337 
 2 files changed, 647 insertions(+)
 create mode 100644 node_device.go
 create mode 100644 node_device_test.go

diff --git a/node_device.go b/node_device.go
new file mode 100644
index 000..cc40451
--- /dev/null
+++ b/node_device.go
@@ -0,0 +1,310 @@
+/*
+ * This file is part of the libvirt-go-xml project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (C) 2017 Red Hat, Inc.
+ *
+ */
+
+package libvirtxml
+
+import (
+   "encoding/xml"
+)
+
+type NodeDevice struct {
+   Name   string   `xml:"name"`
+   Path   string   `xml:"path,omitempty"`
+   Parent string   `xml:"parent,omitempty"`
+   Driver string   `xml:"driver>name,omitempty"`
+   Capability interface{}  `xml:"capability"`
+}
+
+type NodeDeviceVendor struct {
+   ID  string  `xml:"id,attr,omitempty"`
+   Namestring  `xml:",chardata"`
+}
+type NodeDeviceProduct struct {
+   ID  string  `xml:"id,attr,omitempty"`
+   Namestring  `xml:",chardata"`
+}
+
+type NodeDevicePciExpress struct {
+   Links []NodeDevicePciExpressLink`xml:"link"`
+}
+
+type NodeDevicePciExpressLink struct {
+   Validitystring  `xml:"validity,attr,omitempty"`
+   Speed   float64 `xml:"speed,attr,omitempty"`
+   Portint `xml:"port,attr,omitempty"`
+   Width   int `xml:"width,attr,omitempty"`
+}
+
+type NodeDeviceIOMMUGroup struct {
+   Number  int `xml:"number,attr"`
+}
+
+type NodeDeviceNUMA struct {
+   Nodeint `xml:"node,attr"`
+}
+
+type NodeDevicePCIAddress struct {
+   Domain  string  `xml:"domain,attr"`
+   Bus string  `xml:"bus,attr"`
+   Slotstring  `xml:"slot,attr"`
+   Functionstring  `xml:"function,attr"`
+}
+
+type NodeDeviceSystemHardware struct {
+   Vendor  string  `xml:"vendor"`
+   Version string  `xml:"version"`
+   Serial  string  `xml:"serial"`
+   UUIDstring  `xml:"uuid"`
+}
+
+type NodeDeviceSystemFirmware struct {
+   Vendor  string  `xml:"vendor"`
+   Version string  `xml:"version"`
+   ReleaseDate string  `xml:"release_date"`
+}
+
+type NodeDeviceNetOffloadFeatures struct {
+   Namestring  `xml:"name,attr"`
+}
+
+type NodeDeviceNetLink struct {
+   State   string  `xml:"state,attr"`
+   Speed   string  `xml:"speed,attr,omitempty"`
+}
+
+type NodeDevicePciCapability struct {
+   Domain  int `xml:"domain,omitempty"`
+   Bus int `xml:"bus,omitempty"`
+   Slotint `xml:"slot,omitempty"`
+   Functionint 
`xml:"function,omitempty"`
+   Product *NodeDeviceProduct  
`xml:"product,omitempty"`
+   Vendor  *NodeDeviceVendor   `xml:"vendor,omitempty"`
+   IommuGroup  *NodeDeviceIOMMUGroup   
`xml:"iommuGroup,omitempty"`
+   Numa*NodeDeviceNUMA `xml:"numa,omitempty"`
+   PciExpress  *NodeDevicePciExpress   
`xml:"pci-express,omitempty"`
+   Capability  []NodeDeviceNestedPciCapability 
`xml:"capability,omitempty"`
+}
+
+type NodeDeviceNestedPciCapability struct {
+   Typestring  `xml:"type,attr"`
+   Address []NodeDevicePCIAddress  
`xml:"address,omitempty"`
+   MaxCountint 
`xml:"maxCount,attr,omitempty"`
+}
+
+type NodeDeviceSystemCapability struct {
+   Product string  `xml:"product"`
+   Hardware*Nod

Re: [libvirt] [PATCH go-xml] Add support for Node Device with basic testing.

2017-06-02 Thread Daniel P. Berrange
On Wed, May 31, 2017 at 11:35:14AM -0400, Vladik Romanovsky wrote:
> ---
>  node_device.go  | 168 
> 
>  node_device_test.go | 128 +++
>  2 files changed, 296 insertions(+)
>  create mode 100644 node_device.go
>  create mode 100644 node_device_test.go
> 
> diff --git a/node_device.go b/node_device.go
> new file mode 100644
> index 000..d7850e9
> --- /dev/null
> +++ b/node_device.go
> @@ -0,0 +1,168 @@
> +/*
> + * This file is part of the libvirt-go-xml project
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a 
> copy
> + * of this software and associated documentation files (the "Software"), to 
> deal
> + * in the Software without restriction, including without limitation the 
> rights
> + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> + * copies of the Software, and to permit persons to whom the Software is
> + * furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
> THE
> + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
> FROM,
> + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
> + * THE SOFTWARE.
> + *
> + * Copyright (C) 2017 Red Hat, Inc.
> + *
> + */
> +
> +package libvirtxml
> +
> +import (
> + "encoding/xml"
> +)
> +
> +type NodeDevice struct {
> + Name   string `xml:"name"`
> + Path   string `xml:"path,omitempty"`
> + Parent string `xml:"parent,omitempty"`
> + Driver string `xml:"driver>name,omitempty"`
> + Capability []NodeDeviceCapability `xml:"capability"`
> +}
> +
> +type NodeDeviceCapability struct {
> + Domain  int`xml:"domain,omitempty"`
> + Bus int`xml:"bus,omitempty"`
> + Slotint`xml:"slot,omitempty"`
> + Functionint`xml:"function,omitempty"`
> + IommuGroup  *NodeDeviceIOMMUGroup  `xml:"iommuGroup,omitempty"`
> + Numa*NodeDeviceNUMA`xml:"numa,omitempty"`
> + PciExpress  *NodeDevicePciExpress  `xml:"pci-express,omitempty"`

You don't need omitempty on any field that is a pointer.

> + Hardware*NodeDeviceSystemHardware  `xml:"hardware"`
> + Firmware*NodeDeviceSystemFirmware  `xml:"firmware"`
> + Device  int`xml:"device"`
> + Number  int`xml:"number"`
> + Class   int`xml:"class"`
> + Subclassint`xml:"subclass"`
> + Protocolint`xml:"protocol"`
> + Description string `xml:"description,omitempty"`
> + Interface   string `xml:"interface"`
> + Address string `xml:"address"`
> + Link*NodeDeviceNetLink `xml:"link"`
> + Features[]NodeDeviceNetOffloadFeatures `xml:"feature,omitempty"`
> + UniqueIDint`xml:"unique_id"`
> + Target  int`xml:"target"`
> + Lun int`xml:"lun"`
> + Block   string `xml:"block"`
> + DriverType  string `xml:"drive_type"`
> + Model   string `xml:"model"`
> + Serial  string `xml:"serial"`
> + Sizeint`xml:"size"`
> + Hostint`xml:"host"`
> + Typestring `xml:"type"`

I'm surprised we don't ahve omitempty on almost all of these above

> + Product *NodeDeviceProduct `xml:"product,omitempty"`
> + Vendor  *NodeDeviceVendor  `xml:"vendor,omitempty"`
> + Capability  []NodeDeviceNestedCapabilities `xml:"capability,omitempty"`
> +}

Wow, we have a lot of capabilities here. Makes be wonder if your previous
patch was in fact better... will have to think about that more.

> +
> +type NodeDeviceVendor struct {
> + ID   string `xml:"id,attr,omitempty"`
> + Name string `xml:",chardata"`
> +}
> +type NodeDeviceProduct struct {
> + ID   string `xml:"id,attr,omitempty"`
> + Name string `xml:",chardat

[libvirt] [PATCH go-xml] Add support for Node Device with basic testing.

2017-05-31 Thread Vladik Romanovsky
---
 node_device.go  | 168 
 node_device_test.go | 128 +++
 2 files changed, 296 insertions(+)
 create mode 100644 node_device.go
 create mode 100644 node_device_test.go

diff --git a/node_device.go b/node_device.go
new file mode 100644
index 000..d7850e9
--- /dev/null
+++ b/node_device.go
@@ -0,0 +1,168 @@
+/*
+ * This file is part of the libvirt-go-xml project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (C) 2017 Red Hat, Inc.
+ *
+ */
+
+package libvirtxml
+
+import (
+   "encoding/xml"
+)
+
+type NodeDevice struct {
+   Name   string `xml:"name"`
+   Path   string `xml:"path,omitempty"`
+   Parent string `xml:"parent,omitempty"`
+   Driver string `xml:"driver>name,omitempty"`
+   Capability []NodeDeviceCapability `xml:"capability"`
+}
+
+type NodeDeviceCapability struct {
+   Domain  int`xml:"domain,omitempty"`
+   Bus int`xml:"bus,omitempty"`
+   Slotint`xml:"slot,omitempty"`
+   Functionint`xml:"function,omitempty"`
+   IommuGroup  *NodeDeviceIOMMUGroup  `xml:"iommuGroup,omitempty"`
+   Numa*NodeDeviceNUMA`xml:"numa,omitempty"`
+   PciExpress  *NodeDevicePciExpress  `xml:"pci-express,omitempty"`
+   Hardware*NodeDeviceSystemHardware  `xml:"hardware"`
+   Firmware*NodeDeviceSystemFirmware  `xml:"firmware"`
+   Device  int`xml:"device"`
+   Number  int`xml:"number"`
+   Class   int`xml:"class"`
+   Subclassint`xml:"subclass"`
+   Protocolint`xml:"protocol"`
+   Description string `xml:"description,omitempty"`
+   Interface   string `xml:"interface"`
+   Address string `xml:"address"`
+   Link*NodeDeviceNetLink `xml:"link"`
+   Features[]NodeDeviceNetOffloadFeatures `xml:"feature,omitempty"`
+   UniqueIDint`xml:"unique_id"`
+   Target  int`xml:"target"`
+   Lun int`xml:"lun"`
+   Block   string `xml:"block"`
+   DriverType  string `xml:"drive_type"`
+   Model   string `xml:"model"`
+   Serial  string `xml:"serial"`
+   Sizeint`xml:"size"`
+   Hostint`xml:"host"`
+   Typestring `xml:"type"`
+   Product *NodeDeviceProduct `xml:"product,omitempty"`
+   Vendor  *NodeDeviceVendor  `xml:"vendor,omitempty"`
+   Capability  []NodeDeviceNestedCapabilities `xml:"capability,omitempty"`
+}
+
+type NodeDeviceVendor struct {
+   ID   string `xml:"id,attr,omitempty"`
+   Name string `xml:",chardata"`
+}
+type NodeDeviceProduct struct {
+   ID   string `xml:"id,attr,omitempty"`
+   Name string `xml:",chardata"`
+}
+
+type NodeDeviceNestedCapabilities struct {
+   Type   string   `xml:"type,attr"`
+   Address[]NodeDevicePCIAddress   `xml:"address,omitempty"`
+   MaxCount   int  `xml:"maxCount,attr,omitempty"`
+   VportsOPS  *NodeDeviceSCSIVportsOPS `xml:"vports_ops,omitempty"`
+   FCHost *NodeDeviceSCSIFCHost`xml:"fc_host,omitempty"`
+   MediaAvailable int 

Re: [libvirt] [PATCH go-xml] Add support for Node Device with basic testing.

2017-05-31 Thread Daniel P. Berrange
On Tue, May 30, 2017 at 10:36:22AM -0400, Vladik Romanovsky wrote:
> Thanks for the review.
> 
> On Tue, May 30, 2017 at 8:46 AM, Daniel P. Berrange  
> wrote:
> >> +type NodeDevice struct {
> >> + Name   string  `xml:"name"`
> >> + Path   string  `xml:"path,omitempty"`
> >> + Parent string  `xml:"parent,omitempty"`
> >> + Driver string  `xml:"driver>name,omitempty"`
> >> + Capability *CapabilityType `xml:"capability"`
> >> +}
> >
> > A single device can have multiple capabilities.
> Do you mean it should be:
>  Capability []CapabilityType `xml:"capability"` ?

Yes exactly.


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] Add support for Node Device with basic testing.

2017-05-30 Thread Vladik Romanovsky
Thanks for the review.

On Tue, May 30, 2017 at 8:46 AM, Daniel P. Berrange  wrote:
> On Mon, May 29, 2017 at 03:58:52AM -0400, Vladik Romanovsky wrote:
>> ---
>>  node_device.go  | 277 
>> 
>>  node_device_test.go | 111 +
>>  2 files changed, 388 insertions(+)
>>  create mode 100644 node_device.go
>>  create mode 100644 node_device_test.go
>>
>> diff --git a/node_device.go b/node_device.go
>> new file mode 100644
>> index 000..5375d32
>> --- /dev/null
>> +++ b/node_device.go
>> @@ -0,0 +1,277 @@
>> +/*
>> + * This file is part of the libvirt-go-xml project
>> + *
>> + * Permission is hereby granted, free of charge, to any person obtaining a 
>> copy
>> + * of this software and associated documentation files (the "Software"), to 
>> deal
>> + * in the Software without restriction, including without limitation the 
>> rights
>> + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
>> + * copies of the Software, and to permit persons to whom the Software is
>> + * furnished to do so, subject to the following conditions:
>> + *
>> + * The above copyright notice and this permission notice shall be included 
>> in
>> + * all copies or substantial portions of the Software.
>> + *
>> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 
>> OR
>> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
>> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
>> THE
>> + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
>> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
>> FROM,
>> + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
>> + * THE SOFTWARE.
>> + *
>> + * Copyright (C) 2017 Red Hat, Inc.
>> + *
>> + */
>> +
>> +package libvirtxml
>> +
>> +import (
>> + "encoding/xml"
>> + "fmt"
>> +)
>> +
>> +type NodeDevice struct {
>> + Name   string  `xml:"name"`
>> + Path   string  `xml:"path,omitempty"`
>> + Parent string  `xml:"parent,omitempty"`
>> + Driver string  `xml:"driver>name,omitempty"`
>> + Capability *CapabilityType `xml:"capability"`
>> +}
>
> A single device can have multiple capabilities.
Do you mean it should be:
 Capability []CapabilityType `xml:"capability"` ?

>
>> +
>> +type CapabilityType struct {
>> + Type interface{} `xml:"type,attr"`
>> +}
>
> I'm not convinced about this approach - it differs from what we've
> done in other schemas, where we just have a single struct containing
> the union of data from all types. The user has no idea what they
> should be providing for 'Type' here since its a generic interface
> type.
>
Yes. I wasn't sure about this either. Originally, I wanted to avoid
the Type attribute and make
CapabilityType to be an interface type.
However, I figured that it's not possible to write an UnmarshalXML for
an interface type.

The reason I didn't use the same approach as in the rest of the
schemas is because the Capability
determins it's type by a XML attribute and not an element name.
I didn't find an easy way to query the xml attribue as something
like.. `xml:"type=something,attr"`

OK, I'll try a ddiffernt approach.

>>
>> +type IDName struct {
>> + ID   string `xml:"id,attr"`
>> + Name string `xml:",chardata"`
>> +}
>> +
>> +type PciExpress struct {
>> + Links []PciExpressLink `xml:"link"`
>> +}
>> +
>> +type PciExpressLink struct {
>> + Validity string  `xml:"validity,attr,omitempty"`
>> + Speedfloat64 `xml:"speed,attr,omitempty"`
>> + Port int `xml:"port,attr,omitempty"`
>> + Widthint `xml:"width,attr,omitempty"`
>> +}
>> +
>> +type IOMMUGroupType struct {
>> + Number int `xml:"number,attr"`
>> +}
>> +
>> +type NUMA struct {
>> + Node int `xml:"node,attr"`
>> +}
>> +
>> +type PciCapabilityType struct {
>> + Domain   int `xml:"domain,omitempty"`
>> + Bus  int `xml:"bus,omitempty"`
>> + Slot int `xml:"slot,omitempty"`
>> + Function int `xml:"function,omitempty"`
>> + Product  IDName  `xml:"product,omitempty"`
>> + Vendor   IDName  `xml:"vendor,omitempty"`
>> + IommuGroup   IOMMUGroupType  `xml:"iommuGroup,omitempty"`
>> + Numa NUMA`xml:"numa,omitempty"`
>> + PciExpress   PciExpress  `xml:"pci-express,omitempty"`
>> + Capabilities []PciCapability `xml:"capability,omitempty"`
>> +}
>> +
>> +type PCIAddress struct {
>> + Domain   string `xml:"domain,attr"`
>> + Bus  string `xml:"bus,attr"`
>> + Slot string `xml:"slot,attr"`
>> + Function string `xml:"function,attr"`
>> +}
>> +
>> +type PciCapability struct {
>
> There's alot of inconsistency in capitalization of abbreviations
> in this file.  PCI vs Pci, 

Re: [libvirt] [PATCH go-xml] Add support for Node Device with basic testing.

2017-05-30 Thread Daniel P. Berrange
On Mon, May 29, 2017 at 03:58:52AM -0400, Vladik Romanovsky wrote:
> ---
>  node_device.go  | 277 
> 
>  node_device_test.go | 111 +
>  2 files changed, 388 insertions(+)
>  create mode 100644 node_device.go
>  create mode 100644 node_device_test.go
> 
> diff --git a/node_device.go b/node_device.go
> new file mode 100644
> index 000..5375d32
> --- /dev/null
> +++ b/node_device.go
> @@ -0,0 +1,277 @@
> +/*
> + * This file is part of the libvirt-go-xml project
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a 
> copy
> + * of this software and associated documentation files (the "Software"), to 
> deal
> + * in the Software without restriction, including without limitation the 
> rights
> + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> + * copies of the Software, and to permit persons to whom the Software is
> + * furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
> THE
> + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
> FROM,
> + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
> + * THE SOFTWARE.
> + *
> + * Copyright (C) 2017 Red Hat, Inc.
> + *
> + */
> +
> +package libvirtxml
> +
> +import (
> + "encoding/xml"
> + "fmt"
> +)
> +
> +type NodeDevice struct {
> + Name   string  `xml:"name"`
> + Path   string  `xml:"path,omitempty"`
> + Parent string  `xml:"parent,omitempty"`
> + Driver string  `xml:"driver>name,omitempty"`
> + Capability *CapabilityType `xml:"capability"`
> +}

A single device can have multiple capabilities.

> +
> +type CapabilityType struct {
> + Type interface{} `xml:"type,attr"`
> +}

I'm not convinced about this approach - it differs from what we've
done in other schemas, where we just have a single struct containing
the union of data from all types. The user has no idea what they
should be providing for 'Type' here since its a generic interface
type.

>
> +type IDName struct {
> + ID   string `xml:"id,attr"`
> + Name string `xml:",chardata"`
> +}
> +
> +type PciExpress struct {
> + Links []PciExpressLink `xml:"link"`
> +}
> +
> +type PciExpressLink struct {
> + Validity string  `xml:"validity,attr,omitempty"`
> + Speedfloat64 `xml:"speed,attr,omitempty"`
> + Port int `xml:"port,attr,omitempty"`
> + Widthint `xml:"width,attr,omitempty"`
> +}
> +
> +type IOMMUGroupType struct {
> + Number int `xml:"number,attr"`
> +}
> +
> +type NUMA struct {
> + Node int `xml:"node,attr"`
> +}
> +
> +type PciCapabilityType struct {
> + Domain   int `xml:"domain,omitempty"`
> + Bus  int `xml:"bus,omitempty"`
> + Slot int `xml:"slot,omitempty"`
> + Function int `xml:"function,omitempty"`
> + Product  IDName  `xml:"product,omitempty"`
> + Vendor   IDName  `xml:"vendor,omitempty"`
> + IommuGroup   IOMMUGroupType  `xml:"iommuGroup,omitempty"`
> + Numa NUMA`xml:"numa,omitempty"`
> + PciExpress   PciExpress  `xml:"pci-express,omitempty"`
> + Capabilities []PciCapability `xml:"capability,omitempty"`
> +}
> +
> +type PCIAddress struct {
> + Domain   string `xml:"domain,attr"`
> + Bus  string `xml:"bus,attr"`
> + Slot string `xml:"slot,attr"`
> + Function string `xml:"function,attr"`
> +}
> +
> +type PciCapability struct {

There's alot of inconsistency in capitalization of abbreviations
in this file.  PCI vs Pci,  Numa vs NUMA, IOMMU vs Iiommu. They
should generally always be capitalized.

> + Type string`xml:"type,attr"`
> + Address  []PCIAddress `xml:"address,omitempty"`
> + MaxCount int  `xml:"maxCount,attr,omitempty"`
> +}
> +
> +type SystemHardware struct {
> + Vendor  string `xml:"vendor"`
> + Version string `xml:"version"`
> + Serial  string `xml:"serial"`
> + UUIDstring `xml:"uuid"`
> +}
> +
> +type SystemFirmware struct {
> + Vendor  string `xml:"vendor"`
> + Version string `xml:"version"`
> + ReleaseData string `xml:"release_date"`
> +}
> +
> +type SystemCapabilityType struct {
> + Product  string `xml:"product"`
> + Hardware SystemHardware `xml:"hardware"`
> + Firmware SystemFirmware `xml:"firmware"`
> +}
> +
> +type USBDeviceCapabilityType 

[libvirt] [PATCH go-xml] Add support for Node Device with basic testing.

2017-05-29 Thread Vladik Romanovsky
---
 node_device.go  | 277 
 node_device_test.go | 111 +
 2 files changed, 388 insertions(+)
 create mode 100644 node_device.go
 create mode 100644 node_device_test.go

diff --git a/node_device.go b/node_device.go
new file mode 100644
index 000..5375d32
--- /dev/null
+++ b/node_device.go
@@ -0,0 +1,277 @@
+/*
+ * This file is part of the libvirt-go-xml project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (C) 2017 Red Hat, Inc.
+ *
+ */
+
+package libvirtxml
+
+import (
+   "encoding/xml"
+   "fmt"
+)
+
+type NodeDevice struct {
+   Name   string  `xml:"name"`
+   Path   string  `xml:"path,omitempty"`
+   Parent string  `xml:"parent,omitempty"`
+   Driver string  `xml:"driver>name,omitempty"`
+   Capability *CapabilityType `xml:"capability"`
+}
+
+type CapabilityType struct {
+   Type interface{} `xml:"type,attr"`
+}
+
+type IDName struct {
+   ID   string `xml:"id,attr"`
+   Name string `xml:",chardata"`
+}
+
+type PciExpress struct {
+   Links []PciExpressLink `xml:"link"`
+}
+
+type PciExpressLink struct {
+   Validity string  `xml:"validity,attr,omitempty"`
+   Speedfloat64 `xml:"speed,attr,omitempty"`
+   Port int `xml:"port,attr,omitempty"`
+   Widthint `xml:"width,attr,omitempty"`
+}
+
+type IOMMUGroupType struct {
+   Number int `xml:"number,attr"`
+}
+
+type NUMA struct {
+   Node int `xml:"node,attr"`
+}
+
+type PciCapabilityType struct {
+   Domain   int `xml:"domain,omitempty"`
+   Bus  int `xml:"bus,omitempty"`
+   Slot int `xml:"slot,omitempty"`
+   Function int `xml:"function,omitempty"`
+   Product  IDName  `xml:"product,omitempty"`
+   Vendor   IDName  `xml:"vendor,omitempty"`
+   IommuGroup   IOMMUGroupType  `xml:"iommuGroup,omitempty"`
+   Numa NUMA`xml:"numa,omitempty"`
+   PciExpress   PciExpress  `xml:"pci-express,omitempty"`
+   Capabilities []PciCapability `xml:"capability,omitempty"`
+}
+
+type PCIAddress struct {
+   Domain   string `xml:"domain,attr"`
+   Bus  string `xml:"bus,attr"`
+   Slot string `xml:"slot,attr"`
+   Function string `xml:"function,attr"`
+}
+
+type PciCapability struct {
+   Type string   `xml:"type,attr"`
+   Address  []PCIAddress `xml:"address,omitempty"`
+   MaxCount int  `xml:"maxCount,attr,omitempty"`
+}
+
+type SystemHardware struct {
+   Vendor  string `xml:"vendor"`
+   Version string `xml:"version"`
+   Serial  string `xml:"serial"`
+   UUIDstring `xml:"uuid"`
+}
+
+type SystemFirmware struct {
+   Vendor  string `xml:"vendor"`
+   Version string `xml:"version"`
+   ReleaseData string `xml:"release_date"`
+}
+
+type SystemCapabilityType struct {
+   Product  string `xml:"product"`
+   Hardware SystemHardware `xml:"hardware"`
+   Firmware SystemFirmware `xml:"firmware"`
+}
+
+type USBDeviceCapabilityType struct {
+   Bus int`xml:"bus"`
+   Device  int`xml:"device"`
+   Product IDName `xml:"product,omitempty"`
+   Vendor  IDName `xml:"vendor,omitempty"`
+}
+
+type USBCapabilityType struct {
+   Number  int`xml:"number"`
+   Class   int`xml:"class"`
+   Subclassint`xml:"subclass"`
+   Protocolint`xml:"protocol"`
+   Description string `xml:"description,omitempty"`
+}
+
+type NetOffloadFeatures struct {
+   Name string `xml:"number"`
+}
+
+type NetLink struct {
+   State string `xml:"state,attr"`
+   Speed string `xml:"speed,attr,omitempty"`
+}
+
+type NetCapability struct {
+   Type string `xml:"type,attr"`
+}
+
+type NetCapabilityTyp