summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--addDroplet.go142
1 files changed, 138 insertions, 4 deletions
diff --git a/addDroplet.go b/addDroplet.go
index 4266907..4ab7454 100644
--- a/addDroplet.go
+++ b/addDroplet.go
@@ -3,14 +3,17 @@
package main
import (
+ "encoding/xml"
"errors"
"fmt"
+ "os"
pb "go.wit.com/lib/protobuf/virtbuf"
"go.wit.com/log"
"libvirt.org/go/libvirtxml"
)
+// import a libvirt xml file
func addDomainDroplet(domcfg *libvirtxml.Domain) (*DropletT, error) {
if domcfg == nil {
return nil, errors.New("domcfg == nil")
@@ -40,6 +43,136 @@ func addDomainDroplet(domcfg *libvirtxml.Domain) (*DropletT, error) {
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)
return d, nil
}
@@ -92,7 +225,8 @@ func updateDroplet(d *DropletT, domcfg *libvirtxml.Domain) bool {
// check cpus
if d.pb.Cpus != int64(domcfg.VCPU.Value) {
- fmt.Printf("cpus changed. VCPU = %+v\n", domcfg.VCPU)
+ // fmt.Printf("cpus changed. VCPU = %+v\n", domcfg.VCPU)
+ fmt.Printf("cpus changed. from %d to %d\n", d.pb.Cpus, domcfg.VCPU.Value)
d.pb.Cpus = int64(domcfg.VCPU.Value)
me.changed = true
}
@@ -128,7 +262,7 @@ func updateMemory(d *DropletT, domcfg *libvirtxml.Domain) bool {
if d.pb.Memory != m {
d.pb.Memory = m
me.changed = true
- fmt.Printf("Memory changed %d, %d %s\n", d.pb.Memory, domcfg.Memory.Value, domcfg.Memory.Unit)
+ fmt.Printf("Memory changed %s to %d %s\n", pb.HumanFormatBytes(d.pb.Memory), domcfg.Memory.Value, domcfg.Memory.Unit)
}
return true
}
@@ -139,7 +273,7 @@ func updateMemory(d *DropletT, domcfg *libvirtxml.Domain) bool {
if d.pb.Memory != m {
d.pb.Memory = m
me.changed = true
- fmt.Printf("Memory changed %d, %d %s\n", d.pb.Memory, domcfg.Memory.Value, domcfg.Memory.Unit)
+ fmt.Printf("Memory changed %s to %d %s\n", pb.HumanFormatBytes(d.pb.Memory), domcfg.Memory.Value, domcfg.Memory.Unit)
}
return true
}
@@ -150,7 +284,7 @@ func updateMemory(d *DropletT, domcfg *libvirtxml.Domain) bool {
if d.pb.Memory != m {
d.pb.Memory = m
me.changed = true
- fmt.Printf("Memory changed %d, %d %s\n", d.pb.Memory, domcfg.Memory.Value, domcfg.Memory.Unit)
+ fmt.Printf("Memory changed %d, %d %s\n", pb.HumanFormatBytes(d.pb.Memory), domcfg.Memory.Value, domcfg.Memory.Unit)
}
return true
}