diff options
| author | Jeff Carr <[email protected]> | 2024-10-25 19:16:44 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-10-25 19:16:44 -0500 |
| commit | 030af1bcfb7dad880a9fdf4286432fc36d1bf251 (patch) | |
| tree | ae093e875206c32d771c0a52f651ee57380b46da /validate.go | |
| parent | a5eee861ea52fb0a33827fed3770f383aaeca03a (diff) | |
check for duplicate disk names
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'validate.go')
| -rw-r--r-- | validate.go | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/validate.go b/validate.go index 2faaf38..2f7de9b 100644 --- a/validate.go +++ b/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 |
