From 6cb51f21de746404e7ba1be3a5bfe00181bf1dd1 Mon Sep 17 00:00:00 2001 From: Salvador Girones Date: Mon, 22 Jun 2015 10:13:49 -0700 Subject: [PATCH] Make ResourcePool optional --- post-processor/vsphere/post-processor.go | 20 +++++++++++-------- .../post-processors/vsphere.html.markdown | 2 +- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/post-processor/vsphere/post-processor.go b/post-processor/vsphere/post-processor.go index f9a6c37c3..0b25c7b2c 100644 --- a/post-processor/vsphere/post-processor.go +++ b/post-processor/vsphere/post-processor.go @@ -72,7 +72,6 @@ func (p *PostProcessor) Configure(raws ...interface{}) error { "diskmode": &p.config.DiskMode, "host": &p.config.Host, "password": &p.config.Password, - "resource_pool": &p.config.ResourcePool, "username": &p.config.Username, "vm_name": &p.config.VMName, } @@ -107,6 +106,17 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac return nil, false, fmt.Errorf("VMX file not found") } + ovftool_uri := fmt.Sprintf("vi://%s:%s@%s/%s/host/%s", + url.QueryEscape(p.config.Username), + url.QueryEscape(p.config.Password), + p.config.Host, + p.config.Datacenter, + p.config.Cluster) + + if p.config.ResourcePool != "" { + ovftool_uri += "/Resources/" + p.config.ResourcePool + } + args := []string{ fmt.Sprintf("--noSSLVerify=%t", p.config.Insecure), "--acceptAllEulas", @@ -116,13 +126,7 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac fmt.Sprintf("--network=%s", p.config.VMNetwork), fmt.Sprintf("--vmFolder=%s", p.config.VMFolder), fmt.Sprintf("%s", vmx), - fmt.Sprintf("vi://%s:%s@%s/%s/host/%s/Resources/%s/", - url.QueryEscape(p.config.Username), - url.QueryEscape(p.config.Password), - p.config.Host, - p.config.Datacenter, - p.config.Cluster, - p.config.ResourcePool), + fmt.Sprintf("%s", ovftool_uri), } ui.Message(fmt.Sprintf("Uploading %s to vSphere", vmx)) diff --git a/website/source/docs/post-processors/vsphere.html.markdown b/website/source/docs/post-processors/vsphere.html.markdown index a6f790bc1..ca3f3f54a 100644 --- a/website/source/docs/post-processors/vsphere.html.markdown +++ b/website/source/docs/post-processors/vsphere.html.markdown @@ -35,7 +35,7 @@ Required: endpoint. * `resource_pool` (string) - The resource pool to upload the VM to. - This is _not required_ if `datastore` is specified. + This is _not required_. * `username` (string) - The username to use to authenticate to the vSphere endpoint.