Improved creation folder step and fixed documentation
This commit is contained in:
parent
2830b4f3b0
commit
b88fb8bdb2
|
@ -130,7 +130,6 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac
|
|||
|
||||
func (p *PostProcessor) configureURL() error {
|
||||
sdk, err := url.Parse(fmt.Sprintf("https://%v/sdk", p.config.Host))
|
||||
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
"github.com/hashicorp/packer/packer"
|
||||
"github.com/mitchellh/multistep"
|
||||
"github.com/vmware/govmomi/find"
|
||||
"github.com/vmware/govmomi/object"
|
||||
)
|
||||
|
||||
type StepCreateFolder struct {
|
||||
|
@ -31,13 +32,13 @@ func (s *StepCreateFolder) Run(state multistep.StateBag) multistep.StepAction {
|
|||
path := s.Folder
|
||||
base := filepath.Join("/", d, "vm")
|
||||
var folders []string
|
||||
var folder, root string
|
||||
var root *object.Folder
|
||||
var err error
|
||||
|
||||
for {
|
||||
_, err := f.Folder(ctx, filepath.ToSlash(filepath.Join(base, path)))
|
||||
root, err = f.Folder(ctx, filepath.ToSlash(filepath.Join(base, path)))
|
||||
if err != nil {
|
||||
|
||||
root, folder = filepath.Split(path)
|
||||
_, folder := filepath.Split(path)
|
||||
folders = append(folders, folder)
|
||||
if i := strings.LastIndex(path, "/"); i == 0 {
|
||||
break
|
||||
|
@ -50,21 +51,13 @@ func (s *StepCreateFolder) Run(state multistep.StateBag) multistep.StepAction {
|
|||
}
|
||||
|
||||
for i := len(folders) - 1; i >= 0; i-- {
|
||||
folder, err := f.Folder(ctx, filepath.ToSlash(filepath.Join(base, "/", root)))
|
||||
ui.Message(fmt.Sprintf("Creating folder: %v", folders[i]))
|
||||
root, err = root.CreateFolder(ctx, folders[i])
|
||||
if err != nil {
|
||||
state.Put("error", err)
|
||||
ui.Error(err.Error())
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
|
||||
ui.Message(fmt.Sprintf("Creating folder: %v", folders[i]))
|
||||
|
||||
if _, err = folder.CreateFolder(ctx, folders[i]); err != nil {
|
||||
state.Put("error", err)
|
||||
ui.Error(err.Error())
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
root = filepath.Join(root, folders[i], "/")
|
||||
}
|
||||
}
|
||||
return multistep.ActionContinue
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
description: |
|
||||
The Packer vSphere Template post-processor takes an artifact from the VMware-iso builder
|
||||
The Packer vSphere Template post-processor takes an artifact from the VMware-iso builder -**only if remote ESXI is chosen**-
|
||||
and allows to mark a VM as a template and leaving it in a path of choice.
|
||||
layout: docs
|
||||
page_title: 'vSphere Template - Post-Processors'
|
||||
|
@ -20,13 +20,13 @@ An example is shown below, showing only the post-processor configuration:
|
|||
|
||||
``` json
|
||||
{
|
||||
"type":"vsphere-tpl",
|
||||
"host":"vcenter.local",
|
||||
"username":"root",
|
||||
"password":"sssh_is_a_secret",
|
||||
"datacenter":"murlock",
|
||||
"vm_name":"distro-7.3",
|
||||
"folder":"/packer-templates/os/distro-7"
|
||||
"type": "vsphere-tpl",
|
||||
"host": "vcenter.local",
|
||||
"username": "root",
|
||||
"password": "secret",
|
||||
"datacenter": "murlock",
|
||||
"vm_name": "distro-7.3",
|
||||
"folder": "/packer-templates/os/distro-7"
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -53,6 +53,6 @@ Required:
|
|||
|
||||
Optional:
|
||||
|
||||
- `folder` (string) - Target path where the template is created.
|
||||
- `folder` (string) - Target path where the template will be created.
|
||||
|
||||
- `datacenter` (string) - If you have more than one, you will need to specified one.
|
||||
|
|
Loading…
Reference in New Issue