domain.go | 36 ++++++++++++++++++++++++++++++++++++ domain_test.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+)
Signed-off-by: zhenwei.pi <zhenwei.pi@youruncloud.com>
---
domain.go | 36 ++++++++++++++++++++++++++++++++++++
domain_test.go | 44 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 80 insertions(+)
diff --git a/domain.go b/domain.go
index bead49a..1bcc9cc 100644
--- a/domain.go
+++ b/domain.go
@@ -407,6 +407,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"`
@@ -422,6 +445,7 @@ type DomainDeviceList struct {
MemBalloon *DomainMemBalloon `xml:"memballoon"`
Sounds []DomainSound `xml:"sound"`
RNGs []DomainRNG `xml:"rng"`
+ Hostdevs []DomainHostdev `xml:"hostdev"`
}
type DomainMemory struct {
@@ -794,6 +818,18 @@ 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
+}
+
type HexUint uint
func (h *HexUint) UnmarshalXMLAttr(attr xml.Attr) error {
diff --git a/domain_test.go b/domain_test.go
index d1b107d..73dd47b 100644
--- a/domain_test.go
+++ b/domain_test.go
@@ -37,6 +37,13 @@ type Address struct {
Function HexUint
}
+type ScsiAddress struct {
+ Controller uint
+ Bus HexUint
+ Target uint
+ Unit uint
+}
+
var uhciIndex uint = 0
var uhciAddr = Address{0, 0, 1, 2}
@@ -46,6 +53,7 @@ var videoAddr = Address{0, 0, 5, 0}
var fsAddr = Address{0, 0, 6, 0}
var balloonAddr = Address{0, 0, 7, 0}
var duplexAddr = Address{0, 0, 8, 0}
+var hostdevScsi = ScsiAddress{0, 0, 3, 0}
var serialPort uint = 0
var tabletBus HexUint = 0
@@ -1457,6 +1465,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: &hostdevScsi.Bus,
+ Target: &hostdevScsi.Target,
+ Unit: &hostdevScsi.Unit,
+ },
+ },
+ Address: &DomainAddress{
+ Type: "drive",
+ Controller: &hostdevScsi.Controller,
+ Bus: &hostdevScsi.Bus,
+ Target: &hostdevScsi.Target,
+ Unit: &hostdevScsi.Unit,
+ },
+ },
+
+ 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
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
On Fri, Sep 15, 2017 at 02:12:44PM +0800, zhenwei.pi wrote:
> Signed-off-by: zhenwei.pi <zhenwei.pi@youruncloud.com>
> ---
> domain.go | 36 ++++++++++++++++++++++++++++++++++++
> domain_test.go | 44 ++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 80 insertions(+)
>
> diff --git a/domain.go b/domain.go
> index bead49a..1bcc9cc 100644
> --- a/domain.go
> +++ b/domain.go
> @@ -407,6 +407,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"`
This should be WWPN
> + 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"`
SGIO
> + Rawio string `xml:"rawio,attr,omitempty"`
And RawIO
> + Managed string `xml:"managed,attr,omitempty"`
> + Source *DomainHostdevSource `xml:"source"`
> + Address *DomainAddress `xml:"address"`
> +}
> diff --git a/domain_test.go b/domain_test.go
> index d1b107d..73dd47b 100644
> --- a/domain_test.go
> +++ b/domain_test.go
> @@ -37,6 +37,13 @@ type Address struct {
> Function HexUint
> }
>
> +type ScsiAddress struct {
Should be SCSI
ACK, and I'll fix the capitalization when pushing
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
© 2016 - 2026 Red Hat, Inc.