2024-10-31 06:46:16 -05:00
|
|
|
package virtigolib
|
2024-10-27 02:30:00 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
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
|
|
|
|
}
|