From b88fb8bdb2bc8f38f1ca9cdcaa4045ce5c4700b7 Mon Sep 17 00:00:00 2001 From: bugbuilder Date: Mon, 10 Jul 2017 04:13:54 -0400 Subject: [PATCH] Improved creation folder step and fixed documentation --- post-processor/vsphere-tpl/post-processor.go | 1 - .../vsphere-tpl/step_create_folder.go | 21 +++++++------------ .../post-processors/vsphere-template.html.md | 18 ++++++++-------- 3 files changed, 16 insertions(+), 24 deletions(-) diff --git a/post-processor/vsphere-tpl/post-processor.go b/post-processor/vsphere-tpl/post-processor.go index b5fc59325..1793036d0 100644 --- a/post-processor/vsphere-tpl/post-processor.go +++ b/post-processor/vsphere-tpl/post-processor.go @@ -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 } diff --git a/post-processor/vsphere-tpl/step_create_folder.go b/post-processor/vsphere-tpl/step_create_folder.go index d00392c5c..e10161774 100644 --- a/post-processor/vsphere-tpl/step_create_folder.go +++ b/post-processor/vsphere-tpl/step_create_folder.go @@ -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 diff --git a/website/source/docs/post-processors/vsphere-template.html.md b/website/source/docs/post-processors/vsphere-template.html.md index e7351c7f6..38f39a90f 100644 --- a/website/source/docs/post-processors/vsphere-template.html.md +++ b/website/source/docs/post-processors/vsphere-template.html.md @@ -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.