Re: [libvirt] [PATCH go-xml] Add support for memory device element
On Wed, Oct 11, 2017 at 10:25:02AM +0800, zhenwei.pi wrote: > Support model, access and target. > Add Marshal/Unmarshal mothed for memory device. > Add test code for device list in full domain. > > Signed-off-by: zhenwei.pi > --- > domain.go | 29 + > domain_test.go | 45 + > 2 files changed, 74 insertions(+) Reviewed-by: Daniel P. Berrange and pushed to git master. 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
[libvirt] [PATCH go-xml] Add support for memory device element
Support model, access and target. Add Marshal/Unmarshal mothed for memory device. Add test code for device list in full domain. Signed-off-by: zhenwei.pi --- domain.go | 29 + domain_test.go | 45 + 2 files changed, 74 insertions(+) diff --git a/domain.go b/domain.go index 8c2cc1b..bacab11 100644 --- a/domain.go +++ b/domain.go @@ -436,6 +436,22 @@ type DomainHostdev struct { Address *DomainAddress `xml:"address"` } +type DomainMemorydevTargetNode struct { + Value uint `xml:",chardata"` +} + +type DomainMemorydevTarget struct { + Size *DomainMemory `xml:"size"` + Node *DomainMemorydevTargetNode `xml:"node"` +} + +type DomainMemorydev struct { + XMLName xml.Name `xml:"memory"` + Model string `xml:"model,attr"` + Access string `xml:"access,attr"` + Target *DomainMemorydevTarget `xml:"target"` +} + type DomainDeviceList struct { Emulatorstring `xml:"emulator,omitempty"` Controllers []DomainController `xml:"controller"` @@ -452,6 +468,7 @@ type DomainDeviceList struct { Sounds []DomainSound `xml:"sound"` RNGs[]DomainRNG`xml:"rng"` Hostdevs[]DomainHostdev`xml:"hostdev"` + Memorydevs []DomainMemorydev `xml:"memory"` } type DomainMemory struct { @@ -915,6 +932,18 @@ func (d *DomainHostdev) Marshal() (string, error) { return string(doc), nil } +func (d *DomainMemorydev) Unmarshal(doc string) error { + return xml.Unmarshal([]byte(doc), d) +} + +func (d *DomainMemorydev) Marshal() (string, error) { + doc, err := xml.MarshalIndent(d, "", " ") + if err != nil { + return "", err + } + return string(doc), nil +} + type HexUint uint func (h *HexUint) UnmarshalXMLAttr(attr xml.Attr) error { diff --git a/domain_test.go b/domain_test.go index 4fe6bfe..dbebe42 100644 --- a/domain_test.go +++ b/domain_test.go @@ -372,6 +372,21 @@ var domainTestData = []struct { }, }, }, + Memorydevs: []DomainMemorydev{ + DomainMemorydev{ + Model: "dimm", + Access: "private", + Target: &DomainMemorydevTarget{ + Size: &DomainMemory{ + Value: 1, + Unit: "GiB", + }, + Node: &DomainMemorydevTargetNode{ + Value: 0, + }, + }, + }, + }, }, }, Expected: []string{ @@ -414,6 +429,12 @@ var domainTestData = []struct { ``, ` `, ``, + ``, + ` `, + `1`, + `0`, + ` `, + ``, ` `, ``, }, @@ -1630,6 +1651,30 @@ var domainTestData = []struct { ``, }, }, + { + Object: &DomainMemorydev{ + Model: "dimm", + Access: "private", + Target: &DomainMemorydevTarget{ + Size: &DomainMemory{ + Value: 1, + Unit: "GiB", + }, + Node: &DomainMemorydevTargetNode{ + Value: 0, + }, + }, + }, + + Expected: []string{ + ``, + ` `, + `1`, + `0`, + ` `, + ``, + }, + }, } func TestDomain(t *testing.T) { -- 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH go-xml] Add support for memory device element
Support model, access and target. Add Marshal/Unmarshal mothed for memory device. Add test code for device list in full domain. Signed-off-by: zhenwei.pi --- domain.go | 29 + domain_test.go | 45 + 2 files changed, 74 insertions(+) diff --git a/domain.go b/domain.go index 8c2cc1b..bacab11 100644 --- a/domain.go +++ b/domain.go @@ -436,6 +436,22 @@ type DomainHostdev struct { Address *DomainAddress `xml:"address"` } +type DomainMemorydevTargetNode struct { + Value uint `xml:",chardata"` +} + +type DomainMemorydevTarget struct { + Size *DomainMemory `xml:"size"` + Node *DomainMemorydevTargetNode `xml:"node"` +} + +type DomainMemorydev struct { + XMLName xml.Name `xml:"memory"` + Model string `xml:"model,attr"` + Access string `xml:"access,attr"` + Target *DomainMemorydevTarget `xml:"target"` +} + type DomainDeviceList struct { Emulatorstring `xml:"emulator,omitempty"` Controllers []DomainController `xml:"controller"` @@ -452,6 +468,7 @@ type DomainDeviceList struct { Sounds []DomainSound `xml:"sound"` RNGs[]DomainRNG`xml:"rng"` Hostdevs[]DomainHostdev`xml:"hostdev"` + Memorydevs []DomainMemorydev `xml:"memory"` } type DomainMemory struct { @@ -915,6 +932,18 @@ func (d *DomainHostdev) Marshal() (string, error) { return string(doc), nil } +func (d *DomainMemorydev) Unmarshal(doc string) error { + return xml.Unmarshal([]byte(doc), d) +} + +func (d *DomainMemorydev) Marshal() (string, error) { + doc, err := xml.MarshalIndent(d, "", " ") + if err != nil { + return "", err + } + return string(doc), nil +} + type HexUint uint func (h *HexUint) UnmarshalXMLAttr(attr xml.Attr) error { diff --git a/domain_test.go b/domain_test.go index 4fe6bfe..dbebe42 100644 --- a/domain_test.go +++ b/domain_test.go @@ -372,6 +372,21 @@ var domainTestData = []struct { }, }, }, + Memorydevs: []DomainMemorydev{ + DomainMemorydev{ + Model: "dimm", + Access: "private", + Target: &DomainMemorydevTarget{ + Size: &DomainMemory{ + Value: 1, + Unit: "GiB", + }, + Node: &DomainMemorydevTargetNode{ + Value: 0, + }, + }, + }, + }, }, }, Expected: []string{ @@ -414,6 +429,12 @@ var domainTestData = []struct { ``, ` `, ``, + ``, + ` `, + `1`, + `0`, + ` `, + ``, ` `, ``, }, @@ -1630,6 +1651,30 @@ var domainTestData = []struct { ``, }, }, + { + Object: &DomainMemorydev{ + Model: "dimm", + Access: "private", + Target: &DomainMemorydevTarget{ + Size: &DomainMemory{ + Value: 1, + Unit: "GiB", + }, + Node: &DomainMemorydevTargetNode{ + Value: 0, + }, + }, + }, + + Expected: []string{ + ``, + ` `, + `1`, + `0`, + ` `, + ``, + }, + }, } func TestDomain(t *testing.T) { -- 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list