Re: [PATCH go-xml] Added Storage Pool and Storage Volume XML schemes.

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

 



On Fri, Jan 06, 2017 at 03:09:59PM +0100, Alexey Slaykovsky wrote:
> Signed-off-by: Alexey Slaykovsky <aslaikov@xxxxxxxxxx>
> ---
>  domain.go       |   9 +-
>  domain_test.go  |   8 +-
>  memory.go       |  31 +++++
>  storage.go      | 159 ++++++++++++++++++++++
>  storage_test.go | 413 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  5 files changed, 609 insertions(+), 11 deletions(-)
>  create mode 100644 memory.go
>  create mode 100644 storage.go
>  create mode 100644 storage_test.go
> 
> diff --git a/domain.go b/domain.go
> index ec2bd02..f8833a1 100644
> --- a/domain.go
> +++ b/domain.go
> @@ -121,11 +121,6 @@ type DomainDeviceList struct {
>  	Videos      []DomainVideo      `xml:"video"`
>  }
>  
> -type DomainMemory struct {
> -	Value string `xml:",chardata"`
> -	Unit  string `xml:"unit,attr"`
> -}
> -
>  type DomainOSType struct {
>  	Arch    string `xml:"arch,attr"`
>  	Machine string `xml:"machine,attr"`
> @@ -194,8 +189,8 @@ type Domain struct {
>  	Type          string            `xml:"type,attr"`
>  	Name          string            `xml:"name"`
>  	UUID          *string           `xml:"uuid"`
> -	Memory        *DomainMemory     `xml:"memory"`
> -	CurrentMemory *DomainMemory     `xml:"currentMemory"`
> +	Memory        *Memory           `xml:"memory"`
> +	CurrentMemory *Memory           `xml:"currentMemory"`
>  	Devices       *DomainDeviceList `xml:"devices"`
>  	OS            *DomainOS         `xml:"os"`
>  	SysInfo       *DomainSysInfo    `xml:"sysinfo"`
> diff --git a/domain_test.go b/domain_test.go
> index ae262e5..c22c384 100644
> --- a/domain_test.go
> +++ b/domain_test.go
> @@ -125,13 +125,13 @@ var domainTestData = []struct {
>  		Object: &Domain{
>  			Type: "kvm",
>  			Name: "test",
> -			Memory: &DomainMemory{
> +			Memory: &Memory{
>  				Unit:  "KiB",
> -				Value: "8192",
> +				Value: 8192,
>  			},
> -			CurrentMemory: &DomainMemory{
> +			CurrentMemory: &Memory{
>  				Unit:  "KiB",
> -				Value: "4096",
> +				Value: 4096,
>  			},
>  			OS: &DomainOS{
>  				Type: &DomainOSType{
> diff --git a/memory.go b/memory.go
> new file mode 100644
> index 0000000..78844ac
> --- /dev/null
> +++ b/memory.go
> @@ -0,0 +1,31 @@

> +package libvirtxml
> +
> +type Memory struct {
> +	Unit  string `xml:"unit,attr,omitempty"`
> +	Value uint64 `xml:",chardata"`
> +}

Eww, no, we don't want todo this. Although the two schemas happen to
have the same attributes currently, this isn't guaranteed in the future.
IF the <memory> element in the domain XML gains extra attributes, we'd
need to split out a DomainMemory struct once again, which would be a
backwards incompatible change. So just keep the schemas fully separate
from each other in this area.

Also, the storage pool isn't representing memory, its representing disk
usage, so the name is somewhat misleading

> diff --git a/storage.go b/storage.go
> new file mode 100644
> index 0000000..eccbee5
> --- /dev/null
> +++ b/storage.go
> @@ -0,0 +1,159 @@

> +
> +package libvirtxml
> +
> +import "encoding/xml"
> +
> +type StorageFormat struct {
> +	Type string `xml:"type,attr"`
> +}
> +
> +type StoragePermissions struct {
> +	Owner string `xml:"owner,omitempty"`
> +	Group string `xml:"group,omitempty"`
> +	Mode  string `xml:"mode,omitempty"`
> +	Label string `xml:"label,omitempty"`
> +}
> +
> +type StorageTargetEncryptionSecret struct {
> +	Type string `xml:"type,attr,omitempty"`
> +	UUID string `xml:"uuid,attr,omitempty"`
> +}
> +
> +type StorageTargetEncryption struct {
> +	Type   string                         `xml:"type,attr,omitempty"`
> +	Format string                         `xml:"format,attr,omitempty"`
> +	Secret *StorageTargetEncryptionSecret `xml:"secret"`
> +}
> +
> +type StorageTargetTimestamps struct {
> +	Atime string `xml:"atime"`
> +	Mtime string `xml:"mtime"`
> +	Ctime string `xml:"ctime"`
> +}
> +
> +type StorageTargetFeature struct {
> +	LazyRefcounts *struct{} `xml:"lazy_refcounts"`
> +}
> +
> +type StorageTarget struct {
> +	Path        string                   `xml:"path,omitempty"`
> +	Format      *StorageFormat           `xml:"format"`
> +	Permissions *StoragePermissions      `xml:"permissions"`
> +	Timestamps  *StorageTargetTimestamps `xml:"timestamps"`
> +	Compat      string                   `xml:"compat,omitempty"`
> +	NoCOW       *struct{}                `xml:"nocow"`
> +	Features    []StorageTargetFeature   `xml:"features"`
> +	Encryption  *StorageTargetEncryption `xml:"encryption"`
> +}
> +
> +type StoragePoolSourceHost struct {
> +	Name string `xml:"name,attr"`
> +}
> +
> +type StoragePoolSourceDevice struct {
> +	Path          string `xml:"path,attr"`
> +	PartSeparator string `xml:"part_separator,attr,omitempty"`
> +}
> +
> +type StoragePoolSourceAuthSecret struct {
> +	Usage string `xml:"usage,attr"`
> +}
> +
> +type StoragePoolSourceAuth struct {
> +	Type     string                       `xml:"type,attr"`
> +	Username string                       `xml:"username,attr"`
> +	Secret   *StoragePoolSourceAuthSecret `xml:"secret"`
> +}
> +
> +type StoragePoolSourceVendor struct {
> +	Name string `xml:"name,attr"`
> +}
> +
> +type StoragePoolSourceProduct struct {
> +	Name string `xml:"name,attr"`
> +}
> +
> +type StoragePoolSourceAdapterParentAddrAddress struct {
> +	Domain string `xml:"domain,attr"`
> +	Bus    string `xml:"bus,attr"`
> +	Slot   string `xml:"slot,attr"`
> +	Addr   string `xml:"addr,attr"`
> +}
> +
> +type StoragePoolSourceAdapterParentAddr struct {
> +	UniqueID uint64                                     `xml:"unique_id,attr"`
> +	Address  *StoragePoolSourceAdapterParentAddrAddress `xml:"address"`
> +}
> +
> +type StoragePoolSourceAdapter struct {
> +	Type       string                              `xml:"type,attr"`
> +	Name       string                              `xml:"name,attr,omitempty"`
> +	Parent     string                              `xml:"parent,attr,omitempty"`
> +	WWNN       string                              `xml:"wwnn,attr,omitempty"`
> +	WWPN       string                              `xml:"wwpn,attr,omitempty"`
> +	ParentAddr *StoragePoolSourceAdapterParentAddr `xml:"parentaddr"`
> +}
> +
> +type StoragePoolSource struct {
> +	Host    *StoragePoolSourceHost    `xml:"host"`
> +	Device  *StoragePoolSourceDevice  `xml:"device"`
> +	Auth    *StoragePoolSourceAuth    `xml:"auth"`
> +	Vendor  *StoragePoolSourceVendor  `xml:"vendor"`
> +	Product *StoragePoolSourceProduct `xml:"product"`
> +	Format  *StorageFormat            `xml:"format"`
> +	Adapter *StoragePoolSourceAdapter `xml:"adapter"`
> +}
> +
> +type StoragePool struct {
> +	XMLName    xml.Name           `xml:"pool"`
> +	Type       string             `xml:"type,attr"`
> +	Name       string             `xml:"name"`
> +	UUID       string             `xml:"uuid,omitempty"`
> +	Allocation *Memory            `xml:"allocation"`
> +	Capacity   *Memory            `xml:"capacity"`
> +	Available  *Memory            `xml:"available"`
> +	Target     *StorageTarget     `xml:"target"`
> +	Source     *StoragePoolSource `xml:"source"`
> +}
> +
> +type StorageVolumeBackingStore struct {
> +	Path        string              `xml:"path"`
> +	Format      *StorageFormat      `xml:"format"`

This Format is not the same thing as the pool Format, so we should
use separate structs.

> +	Permissions *StoragePermissions `xml:"permissions"`
> +}
> +
> +type StorageVolume struct {
> +	XMLName      xml.Name                   `xml:"volume"`
> +	Type         string                     `xml:"type,attr,omitempty"`
> +	Name         string                     `xml:"name"`
> +	Key          string                     `xml:"key,omitempty"`
> +	Allocation   *Memory                    `xml:"allocation"`
> +	Capacity     *Memory                    `xml:"capacity"`
> +	Physical     *Memory                    `xml:"physical"`
> +	Target       *StorageTarget             `xml:"target"`

Again, can you make sure to use separate StorageVolumeTarget and
StoragePoolTarget structs to ensure future extensibility

> +	BackingStore *StorageVolumeBackingStore `xml:"backingStore"`
> +}

Can you use storage_vol.go and storage_pool.go for these, since they
are in fact separate XML schemas. Likewise for the test files.


Regards,
Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://entangle-photo.org       -o-    http://search.cpan.org/~danberr/ :|

--
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