updated documentation, vm_name mandatory and cleaning code

This commit is contained in:
bugbuilder 2017-07-31 00:26:58 -04:00
parent 08c6139da4
commit 786d3c0a9d
4 changed files with 18 additions and 20 deletions

View File

@ -55,6 +55,7 @@ func (p *PostProcessor) Configure(raws ...interface{}) error {
"host": &p.config.Host,
"username": &p.config.Username,
"password": &p.config.Password,
"vm_name": &p.config.VMName,
}
for key, ptr := range vc {

View File

@ -3,8 +3,7 @@ package vsphere_template
import (
"context"
"fmt"
"path/filepath"
"strings"
"path"
"github.com/hashicorp/packer/packer"
"github.com/mitchellh/multistep"
@ -24,8 +23,8 @@ func (s *stepCreateFolder) Run(state multistep.StateBag) multistep.StepAction {
if s.Folder != "" {
ui.Say("Creating or checking destination folders...")
base := filepath.Join(dcPath, "vm")
path := filepath.ToSlash(filepath.Join(base, s.Folder))
base := path.Join(dcPath, "vm")
fullPath := path.Join(base, s.Folder)
si := object.NewSearchIndex(cli.Client)
var folders []string
@ -36,23 +35,24 @@ func (s *stepCreateFolder) Run(state multistep.StateBag) multistep.StepAction {
// If we don't find it, we save the folder name and continue with the previous path
// The iteration ends when we find an existing path otherwise it throws error
for {
ref, err = si.FindByInventoryPath(context.Background(), path)
ref, err = si.FindByInventoryPath(context.Background(), fullPath)
if err != nil {
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
if ref == nil {
_, folder := filepath.Split(path)
folders = append(folders, folder)
path = path[:strings.LastIndex(path, "/")]
dir, folder := path.Split(fullPath)
fullPath = path.Clean(dir)
if path == dcPath {
err = fmt.Errorf("vSphere base path %s not found", filepath.ToSlash(base))
if fullPath == dcPath {
err = fmt.Errorf("vSphere base path %s not found", base)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
folders = append(folders, folder)
} else {
break
}

View File

@ -2,7 +2,7 @@ package vsphere_template
import (
"context"
"path/filepath"
"path"
"github.com/hashicorp/packer/packer"
"github.com/mitchellh/multistep"
@ -24,7 +24,7 @@ func (s *stepMoveTemplate) Run(state multistep.StateBag) multistep.StepAction {
if s.Folder != "" {
ui.Say("Moving template...")
folder, err := finder.Folder(context.Background(), filepath.ToSlash(filepath.Join(dcPath, "vm", s.Folder)))
folder, err := finder.Folder(context.Background(), path.Join(dcPath, "vm", s.Folder))
if err != nil {
state.Put("error", err)
ui.Error(err.Error())

View File

@ -39,16 +39,11 @@ each category, the available configuration keys are alphabetized.
Required:
- `host` (string) - The vSphere host that contains the VM built by the vmware-iso.
- `insecure` (boolean) - If it's true Skip verification of server certificate.
Default is false
- `host` (string) - The vSphere host that contains the VM built by the vmware-iso.
- `password` (string) - Password to use to authenticate to the
vSphere endpoint.
- `password` (string) - Password to use to authenticate to the vSphere endpoint.
- `username` (string) - The username to use to authenticate to the
vSphere endpoint.
- `username` (string) - The username to use to authenticate to the vSphere endpoint.
- `vm_name` (string) - The name of the VM once it is uploaded.
@ -57,3 +52,5 @@ Optional:
- `datacenter` (string) - If you have more than one, you will need to specify which one the ESXi used.
- `folder` (string) - Target path where the template will be created.
- `insecure` (boolean) - If it's true skip verification of server certificate. Default is false