Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-10-26 19:34:32 -05:00
parent 07ef0b9f5b
commit 970e6c24dc
4 changed files with 39 additions and 5 deletions

View File

@ -16,6 +16,7 @@ release-build:
# makes a .deb package
debian:
rm -f ~/incoming/virtigod*deb
go-deb --no-gui --repo go.wit.com/lib/daemons/virtigod
goimports:
@ -39,3 +40,6 @@ git-clone:
start:
rm -f /tmp/pihole.wit.com.xml
./virtigod --start pihole.wit.com
start-pihole.wit.com-http:
curl --silent http://localhost:8080/start?start=pihole.wit.com

32
http.go
View File

@ -2,11 +2,13 @@ package main
import (
"fmt"
"io/ioutil"
"net/http"
"os"
"strings"
"go.wit.com/lib/gui/shell"
pb "go.wit.com/lib/protobuf/virtbuf"
"go.wit.com/log"
)
@ -24,7 +26,14 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
tmp = cleanURL(r.URL.Path)
log.Info("Got URL:", tmp)
msg, err := ioutil.ReadAll(r.Body) // Read the body as []byte
if err != nil {
fmt.Fprintln(w, "ReadAll() error =", err)
return
}
log.Info("Got URL msg:", string(msg))
log.Info("Got URL jcarr2 tmp:", tmp)
if tmp == "/" {
fmt.Fprintln(w, "OK")
return
@ -59,6 +68,7 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
}
if tmp == "/start" {
fmt.Fprintln(w, "/start jcarr actually doing START")
start := r.URL.Query().Get("start")
xml := "/tmp/" + start + ".xml"
if shell.Unlink(xml) {
@ -67,7 +77,25 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "error =", "file still exists after unlink")
return
}
if err := newStart(start); err != nil {
// fmt.Fprintln(w, "HTTP:", r.Body)
var d *pb.Droplet
// msg, err := ioutil.ReadAll(r.Body) // Read the body as []byte
fmt.Fprintln(w, "/start ReadAll() START")
fmt.Fprintln(w, "msg =", string(msg))
fmt.Fprintln(w, "/start ReadAll() END")
if err != nil {
fmt.Fprintln(w, "START FAILED")
fmt.Fprintln(w, "error =", err)
return
}
fmt.Fprintln(w, "START len(msg) =", len(msg))
// err = d.UnmarshalJSON(msg)
if err != nil {
fmt.Fprintln(w, "START FAILED")
fmt.Fprintln(w, "error =", err)
}
if err := newStart(start, d); err != nil {
fmt.Fprintln(w, "START FAILED")
fmt.Fprintln(w, "error =", err)
return

View File

@ -62,7 +62,8 @@ func main() {
}
if argv.Start != "" {
newStart(argv.Start)
d := me.cluster.FindDroplet(argv.Start)
newStart(argv.Start, d)
os.Exit(0)
}

View File

@ -5,13 +5,14 @@ package main
import (
"errors"
pb "go.wit.com/lib/protobuf/virtbuf"
"go.wit.com/lib/virtigoxml"
"go.wit.com/log"
"libvirt.org/go/libvirtxml"
)
func newStart(start string) error {
d := me.cluster.FindDroplet(start)
func newStart(start string, d *pb.Droplet) error {
// d := me.cluster.FindDroplet(start)
if d == nil {
log.Info("droplet is unknown:", start)
return errors.New("droplet is unknown: " + start)