summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--addDroplet.go134
-rw-r--r--xml.go136
2 files changed, 138 insertions, 132 deletions
diff --git a/addDroplet.go b/addDroplet.go
index 4ab7454..d4b426d 100644
--- a/addDroplet.go
+++ b/addDroplet.go
@@ -3,10 +3,8 @@
package main
import (
- "encoding/xml"
"errors"
"fmt"
- "os"
pb "go.wit.com/lib/protobuf/virtbuf"
"go.wit.com/log"
@@ -42,137 +40,9 @@ func addDomainDroplet(domcfg *libvirtxml.Domain) (*DropletT, error) {
log.Info("updateDroplet() failed for", d.pb.Hostname)
return d, errors.New("update failed for " + domcfg.Name)
}
- log.Info("added new droplet", domcfg.Name, domcfg.UUID)
-
- // 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)
+ log.Info("added new droplet", domcfg.Name, domcfg.UUID)
+ dumpNonStandardXML(domcfg)
return d, nil
}
diff --git a/xml.go b/xml.go
index 86157d2..be9ac28 100644
--- a/xml.go
+++ b/xml.go
@@ -3,6 +3,7 @@
package main
import (
+ "encoding/xml"
"fmt"
"os"
@@ -186,3 +187,138 @@ func setRandomMacs(domcfg *libvirtxml.Domain) {
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)
+}