check for duplicate disk names
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
a5eee861ea
commit
030af1bcfb
2
Makefile
2
Makefile
|
@ -10,7 +10,7 @@ all:
|
|||
./virtigo --help
|
||||
|
||||
xml-add:
|
||||
./virtigo --libvirt *.xml
|
||||
./virtigo --libvirt ~/libvirt/*.xml --xml-ignore-disk
|
||||
|
||||
start-all-droplets:
|
||||
curl --silent http://localhost:8080/start?start=git.wit.org
|
||||
|
|
|
@ -180,7 +180,6 @@ func updateDroplet(d *DropletT, domcfg *libvirtxml.Domain) ([]*pb.Event, error)
|
|||
return alle, errors.New("updateDisk() failed")
|
||||
}
|
||||
|
||||
|
||||
if alle == nil {
|
||||
log.Info("libvirt xml import worked. nothing changed", domcfg.Name)
|
||||
return alle, nil
|
||||
|
|
15
argv.go
15
argv.go
|
@ -11,13 +11,14 @@ import "go.wit.com/log"
|
|||
var argv args
|
||||
|
||||
type args struct {
|
||||
Xml []string `arg:"--libvirt" help:"import qemu xml files: --libvirt /etc/libvirt/qemu/*.xml"`
|
||||
IgnoreCpu bool `arg:"--xml-ignore-cpu" default:"true" help:"ignore non-standard libvirt xml cpus"`
|
||||
IgnoreBr bool `arg:"--xml-ignore-net" default:"true" help:"ignore network bridge name changes"`
|
||||
Save bool `arg:"--save" default:"false" help:"save protobuf config after import"`
|
||||
Config string `arg:"env:VIRTIGO_HOME" help:"defaults to ~/.config/virtigo/"`
|
||||
Port int `arg:"--port" default:"8080" help:"allow droplet events via http"`
|
||||
Daemon bool `arg:"--daemon" help:"run in daemon mode"`
|
||||
Xml []string `arg:"--libvirt" help:"import qemu xml files: --libvirt /etc/libvirt/qemu/*.xml"`
|
||||
IgnoreCpu bool `arg:"--xml-ignore-cpu" default:"true" help:"ignore non-standard libvirt xml cpus"`
|
||||
IgnoreBr bool `arg:"--xml-ignore-net" default:"true" help:"ignore network bridge name changes"`
|
||||
IgnDisk bool `arg:"--xml-ignore-disk" default:"false" help:"ignore duplicate disk names"`
|
||||
Save bool `arg:"--save" default:"false" help:"save protobuf config after import"`
|
||||
Config string `arg:"env:VIRTIGO_HOME" help:"defaults to ~/.config/virtigo/"`
|
||||
Port int `arg:"--port" default:"8080" help:"allow droplet events via http"`
|
||||
Daemon bool `arg:"--daemon" help:"run in daemon mode"`
|
||||
}
|
||||
|
||||
// Uptime bool `arg:"--uptime" default:"true" help:"allow uptime checks for things like Kuma"`
|
||||
|
|
|
@ -376,7 +376,10 @@ func dumpNonStandardXML(domcfg *libvirtxml.Domain) (string, error) {
|
|||
// this is probably something about what kind of OS you might be running
|
||||
// todo: get this directly from the disk image
|
||||
if domcfg.Metadata != nil {
|
||||
fmt.Printf("Not saving Domain.Metadata: %+v\n", domcfg.Metadata)
|
||||
var s string
|
||||
s = domcfg.Metadata.XML
|
||||
log.Info("Not saving Domain.Metadata.XML:", s)
|
||||
log.Info("todo: get this from disk image")
|
||||
domcfg.Metadata = nil
|
||||
}
|
||||
|
||||
|
|
38
main.go
38
main.go
|
@ -53,10 +53,17 @@ func main() {
|
|||
os.Exit(-1)
|
||||
}
|
||||
|
||||
var newEvents []*pb.Event
|
||||
|
||||
// sanity check the droplets
|
||||
checkDroplets(false)
|
||||
newe := checkDiskFilenames()
|
||||
for _, e := range newe {
|
||||
newEvents = append(newEvents, e)
|
||||
}
|
||||
checkUniqueFilenames()
|
||||
|
||||
|
||||
var newEvents []*pb.Event
|
||||
for _, filename := range argv.Xml {
|
||||
domcfg, err := readXml(filename)
|
||||
if err != nil {
|
||||
|
@ -81,21 +88,22 @@ func main() {
|
|||
newEvents = append(newEvents, e)
|
||||
}
|
||||
}
|
||||
for i, e := range newEvents {
|
||||
log.Info(i, "Event:", e.Droplet, e.FieldName, "orig:", e.OrigVal, "new:", e.NewVal)
|
||||
me.changed = true
|
||||
}
|
||||
if me.changed {
|
||||
if argv.Save {
|
||||
writeConfigFile()
|
||||
writeConfigFileDroplets()
|
||||
log.Info("XML changes saved in protobuf config")
|
||||
os.Exit(0)
|
||||
} else {
|
||||
log.Info("Not saving changes (use --save to save)")
|
||||
os.Exit(0)
|
||||
}
|
||||
}
|
||||
if len(argv.Xml) != 0 {
|
||||
for i, e := range newEvents {
|
||||
log.Info(i, "Event:", e.Droplet, e.FieldName, "orig:", e.OrigVal, "new:", e.NewVal)
|
||||
}
|
||||
if me.changed {
|
||||
if argv.Save {
|
||||
writeConfigFile()
|
||||
writeConfigFileDroplets()
|
||||
log.Info("XML changes saved in protobuf config")
|
||||
os.Exit(0)
|
||||
} else {
|
||||
log.Info("Not saving changes (use --save to save)")
|
||||
os.Exit(0)
|
||||
}
|
||||
}
|
||||
log.Info("No XML changes found")
|
||||
os.Exit(0)
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ type virtigoT struct {
|
|||
killcount int
|
||||
unstable time.Time // the last time the cluster was incorrect
|
||||
changed bool
|
||||
dirs []string // all the paths too search for a qcow image
|
||||
}
|
||||
|
||||
// the stuff that is needed for a hypervisor
|
||||
|
|
76
validate.go
76
validate.go
|
@ -15,9 +15,11 @@ package main
|
|||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
pb "go.wit.com/lib/protobuf/virtbuf"
|
||||
"go.wit.com/log"
|
||||
)
|
||||
|
||||
|
@ -34,6 +36,80 @@ func checkUniqueMac(mac string) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func addClusterFilepath(dir string) {
|
||||
var found bool = false
|
||||
for _, d := range me.dirs {
|
||||
if d == dir {
|
||||
// found dir
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
me.dirs = append(me.dirs, dir)
|
||||
}
|
||||
}
|
||||
|
||||
func checkUniqueFilenames() bool {
|
||||
var ok bool = true
|
||||
var disks map[string]string
|
||||
disks = make(map[string]string)
|
||||
|
||||
for _, d := range me.cluster.Droplets {
|
||||
for _, disk := range d.Disks {
|
||||
filename := disk.Filename
|
||||
if _, ok := disks[filename]; ok {
|
||||
/*
|
||||
if argv.IgnDisk {
|
||||
log.Info("ignore dup disk", filename, disks[filename], d.Hostname)
|
||||
} else {
|
||||
}
|
||||
*/
|
||||
log.Info("file", filename, "on droplet", disks[filename])
|
||||
log.Info("file", filename, "on droplet", d.Hostname)
|
||||
log.Info("duplicate disk names (--xml-ignore-disk to ignore)")
|
||||
ok = false
|
||||
}
|
||||
disks[filename] = d.Hostname
|
||||
}
|
||||
}
|
||||
if ok {
|
||||
log.Println("validated okay: no duplicate disk images")
|
||||
}
|
||||
return ok
|
||||
}
|
||||
|
||||
func checkDiskFilenames() []*pb.Event {
|
||||
var alle []*pb.Event
|
||||
|
||||
for _, d := range me.cluster.Droplets {
|
||||
for _, disk := range d.Disks {
|
||||
filename := disk.Filename
|
||||
filebase := filepath.Base(filename)
|
||||
dir := filepath.Dir(filename)
|
||||
if disk.Filename != filebase {
|
||||
// update filename
|
||||
e := NewChangeEvent(d, "Disk.Filename", disk.Filename, filebase)
|
||||
alle = append(alle, e)
|
||||
disk.Filename = filebase
|
||||
}
|
||||
if dir == "." {
|
||||
continue
|
||||
}
|
||||
if dir == "" {
|
||||
continue
|
||||
}
|
||||
if disk.Filepath != dir {
|
||||
// update filename
|
||||
e := NewChangeEvent(d, "Disk.Filepath", disk.Filepath, dir)
|
||||
alle = append(alle, e)
|
||||
disk.Filepath = dir
|
||||
}
|
||||
}
|
||||
}
|
||||
return alle
|
||||
}
|
||||
|
||||
func checkDroplets(dump bool) bool {
|
||||
// uuid map to check for duplicates
|
||||
var umap map[string]string
|
||||
|
|
Loading…
Reference in New Issue