packer-cn/builder/vmware/common/artifact.go

70 lines
1.3 KiB
Go
Raw Normal View History

package common
import (
"fmt"
"os"
"path/filepath"
2017-04-04 16:39:01 -04:00
"github.com/hashicorp/packer/packer"
)
// 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 {
2017-07-27 20:59:11 -04:00
id string
dir string
f []string
}
// NewLocalArtifact returns a VMware artifact containing the files
// in the given directory.
2017-07-27 20:59:11 -04:00
func NewLocalArtifact(id string, dir string) (packer.Artifact, error) {
files := make([]string, 0, 5)
visit := func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if !info.IsDir() {
files = append(files, path)
}
return nil
}
if err := filepath.Walk(dir, visit); err != nil {
return nil, err
}
return &localArtifact{
2017-07-27 20:59:11 -04:00
id: id,
dir: dir,
f: files,
}, nil
}
func (a *localArtifact) BuilderId() string {
return BuilderId
}
func (a *localArtifact) Files() []string {
return a.f
}
2017-07-27 20:59:11 -04:00
func (a *localArtifact) Id() string {
return a.id
}
func (a *localArtifact) String() string {
return fmt.Sprintf("VM files in directory: %s", a.dir)
}
func (a *localArtifact) State(name string) interface{} {
return nil
}
func (a *localArtifact) Destroy() error {
return os.RemoveAll(a.dir)
}