2013-12-25 13:27:53 -05:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
|
2017-04-04 16:39:01 -04:00
|
|
|
"github.com/hashicorp/packer/packer"
|
2013-12-25 13:27:53 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// BuilderId for the local artifacts
|
|
|
|
const BuilderId = "mitchellh.vmware"
|
|
|
|
|
|
|
|
// Artifact is the result of running the VMware builder, namely a set
|
|
|
|
// of files associated with the resulting machine.
|
|
|
|
type localArtifact struct {
|
|
|
|
dir string
|
|
|
|
f []string
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewLocalArtifact returns a VMware artifact containing the files
|
|
|
|
// in the given directory.
|
|
|
|
func NewLocalArtifact(dir string) (packer.Artifact, error) {
|
|
|
|
files := make([]string, 0, 5)
|
|
|
|
visit := func(path string, info os.FileInfo, err error) error {
|
2017-01-26 19:32:21 -05:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2013-12-25 13:27:53 -05:00
|
|
|
if !info.IsDir() {
|
|
|
|
files = append(files, path)
|
|
|
|
}
|
2017-01-26 19:32:21 -05:00
|
|
|
return nil
|
2013-12-25 13:27:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := filepath.Walk(dir, visit); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &localArtifact{
|
|
|
|
dir: dir,
|
|
|
|
f: files,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *localArtifact) BuilderId() string {
|
|
|
|
return BuilderId
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *localArtifact) Files() []string {
|
|
|
|
return a.f
|
|
|
|
}
|
|
|
|
|
|
|
|
func (*localArtifact) Id() string {
|
|
|
|
return "VM"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *localArtifact) String() string {
|
|
|
|
return fmt.Sprintf("VM files in directory: %s", a.dir)
|
|
|
|
}
|
|
|
|
|
2014-01-19 13:32:44 -05:00
|
|
|
func (a *localArtifact) State(name string) interface{} {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2013-12-25 13:27:53 -05:00
|
|
|
func (a *localArtifact) Destroy() error {
|
|
|
|
return os.RemoveAll(a.dir)
|
|
|
|
}
|