Post-Processor/Vsphere: Added overwrite option

This commit is contained in:
Eloy Coto 2015-06-24 08:28:14 +01:00
parent df8f88b3d1
commit 34f163ce87
2 changed files with 22 additions and 4 deletions

View File

@ -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 {

View File

@ -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