[libvirt] [PATCH go-xml] Added domain OS struct and tests

Alexey Slaykovsky aslaikov at redhat.com
Thu Jan 5 08:54:25 UTC 2017


Signed-off-by: Alexey Slaykovsky <aslaikov at redhat.com>
---
 domain.go      |  68 ++++++++++++++++++++++++
 domain_test.go | 164 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 232 insertions(+)

diff --git a/domain.go b/domain.go
index c98908e..25155ee 100644
--- a/domain.go
+++ b/domain.go
@@ -126,6 +126,69 @@ type DomainMemory struct {
 	Unit  string `xml:"unit,attr"`
 }
 
+type DomainOSType struct {
+	Arch    string `xml:"arch,attr"`
+	Machine string `xml:"machine,attr"`
+	Type    string `xml:",chardata"`
+}
+
+type DomainSMBios struct {
+	Mode string `xml:"mode,attr"`
+}
+
+type DomainNVRam struct {
+	NVRam    string `xml:",chardata"`
+	Template string `xml:"template,attr,omitempty"`
+}
+
+type DomainBootDevice struct {
+	Dev string `xml:"dev,attr"`
+}
+
+type DomainBootMenu struct {
+	Enabled string `xml:"enabled,attr"`
+	Timeout string `xml:"timeout,attr,omitempty"`
+}
+
+type DomainSysInfo struct {
+	Type      string        `xml:"type,attr"`
+	System    []DomainEntry `xml:"system>entry"`
+	BIOS      []DomainEntry `xml:"bios>entry"`
+	BaseBoard []DomainEntry `xml:"baseBoard>entry"`
+}
+
+type DomainEntry struct {
+	Name  string `xml:"name,attr"`
+	Value string `xml:",chardata"`
+}
+
+type DomainBIOS struct {
+	UseSerial     string `xml:"useserial,attr"`
+	RebootTimeout string `xml:"rebootTimeout,attr"`
+}
+
+type DomainLoader struct {
+	Path     string `xml:",chardata"`
+	Readonly string `xml:"readonly,attr"`
+	Secure   string `xml:"secure,attr"`
+	Type     string `xml:"type,attr"`
+}
+
+type DomainOS struct {
+	Type        *DomainOSType      `xml:"type"`
+	Loader      *DomainLoader      `xml:"loader,omitempty"`
+	NVRam       *DomainNVRam       `xml:"nvram"`
+	Kernel      string             `xml:"kernel,omitempty"`
+	Initrd      string             `xml:"initrd,omitempty"`
+	KernelArgs  string             `xml:"cmdline,omitempty"`
+	BootDevices []DomainBootDevice `xml:"boot"`
+	BootMenu    *DomainBootMenu    `xml:"bootmenu,omitempty"`
+	SMBios      *DomainSMBios      `xml:"smbios,omitempty"`
+	BIOS        *DomainBIOS        `xml:"bios,omitempty"`
+	Init        string             `xml:"init,omitempty"`
+	InitArgs    []string           `xml:"initarg,omitempty"`
+}
+
 type Domain struct {
 	XMLName       xml.Name          `xml:"domain"`
 	Type          string            `xml:"type,attr"`
@@ -134,4 +197,9 @@ type Domain struct {
 	Memory        *DomainMemory     `xml:"memory"`
 	CurrentMemory *DomainMemory     `xml:"currentMemory"`
 	Devices       *DomainDeviceList `xml:"devices"`
+	OS            *DomainOS         `xml:"os,omitempty"`
+	SysInfo       *DomainSysInfo    `xml:"sysinfo,omitempty"`
+	OnPoweroff    string            `xml:"on_poweroff,omitempty"`
+	OnReboot      string            `xml:"on_reboot,omitempty"`
+	OnCrash       string            `xml:"on_crash,omitempty"`
 }
diff --git a/domain_test.go b/domain_test.go
index e403aeb..8ee9699 100644
--- a/domain_test.go
+++ b/domain_test.go
@@ -121,6 +121,170 @@ var domainTestData = []struct {
 			`</domain>`,
 		},
 	},
+	{
+		Object: &Domain{
+			Type: "kvm",
+			Name: "test",
+			Memory: &DomainMemory{
+				Unit:  "KiB",
+				Value: "8192",
+			},
+			CurrentMemory: &DomainMemory{
+				Unit:  "KiB",
+				Value: "4096",
+			},
+			OS: &DomainOS{
+				Type: &DomainOSType{
+					Arch:    "x86_64",
+					Machine: "pc",
+					Type:    "hvm",
+				},
+				BootDevices: []DomainBootDevice{
+					DomainBootDevice{
+						Dev: "hd",
+					},
+				},
+				Loader: &DomainLoader{
+					Readonly: "yes",
+					Secure:   "no",
+					Type:     "rom",
+					Path:     "/loader",
+				},
+				SMBios: &DomainSMBios{
+					Mode: "sysinfo",
+				},
+				BIOS: &DomainBIOS{
+					UseSerial:     "yes",
+					RebootTimeout: "0",
+				},
+				Init: "/bin/systemd",
+				InitArgs: []string{
+					"--unit",
+					"emergency.service",
+				},
+			},
+			SysInfo: &DomainSysInfo{
+				Type: "smbios",
+				BIOS: []DomainEntry{
+					DomainEntry{
+						Name:  "vendor",
+						Value: "vendor",
+					},
+				},
+				System: []DomainEntry{
+					DomainEntry{
+						Name:  "manufacturer",
+						Value: "manufacturer",
+					},
+					DomainEntry{
+						Name:  "product",
+						Value: "product",
+					},
+					DomainEntry{
+						Name:  "version",
+						Value: "version",
+					},
+				},
+				BaseBoard: []DomainEntry{
+					DomainEntry{
+						Name:  "manufacturer",
+						Value: "manufacturer",
+					},
+					DomainEntry{
+						Name:  "product",
+						Value: "product",
+					},
+					DomainEntry{
+						Name:  "version",
+						Value: "version",
+					},
+					DomainEntry{
+						Name:  "serial",
+						Value: "serial",
+					},
+				},
+			},
+		},
+		Expected: []string{
+			`<domain type="kvm">`,
+			`  <name>test</name>`,
+			`  <memory unit="KiB">8192</memory>`,
+			`  <currentMemory unit="KiB">4096</currentMemory>`,
+			`  <os>`,
+			`    <type arch="x86_64" machine="pc">hvm</type>`,
+			`    <loader readonly="yes" secure="no" type="rom">/loader</loader>`,
+			`    <boot dev="hd"></boot>`,
+			`    <smbios mode="sysinfo"></smbios>`,
+			`    <bios useserial="yes" rebootTimeout="0"></bios>`,
+			`    <init>/bin/systemd</init>`,
+			`    <initarg>--unit</initarg>`,
+			`    <initarg>emergency.service</initarg>`,
+			`  </os>`,
+			`  <sysinfo type="smbios">`,
+			`    <system>`,
+			`      <entry name="manufacturer">manufacturer</entry>`,
+			`      <entry name="product">product</entry>`,
+			`      <entry name="version">version</entry>`,
+			`    </system>`,
+			`    <bios>`,
+			`      <entry name="vendor">vendor</entry>`,
+			`    </bios>`,
+			`    <baseBoard>`,
+			`      <entry name="manufacturer">manufacturer</entry>`,
+			`      <entry name="product">product</entry>`,
+			`      <entry name="version">version</entry>`,
+			`      <entry name="serial">serial</entry>`,
+			`    </baseBoard>`,
+			`  </sysinfo>`,
+			`</domain>`,
+		},
+	},
+	{
+		Object: &Domain{
+			Type: "kvm",
+			Name: "test",
+			OS: &DomainOS{
+				NVRam: &DomainNVRam{
+					Template: "/t.fd",
+					NVRam:    "/vars.fd",
+				},
+				BootMenu: &DomainBootMenu{
+					Enabled: "yes",
+					Timeout: "3000",
+				},
+			},
+		},
+		Expected: []string{
+			`<domain type="kvm">`,
+			`  <name>test</name>`,
+			`  <os>`,
+			`    <nvram template="/t.fd">/vars.fd</nvram>`,
+			`    <bootmenu enabled="yes" timeout="3000"></bootmenu>`,
+			`  </os>`,
+			`</domain>`,
+		},
+	},
+	{
+		Object: &Domain{
+			Type: "kvm",
+			Name: "test",
+			OS: &DomainOS{
+				Kernel:     "/vmlinuz",
+				Initrd:     "/initrd",
+				KernelArgs: "arg",
+			},
+		},
+		Expected: []string{
+			`<domain type="kvm">`,
+			`  <name>test</name>`,
+			`  <os>`,
+			`    <kernel>/vmlinuz</kernel>`,
+			`    <initrd>/initrd</initrd>`,
+			`    <cmdline>arg</cmdline>`,
+			`  </os>`,
+			`</domain>`,
+		},
+	},
 }
 
 func TestDomain(t *testing.T) {
-- 
2.11.0




More information about the libvir-list mailing list