adding artifact testing and using builder id
This commit is contained in:
parent
f1773a57f8
commit
75a4ca7351
|
@ -125,7 +125,7 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac
|
|||
&stepCreateFolder{
|
||||
Folder: p.config.Folder,
|
||||
},
|
||||
NewStepMarkAsTemplate(artifact.Id(), source),
|
||||
NewStepMarkAsTemplate(artifact, source),
|
||||
}
|
||||
runner := common.NewRunnerWithPauseFn(steps, p.config.PackerConfig, ui, state)
|
||||
runner.Run(state)
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/hashicorp/packer/packer"
|
||||
"github.com/hashicorp/packer/post-processor/vsphere"
|
||||
"github.com/mitchellh/multistep"
|
||||
"github.com/vmware/govmomi"
|
||||
"github.com/vmware/govmomi/object"
|
||||
|
@ -18,18 +19,16 @@ type stepMarkAsTemplate struct {
|
|||
RemoteFolder string
|
||||
}
|
||||
|
||||
func NewStepMarkAsTemplate(vmname, source string) *stepMarkAsTemplate {
|
||||
func NewStepMarkAsTemplate(artifact packer.Artifact, source string) *stepMarkAsTemplate {
|
||||
remoteFolder := "Discovered virtual machine"
|
||||
vmname := artifact.Id()
|
||||
|
||||
if strings.Contains(vmname, "::") {
|
||||
local := strings.Split(vmname, "::")
|
||||
|
||||
datastore := local[0]
|
||||
remoteFolder = local[1]
|
||||
vmname = local[2]
|
||||
|
||||
if artifact.BuilderId() == vsphere.BuilderId {
|
||||
id := strings.Split(artifact.Id(), "::")
|
||||
datastore := id[0]
|
||||
remoteFolder = id[1]
|
||||
vmname = id[2]
|
||||
source = path.Join("/vmfs/volumes/", datastore, vmname, vmname+".vmx")
|
||||
|
||||
}
|
||||
|
||||
return &stepMarkAsTemplate{
|
||||
|
|
|
@ -13,6 +13,15 @@ type Artifact struct {
|
|||
vmname string
|
||||
}
|
||||
|
||||
func NewArtifact(datastore, vmfolder, vmname string, files []string) *Artifact {
|
||||
return &Artifact{
|
||||
files: files,
|
||||
datastore: datastore,
|
||||
vmfolder: vmfolder,
|
||||
vmname: vmname,
|
||||
}
|
||||
}
|
||||
|
||||
func (*Artifact) BuilderId() string {
|
||||
return BuilderId
|
||||
}
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
package vsphere
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/packer/packer"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestArtifact_ImplementsArtifact(t *testing.T) {
|
||||
var raw interface{}
|
||||
raw = &Artifact{}
|
||||
if _, ok := raw.(packer.Artifact); !ok {
|
||||
t.Fatalf("Artifact should be a Artifact")
|
||||
}
|
||||
}
|
||||
|
||||
func TestArtifact_Id(t *testing.T) {
|
||||
artifact := NewArtifact("datastore", "vmfolder", "vmname", nil)
|
||||
if artifact.Id() != "datastore::vmfolder::vmname" {
|
||||
t.Fatalf("must return datastore, vmfolder and vmname splitted by :: as Id")
|
||||
}
|
||||
}
|
|
@ -142,12 +142,7 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac
|
|||
return nil, false, fmt.Errorf("Failed: %s\n", err)
|
||||
}
|
||||
|
||||
artifact = &Artifact{
|
||||
datastore: p.config.Datastore,
|
||||
files: artifact.Files(),
|
||||
vmfolder: p.config.VMFolder,
|
||||
vmname: p.config.VMName,
|
||||
}
|
||||
artifact = NewArtifact(p.config.Datastore, p.config.VMFolder, p.config.VMName, artifact.Files())
|
||||
|
||||
return artifact, true, nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue