From 07ef0b9f5bad28d5e280f7cfb55feafd36b35e80 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 26 Oct 2024 12:32:37 -0500 Subject: [PATCH] xml generation works Signed-off-by: Jeff Carr --- http.go | 13 ++++++++++++- main.go | 3 +++ start.go | 8 ++++---- structs.go | 2 +- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/http.go b/http.go index 468f373..63d3f3a 100644 --- a/http.go +++ b/http.go @@ -60,7 +60,18 @@ func okHandler(w http.ResponseWriter, r *http.Request) { if tmp == "/start" { start := r.URL.Query().Get("start") - xml := "/root/jcarr/machines/autostart/" + start + ".xml" + xml := "/tmp/" + start + ".xml" + if shell.Unlink(xml) { + fmt.Fprintln(w, "START FAILED") + fmt.Fprintln(w, "error =", "could not remove existing xml file", xml) + fmt.Fprintln(w, "error =", "file still exists after unlink") + return + } + if err := newStart(start); err != nil { + fmt.Fprintln(w, "START FAILED") + fmt.Fprintln(w, "error =", err) + return + } cmd := []string{"virsh", "create", xml} fmt.Fprintln(w, "Handling URL:", tmp, "start droplet") diff --git a/main.go b/main.go index a72ef74..85e0c80 100644 --- a/main.go +++ b/main.go @@ -57,6 +57,9 @@ func main() { for i, e := range me.cluster.Events { log.Info("Event", i, e) } + for i, d := range me.cluster.Droplets { + log.Info("Event", i, d.Hostname) + } if argv.Start != "" { newStart(argv.Start) diff --git a/start.go b/start.go index fac3435..ada3824 100644 --- a/start.go +++ b/start.go @@ -3,18 +3,18 @@ package main import ( - "os" + "errors" "go.wit.com/lib/virtigoxml" "go.wit.com/log" "libvirt.org/go/libvirtxml" ) -func newStart(start string) { +func newStart(start string) error { d := me.cluster.FindDroplet(start) if d == nil { log.Info("droplet is unknown:", start) - os.Exit(0) + return errors.New("droplet is unknown: " + start) } log.Info("start droplet here:", d.Hostname) domcfg := &libvirtxml.Domain{} @@ -25,7 +25,7 @@ func newStart(start string) { newAddXml(domcfg, "spice") newAddXml(domcfg, "qcow") - virtigoxml.StartDropletXml(me.cluster, d, domcfg, start) + return virtigoxml.GenerateDropletXml(me.cluster, d, domcfg, start) } func newAddXml(domcfg *libvirtxml.Domain, filename string) error { diff --git a/structs.go b/structs.go index ff134aa..a99883a 100644 --- a/structs.go +++ b/structs.go @@ -8,7 +8,7 @@ var me Virtigod // this app's variables type Virtigod struct { - cluster *virtbuf.Cluster + cluster *virtbuf.Cluster // droplets *virtbuf.Droplets // events *virtbuf.Events }