Commit b9fb065d authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

packer: Add Destroy method to artifact

[GH-18]
parent 42dc1938
package amazonebs package amazonebs
import ( import (
"errors"
"fmt" "fmt"
"strings" "strings"
) )
...@@ -33,3 +34,7 @@ func (a *artifact) String() string { ...@@ -33,3 +34,7 @@ func (a *artifact) String() string {
return fmt.Sprintf("AMIs were created:\n\n%s", strings.Join(amiStrings, "\n")) return fmt.Sprintf("AMIs were created:\n\n%s", strings.Join(amiStrings, "\n"))
} }
func (a *artifact) Destroy() error {
return errors.New("not implemented yet")
}
package digitalocean package digitalocean
import ( import (
"errors"
"fmt" "fmt"
) )
...@@ -25,3 +26,7 @@ func (a *Artifact) Id() string { ...@@ -25,3 +26,7 @@ func (a *Artifact) Id() string {
func (a *Artifact) String() string { func (a *Artifact) String() string {
return fmt.Sprintf("A snapshot was created: %v", a.snapshotName) return fmt.Sprintf("A snapshot was created: %v", a.snapshotName)
} }
func (a *Artifact) Destroy() error {
return errors.New("not implemented yet")
}
package vmware package vmware
import "fmt" import (
"fmt"
"os"
)
// Artifact is the result of running the VMware builder, namely a set // Artifact is the result of running the VMware builder, namely a set
// of files associated with the resulting machine. // of files associated with the resulting machine.
...@@ -24,3 +27,7 @@ func (*Artifact) Id() string { ...@@ -24,3 +27,7 @@ func (*Artifact) Id() string {
func (a *Artifact) String() string { func (a *Artifact) String() string {
return fmt.Sprintf("VM files in directory: %s", a.dir) return fmt.Sprintf("VM files in directory: %s", a.dir)
} }
func (a *Artifact) Destroy() error {
return os.RemoveAll(a.dir)
}
...@@ -24,4 +24,9 @@ type Artifact interface { ...@@ -24,4 +24,9 @@ type Artifact interface {
// Returns human-readable output that describes the artifact created. // Returns human-readable output that describes the artifact created.
// This is used for UI output. It can be multiple lines. // This is used for UI output. It can be multiple lines.
String() string String() string
// Destroy deletes the artifact. Packer calls this for various reasons,
// such as if a post-processor has processed this artifact and it is
// no longer needed.
Destroy() error
} }
...@@ -17,3 +17,7 @@ func (*TestArtifact) Id() string { ...@@ -17,3 +17,7 @@ func (*TestArtifact) Id() string {
func (*TestArtifact) String() string { func (*TestArtifact) String() string {
return "string" return "string"
} }
func (*TestArtifact) Destroy() error {
return nil
}
...@@ -41,6 +41,15 @@ func (a *artifact) String() (result string) { ...@@ -41,6 +41,15 @@ func (a *artifact) String() (result string) {
return return
} }
func (a *artifact) Destroy() error {
var result error
if err := a.client.Call("Artifact.Destroy", new(interface{}), &result); err != nil {
return err
}
return result
}
func (s *ArtifactServer) BuilderId(args *interface{}, reply *string) error { func (s *ArtifactServer) BuilderId(args *interface{}, reply *string) error {
*reply = s.artifact.BuilderId() *reply = s.artifact.BuilderId()
return nil return nil
...@@ -60,3 +69,13 @@ func (s *ArtifactServer) String(args *interface{}, reply *string) error { ...@@ -60,3 +69,13 @@ func (s *ArtifactServer) String(args *interface{}, reply *string) error {
*reply = s.artifact.String() *reply = s.artifact.String()
return nil return nil
} }
func (s *ArtifactServer) Destroy(args *interface{}, reply *error) error {
err := s.artifact.Destroy()
if err != nil {
err = NewBasicError(err)
}
*reply = err
return nil
}
...@@ -25,6 +25,10 @@ func (testArtifact) String() string { ...@@ -25,6 +25,10 @@ func (testArtifact) String() string {
return "string" return "string"
} }
func (testArtifact) Destroy() error {
return nil
}
func TestArtifactRPC(t *testing.T) { func TestArtifactRPC(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true) assert := asserts.NewTestingAsserts(t, true)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment