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"` common.PackerConfig `mapstructure:",squash"`
Insecure bool `mapstructure:"insecure"` Insecure bool `mapstructure:"insecure"`
Cluster string `mapstructure:"cluster"`
Datacenter string `mapstructure:"datacenter"` Datacenter string `mapstructure:"datacenter"`
Datastore string `mapstructure:"datastore"` Datastore string `mapstructure:"datastore"`
Debug bool `mapstructure:"debug"`
Host string `mapstructure:"host"` Host string `mapstructure:"host"`
Password string `mapstructure:"password"` Password string `mapstructure:"password"`
PathToResourcePool string `mapstructure:"path_to_resource_pool"` ResourcePool string `mapstructure:"resource_pool"`
Username string `mapstructure:"username"` Username string `mapstructure:"username"`
VMFolder string `mapstructure:"vm_folder"` VMFolder string `mapstructure:"vm_folder"`
VMName string `mapstructure:"vm_name"` VMName string `mapstructure:"vm_name"`
@ -37,7 +39,7 @@ func (p *PostProcessor) Configure(raws ...interface{}) error {
if err != nil { if err != nil {
return err return err
} }
tpl, err := packer.NewConfigTemplate() tpl, err := packer.NewConfigTemplate()
if err != nil { if err != nil {
return err return err
@ -46,22 +48,28 @@ func (p *PostProcessor) Configure(raws ...interface{}) error {
// Accumulate any errors // Accumulate any errors
errs := new(packer.MultiError) 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 { if _, err := exec.LookPath("ovftool"); err != nil {
errs = packer.MultiErrorAppend( errs = packer.MultiErrorAppend(
errs, fmt.Errorf("ovftool not found: %s", err)) errs, fmt.Errorf("ovftool not found: %s", err))
} }
validates := map[string]*string{ validates := map[string]*string{
"datacenter": &p.config.Datacenter, "cluster": &p.config.Cluster,
"datastore": &p.config.Datastore, "datacenter": &p.config.Datacenter,
"host": &p.config.Host, "datastore": &p.config.Datastore,
"vm_network": &p.config.VMNetwork, "host": &p.config.Host,
"password": &p.config.Password, "vm_network": &p.config.VMNetwork,
"path_to_resource_pool": &p.config.PathToResourcePool, "password": &p.config.Password,
"username": &p.config.Username, "resource_pool": &p.config.ResourcePool,
"vm_folder": &p.config.VMFolder, "username": &p.config.Username,
"vm_name": &p.config.VMName, "vm_folder": &p.config.VMFolder,
"vm_name": &p.config.VMName,
} }
for n := range validates { 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("--datastore=%s", p.config.Datastore),
fmt.Sprintf("--network=%s", p.config.VMNetwork), fmt.Sprintf("--network=%s", p.config.VMNetwork),
fmt.Sprintf("--vmFolder=%s", p.config.VMFolder), 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.Username,
p.config.Password, p.config.Password,
p.config.Host, p.config.Host,
p.config.Datacenter, 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 var out bytes.Buffer