make something to dump out all the 'standard' xml
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
367addedff
commit
8a1321169e
134
addDroplet.go
134
addDroplet.go
|
@ -3,10 +3,8 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/xml"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
|
|
||||||
pb "go.wit.com/lib/protobuf/virtbuf"
|
pb "go.wit.com/lib/protobuf/virtbuf"
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
|
@ -42,137 +40,9 @@ func addDomainDroplet(domcfg *libvirtxml.Domain) (*DropletT, error) {
|
||||||
log.Info("updateDroplet() failed for", d.pb.Hostname)
|
log.Info("updateDroplet() failed for", d.pb.Hostname)
|
||||||
return d, errors.New("update failed for " + domcfg.Name)
|
return d, errors.New("update failed for " + domcfg.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Info("added new droplet", domcfg.Name, domcfg.UUID)
|
log.Info("added new droplet", domcfg.Name, domcfg.UUID)
|
||||||
|
dumpNonStandardXML(domcfg)
|
||||||
// Add more parts you are interested in
|
|
||||||
fmt.Printf("CPU Model: %+v\n", domcfg.CPU)
|
|
||||||
|
|
||||||
// dump all the clock stuff if it's standard
|
|
||||||
var normalclock bool = true
|
|
||||||
if domcfg.Clock.Offset != "utc" {
|
|
||||||
normalclock = false
|
|
||||||
}
|
|
||||||
for i, t := range domcfg.Clock.Timer {
|
|
||||||
// fmt.Printf("Test Clock Timer: %d , %s , %+v\n", i, t.Name, t)
|
|
||||||
switch t.Name {
|
|
||||||
case "rtc":
|
|
||||||
if t.TickPolicy != "catchup" {
|
|
||||||
fmt.Printf("Clock Name: %+v , %+v\n", i, t)
|
|
||||||
normalclock = false
|
|
||||||
}
|
|
||||||
case "pit":
|
|
||||||
if t.TickPolicy != "delay" {
|
|
||||||
fmt.Printf("Clock Name: %+v , %+v\n", i, t)
|
|
||||||
normalclock = false
|
|
||||||
}
|
|
||||||
case "hpet":
|
|
||||||
if t.Present != "no" {
|
|
||||||
fmt.Printf("Clock Name: %+v , %+v\n", i, t)
|
|
||||||
normalclock = false
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
fmt.Printf("Clock Name: %+v , %+v\n", i, t)
|
|
||||||
normalclock = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if normalclock {
|
|
||||||
domcfg.Clock = nil
|
|
||||||
} else {
|
|
||||||
fmt.Printf("Clock was 'nonstandard' %+v\n", domcfg.Clock.Timer)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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
|
|
||||||
} else {
|
|
||||||
featurematch = false
|
|
||||||
}
|
|
||||||
// ignore if APIC is set or not
|
|
||||||
if domcfg.Features.APIC != nil {
|
|
||||||
domcfg.Features.APIC = nil
|
|
||||||
} else {
|
|
||||||
featurematch = false
|
|
||||||
}
|
|
||||||
// what is VMPort anyway?
|
|
||||||
if domcfg.Features.VMPort.State == "off" {
|
|
||||||
domcfg.Features.VMPort = nil
|
|
||||||
} else {
|
|
||||||
featurematch = false
|
|
||||||
}
|
|
||||||
// screwit, if all three of those match just erase
|
|
||||||
// this. not sure what uses it anyway but it's probably obscure
|
|
||||||
// and I'm not using it on any of my machines right now
|
|
||||||
// also, this is dumb that I'm doing this but I want to
|
|
||||||
// fine tooth comb through this right now
|
|
||||||
// also, I don't have a boss so nobody can tell me what to do
|
|
||||||
if featurematch {
|
|
||||||
domcfg.Features = nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// fmt.Printf("Features: %+v\n", domcfg.Features)
|
|
||||||
|
|
||||||
// for i, f := range domcfg.Features {
|
|
||||||
// fmt.Printf("Feature: %+v , %+v\n", i, f)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// these should always just be strings?
|
|
||||||
domcfg.Name = ""
|
|
||||||
domcfg.UUID = ""
|
|
||||||
|
|
||||||
// todo: actually check these for anything different
|
|
||||||
domcfg.Memory = nil
|
|
||||||
domcfg.CurrentMemory = nil
|
|
||||||
domcfg.VCPU = nil
|
|
||||||
|
|
||||||
// clear out this crap
|
|
||||||
if domcfg.OnPoweroff == "destroy" {
|
|
||||||
domcfg.OnPoweroff = ""
|
|
||||||
}
|
|
||||||
if domcfg.OnCrash == "destroy" {
|
|
||||||
domcfg.OnCrash = ""
|
|
||||||
}
|
|
||||||
if domcfg.OnReboot == "restart" {
|
|
||||||
domcfg.OnReboot = ""
|
|
||||||
}
|
|
||||||
|
|
||||||
// only keep non-qemu stuff
|
|
||||||
var qemu bool = true
|
|
||||||
for _, disk := range domcfg.Devices.Disks {
|
|
||||||
if disk.Driver.Name != "qemu" {
|
|
||||||
fmt.Printf("- Disk: %s, Device: %s, Source: %s\n", disk.Device, disk.Driver.Name, disk.Source.File.File)
|
|
||||||
fmt.Printf("FOUND NON QEMU DISK\n")
|
|
||||||
fmt.Printf("FOUND NON QEMU DISKS\n")
|
|
||||||
qemu = false
|
|
||||||
} else {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if qemu {
|
|
||||||
domcfg.Devices.Disks = nil
|
|
||||||
} else {
|
|
||||||
// fmt.Printf("FOUND NON QEMU DISKS\n")
|
|
||||||
}
|
|
||||||
|
|
||||||
domcfg.Devices.Interfaces = nil
|
|
||||||
for _, iface := range domcfg.Devices.Interfaces {
|
|
||||||
fmt.Printf("- Network Interface: %+v\n", iface)
|
|
||||||
}
|
|
||||||
for _, controller := range domcfg.Devices.Controllers {
|
|
||||||
fmt.Printf("- Controller: Type: %s, Index: %d\n", controller.Type, controller.Index)
|
|
||||||
}
|
|
||||||
|
|
||||||
updatedXML, err := xml.MarshalIndent(domcfg, "", " ")
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Failed to marshal updated XML: %v\n", err)
|
|
||||||
os.Exit(-1)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Print the updated XML to verify
|
|
||||||
fmt.Println(string(updatedXML))
|
|
||||||
os.Exit(-1)
|
|
||||||
return d, nil
|
return d, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
136
xml.go
136
xml.go
|
@ -3,6 +3,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/xml"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
@ -186,3 +187,138 @@ func setRandomMacs(domcfg *libvirtxml.Domain) {
|
||||||
fmt.Printf("mac addr %s\n", x.MAC.Address)
|
fmt.Printf("mac addr %s\n", x.MAC.Address)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// just 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
|
||||||
|
func dumpNonStandardXML(domcfg *libvirtxml.Domain) {
|
||||||
|
// Add more parts you are interested in
|
||||||
|
fmt.Printf("CPU Model: %+v\n", domcfg.CPU)
|
||||||
|
|
||||||
|
// dump all the clock stuff if it's standard
|
||||||
|
var normalclock bool = true
|
||||||
|
if domcfg.Clock.Offset != "utc" {
|
||||||
|
normalclock = false
|
||||||
|
}
|
||||||
|
for i, t := range domcfg.Clock.Timer {
|
||||||
|
// fmt.Printf("Test Clock Timer: %d , %s , %+v\n", i, t.Name, t)
|
||||||
|
switch t.Name {
|
||||||
|
case "rtc":
|
||||||
|
if t.TickPolicy != "catchup" {
|
||||||
|
fmt.Printf("Clock Name: %+v , %+v\n", i, t)
|
||||||
|
normalclock = false
|
||||||
|
}
|
||||||
|
case "pit":
|
||||||
|
if t.TickPolicy != "delay" {
|
||||||
|
fmt.Printf("Clock Name: %+v , %+v\n", i, t)
|
||||||
|
normalclock = false
|
||||||
|
}
|
||||||
|
case "hpet":
|
||||||
|
if t.Present != "no" {
|
||||||
|
fmt.Printf("Clock Name: %+v , %+v\n", i, t)
|
||||||
|
normalclock = false
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
fmt.Printf("Clock Name: %+v , %+v\n", i, t)
|
||||||
|
normalclock = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if normalclock {
|
||||||
|
domcfg.Clock = nil
|
||||||
|
} else {
|
||||||
|
fmt.Printf("Clock was 'nonstandard' %+v\n", domcfg.Clock.Timer)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
} else {
|
||||||
|
featurematch = false
|
||||||
|
}
|
||||||
|
// ignore if APIC is set or not
|
||||||
|
if domcfg.Features.APIC != nil {
|
||||||
|
domcfg.Features.APIC = nil
|
||||||
|
} else {
|
||||||
|
featurematch = false
|
||||||
|
}
|
||||||
|
// what is VMPort anyway?
|
||||||
|
if domcfg.Features.VMPort.State == "off" {
|
||||||
|
domcfg.Features.VMPort = nil
|
||||||
|
} else {
|
||||||
|
featurematch = false
|
||||||
|
}
|
||||||
|
// screwit, if all three of those match just erase
|
||||||
|
// this. not sure what uses it anyway but it's probably obscure
|
||||||
|
// and I'm not using it on any of my machines right now
|
||||||
|
// also, this is dumb that I'm doing this but I want to
|
||||||
|
// fine tooth comb through this right now
|
||||||
|
// also, I don't have a boss so nobody can tell me what to do
|
||||||
|
if featurematch {
|
||||||
|
domcfg.Features = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// fmt.Printf("Features: %+v\n", domcfg.Features)
|
||||||
|
|
||||||
|
// for i, f := range domcfg.Features {
|
||||||
|
// fmt.Printf("Feature: %+v , %+v\n", i, f)
|
||||||
|
// }
|
||||||
|
|
||||||
|
// these should always just be strings?
|
||||||
|
domcfg.Name = ""
|
||||||
|
domcfg.UUID = ""
|
||||||
|
|
||||||
|
// todo: actually check these for anything different
|
||||||
|
domcfg.Memory = nil
|
||||||
|
domcfg.CurrentMemory = nil
|
||||||
|
domcfg.VCPU = nil
|
||||||
|
|
||||||
|
// clear out this crap
|
||||||
|
if domcfg.OnPoweroff == "destroy" {
|
||||||
|
domcfg.OnPoweroff = ""
|
||||||
|
}
|
||||||
|
if domcfg.OnCrash == "destroy" {
|
||||||
|
domcfg.OnCrash = ""
|
||||||
|
}
|
||||||
|
if domcfg.OnReboot == "restart" {
|
||||||
|
domcfg.OnReboot = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// only keep non-qemu stuff
|
||||||
|
var qemu bool = true
|
||||||
|
for _, disk := range domcfg.Devices.Disks {
|
||||||
|
if disk.Driver.Name != "qemu" {
|
||||||
|
fmt.Printf("- Disk: %s, Device: %s, Source: %s\n", disk.Device, disk.Driver.Name, disk.Source.File.File)
|
||||||
|
fmt.Printf("FOUND NON QEMU DISK\n")
|
||||||
|
fmt.Printf("FOUND NON QEMU DISKS\n")
|
||||||
|
qemu = false
|
||||||
|
} else {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if qemu {
|
||||||
|
domcfg.Devices.Disks = nil
|
||||||
|
} else {
|
||||||
|
// fmt.Printf("FOUND NON QEMU DISKS\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
domcfg.Devices.Interfaces = nil
|
||||||
|
for _, iface := range domcfg.Devices.Interfaces {
|
||||||
|
fmt.Printf("- Network Interface: %+v\n", iface)
|
||||||
|
}
|
||||||
|
for _, controller := range domcfg.Devices.Controllers {
|
||||||
|
fmt.Printf("- Controller: Type: %s, Index: %d\n", controller.Type, controller.Index)
|
||||||
|
}
|
||||||
|
|
||||||
|
updatedXML, err := xml.MarshalIndent(domcfg, "", " ")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Failed to marshal updated XML: %v\n", err)
|
||||||
|
os.Exit(-1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print the updated XML to verify
|
||||||
|
fmt.Println(string(updatedXML))
|
||||||
|
os.Exit(-1)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue