summaryrefslogtreecommitdiff
path: root/validate.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-10-30 13:17:04 -0500
committerJeff Carr <[email protected]>2024-10-30 13:17:04 -0500
commitbf52632cb79e91703079765cd8a85fc9f4098e92 (patch)
treebcf7f6453f0d1eef6f65fe42783604dc8187313a /validate.go
parent2a18f506c7e37903e58b838e52b6b6554e7e039c (diff)
force filenames to match hostnames
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'validate.go')
-rw-r--r--validate.go24
1 files changed, 22 insertions, 2 deletions
diff --git a/validate.go b/validate.go
index 4105c6f..42c9ab6 100644
--- a/validate.go
+++ b/validate.go
@@ -17,6 +17,7 @@ import (
"errors"
"fmt"
"path/filepath"
+ "strings"
"github.com/google/uuid"
@@ -102,10 +103,11 @@ func ValidateUniqueFilenames(cluster *pb.Cluster) bool {
return ok
}
-func ValidateDiskFilenames(cluster *pb.Cluster) []*pb.Event {
+func ValidateDiskFilenames(cluster *pb.Cluster) ([]*pb.Event, error) {
var alle []*pb.Event
for _, d := range cluster.Droplets {
+ var found bool = false
for _, disk := range d.Disks {
filename := disk.Filename
filebase := filepath.Base(filename)
@@ -117,6 +119,20 @@ func ValidateDiskFilenames(cluster *pb.Cluster) []*pb.Event {
alle = append(alle, e)
disk.Filename = filebase
}
+ // make sure the filename is the hostname + .qcow2
+ filetype := filepath.Ext(filebase)
+ if filetype == ".img" {
+ found = true
+ continue
+ }
+ if filetype != ".qcow2" {
+ log.Info("file type", filetype, "not supported for", filebase, "on", d.Hostname)
+ return nil, errors.New("only supporting qcow2 images for now")
+ }
+ test := strings.TrimSuffix(filebase, filetype)
+ if test == d.Hostname {
+ found = true
+ }
if dir == "." {
continue
}
@@ -130,8 +146,12 @@ func ValidateDiskFilenames(cluster *pb.Cluster) []*pb.Event {
disk.Filepath = dir
}
}
+ if !found {
+ log.Info("droplet", d.Hostname, d.Disks)
+ return nil, errors.New("droplet " + d.Hostname + " has nonstandard disk names")
+ }
}
- return alle
+ return alle, nil
}
func getNewMac() string {