Merge pull request #2304 from eloycoto/master

Post-Processor/Vsphere: Added overwrite option
This commit is contained in:
Chris Bednarski 2016-02-02 14:14:54 -08:00
commit dab36cbdee
2 changed files with 32 additions and 13 deletions

View File

@ -22,18 +22,20 @@ var builtins = map[string]string{
type Config struct { type Config struct {
common.PackerConfig `mapstructure:",squash"` common.PackerConfig `mapstructure:",squash"`
Insecure bool `mapstructure:"insecure"` 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"`
Password string `mapstructure:"password"` Options []string `mapstructure:"options"`
ResourcePool string `mapstructure:"resource_pool"` Overwrite bool `mapstructure:"overwrite"`
Username string `mapstructure:"username"` Password string `mapstructure:"password"`
VMFolder string `mapstructure:"vm_folder"` ResourcePool string `mapstructure:"resource_pool"`
VMName string `mapstructure:"vm_name"` Username string `mapstructure:"username"`
VMNetwork string `mapstructure:"vm_network"` VMFolder string `mapstructure:"vm_folder"`
VMName string `mapstructure:"vm_name"`
VMNetwork string `mapstructure:"vm_network"`
ctx interpolate.Context ctx interpolate.Context
} }
@ -131,6 +133,16 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac
fmt.Sprintf("\"%s\"", ovftool_uri), fmt.Sprintf("\"%s\"", ovftool_uri),
} }
ui.Message(fmt.Sprintf("Uploading %s to vSphere", source))
if p.config.Overwrite == true {
args = append(args, "--overwrite")
}
if len(p.config.Options) > 0 {
args = append(args, p.config.Options...)
}
ui.Message(fmt.Sprintf("Uploading %s to vSphere", source)) ui.Message(fmt.Sprintf("Uploading %s to vSphere", source))
var out bytes.Buffer var out bytes.Buffer
log.Printf("Starting ovftool with parameters: %s", strings.Join(args, " ")) log.Printf("Starting ovftool with parameters: %s", strings.Join(args, " "))

View File

@ -53,4 +53,11 @@ Optional:
- `vm_folder` (string) - The folder within the datastore to store the VM. - `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
- `options` (array of strings) - Custom options to add in ovftool. See `ovftool
--help` to list all the options