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 <zhenwei.pi(a)youruncloud.com>
---
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 {
Emulator string `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 {
` <source mode="connect" service="1234"
host="1.2.3.4"></source>`,
` </backend>`,
` </rng>`,
+ ` <memory model="dimm" access="private">`,
+ ` <target>`,
+ ` <size unit="GiB">1</size>`,
+ ` <node>0</node>`,
+ ` </target>`,
+ ` </memory>`,
` </devices>`,
`</domain>`,
},
@@ -1630,6 +1651,30 @@ var domainTestData = []struct {
`</hostdev>`,
},
},
+ {
+ Object: &DomainMemorydev{
+ Model: "dimm",
+ Access: "private",
+ Target: &DomainMemorydevTarget{
+ Size: &DomainMemory{
+ Value: 1,
+ Unit: "GiB",
+ },
+ Node: &DomainMemorydevTargetNode{
+ Value: 0,
+ },
+ },
+ },
+
+ Expected: []string{
+ `<memory model="dimm" access="private">`,
+ ` <target>`,
+ ` <size unit="GiB">1</size>`,
+ ` <node>0</node>`,
+ ` </target>`,
+ `</memory>`,
+ },
+ },
}
func TestDomain(t *testing.T) {
--
2.7.4