builder/vmware: Artifacts implemented
This commit is contained in:
parent
378a7320a3
commit
f851e56dbd
|
@ -0,0 +1,26 @@
|
|||
package vmware
|
||||
|
||||
import "fmt"
|
||||
|
||||
// Artifact is the result of running the VMware builder, namely a set
|
||||
// of files associated with the resulting machine.
|
||||
type Artifact struct {
|
||||
dir string
|
||||
f []string
|
||||
}
|
||||
|
||||
func (*Artifact) BuilderId() string {
|
||||
return BuilderId
|
||||
}
|
||||
|
||||
func (a *Artifact) Files() []string {
|
||||
return a.f
|
||||
}
|
||||
|
||||
func (*Artifact) Id() string {
|
||||
return "VM"
|
||||
}
|
||||
|
||||
func (a *Artifact) String() string {
|
||||
return fmt.Sprintf("VM files in directory: %s", a.dir)
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package vmware
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"github.com/mitchellh/packer/packer"
|
||||
)
|
||||
|
||||
func TestArtifact_Impl(t *testing.T) {
|
||||
var raw interface{}
|
||||
raw = &Artifact{}
|
||||
if _, ok := raw.(packer.Artifact); !ok {
|
||||
t.Fatal("Artifact must be a proper artifact")
|
||||
}
|
||||
}
|
|
@ -7,6 +7,8 @@ import (
|
|||
"github.com/mitchellh/multistep"
|
||||
"github.com/mitchellh/packer/packer"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -114,7 +116,28 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook) packer.Artifact {
|
|||
b.runner = &multistep.BasicRunner{Steps: steps}
|
||||
b.runner.Run(state)
|
||||
|
||||
return nil
|
||||
// If we were interrupted or cancelled, then just exit.
|
||||
if _, ok := state[multistep.StateCancelled]; ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
if _, ok := state[multistep.StateHalted]; ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Compile the artifact list
|
||||
files := make([]string, 0, 10)
|
||||
visit := func(path string, info os.FileInfo, err error) error {
|
||||
files = append(files, path)
|
||||
return err
|
||||
}
|
||||
|
||||
if err := filepath.Walk(b.config.OutputDir, visit); err != nil {
|
||||
ui.Error(fmt.Sprintf("Error collecting result files: %s", err))
|
||||
return nil
|
||||
}
|
||||
|
||||
return &Artifact{b.config.OutputDir, files}
|
||||
}
|
||||
|
||||
func (b *Builder) Cancel() {
|
||||
|
|
Loading…
Reference in New Issue