fix vshere ToolsSyncTime and ToolsUpgradePolicy
This commit is contained in:
parent
af9d2e6f22
commit
63f9282f5c
|
@ -7,6 +7,8 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/vmware/govmomi/vim25/types"
|
||||||
|
|
||||||
"github.com/hashicorp/packer/builder/vsphere/driver"
|
"github.com/hashicorp/packer/builder/vsphere/driver"
|
||||||
"github.com/hashicorp/packer/helper/multistep"
|
"github.com/hashicorp/packer/helper/multistep"
|
||||||
"github.com/hashicorp/packer/packer"
|
"github.com/hashicorp/packer/packer"
|
||||||
|
@ -17,8 +19,7 @@ type ConfigParamsConfig struct {
|
||||||
// ConfigSpec: https://pubs.vmware.com/vi3/sdk/ReferenceGuide/vim.vm.ConfigSpec.html
|
// ConfigSpec: https://pubs.vmware.com/vi3/sdk/ReferenceGuide/vim.vm.ConfigSpec.html
|
||||||
ConfigParams map[string]string `mapstructure:"configuration_parameters"`
|
ConfigParams map[string]string `mapstructure:"configuration_parameters"`
|
||||||
|
|
||||||
// Enables time synchronization with the host. If set to true will set `tools.syncTime` to `TRUE`.
|
// Enables time synchronization with the host. Defaults to false.
|
||||||
// Defaults to FALSE.
|
|
||||||
ToolsSyncTime bool `mapstructure:"tools_sync_time"`
|
ToolsSyncTime bool `mapstructure:"tools_sync_time"`
|
||||||
|
|
||||||
// If sets to true, vSphere will automatically check and upgrade VMware Tools upon a system power cycle.
|
// If sets to true, vSphere will automatically check and upgrade VMware Tools upon a system power cycle.
|
||||||
|
@ -39,17 +40,22 @@ func (s *StepConfigParams) Run(_ context.Context, state multistep.StateBag) mult
|
||||||
configParams = s.Config.ConfigParams
|
configParams = s.Config.ConfigParams
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.Config.ToolsSyncTime {
|
var info *types.ToolsConfigInfo
|
||||||
configParams["tools.syncTime"] = "TRUE"
|
if s.Config.ToolsSyncTime || s.Config.ToolsUpgradePolicy {
|
||||||
|
info = &types.ToolsConfigInfo{}
|
||||||
|
|
||||||
|
if s.Config.ToolsSyncTime {
|
||||||
|
info.SyncTimeWithHost = &s.Config.ToolsSyncTime
|
||||||
|
}
|
||||||
|
|
||||||
|
if s.Config.ToolsUpgradePolicy {
|
||||||
|
info.ToolsUpgradePolicy = "UpgradeAtPowerCycle"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.Config.ToolsUpgradePolicy {
|
if len(configParams) > 0 || info != nil {
|
||||||
configParams["tools.upgrade.policy"] = "upgradeAtPowerCycle"
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(configParams) > 0 {
|
|
||||||
ui.Say("Adding configuration parameters...")
|
ui.Say("Adding configuration parameters...")
|
||||||
if err := vm.AddConfigParams(configParams); err != nil {
|
if err := vm.AddConfigParams(configParams, info); err != nil {
|
||||||
state.Put("error", fmt.Errorf("error adding configuration parameters: %v", err))
|
state.Put("error", fmt.Errorf("error adding configuration parameters: %v", err))
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
}
|
}
|
||||||
|
|
|
@ -800,18 +800,24 @@ func (vm *VirtualMachine) addDevice(device types.BaseVirtualDevice) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (vm *VirtualMachine) AddConfigParams(params map[string]string) error {
|
func (vm *VirtualMachine) AddConfigParams(params map[string]string, info *types.ToolsConfigInfo) error {
|
||||||
var confSpec types.VirtualMachineConfigSpec
|
var confSpec types.VirtualMachineConfigSpec
|
||||||
|
|
||||||
var ov []types.BaseOptionValue
|
if len(params) > 0 {
|
||||||
for k, v := range params {
|
var ov []types.BaseOptionValue
|
||||||
o := types.OptionValue{
|
for k, v := range params {
|
||||||
Key: k,
|
o := types.OptionValue{
|
||||||
Value: v,
|
Key: k,
|
||||||
|
Value: v,
|
||||||
|
}
|
||||||
|
ov = append(ov, &o)
|
||||||
}
|
}
|
||||||
ov = append(ov, &o)
|
confSpec.ExtraConfig = ov
|
||||||
|
}
|
||||||
|
|
||||||
|
if info != nil {
|
||||||
|
confSpec.Tools = info
|
||||||
}
|
}
|
||||||
confSpec.ExtraConfig = ov
|
|
||||||
|
|
||||||
task, err := vm.vm.Reconfigure(vm.driver.ctx, confSpec)
|
task, err := vm.vm.Reconfigure(vm.driver.ctx, confSpec)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -3,8 +3,7 @@
|
||||||
- `configuration_parameters` (map[string]string) - configuration_parameters is a direct passthrough to the VSphere API's
|
- `configuration_parameters` (map[string]string) - configuration_parameters is a direct passthrough to the VSphere API's
|
||||||
ConfigSpec: https://pubs.vmware.com/vi3/sdk/ReferenceGuide/vim.vm.ConfigSpec.html
|
ConfigSpec: https://pubs.vmware.com/vi3/sdk/ReferenceGuide/vim.vm.ConfigSpec.html
|
||||||
|
|
||||||
- `tools_sync_time` (bool) - Enables time synchronization with the host. If set to true will set `tools.syncTime` to `TRUE`.
|
- `tools_sync_time` (bool) - Enables time synchronization with the host. Defaults to false.
|
||||||
Defaults to FALSE.
|
|
||||||
|
|
||||||
- `tools_upgrade_policy` (bool) - If sets to true, vSphere will automatically check and upgrade VMware Tools upon a system power cycle.
|
- `tools_upgrade_policy` (bool) - If sets to true, vSphere will automatically check and upgrade VMware Tools upon a system power cycle.
|
||||||
If not set, defaults to manual upgrade.
|
If not set, defaults to manual upgrade.
|
||||||
|
|
Loading…
Reference in New Issue