packer-plugin-xenserver/builder/xenserver/artifact.go

56 lines
933 B
Go
Raw Normal View History

package xenserver
import (
2014-12-08 09:34:48 -06:00
"fmt"
"github.com/mitchellh/packer/packer"
"os"
"path/filepath"
)
type LocalArtifact struct {
2014-12-08 09:34:48 -06:00
dir string
f []string
}
func NewArtifact(dir string) (packer.Artifact, error) {
2014-12-08 09:34:48 -06:00
files := make([]string, 0, 1)
visit := func(path string, info os.FileInfo, err error) error {
if !info.IsDir() {
files = append(files, path)
}
return err
}
if err := filepath.Walk(dir, visit); err != nil {
return nil, err
}
return &LocalArtifact{
dir: dir,
f: files,
}, nil
}
func (*LocalArtifact) BuilderId() string {
2014-12-08 09:34:48 -06:00
return BuilderId
}
func (a *LocalArtifact) Files() []string {
2014-12-08 09:34:48 -06:00
return a.f
}
func (*LocalArtifact) Id() string {
2014-12-08 09:34:48 -06:00
return "VM"
}
func (a *LocalArtifact) String() string {
2014-12-08 09:34:48 -06:00
return fmt.Sprintf("VM files in directory: %s", a.dir)
}
func (a *LocalArtifact) State(name string) interface{} {
2014-12-08 09:34:48 -06:00
return nil
}
func (a *LocalArtifact) Destroy() error {
2014-12-08 09:34:48 -06:00
return os.RemoveAll(a.dir)
}