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
|
./virtigo --help
|
||||||
|
|
||||||
xml-add:
|
xml-add:
|
||||||
./virtigo --libvirt *.xml
|
./virtigo --libvirt ~/libvirt/*.xml --xml-ignore-disk
|
||||||
|
|
||||||
start-all-droplets:
|
start-all-droplets:
|
||||||
curl --silent http://localhost:8080/start?start=git.wit.org
|
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")
|
return alle, errors.New("updateDisk() failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if alle == nil {
|
if alle == nil {
|
||||||
log.Info("libvirt xml import worked. nothing changed", domcfg.Name)
|
log.Info("libvirt xml import worked. nothing changed", domcfg.Name)
|
||||||
return alle, nil
|
return alle, nil
|
||||||
|
|
15
argv.go
15
argv.go
|
@ -11,13 +11,14 @@ import "go.wit.com/log"
|
||||||
var argv args
|
var argv args
|
||||||
|
|
||||||
type args struct {
|
type args struct {
|
||||||
Xml []string `arg:"--libvirt" help:"import qemu xml files: --libvirt /etc/libvirt/qemu/*.xml"`
|
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"`
|
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"`
|
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"`
|
IgnDisk bool `arg:"--xml-ignore-disk" default:"false" help:"ignore duplicate disk names"`
|
||||||
Config string `arg:"env:VIRTIGO_HOME" help:"defaults to ~/.config/virtigo/"`
|
Save bool `arg:"--save" default:"false" help:"save protobuf config after import"`
|
||||||
Port int `arg:"--port" default:"8080" help:"allow droplet events via http"`
|
Config string `arg:"env:VIRTIGO_HOME" help:"defaults to ~/.config/virtigo/"`
|
||||||
Daemon bool `arg:"--daemon" help:"run in daemon mode"`
|
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"`
|
// 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
|
// this is probably something about what kind of OS you might be running
|
||||||
// todo: get this directly from the disk image
|
// todo: get this directly from the disk image
|
||||||
if domcfg.Metadata != nil {
|
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
|
domcfg.Metadata = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
38
main.go
38
main.go
|
@ -53,10 +53,17 @@ func main() {
|
||||||
os.Exit(-1)
|
os.Exit(-1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var newEvents []*pb.Event
|
||||||
|
|
||||||
// sanity check the droplets
|
// sanity check the droplets
|
||||||
checkDroplets(false)
|
checkDroplets(false)
|
||||||
|
newe := checkDiskFilenames()
|
||||||
|
for _, e := range newe {
|
||||||
|
newEvents = append(newEvents, e)
|
||||||
|
}
|
||||||
|
checkUniqueFilenames()
|
||||||
|
|
||||||
|
|
||||||
var newEvents []*pb.Event
|
|
||||||
for _, filename := range argv.Xml {
|
for _, filename := range argv.Xml {
|
||||||
domcfg, err := readXml(filename)
|
domcfg, err := readXml(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -81,21 +88,22 @@ func main() {
|
||||||
newEvents = append(newEvents, e)
|
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 {
|
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")
|
log.Info("No XML changes found")
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,7 @@ type virtigoT struct {
|
||||||
killcount int
|
killcount int
|
||||||
unstable time.Time // the last time the cluster was incorrect
|
unstable time.Time // the last time the cluster was incorrect
|
||||||
changed bool
|
changed bool
|
||||||
|
dirs []string // all the paths too search for a qcow image
|
||||||
}
|
}
|
||||||
|
|
||||||
// the stuff that is needed for a hypervisor
|
// the stuff that is needed for a hypervisor
|
||||||
|
|
76
validate.go
76
validate.go
|
@ -15,9 +15,11 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
|
||||||
|
pb "go.wit.com/lib/protobuf/virtbuf"
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -34,6 +36,80 @@ func checkUniqueMac(mac string) bool {
|
||||||
return true
|
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 {
|
func checkDroplets(dump bool) bool {
|
||||||
// uuid map to check for duplicates
|
// uuid map to check for duplicates
|
||||||
var umap map[string]string
|
var umap map[string]string
|
||||||
|
|
Loading…
Reference in New Issue