2013-06-17 13:01:42 +02:00
|
|
|
package digitalocean
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2013-06-18 21:54:15 -07:00
|
|
|
"log"
|
2014-11-24 08:14:05 +00:00
|
|
|
"strconv"
|
2015-06-10 14:02:06 -07:00
|
|
|
|
|
|
|
"github.com/digitalocean/godo"
|
2013-06-17 13:01:42 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type Artifact struct {
|
|
|
|
// The name of the snapshot
|
|
|
|
snapshotName string
|
2013-06-18 21:54:15 -07:00
|
|
|
|
|
|
|
// The ID of the image
|
2015-06-10 14:02:06 -07:00
|
|
|
snapshotId int
|
2013-06-18 21:54:15 -07:00
|
|
|
|
2013-10-05 19:29:02 -07:00
|
|
|
// The name of the region
|
|
|
|
regionName string
|
|
|
|
|
2013-06-18 21:54:15 -07:00
|
|
|
// The client for making API calls
|
2015-06-10 14:02:06 -07:00
|
|
|
client *godo.Client
|
2013-06-17 13:01:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (*Artifact) BuilderId() string {
|
|
|
|
return BuilderId
|
|
|
|
}
|
|
|
|
|
|
|
|
func (*Artifact) Files() []string {
|
|
|
|
// No files with DigitalOcean
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *Artifact) Id() string {
|
2014-11-24 08:14:05 +00:00
|
|
|
return strconv.FormatUint(uint64(a.snapshotId), 10)
|
2013-06-17 13:01:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *Artifact) String() string {
|
2013-10-05 19:29:02 -07:00
|
|
|
return fmt.Sprintf("A snapshot was created: '%v' in region '%v'", a.snapshotName, a.regionName)
|
2013-06-17 13:01:42 +02:00
|
|
|
}
|
2013-06-18 16:01:14 -07:00
|
|
|
|
2014-01-19 18:32:44 +00:00
|
|
|
func (a *Artifact) State(name string) interface{} {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2013-06-18 16:01:14 -07:00
|
|
|
func (a *Artifact) Destroy() error {
|
2013-10-05 19:29:02 -07:00
|
|
|
log.Printf("Destroying image: %d (%s)", a.snapshotId, a.snapshotName)
|
2015-06-10 14:02:06 -07:00
|
|
|
_, err := a.client.Images.Delete(a.snapshotId)
|
|
|
|
return err
|
2013-06-18 16:01:14 -07:00
|
|
|
}
|