[libvirt] [PATCH go-xml] Add support for domain hostdev and test code

zhenwei.pi zhenwei.pi at youruncloud.com
Sat Aug 19 06:57:21 UTC 2017


Signed-off-by: zhenwei.pi <zhenwei.pi at youruncloud.com>
---
 domain.go      | 36 ++++++++++++++++++++++++++++++++++++
 domain_test.go | 36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 72 insertions(+)

diff --git a/domain.go b/domain.go
index a5d3203..2c63307 100644
--- a/domain.go
+++ b/domain.go
@@ -406,6 +406,29 @@ type DomainRNG struct {
 	Backend *DomainRNGBackend `xml:"backend"`
 }
 
+type DomainHostdevAdapter struct {
+	Name string `xml:"name,attr,omitempty"`
+}
+
+type DomainHostdevSource struct {
+	Protocol string                `xml:"protocol,attr,omitempty"`
+	Name     string                `xml:"name,attr,omitempty"`
+	Wwpn     string                `xml:"wwpn,attr,omitempty"`
+	Adapter  *DomainHostdevAdapter `xml:"adapter"`
+	Address  *DomainAddress        `xml:"address"`
+}
+
+type DomainHostdev struct {
+	XMLName xml.Name             `xml:"hostdev"`
+	Mode    string               `xml:"mode,attr"`
+	Type    string               `xml:"type,attr"`
+	Sgio    string               `xml:"sgio,attr,omitempty"`
+	Rawio   string               `xml:"rawio,attr,omitempty"`
+	Managed string               `xml:"managed,attr,omitempty"`
+	Source  *DomainHostdevSource `xml:"source"`
+	Address *DomainAddress       `xml:"address"`
+}
+
 type DomainDeviceList struct {
 	Emulator    string             `xml:"emulator,omitempty"`
 	Controllers []DomainController `xml:"controller"`
@@ -421,6 +444,7 @@ type DomainDeviceList struct {
 	MemBalloon  *DomainMemBalloon  `xml:"memballoon"`
 	Sounds      []DomainSound      `xml:"sound"`
 	RNGs        []DomainRNG        `xml:"rng"`
+	Hostdevs    []DomainHostdev    `xml:"hostdev"`
 }
 
 type DomainMemory struct {
@@ -792,3 +816,15 @@ func (d *DomainRNG) Marshal() (string, error) {
 	}
 	return string(doc), nil
 }
+
+func (d *DomainHostdev) Unmarshal(doc string) error {
+	return xml.Unmarshal([]byte(doc), d)
+}
+
+func (d *DomainHostdev) Marshal() (string, error) {
+	doc, err := xml.MarshalIndent(d, "", "  ")
+	if err != nil {
+		return "", err
+	}
+	return string(doc), nil
+}
diff --git a/domain_test.go b/domain_test.go
index 2af451f..e3abbbf 100644
--- a/domain_test.go
+++ b/domain_test.go
@@ -1457,6 +1457,42 @@ var domainTestData = []struct {
 			`</rng>`,
 		},
 	},
+	{
+		Object: &DomainHostdev{
+			Mode:  "subsystem",
+			Type:  "scsi",
+			Sgio:  "unfiltered",
+			Rawio: "yes",
+			Source: &DomainHostdevSource{
+				Adapter: &DomainHostdevAdapter{
+					Name: "scsi_host0",
+				},
+				Address: &DomainAddress{
+					Type:   "scsi",
+					Bus:    &diskAddr.Bus,
+					Target: &diskAddr.Slot,
+					Unit:   &diskAddr.Function,
+				},
+			},
+			Address: &DomainAddress{
+				Type:       "drive",
+				Controller: &diskAddr.Domain,
+				Bus:        &diskAddr.Bus,
+				Target:     &diskAddr.Slot,
+				Unit:       &diskAddr.Function,
+			},
+		},
+
+		Expected: []string{
+			`<hostdev mode="subsystem" type="scsi" sgio="unfiltered" rawio="yes">`,
+			`  <source>`,
+			`    <adapter name="scsi_host0"></adapter>`,
+			`    <address type="scsi" bus="0" target="3" unit="0"></address>`,
+			`  </source>`,
+			`  <address type="drive" controller="0" bus="0" target="3" unit="0"></address>`,
+			`</hostdev>`,
+		},
+	},
 }
 
 func TestDomain(t *testing.T) {
-- 
2.7.4




More information about the libvir-list mailing list