Commit b9fb065d authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

packer: Add Destroy method to artifact

[GH-18]
parent 42dc1938
package amazonebs
import (
"errors"
"fmt"
"strings"
)
......@@ -33,3 +34,7 @@ func (a *artifact) String() string {
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
import (
"errors"
"fmt"
)
......@@ -25,3 +26,7 @@ func (a *Artifact) Id() string {
func (a *Artifact) String() string {
return fmt.Sprintf("A snapshot was created: %v", a.snapshotName)
}
func (a *Artifact) Destroy() error {
return errors.New("not implemented yet")
}
package vmware
import "fmt"
import (
"fmt"
"os"
)
// Artifact is the result of running the VMware builder, namely a set
// of files associated with the resulting machine.
......@@ -24,3 +27,7 @@ func (*Artifact) Id() string {
func (a *Artifact) String() string {
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 {
// Returns human-readable output that describes the artifact created.
// This is used for UI output. It can be multiple lines.
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 {
func (*TestArtifact) String() string {
return "string"
}
func (*TestArtifact) Destroy() error {
return nil
}
......@@ -41,6 +41,15 @@ func (a *artifact) String() (result string) {
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 {
*reply = s.artifact.BuilderId()
return nil
......@@ -60,3 +69,13 @@ func (s *ArtifactServer) String(args *interface{}, reply *string) error {
*reply = s.artifact.String()
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 {
return "string"
}
func (testArtifact) Destroy() error {
return nil
}
func TestArtifactRPC(t *testing.T) {
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