Merge pull request #5187 from mkuzmin/vmware-artifactid

vmware: Publish artifact ID
This commit is contained in:
Matthew Hooker 2017-08-30 13:56:49 -07:00 committed by GitHub
commit cd11e4ff33
5 changed files with 14 additions and 7 deletions

View File

@ -14,13 +14,14 @@ const BuilderId = "mitchellh.vmware"
// Artifact is the result of running the VMware builder, namely a set // Artifact is the result of running the VMware builder, namely a set
// of files associated with the resulting machine. // of files associated with the resulting machine.
type localArtifact struct { type localArtifact struct {
id string
dir string dir string
f []string f []string
} }
// NewLocalArtifact returns a VMware artifact containing the files // NewLocalArtifact returns a VMware artifact containing the files
// in the given directory. // in the given directory.
func NewLocalArtifact(dir string) (packer.Artifact, error) { func NewLocalArtifact(id string, dir string) (packer.Artifact, error) {
files := make([]string, 0, 5) files := make([]string, 0, 5)
visit := func(path string, info os.FileInfo, err error) error { visit := func(path string, info os.FileInfo, err error) error {
if err != nil { if err != nil {
@ -37,6 +38,7 @@ func NewLocalArtifact(dir string) (packer.Artifact, error) {
} }
return &localArtifact{ return &localArtifact{
id: id,
dir: dir, dir: dir,
f: files, f: files,
}, nil }, nil
@ -50,8 +52,8 @@ func (a *localArtifact) Files() []string {
return a.f return a.f
} }
func (*localArtifact) Id() string { func (a *localArtifact) Id() string {
return "VM" return a.id
} }
func (a *localArtifact) String() string { func (a *localArtifact) String() string {

View File

@ -29,7 +29,7 @@ func TestNewLocalArtifact(t *testing.T) {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
a, err := NewLocalArtifact(td) a, err := NewLocalArtifact("vm1", td)
if err != nil { if err != nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
@ -37,6 +37,9 @@ func TestNewLocalArtifact(t *testing.T) {
if a.BuilderId() != BuilderId { if a.BuilderId() != BuilderId {
t.Fatalf("bad: %#v", a.BuilderId()) t.Fatalf("bad: %#v", a.BuilderId())
} }
if a.Id() != "vm1" {
t.Fatalf("bad: %#v", a.Id())
}
if len(a.Files()) != 1 { if len(a.Files()) != 1 {
t.Fatalf("should length 1: %d", len(a.Files())) t.Fatalf("should length 1: %d", len(a.Files()))
} }

View File

@ -8,6 +8,7 @@ import (
// of files associated with the resulting machine. // of files associated with the resulting machine.
type Artifact struct { type Artifact struct {
builderId string builderId string
id string
dir OutputDir dir OutputDir
f []string f []string
} }
@ -20,8 +21,8 @@ func (a *Artifact) Files() []string {
return a.f return a.f
} }
func (*Artifact) Id() string { func (a *Artifact) Id() string {
return "VM" return a.id
} }
func (a *Artifact) String() string { func (a *Artifact) String() string {

View File

@ -349,6 +349,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
return &Artifact{ return &Artifact{
builderId: builderId, builderId: builderId,
id: b.config.VMName,
dir: dir, dir: dir,
f: files, f: files,
}, nil }, nil

View File

@ -142,7 +142,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
return nil, errors.New("Build was halted.") return nil, errors.New("Build was halted.")
} }
return vmwcommon.NewLocalArtifact(b.config.OutputDir) return vmwcommon.NewLocalArtifact(b.config.VMName, b.config.OutputDir)
} }
// Cancel. // Cancel.