48 lines
887 B
Go
48 lines
887 B
Go
package hcloud
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"log"
|
|
"strconv"
|
|
|
|
"github.com/hetznercloud/hcloud-go/hcloud"
|
|
)
|
|
|
|
type Artifact struct {
|
|
// The name of the snapshot
|
|
snapshotName string
|
|
|
|
// The ID of the image
|
|
snapshotId int
|
|
|
|
// The hcloudClient for making API calls
|
|
hcloudClient *hcloud.Client
|
|
}
|
|
|
|
func (*Artifact) BuilderId() string {
|
|
return BuilderId
|
|
}
|
|
|
|
func (*Artifact) Files() []string {
|
|
return nil
|
|
}
|
|
|
|
func (a *Artifact) Id() string {
|
|
return strconv.Itoa(a.snapshotId)
|
|
}
|
|
|
|
func (a *Artifact) String() string {
|
|
return fmt.Sprintf("A snapshot was created: '%v' (ID: %v)", a.snapshotName, a.snapshotId)
|
|
}
|
|
|
|
func (a *Artifact) State(name string) interface{} {
|
|
return nil
|
|
}
|
|
|
|
func (a *Artifact) Destroy() error {
|
|
log.Printf("Destroying image: %d (%s)", a.snapshotId, a.snapshotName)
|
|
_, err := a.hcloudClient.Image.Delete(context.TODO(), &hcloud.Image{ID: a.snapshotId})
|
|
return err
|
|
}
|