From 2aaec946b3b7990c29d94583940d211415ef0799 Mon Sep 17 00:00:00 2001 From: mheidenr Date: Fri, 29 Nov 2013 17:33:26 +0100 Subject: [PATCH] fix post-processor vsphere --- post-processor/vsphere/post-processor.go | 42 ++++++++++++++++-------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/post-processor/vsphere/post-processor.go b/post-processor/vsphere/post-processor.go index 5508638fd..113d6b3a0 100644 --- a/post-processor/vsphere/post-processor.go +++ b/post-processor/vsphere/post-processor.go @@ -17,11 +17,13 @@ type Config struct { common.PackerConfig `mapstructure:",squash"` Insecure bool `mapstructure:"insecure"` + Cluster string `mapstructure:"cluster"` Datacenter string `mapstructure:"datacenter"` Datastore string `mapstructure:"datastore"` + Debug bool `mapstructure:"debug"` Host string `mapstructure:"host"` Password string `mapstructure:"password"` - PathToResourcePool string `mapstructure:"path_to_resource_pool"` + ResourcePool string `mapstructure:"resource_pool"` Username string `mapstructure:"username"` VMFolder string `mapstructure:"vm_folder"` VMName string `mapstructure:"vm_name"` @@ -37,7 +39,7 @@ func (p *PostProcessor) Configure(raws ...interface{}) error { if err != nil { return err } - + tpl, err := packer.NewConfigTemplate() if err != nil { return err @@ -46,22 +48,28 @@ func (p *PostProcessor) Configure(raws ...interface{}) error { // Accumulate any errors errs := new(packer.MultiError) - + + if err := tpl.Validate(p.config.VMName); err != nil { + errs = packer.MultiErrorAppend( + errs, fmt.Errorf("Error parsing output template: %s", err)) + } + if _, err := exec.LookPath("ovftool"); err != nil { errs = packer.MultiErrorAppend( errs, fmt.Errorf("ovftool not found: %s", err)) } validates := map[string]*string{ - "datacenter": &p.config.Datacenter, - "datastore": &p.config.Datastore, - "host": &p.config.Host, - "vm_network": &p.config.VMNetwork, - "password": &p.config.Password, - "path_to_resource_pool": &p.config.PathToResourcePool, - "username": &p.config.Username, - "vm_folder": &p.config.VMFolder, - "vm_name": &p.config.VMName, + "cluster": &p.config.Cluster, + "datacenter": &p.config.Datacenter, + "datastore": &p.config.Datastore, + "host": &p.config.Host, + "vm_network": &p.config.VMNetwork, + "password": &p.config.Password, + "resource_pool": &p.config.ResourcePool, + "username": &p.config.Username, + "vm_folder": &p.config.VMFolder, + "vm_name": &p.config.VMName, } for n := range validates { @@ -104,12 +112,18 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac fmt.Sprintf("--datastore=%s", p.config.Datastore), fmt.Sprintf("--network=%s", p.config.VMNetwork), fmt.Sprintf("--vmFolder=%s", p.config.VMFolder), - fmt.Sprintf("vi://%s:%s@%s/%s/%s", + fmt.Sprintf("%s", vmx), + fmt.Sprintf("vi://%s:%s@%s/%s/host/%s/Resources/%s", p.config.Username, p.config.Password, p.config.Host, p.config.Datacenter, - p.config.PathToResourcePool), + p.config.Cluster, + p.config.ResourcePool), + } + + if p.config.Debug { + ui.Message(fmt.Sprintf("DEBUG: %s", args)) } var out bytes.Buffer