diff options
| author | Jeff Carr <[email protected]> | 2024-10-27 02:30:00 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-10-27 02:30:00 -0500 |
| commit | e23c99d7717524114dc0ad00570cd6403229db75 (patch) | |
| tree | 7094cb6b219c3cca9ce541cc61166bfc21af8f9e /disks.go | |
| parent | 255ffc94883bb5f023f722dd55e55e8154287f4d (diff) | |
validate code shouldn't be here
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'disks.go')
| -rw-r--r-- | disks.go | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/disks.go b/disks.go new file mode 100644 index 0000000..d122e8c --- /dev/null +++ b/disks.go @@ -0,0 +1,37 @@ +package virtigoxml + +/* + makes a droplet hard disk record + The full path doesn't matter. + We really just care about the qcow2 filename + it probably should be forced to be <hostname>.qcow2 +*/ + +import ( + "path/filepath" + + pb "go.wit.com/lib/protobuf/virtbuf" + "go.wit.com/log" +) + +func InsertFilename(d *pb.Droplet, filename string) (*pb.Event, error) { + filebase := filepath.Base(filename) + dir := filepath.Dir(filename) + for _, disk := range d.Disks { + if disk.Filename == filebase { + log.Info("droplet", d.Hostname, "already has this disk", filename) + return nil, nil + } + } + // make a new Add Event + e := d.NewChangeEvent("Add Disk", "", filename) + + // add the disk protobuf entry + var disk *pb.Disk + disk = new(pb.Disk) + disk.Filename = filebase + disk.Filepath = dir + d.Disks = append(d.Disks, disk) + log.Info("New filename", filebase, dir) + return e, nil +} |
