cleanup instructions

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-10-24 18:55:35 -05:00
parent 78fbc9631c
commit fea819956f
6 changed files with 109 additions and 15 deletions

View File

@ -56,9 +56,15 @@ func findDomain(domcfg *libvirtxml.Domain) (*DropletT, error) {
for _, d := range me.droplets { for _, d := range me.droplets {
if d.pb.Hostname == domcfg.Name { if d.pb.Hostname == domcfg.Name {
if d.pb.Uuid != domcfg.UUID { if d.pb.Uuid != domcfg.UUID {
fmt.Println("CHANGED UUID", d.pb.Uuid, domcfg.UUID) if domcfg.UUID == "" {
d.pb.Uuid = domcfg.UUID // ignore blank or nonexistent UUID's
me.changed = true // todo: check to see if the uuid already exists ?
domcfg.UUID = d.pb.Uuid
} else {
fmt.Println("Will Change UUID from", d.pb.Uuid, "to", domcfg.UUID, "for hostname", d.pb.Hostname)
d.pb.Uuid = domcfg.UUID
me.changed = true
}
} }
if found == nil { if found == nil {
found = d found = d

26
argv.go
View File

@ -11,31 +11,33 @@ import "go.wit.com/log"
var argv args var argv args
type args struct { type args struct {
Xml []string `arg:"--libvirt" help:"add current xml files: --libvirt /etc/libvirt/qemu/*.xml"` Xml []string `arg:"--libvirt" help:"import qemu xml files: --libvirt /etc/libvirt/qemu/*.xml"`
Save bool `arg:"--save" default:"false" help:"save config protobuf after libvirt file import"` Save bool `arg:"--save" default:"false" help:"save protobuf config after import"`
Config string `arg:"--config" help:"defaults to ~/.config/virtigo/"` Config string `arg:"env:VIRTIGO_HOME" help:"defaults to ~/.config/virtigo/"`
Port int `arg:"--port" default:"8080" help:"allow droplet events via http"` Port int `arg:"--port" default:"8080" help:"allow droplet events via http"`
Daemon bool `arg:"--daemon" help:"run in daemon mode"` Daemon bool `arg:"--daemon" help:"run in daemon mode"`
} }
// Uptime bool `arg:"--uptime" default:"true" help:"allow uptime checks for things like Kuma"` // Uptime bool `arg:"--uptime" default:"true" help:"allow uptime checks for things like Kuma"`
// Hosts []string `arg:"--hosts" help:"hosts to connect to"` // Hosts []string `arg:"--hosts" help:"hosts to connect to"`
func (a args) Description() string { func (a args) Description() string {
return ` return `
virtigo will help control your cluster of hypervisiors virtigo will help control your cluster
This maintains a master list of all your vm's (aka 'droplets') This maintains a master list of all your vm's (aka 'droplets')
in your homelab cloud. You can import libvirt xml files. in your homelab cloud. You can import libvirt xml files.
This app talks to your hypervisors via the virtigod daemon. This app talks to your hypervisors via the virtigod daemon.
Runs a http server so you can control your virtual machines with things like:
start virtual machines with:
curl http://virtigo.wit.com/start?www.wit.com
Import your existing libvirt xml files with: Import your existing libvirt xml files with:
virtigo --libvirt ~/mymachines/*.xml --save virtigo --libvirt /etc/libvirt/qemu/*.xml --save
This runs a http server so you can control your virtual machines.
For example to start a vm called 'www.wit.com' your cluster 'foo.bar.com':
curl http://foo.bar.com/start?www.wit.com
` `
} }

View File

@ -1,5 +1,17 @@
package main package main
/*
All the information is defined by protobuf files
The config files written out by default into
~/.config/virtigo/
protobuf definitions are by nature non-relational
so each protobuf is written out as a seperate file.
This seems like the simpilist way to handle this.
*/
import ( import (
"errors" "errors"
"fmt" "fmt"

View File

@ -43,6 +43,9 @@ func main() {
cfgfile() cfgfile()
// sanity check the droplets
checkDroplets()
var ok bool = true var ok bool = true
for _, filename := range argv.Xml { for _, filename := range argv.Xml {
domcfg, err := readXml(filename) domcfg, err := readXml(filename)

View File

@ -22,6 +22,7 @@ func (b *virtigoT) Enable() {
// this app's variables // this app's variables
type virtigoT struct { type virtigoT struct {
cluster *pb.Cluster cluster *pb.Cluster
events *pb.Events
names []string names []string
hypers []*HyperT hypers []*HyperT
droplets []*DropletT droplets []*DropletT

70
validate.go Normal file
View File

@ -0,0 +1,70 @@
package main
/*
validate / sanity check / consistancy check the data
here is some code to do smart things like:
* check mac addresses are unique
* check uuid's are unique
* double check filenames are unique
* return a unique mac address
* return a unique uuid
*/
import (
"os"
"github.com/google/uuid"
"go.wit.com/log"
)
func checkDroplets() bool {
// uuid map to check for duplicates
var umap map[string]string
umap = make(map[string]string)
// mac address map to check for duplicates
var macs map[string]string
macs = make(map[string]string)
for _, d := range me.cluster.Droplets {
// Generate a new UUID
if d.Uuid == "" {
u := uuid.New()
d.Uuid = u.String()
}
// seconds, ok := timeZone[tz]; ok {
if _, ok := umap[d.Uuid]; ok {
// UUID already exists
log.Info("duplicate UUID", d.Uuid, umap[d.Uuid])
log.Info("duplicate UUID", d.Uuid, d.Hostname)
os.Exit(-1)
}
umap[d.Uuid] = d.Hostname
for _, n := range d.Networks {
// log.Println("network:", n.Mac, d.Uuid, d.Hostname)
if _, ok := macs[n.Mac]; ok {
// UUID already exists
log.Info("duplicate MAC", n.Mac, macs[n.Mac], umap[macs[n.Mac]])
log.Info("duplicate MAC", n.Mac, d.Hostname)
os.Exit(-1)
}
macs[n.Mac] = d.Uuid
}
}
for u, hostname := range umap {
log.Println("uuid:", u, "hostname:", hostname)
}
for mac, uuid := range macs {
log.Println("mac:", mac, "uuid", uuid, "hostname:", umap[uuid])
}
return false
}