github.phpd.cn/hashicorp/packer@v1.3.2/builder/hcloud/artifact.go (about) 1 package hcloud 2 3 import ( 4 "context" 5 "fmt" 6 "log" 7 "strconv" 8 9 "github.com/hetznercloud/hcloud-go/hcloud" 10 ) 11 12 type Artifact struct { 13 // The name of the snapshot 14 snapshotName string 15 16 // The ID of the image 17 snapshotId int 18 19 // The hcloudClient for making API calls 20 hcloudClient *hcloud.Client 21 } 22 23 func (*Artifact) BuilderId() string { 24 return BuilderId 25 } 26 27 func (*Artifact) Files() []string { 28 return nil 29 } 30 31 func (a *Artifact) Id() string { 32 return strconv.Itoa(a.snapshotId) 33 } 34 35 func (a *Artifact) String() string { 36 return fmt.Sprintf("A snapshot was created: '%v' (ID: %v)", a.snapshotName, a.snapshotId) 37 } 38 39 func (a *Artifact) State(name string) interface{} { 40 return nil 41 } 42 43 func (a *Artifact) Destroy() error { 44 log.Printf("Destroying image: %d (%s)", a.snapshotId, a.snapshotName) 45 _, err := a.hcloudClient.Image.Delete(context.TODO(), &hcloud.Image{ID: a.snapshotId}) 46 return err 47 }