From 34f163ce87b51d3dd2fc3be02a73d43dc15d3036 Mon Sep 17 00:00:00 2001 From: Eloy Coto Date: Wed, 24 Jun 2015 08:28:14 +0100 Subject: [PATCH] Post-Processor/Vsphere: Added overwrite option --- post-processor/vsphere/post-processor.go | 20 ++++++++++++++++--- .../post-processors/vsphere.html.markdown | 6 +++++- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/post-processor/vsphere/post-processor.go b/post-processor/vsphere/post-processor.go index 21ae9490c..514face0f 100644 --- a/post-processor/vsphere/post-processor.go +++ b/post-processor/vsphere/post-processor.go @@ -22,12 +22,13 @@ var builtins = map[string]string{ type Config struct { common.PackerConfig `mapstructure:",squash"` - Insecure bool `mapstructure:"insecure"` Cluster string `mapstructure:"cluster"` Datacenter string `mapstructure:"datacenter"` Datastore string `mapstructure:"datastore"` DiskMode string `mapstructure:"disk_mode"` Host string `mapstructure:"host"` + Insecure bool `mapstructure:"insecure"` + Overwrite bool `mapstructure:"overwrite"` Password string `mapstructure:"password"` ResourcePool string `mapstructure:"resource_pool"` Username string `mapstructure:"username"` @@ -119,7 +120,7 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac ovftool_uri += "/Resources/" + p.config.ResourcePool } - args := []string{ + options := []string{ fmt.Sprintf("--noSSLVerify=%t", p.config.Insecure), "--acceptAllEulas", fmt.Sprintf("--name=%s", p.config.VMName), @@ -132,8 +133,21 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac } ui.Message(fmt.Sprintf("Uploading %s to vSphere", source)) + + args := []string{ + fmt.Sprintf("%s", vmx), + fmt.Sprintf("%s", ovftool_uri), + } + + if p.config.Overwrite == true { + options = append(options, "--overwrite") + } + + command := append(options, args...) + + ui.Message(fmt.Sprintf("Uploading %s to vSphere", vmx)) var out bytes.Buffer - log.Printf("Starting ovftool with parameters: %s", strings.Join(args, " ")) + log.Printf("Starting ovftool with parameters: %s", strings.Join(command, " ")) cmd := exec.Command("ovftool", args...) cmd.Stdout = &out if err := cmd.Run(); err != nil { diff --git a/website/source/docs/post-processors/vsphere.html.markdown b/website/source/docs/post-processors/vsphere.html.markdown index 300155773..326fdf56c 100644 --- a/website/source/docs/post-processors/vsphere.html.markdown +++ b/website/source/docs/post-processors/vsphere.html.markdown @@ -53,4 +53,8 @@ Optional: - `vm_folder` (string) - The folder within the datastore to store the VM. -- `vm_network` (string) - The name of the VM network this VM will be added to. +- `vm_network` (string) - The name of the VM network this VM will be + added to. + +- `overwrite` (boolean) - If it's true force the system to overwrite the + existing files instead create new ones. Default is false