xml generation works

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-10-26 12:32:37 -05:00
parent 783a06b050
commit 07ef0b9f5b
4 changed files with 20 additions and 6 deletions

13
http.go
View File

@ -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")

View File

@ -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)

View File

@ -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 {