summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-10-27 03:17:34 -0500
committerJeff Carr <[email protected]>2024-10-27 03:17:34 -0500
commitd948581300ecea1b5407662be9e812ddf237e6cf (patch)
treefd3d244edb003686e7fc97f5e2cd65ccb30f7ccc
parent71f83d400048f6d4219793a76a3ffce16b8c63d8 (diff)
add /dumpdroplets
Signed-off-by: Jeff Carr <[email protected]>
-rw-r--r--dump.go26
-rw-r--r--http.go5
-rw-r--r--main.go2
-rw-r--r--validate.go45
4 files changed, 37 insertions, 41 deletions
diff --git a/dump.go b/dump.go
index 1e6a596..57a3404 100644
--- a/dump.go
+++ b/dump.go
@@ -3,6 +3,9 @@ package main
import (
"fmt"
"net/http"
+ "strings"
+
+ pb "go.wit.com/lib/protobuf/virtbuf"
)
/*
@@ -11,7 +14,7 @@ import (
*/
func dumpCluster(w http.ResponseWriter) {
- umap, macs := safeValidateDroplets(me.cluster)
+ umap, macs, err := ValidateDroplets(me.cluster)
for u, hostname := range umap {
fmt.Fprintln(w, "uuid:", u, "hostname:", hostname)
}
@@ -19,4 +22,25 @@ func dumpCluster(w http.ResponseWriter) {
for mac, uuid := range macs {
fmt.Fprintln(w, "mac:", mac, "uuid", uuid, "hostname:", umap[uuid])
}
+ if err != nil {
+ fmt.Fprintln(w, "ValidateDroplets() failed:", err)
+ }
+}
+
+// list running droplets and droplets that should be running
+func dumpDroplets(w http.ResponseWriter) {
+ for i, d := range me.cluster.Droplets {
+ var macs []string
+ for _, n := range d.Networks {
+ macs = append(macs, n.Mac)
+ }
+ arp := strings.Join(macs, " ")
+ if d.CurrentState == pb.DropletState_ON {
+ fmt.Fprintln(w, i, "droplet:", arp, d.Hostname, d.StartState, d.CurrentState)
+ continue
+ }
+ if d.StartState == pb.DropletState_ON {
+ fmt.Fprintln(w, i, "droplet:", arp, d.Hostname, d.StartState, d.CurrentState, "(should be on)")
+ }
+ }
}
diff --git a/http.go b/http.go
index 8d819f5..51c5a10 100644
--- a/http.go
+++ b/http.go
@@ -114,6 +114,11 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
return
}
+ if route == "/dumpdroplets" {
+ dumpDroplets(w)
+ return
+ }
+
if route == "/dumplibvirtxml" {
virtigoxml.DumpLibvirtxmlDomainNames()
return
diff --git a/main.go b/main.go
index 794ee83..31fbd3d 100644
--- a/main.go
+++ b/main.go
@@ -72,7 +72,7 @@ func main() {
var newEvents []*pb.Event
// sanity check the cluster & droplets
- if err := ValidateDroplets(me.cluster); err != nil {
+ if _, _, err := ValidateDroplets(me.cluster); err != nil {
log.Info("todo: add flag to ignore. for now, fix problems in the config file.")
os.Exit(0)
}
diff --git a/validate.go b/validate.go
index 274033c..16d78ac 100644
--- a/validate.go
+++ b/validate.go
@@ -71,41 +71,6 @@ func lookupFilename(cluster *pb.Cluster, filename string) *pb.Droplet {
return nil
}
-/*
-func InsertFilename(cluster *pb.Cluster, d *pb.Droplet, filename string) (*pb.Event, error) {
- dupd := lookupFilename(cluster, filename)
- if dupd != nil {
- log.Info("file", filename, "already on droplet", dupd.Hostname)
- log.Info("file", filename, "on new droplet", d.Hostname)
- if os.Getenv("VIRTIGO_IGNORE_DISKDUP") == "" {
- log.Info("duplicate disk names (--xml-ignore-disk to ignore)")
- return nil, errors.New("duplicate disk names")
- } else {
- log.Info("ignore duplicate disk names (--xml-ignore-disk=true)")
- }
- }
- filebase := filepath.Base(filename)
- dir := filepath.Dir(filename)
- for _, disk := range d.Disks {
- if disk.Filename == filebase {
- log.Info("already have disk", filename)
- return nil, nil
- }
- }
- // make a new Add Event
- e := d.NewChangeEvent("Add Disk", "", filename)
-
- // add the disk protobuf entry
- var disk *pb.Disk
- disk = new(pb.Disk)
- disk.Filename = filebase
- disk.Filepath = dir
- d.Disks = append(d.Disks, disk)
- log.Info("New filename", filebase, dir)
- return e, nil
-}
-*/
-
func ValidateUniqueFilenames(cluster *pb.Cluster) bool {
var ok bool = true
var disks map[string]string
@@ -170,7 +135,7 @@ func ValidateDiskFilenames(cluster *pb.Cluster) []*pb.Event {
// runs on startup. dies if there are duplicates
// the config file must then be edited by hand
-func ValidateDroplets(cluster *pb.Cluster) error {
+func ValidateDroplets(cluster *pb.Cluster) (map[string]string, map[string]string, error) {
// uuid map to check for duplicates
var umap map[string]string
umap = make(map[string]string)
@@ -191,7 +156,7 @@ func ValidateDroplets(cluster *pb.Cluster) error {
// UUID already exists
log.Info("duplicate UUID", d.Uuid, umap[d.Uuid])
log.Info("duplicate UUID", d.Uuid, d.Hostname)
- return errors.New("duplicate UUID: " + d.Uuid)
+ return umap, macs, errors.New("duplicate UUID: " + d.Uuid)
}
umap[d.Uuid] = d.Hostname
@@ -201,7 +166,7 @@ func ValidateDroplets(cluster *pb.Cluster) error {
// UUID already exists
log.Info("duplicate MAC", n.Mac, macs[n.Mac], umap[macs[n.Mac]])
log.Info("duplicate MAC", n.Mac, d.Hostname)
- return errors.New("duplicate MAC: " + n.Mac)
+ return umap, macs, errors.New("duplicate MAC: " + n.Mac)
}
macs[n.Mac] = d.Uuid
}
@@ -209,9 +174,10 @@ func ValidateDroplets(cluster *pb.Cluster) error {
log.Println("validated okay: no duplicate MAC addr")
log.Println("validated okay: no duplicate UUID")
- return nil
+ return umap, macs, nil
}
+/*
func safeValidateDroplets(cluster *pb.Cluster) (map[string]string, map[string]string) {
// uuid map to check for duplicates
var umap map[string]string
@@ -253,3 +219,4 @@ func safeValidateDroplets(cluster *pb.Cluster) (map[string]string, map[string]st
return umap, macs
}
+*/