github.com/rothwerx/packer@v0.9.0/builder/digitalocean/artifact.go (about) 1 package digitalocean 2 3 import ( 4 "fmt" 5 "log" 6 "strconv" 7 8 "github.com/digitalocean/godo" 9 ) 10 11 type Artifact struct { 12 // The name of the snapshot 13 snapshotName string 14 15 // The ID of the image 16 snapshotId int 17 18 // The name of the region 19 regionName string 20 21 // The client for making API calls 22 client *godo.Client 23 } 24 25 func (*Artifact) BuilderId() string { 26 return BuilderId 27 } 28 29 func (*Artifact) Files() []string { 30 // No files with DigitalOcean 31 return nil 32 } 33 34 func (a *Artifact) Id() string { 35 return fmt.Sprintf("%s:%s", a.regionName, strconv.FormatUint(uint64(a.snapshotId), 10)) 36 } 37 38 func (a *Artifact) String() string { 39 return fmt.Sprintf("A snapshot was created: '%v' (ID: %v) in region '%v'", a.snapshotName, a.snapshotId, a.regionName) 40 } 41 42 func (a *Artifact) State(name string) interface{} { 43 return nil 44 } 45 46 func (a *Artifact) Destroy() error { 47 log.Printf("Destroying image: %d (%s)", a.snapshotId, a.snapshotName) 48 _, err := a.client.Images.Delete(a.snapshotId) 49 return err 50 }