2014-12-29 06:46:54 -06:00
|
|
|
package common
|
2014-11-10 12:16:02 -06:00
|
|
|
|
|
|
|
import (
|
2014-12-08 09:34:48 -06:00
|
|
|
"fmt"
|
2021-02-23 16:43:20 -06:00
|
|
|
"github.com/hashicorp/packer-plugin-sdk/packer"
|
2014-12-08 09:34:48 -06:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2014-11-10 12:16:02 -06:00
|
|
|
)
|
|
|
|
|
2014-12-29 06:46:54 -06:00
|
|
|
// This is the common builder ID to all of these artifacts.
|
|
|
|
const BuilderId = "packer.xenserver"
|
|
|
|
|
2014-11-10 12:16:02 -06:00
|
|
|
type LocalArtifact struct {
|
2014-12-08 09:34:48 -06:00
|
|
|
dir string
|
|
|
|
f []string
|
2014-11-10 12:16:02 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2014-11-10 12:16:02 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func (*LocalArtifact) BuilderId() string {
|
2014-12-08 09:34:48 -06:00
|
|
|
return BuilderId
|
2014-11-10 12:16:02 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *LocalArtifact) Files() []string {
|
2014-12-08 09:34:48 -06:00
|
|
|
return a.f
|
2014-11-10 12:16:02 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func (*LocalArtifact) Id() string {
|
2014-12-08 09:34:48 -06:00
|
|
|
return "VM"
|
2014-11-10 12:16:02 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *LocalArtifact) String() string {
|
2014-12-08 09:34:48 -06:00
|
|
|
return fmt.Sprintf("VM files in directory: %s", a.dir)
|
2014-11-10 12:16:02 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *LocalArtifact) State(name string) interface{} {
|
2014-12-08 09:34:48 -06:00
|
|
|
return nil
|
2014-11-10 12:16:02 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *LocalArtifact) Destroy() error {
|
2014-12-08 09:34:48 -06:00
|
|
|
return os.RemoveAll(a.dir)
|
2014-11-10 12:16:02 -06:00
|
|
|
}
|