clean up if logic

This commit is contained in:
Joshua Foster 2020-07-02 12:33:28 -04:00
parent 63f9282f5c
commit e4dffeed35
2 changed files with 19 additions and 21 deletions

View File

@ -51,9 +51,7 @@ func (s *StepConfigParams) Run(_ context.Context, state multistep.StateBag) mult
if s.Config.ToolsUpgradePolicy {
info.ToolsUpgradePolicy = "UpgradeAtPowerCycle"
}
}
if len(configParams) > 0 || info != nil {
ui.Say("Adding configuration parameters...")
if err := vm.AddConfigParams(configParams, info); err != nil {
state.Put("error", fmt.Errorf("error adding configuration parameters: %v", err))

View File

@ -802,29 +802,29 @@ func (vm *VirtualMachine) addDevice(device types.BaseVirtualDevice) error {
func (vm *VirtualMachine) AddConfigParams(params map[string]string, info *types.ToolsConfigInfo) error {
var confSpec types.VirtualMachineConfigSpec
var err error
if len(params) > 0 {
var ov []types.BaseOptionValue
for k, v := range params {
o := types.OptionValue{
Key: k,
Value: v,
}
ov = append(ov, &o)
var ov []types.BaseOptionValue
for k, v := range params {
o := types.OptionValue{
Key: k,
Value: v,
}
confSpec.ExtraConfig = ov
ov = append(ov, &o)
}
confSpec.ExtraConfig = ov
confSpec.Tools = info
if len(confSpec.ExtraConfig) > 0 || confSpec.Tools != nil {
task, err := vm.vm.Reconfigure(vm.driver.ctx, confSpec)
if err != nil {
return err
}
_, err = task.WaitForResult(vm.driver.ctx, nil)
}
if info != nil {
confSpec.Tools = info
}
task, err := vm.vm.Reconfigure(vm.driver.ctx, confSpec)
if err != nil {
return err
}
_, err = task.WaitForResult(vm.driver.ctx, nil)
return err
}