summaryrefslogtreecommitdiff
path: root/xml.go
diff options
context:
space:
mode:
Diffstat (limited to 'xml.go')
-rw-r--r--xml.go138
1 files changed, 131 insertions, 7 deletions
diff --git a/xml.go b/xml.go
index be9ac28..e1a2aa5 100644
--- a/xml.go
+++ b/xml.go
@@ -6,6 +6,7 @@ import (
"encoding/xml"
"fmt"
"os"
+ "reflect"
"go.wit.com/log"
"libvirt.org/go/libvirtxml"
@@ -188,9 +189,10 @@ func setRandomMacs(domcfg *libvirtxml.Domain) {
}
}
-// just go through the libvirt xml object and dump out everything
+// go through the libvirt xml object and dump out everything
// that is "standard". This is just a way to double check that
// there might be something interesting in a VM
+// 'standard' here means what I think is standard
func dumpNonStandardXML(domcfg *libvirtxml.Domain) {
// Add more parts you are interested in
fmt.Printf("CPU Model: %+v\n", domcfg.CPU)
@@ -229,10 +231,10 @@ func dumpNonStandardXML(domcfg *libvirtxml.Domain) {
fmt.Printf("Clock was 'nonstandard' %+v\n", domcfg.Clock.Timer)
}
+ // probably just dump Features for now
// fmt.Printf("Features: %+v\n", domcfg.Features)
// fmt.Printf("Feature VMPort: %+v\n", domcfg.Features.VMPort)
// ignore if ACPI is set or not
-
var featurematch bool = true
if domcfg.Features.ACPI != nil {
domcfg.Features.ACPI = nil
@@ -276,7 +278,7 @@ func dumpNonStandardXML(domcfg *libvirtxml.Domain) {
domcfg.CurrentMemory = nil
domcfg.VCPU = nil
- // clear out this crap
+ // this will move elsewhere in the protobuf someday
if domcfg.OnPoweroff == "destroy" {
domcfg.OnPoweroff = ""
}
@@ -286,6 +288,8 @@ func dumpNonStandardXML(domcfg *libvirtxml.Domain) {
if domcfg.OnReboot == "restart" {
domcfg.OnReboot = ""
}
+ // same with PM. move to protobuf
+ domcfg.PM = nil
// only keep non-qemu stuff
var qemu bool = true
@@ -304,12 +308,132 @@ func dumpNonStandardXML(domcfg *libvirtxml.Domain) {
// fmt.Printf("FOUND NON QEMU DISKS\n")
}
+ // network interfaces get processed elsewhere
domcfg.Devices.Interfaces = nil
- for _, iface := range domcfg.Devices.Interfaces {
- fmt.Printf("- Network Interface: %+v\n", iface)
- }
+
+ // look for strange stuff here
+ var normalPCI bool = true
+ var keepPCI []libvirtxml.DomainController
for _, controller := range domcfg.Devices.Controllers {
- fmt.Printf("- Controller: Type: %s, Index: %d\n", controller.Type, controller.Index)
+ switch controller.Type {
+ case "usb":
+ switch controller.Model {
+ case "ich9-ehci1":
+ fmt.Printf("OK USB: %s, %d\n", controller.Model, *controller.Index)
+ case "ich9-uhci1":
+ fmt.Printf("OK USB: %s, %d\n", controller.Model, *controller.Index)
+ case "ich9-uhci2":
+ fmt.Printf("OK USB: %s, %d\n", controller.Model, *controller.Index)
+ case "ich9-uhci3":
+ fmt.Printf("OK USB: %s, %d\n", controller.Model, *controller.Index)
+ default:
+ keepPCI = append(keepPCI, controller)
+ normalPCI = false
+ fmt.Printf("USB: %s, %d\n", controller.Model, *controller.Index)
+ // Domain:0xc0002d2760 Bus:0xc0002d2768 Slot:0xc0002d2770 Function:0xc0002d2778 MultiFunction:
+ pci := controller.Address.PCI
+ fmt.Printf("USB: Domain: %+v Slot %d Function %d\n", *pci.Domain, *pci.Slot, *pci.Function)
+ }
+ case "ide":
+ fmt.Printf("IGNORE IDE\n")
+ case "virtio-serial":
+ fmt.Printf("IGNORE virtio-serial\n")
+ case "scsi":
+ switch controller.Model {
+ case "lsilogic":
+ fmt.Printf("IGNORE SCSI: lsilogic\n")
+ default:
+ keepPCI = append(keepPCI, controller)
+ normalPCI = false
+ }
+ case "pci":
+ fmt.Printf("PCI: %s, %d\n", controller.Model, *controller.Index)
+ // Domain:0xc0002d2760 Bus:0xc0002d2768 Slot:0xc0002d2770 Function:0xc0002d2778 MultiFunction:
+ pci := controller.Address.PCI
+ fmt.Printf("PCI: Domain: %+v Slot %d Function %d\n", *pci.Domain, *pci.Slot, *pci.Function)
+ normalPCI = false
+ keepPCI = append(keepPCI, controller)
+ default:
+ fmt.Printf("? %s: %+v\n", controller.Type, controller)
+ normalPCI = false
+ keepPCI = append(keepPCI, controller)
+ }
+ }
+ if normalPCI {
+ domcfg.Devices.Controllers = nil
+ } else {
+ domcfg.Devices.Controllers = keepPCI
+ }
+
+ // ignore serial and console
+ domcfg.Devices.Serials = nil
+ domcfg.Devices.Consoles = nil
+
+ // ignore sound
+ domcfg.Devices.Sounds = nil
+
+ // ignore input
+ domcfg.Devices.Inputs = nil
+
+ // ignore MemoryBalloon. This is cool, but no mortal humans
+ // are going to use it at this point. By that I mean me.
+ // someday this will be in protobuf?
+ domcfg.Devices.MemBalloon = nil
+
+ if domcfg.Devices.Emulator == "/usr/bin/qemu-system-x86_64" {
+ domcfg.Devices.Emulator = ""
+ }
+
+ // ignore Graphics == Spice when AutoPort = 'yes'
+ var normalSpice bool = true
+ if domcfg.Devices.Graphics != nil {
+ for _, g := range domcfg.Devices.Graphics {
+ if g.Spice != nil {
+ // fmt.Printf("Graphics: %d %+v\n", i, g)
+ var s *libvirtxml.DomainGraphicSpice
+ s = g.Spice
+ // fmt.Printf("Spice: %d %+v %s\n", i, s, s.AutoPort)
+ if s.AutoPort != "yes" {
+ normalSpice = false
+ }
+ } else {
+ normalSpice = false
+ }
+ }
+ }
+ if normalSpice {
+ domcfg.Devices.Graphics = nil
+ }
+
+ // ignore Channels == SpiceVMC
+ normalSpice = true
+ if domcfg.Devices.Channels != nil {
+ for _, c := range domcfg.Devices.Channels {
+ if c.Source != nil {
+ s := c.Source
+ if s != nil {
+ // fmt.Printf("Channels: %+v\n", s.SpiceVMC)
+ } else {
+ fmt.Printf("? Channels: %+v\n", c)
+ normalSpice = false
+ }
+ } else {
+ fmt.Printf("? Channels: %+v\n", c)
+ normalSpice = false
+ }
+ }
+ }
+ if normalSpice {
+ domcfg.Devices.Channels = nil
+ }
+
+ var domain libvirtxml.DomainDeviceList
+ t := reflect.TypeOf(domain)
+
+ fmt.Println("Fields in libvirtxml.DomainDeviceList:")
+ for i := 0; i < t.NumField(); i++ {
+ field := t.Field(i)
+ fmt.Println(field.Name)
}
updatedXML, err := xml.MarshalIndent(domcfg, "", " ")