packer-xcp-ng/builder/xenserver/common/artifact.go

59 lines
1.0 KiB
Go
Raw Permalink Normal View History

2023-02-14 15:48:24 +01:00
package common
import (
"fmt"
"github.com/hashicorp/packer-plugin-sdk/packer"
"os"
"path/filepath"
)
// This is the common builder ID to all of these artifacts.
2023-04-14 17:16:54 +02:00
const BuilderId = "packer.xcp-ng"
2023-02-14 15:48:24 +01:00
type LocalArtifact struct {
dir string
f []string
}
func NewArtifact(dir string) (packer.Artifact, error) {
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 {
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)
}
func (a *LocalArtifact) State(name string) interface{} {
return nil
}
func (a *LocalArtifact) Destroy() error {
return os.RemoveAll(a.dir)
}