fix post-processor vsphere

This commit is contained in:
mheidenr 2013-11-29 17:33:26 +01:00
parent 30ba7307b6
commit 2aaec946b3
1 changed files with 28 additions and 14 deletions

View File

@ -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"`
@ -47,18 +49,24 @@ 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{
"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,
"path_to_resource_pool": &p.config.PathToResourcePool,
"resource_pool": &p.config.ResourcePool,
"username": &p.config.Username,
"vm_folder": &p.config.VMFolder,
"vm_name": &p.config.VMName,
@ -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