From c9ccf688c27749dfbab31004b6258dbb759962b2 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Fri, 18 Oct 2024 07:40:06 -0500 Subject: [PATCH] start simple xml handling Signed-off-by: Jeff Carr --- Makefile | 2 +- argv.go | 3 ++- main.go | 4 ++-- poll.go | 4 ++-- resources/xml/jcarr.xml | 2 ++ xml.go | 24 ++++++++++++++++++++++-- 6 files changed, 31 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 8450c66..b3133ae 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ REDOMOD = $(shell if [ -e go.sum ]; then echo go.sum exists; else GO111MODULE= all: GO111MODULE=off go build -v -ldflags "-X main.Version=${VERSION} -X gui.GUIVERSION=${VERSION}" ./virtigo --version - ./virtigo --hosts farm01 farm02 farm03 + # ./virtigo --hosts farm01 farm02 farm03 ./virtigo --start jcarr start-all-droplets: diff --git a/argv.go b/argv.go index b656bee..003f170 100644 --- a/argv.go +++ b/argv.go @@ -33,6 +33,7 @@ func (args) Version() string { var INFO *log.LogFlag var POLL *log.LogFlag var WARN *log.LogFlag +var SPEW *log.LogFlag var EVENT *log.LogFlag func init() { @@ -41,6 +42,6 @@ func init() { INFO = log.NewFlag("INFO", false, full, short, "general virtigo") POLL = log.NewFlag("POLL", false, full, short, "virtigo polling") - WARN = log.NewFlag("WARN", true, full, short, "bad things") + SPEW = log.NewFlag("SPEW", true, full, short, "bad things") EVENT = log.NewFlag("EVENT", true, full, short, "hypeprvisor/droplet events") } diff --git a/main.go b/main.go index 1c62669..ce4823a 100644 --- a/main.go +++ b/main.go @@ -51,8 +51,8 @@ func main() { log.Info("droplet is unknown:", argv.Start) os.Exit(0) } - log.Info("start droplet here:", d.Hostname) - makeXml(d) + log.Info("start droplet here:", d.Hostname) + makeStandardXml(d) os.Exit(0) } diff --git a/poll.go b/poll.go index b4e7654..276332b 100644 --- a/poll.go +++ b/poll.go @@ -59,12 +59,12 @@ func (h *HyperT) pollHypervisor() { // this should mean a droplet is running where the config file says it probably should be running if d.hyperPreferred == h.Hostname { - log.Log(EVENT, "new droplet", d.Hostname, "(matches config hypervisor", h.Hostname + ")") + log.Log(EVENT, "new droplet", d.Hostname, "(matches config hypervisor", h.Hostname+")") d.hname = h.Hostname continue } - log.Log(EVENT, "new droplet", d.Hostname, "on", h.Hostname, "(in config file without preferred hypervisor)") + log.Log(EVENT, "new droplet", d.Hostname, "on", h.Hostname, "(in config file without preferred hypervisor)") } d.hname = h.Hostname } diff --git a/resources/xml/jcarr.xml b/resources/xml/jcarr.xml index 0e55c25..14f44af 100644 --- a/resources/xml/jcarr.xml +++ b/resources/xml/jcarr.xml @@ -1,4 +1,6 @@ jcarr c8684902-c405-4f31-b532-128c277056cc + 4 + 8 diff --git a/xml.go b/xml.go index 2b1e7bb..dc856b3 100644 --- a/xml.go +++ b/xml.go @@ -10,21 +10,41 @@ import ( "libvirt.org/go/libvirtxml" ) -func makeXml(d *DropletT) { +func makeStandardXml(d *DropletT) { log.Info("create new xml file for:", d.Hostname) domcfg := &libvirtxml.Domain{} - addDefaults(domcfg, d.Hostname) addDefaults(domcfg, "standard.x86") addDefaults(domcfg, "memory") addDefaults(domcfg, "network") addDefaults(domcfg, "spice") addDefaults(domcfg, "qcow") + addDefaults(domcfg, d.Hostname) fmt.Printf("Virt type %s\n", domcfg.Type) fmt.Printf("Virt name %s\n", domcfg.Name) fmt.Printf("Virt UUID %s\n", domcfg.UUID) fmt.Printf("Virt Memory %s\n", domcfg.Memory) + // domcfg.Memory = 3333 + fmt.Printf("Virt Devices %s\n", domcfg.Devices.Disks) + // log.Spew(domcfg.Devices) + // fmt.Printf("Virt Devices %s\n", domcfg.DiskDriver) + log.Info("DISKS") + log.Info("DISKS") + log.Info("") + // structure DomainDeviceList shows what can be done as a range + for i, x := range domcfg.Devices.Disks { + // Create a new DomainDiskSourceFile struct + newSource := &libvirtxml.DomainDiskSourceFile{ + File: "mynew.qcow2", // Set the file name here + } + + // Assign it to the disk's source + domcfg.Devices.Disks[i].Source.File = newSource + + // fmt.Printf("Disk Source %s\n", name) + fmt.Printf("Disk Device %s\n", x.Source.File) + } xmldoc, err := domcfg.Marshal()