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
// of files associated with the resulting machine.
type localArtifact struct {
id string
dir string
f []string
}
// NewLocalArtifact returns a VMware artifact containing the files
// 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)
visit := func(path string, info os.FileInfo, err error) error {
if err != nil {
@ -37,6 +38,7 @@ func NewLocalArtifact(dir string) (packer.Artifact, error) {
}
return &localArtifact{
id: id,
dir: dir,
f: files,
}, nil
@ -50,8 +52,8 @@ func (a *localArtifact) Files() []string {
return a.f
}
func (*localArtifact) Id() string {
return "VM"
func (a *localArtifact) Id() string {
return a.id
}
func (a *localArtifact) String() string {

View File

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

View File

@ -8,6 +8,7 @@ import (
// of files associated with the resulting machine.
type Artifact struct {
builderId string
id string
dir OutputDir
f []string
}
@ -20,8 +21,8 @@ func (a *Artifact) Files() []string {
return a.f
}
func (*Artifact) Id() string {
return "VM"
func (a *Artifact) Id() string {
return a.id
}
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{
builderId: builderId,
id: b.config.VMName,
dir: dir,
f: files,
}, 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 vmwcommon.NewLocalArtifact(b.config.OutputDir)
return vmwcommon.NewLocalArtifact(b.config.VMName, b.config.OutputDir)
}
// Cancel.