From 34f163ce87b51d3dd2fc3be02a73d43dc15d3036 Mon Sep 17 00:00:00 2001 From: Eloy Coto Date: Wed, 24 Jun 2015 08:28:14 +0100 Subject: [PATCH 1/3] 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 From 0bc042a15c52d326b3de5e9c0918de84428741fa Mon Sep 17 00:00:00 2001 From: Eloy Coto Date: Wed, 24 Jun 2015 11:50:19 +0100 Subject: [PATCH 2/3] Post-Processor/Vsphere: Added custom options --- post-processor/vsphere/post-processor.go | 33 +++++++++++-------- .../post-processors/vsphere.html.markdown | 4 +++ 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/post-processor/vsphere/post-processor.go b/post-processor/vsphere/post-processor.go index 514face0f..182be5c0e 100644 --- a/post-processor/vsphere/post-processor.go +++ b/post-processor/vsphere/post-processor.go @@ -22,19 +22,20 @@ var builtins = map[string]string{ type Config struct { common.PackerConfig `mapstructure:",squash"` - 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"` - VMFolder string `mapstructure:"vm_folder"` - VMName string `mapstructure:"vm_name"` - VMNetwork string `mapstructure:"vm_network"` + 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"` + Options []string `mapstructure:"options"` + Overwrite bool `mapstructure:"overwrite"` + Password string `mapstructure:"password"` + ResourcePool string `mapstructure:"resource_pool"` + Username string `mapstructure:"username"` + VMFolder string `mapstructure:"vm_folder"` + VMName string `mapstructure:"vm_name"` + VMNetwork string `mapstructure:"vm_network"` ctx interpolate.Context } @@ -143,12 +144,16 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac options = append(options, "--overwrite") } + if len(p.config.Options) > 0 { + options = append(options, p.config.Options...) + } + 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(command, " ")) - cmd := exec.Command("ovftool", args...) + cmd := exec.Command("ovftool", command...) cmd.Stdout = &out if err := cmd.Run(); err != nil { return nil, false, fmt.Errorf("Failed: %s\nStdout: %s", err, out.String()) diff --git a/website/source/docs/post-processors/vsphere.html.markdown b/website/source/docs/post-processors/vsphere.html.markdown index 326fdf56c..7cb790418 100644 --- a/website/source/docs/post-processors/vsphere.html.markdown +++ b/website/source/docs/post-processors/vsphere.html.markdown @@ -58,3 +58,7 @@ Optional: - `overwrite` (boolean) - If it's true force the system to overwrite the existing files instead create new ones. Default is false + +* `options` (array of strings) - Custom options to add in ovftool. See `ovftool + --help` to list all the options + From 63d21ec9f3b00441a5f48416a9891e92d81e1f91 Mon Sep 17 00:00:00 2001 From: Eloy Coto Date: Thu, 29 Oct 2015 09:42:26 +0000 Subject: [PATCH 3/3] Vsphere post-processor: Fix merge problems --- post-processor/vsphere/post-processor.go | 19 ++++++------------- .../post-processors/vsphere.html.markdown | 3 +-- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/post-processor/vsphere/post-processor.go b/post-processor/vsphere/post-processor.go index 182be5c0e..cde3d5480 100644 --- a/post-processor/vsphere/post-processor.go +++ b/post-processor/vsphere/post-processor.go @@ -121,7 +121,7 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac ovftool_uri += "/Resources/" + p.config.ResourcePool } - options := []string{ + args := []string{ fmt.Sprintf("--noSSLVerify=%t", p.config.Insecure), "--acceptAllEulas", fmt.Sprintf("--name=%s", p.config.VMName), @@ -135,25 +135,18 @@ 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") + args = append(args, "--overwrite") } if len(p.config.Options) > 0 { - options = append(options, p.config.Options...) + args = append(args, p.config.Options...) } - command := append(options, args...) - - ui.Message(fmt.Sprintf("Uploading %s to vSphere", vmx)) + ui.Message(fmt.Sprintf("Uploading %s to vSphere", source)) var out bytes.Buffer - log.Printf("Starting ovftool with parameters: %s", strings.Join(command, " ")) - cmd := exec.Command("ovftool", command...) + log.Printf("Starting ovftool with parameters: %s", strings.Join(args, " ")) + cmd := exec.Command("ovftool", args...) cmd.Stdout = &out if err := cmd.Run(); err != nil { return nil, false, fmt.Errorf("Failed: %s\nStdout: %s", err, out.String()) diff --git a/website/source/docs/post-processors/vsphere.html.markdown b/website/source/docs/post-processors/vsphere.html.markdown index 7cb790418..90bf6f40b 100644 --- a/website/source/docs/post-processors/vsphere.html.markdown +++ b/website/source/docs/post-processors/vsphere.html.markdown @@ -59,6 +59,5 @@ Optional: - `overwrite` (boolean) - If it's true force the system to overwrite the existing files instead create new ones. Default is false -* `options` (array of strings) - Custom options to add in ovftool. See `ovftool +- `options` (array of strings) - Custom options to add in ovftool. See `ovftool --help` to list all the options -