Post-Processor/Vsphere: Added custom options

This commit is contained in:
Eloy Coto 2015-06-24 11:50:19 +01:00
parent 34f163ce87
commit 0bc042a15c
2 changed files with 23 additions and 14 deletions

View File

@ -22,19 +22,20 @@ var builtins = map[string]string{
type Config struct { type Config struct {
common.PackerConfig `mapstructure:",squash"` common.PackerConfig `mapstructure:",squash"`
Cluster string `mapstructure:"cluster"` Cluster string `mapstructure:"cluster"`
Datacenter string `mapstructure:"datacenter"` Datacenter string `mapstructure:"datacenter"`
Datastore string `mapstructure:"datastore"` Datastore string `mapstructure:"datastore"`
DiskMode string `mapstructure:"disk_mode"` DiskMode string `mapstructure:"disk_mode"`
Host string `mapstructure:"host"` Host string `mapstructure:"host"`
Insecure bool `mapstructure:"insecure"` Insecure bool `mapstructure:"insecure"`
Overwrite bool `mapstructure:"overwrite"` Options []string `mapstructure:"options"`
Password string `mapstructure:"password"` Overwrite bool `mapstructure:"overwrite"`
ResourcePool string `mapstructure:"resource_pool"` Password string `mapstructure:"password"`
Username string `mapstructure:"username"` ResourcePool string `mapstructure:"resource_pool"`
VMFolder string `mapstructure:"vm_folder"` Username string `mapstructure:"username"`
VMName string `mapstructure:"vm_name"` VMFolder string `mapstructure:"vm_folder"`
VMNetwork string `mapstructure:"vm_network"` VMName string `mapstructure:"vm_name"`
VMNetwork string `mapstructure:"vm_network"`
ctx interpolate.Context ctx interpolate.Context
} }
@ -143,12 +144,16 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac
options = append(options, "--overwrite") options = append(options, "--overwrite")
} }
if len(p.config.Options) > 0 {
options = append(options, p.config.Options...)
}
command := append(options, args...) command := append(options, args...)
ui.Message(fmt.Sprintf("Uploading %s to vSphere", vmx)) ui.Message(fmt.Sprintf("Uploading %s to vSphere", vmx))
var out bytes.Buffer var out bytes.Buffer
log.Printf("Starting ovftool with parameters: %s", strings.Join(command, " ")) log.Printf("Starting ovftool with parameters: %s", strings.Join(command, " "))
cmd := exec.Command("ovftool", args...) cmd := exec.Command("ovftool", command...)
cmd.Stdout = &out cmd.Stdout = &out
if err := cmd.Run(); err != nil { if err := cmd.Run(); err != nil {
return nil, false, fmt.Errorf("Failed: %s\nStdout: %s", err, out.String()) return nil, false, fmt.Errorf("Failed: %s\nStdout: %s", err, out.String())

View File

@ -58,3 +58,7 @@ Optional:
- `overwrite` (boolean) - If it's true force the system to overwrite the - `overwrite` (boolean) - If it's true force the system to overwrite the
existing files instead create new ones. Default is false 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