blob: d122e8c86091c52eaa8d00f770489b62d92d5808 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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
}
|