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

59 lines
1.0 KiB
Go
Raw Normal View History

package common
import (
2014-12-08 09:34:48 -06:00
"fmt"
"github.com/mitchellh/packer/packer"
"os"
"path/filepath"
)
// This is the common builder ID to all of these artifacts.
const BuilderId = "packer.xenserver"
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)
}