Add DomainAddressISA for panic device address.
Add DomainPanic.
Add test code.
Signed-off-by: zhenwei.pi <zhenwei.pi(a)youruncloud.com>
---
domain.go | 38 ++++++++++++++++++++++++++++++++++++++
domain_test.go | 28 +++++++++++++++++++++++++---
2 files changed, 63 insertions(+), 3 deletions(-)
diff --git a/domain.go b/domain.go
index f4ef35c..8086e28 100644
--- a/domain.go
+++ b/domain.go
@@ -312,11 +312,16 @@ type DomainAddressDIMM struct {
Base *uint64 `xml:"base,attr"`
}
+type DomainAddressISA struct {
+ Iobase *uint `xml:"iobase,attr"`
+}
+
type DomainAddress struct {
USB *DomainAddressUSB
PCI *DomainAddressPCI
Drive *DomainAddressDrive
DIMM *DomainAddressDIMM
+ ISA *DomainAddressISA
}
type DomainConsole struct {
@@ -403,6 +408,12 @@ type DomainMemBalloon struct {
Address *DomainAddress `xml:"address"`
}
+type DomainPanic struct {
+ XMLName xml.Name `xml:"panic"`
+ Model string `xml:"model,attr"`
+ Address *DomainAddress `xml:"address"`
+}
+
type DomainSoundCodec struct {
Type string `xml:"type,attr"`
}
@@ -486,6 +497,7 @@ type DomainDeviceList struct {
Videos []DomainVideo `xml:"video"`
Channels []DomainChannel `xml:"channel"`
MemBalloon *DomainMemBalloon `xml:"memballoon"`
+ Panics []DomainPanic `xml:"panic"`
Sounds []DomainSound `xml:"sound"`
RNGs []DomainRNG `xml:"rng"`
Hostdevs []DomainHostdev `xml:"hostdev"`
@@ -1058,6 +1070,16 @@ func (a *DomainAddressDIMM) MarshalXML(e *xml.Encoder, start
xml.StartElement) e
return nil
}
+func (a *DomainAddressISA) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
+ start.Attr = append(start.Attr, xml.Attr{
+ xml.Name{Local: "type"}, "isa",
+ })
+ marshallUintAttr(&start, "iobase", a.Iobase, 16)
+ e.EncodeToken(start)
+ e.EncodeToken(start.End())
+ return nil
+}
+
func (a *DomainAddress) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
if a.USB != nil {
return a.USB.MarshalXML(e, start)
@@ -1067,6 +1089,8 @@ func (a *DomainAddress) MarshalXML(e *xml.Encoder, start
xml.StartElement) error
return a.Drive.MarshalXML(e, start)
} else if a.DIMM != nil {
return a.DIMM.MarshalXML(e, start)
+ } else if a.ISA != nil {
+ return a.ISA.MarshalXML(e, start)
} else {
return nil
}
@@ -1173,6 +1197,17 @@ func (a *DomainAddressDIMM) UnmarshalXML(d *xml.Decoder, start
xml.StartElement)
return nil
}
+func (a *DomainAddressISA) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
+ for _, attr := range start.Attr {
+ if attr.Name.Local == "iobase" {
+ if err := unmarshallUintAttr(attr.Value, &a.Iobase, 16); err != nil {
+ return err
+ }
+ }
+ }
+ return nil
+}
+
func (a *DomainAddress) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
var typ string
d.Skip()
@@ -1198,6 +1233,9 @@ func (a *DomainAddress) UnmarshalXML(d *xml.Decoder, start
xml.StartElement) err
} else if typ == "dimm" {
a.DIMM = &DomainAddressDIMM{}
return a.DIMM.UnmarshalXML(d, start)
+ } else if typ == "isa" {
+ a.ISA = &DomainAddressISA{}
+ return a.ISA.UnmarshalXML(d, start)
}
return nil
diff --git a/domain_test.go b/domain_test.go
index 1ad5125..31787a5 100644
--- a/domain_test.go
+++ b/domain_test.go
@@ -45,6 +45,10 @@ type DriveAddress struct {
Unit uint
}
+type ISAAddress struct {
+ Iobase uint
+}
+
var uhciIndex uint = 0
var uhciAddr = PCIAddress{0, 0, 1, 2}
@@ -53,6 +57,7 @@ var ifaceAddr = PCIAddress{0, 0, 4, 0}
var videoAddr = PCIAddress{0, 0, 5, 0}
var fsAddr = PCIAddress{0, 0, 6, 0}
var balloonAddr = PCIAddress{0, 0, 7, 0}
+var panicAddr = ISAAddress{0x505}
var duplexAddr = PCIAddress{0, 0, 8, 0}
var hostdevSCSI = DriveAddress{0, 0, 3, 0}
@@ -303,6 +308,19 @@ var domainTestData = []struct {
},
},
},
+ Panics: []DomainPanic{
+ DomainPanic{
+ Model: "hyperv",
+ },
+ DomainPanic{
+ Model: "isa",
+ Address: &DomainAddress{
+ ISA: &DomainAddressISA{
+ Iobase: &panicAddr.Iobase,
+ },
+ },
+ },
+ },
Consoles: []DomainConsole{
DomainConsole{
Type: "pty",
@@ -433,6 +451,10 @@ var domainTestData = []struct {
` <memballoon model="virtio">`,
` <address type="pci" domain="0x0" bus="0x0"
slot="0x7" function="0x0"></address>`,
` </memballoon>`,
+ ` <panic model="hyperv"></panic>`,
+ ` <panic model="isa">`,
+ ` <address type="isa"
iobase="0x505"></address>`,
+ ` </panic>`,
` <sound model="ich6">`,
` <codec type="duplex"></codec>`,
` <address type="pci" domain="0x0" bus="0x0"
slot="0x8" function="0x0"></address>`,
@@ -1725,9 +1747,9 @@ var domainTestData = []struct {
/* Host Bootloader -- bhyve, Xen */
{
Object: &Domain{
- Type: "bhyve",
- Name: "test",
- Bootloader: "/usr/local/sbin/grub-bhyve",
+ Type: "bhyve",
+ Name: "test",
+ Bootloader: "/usr/local/sbin/grub-bhyve",
BootloaderArgs: "-r cd0 -m /tmp/test-device.map -M 1024M linuxguest",
},
Expected: []string{
--
2.7.4