diff options
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 +} |
