Andy Williams d36b653d3f Make DigitalOcean artifact ID match AWS format
The Vagrant post processor expects the DO artifact ID to look like an
AWS artifact ID (region_id:snapshot_id). This commit makes the DO
artifact Id() function output this format.
2015-11-08 14:38:56 -05:00

51 lines
954 B
Go

package digitalocean
import (
"fmt"
"log"
"strconv"
"github.com/digitalocean/godo"
)
type Artifact struct {
// The name of the snapshot
snapshotName string
// The ID of the image
snapshotId int
// The name of the region
regionName string
// The client for making API calls
client *godo.Client
}
func (*Artifact) BuilderId() string {
return BuilderId
}
func (*Artifact) Files() []string {
// No files with DigitalOcean
return nil
}
func (a *Artifact) Id() string {
return fmt.Sprintf("%s:%s", a.regionName, strconv.FormatUint(uint64(a.snapshotId), 10))
}
func (a *Artifact) String() string {
return fmt.Sprintf("A snapshot was created: '%v' in region '%v'", a.snapshotName, a.regionName)
}
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.client.Images.Delete(a.snapshotId)
return err
}