packer: Add Destroy method to artifact

[GH-18]
This commit is contained in:
Mitchell Hashimoto 2013-06-18 16:01:14 -07:00
parent ce1900c477
commit 0f354c79d1
7 changed files with 50 additions and 1 deletions

View File

@ -1,6 +1,7 @@
package amazonebs package amazonebs
import ( import (
"errors"
"fmt" "fmt"
"strings" "strings"
) )
@ -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")
}

View File

@ -1,6 +1,7 @@
package digitalocean package digitalocean
import ( import (
"errors"
"fmt" "fmt"
) )
@ -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")
}

View File

@ -1,6 +1,9 @@
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 {
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)
}

View File

@ -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
} }

View File

@ -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
}

View File

@ -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 {
*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
}

View File

@ -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)