Add 'configuration_parameters' option
This commit is contained in:
parent
099215cebc
commit
39f1e4a394
22
driver/vm.go
22
driver/vm.go
|
@ -519,3 +519,25 @@ func (vm *VirtualMachine) addDevice(device types.BaseVirtualDevice) error {
|
|||
func convertGiBToKiB(gib int64) int64 {
|
||||
return gib * 1024 * 1024
|
||||
}
|
||||
|
||||
func (vm *VirtualMachine) AddConfigParams(params map[string]string) error {
|
||||
var confSpec types.VirtualMachineConfigSpec
|
||||
|
||||
var ov []types.BaseOptionValue
|
||||
for k, v := range params {
|
||||
o := types.OptionValue{
|
||||
Key: k,
|
||||
Value: v,
|
||||
}
|
||||
ov = append(ov, &o)
|
||||
}
|
||||
confSpec.ExtraConfig = ov
|
||||
|
||||
task, err := vm.vm.Reconfigure(vm.driver.ctx, confSpec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = task.WaitForResult(vm.driver.ctx, nil)
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -50,6 +50,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
|||
Config: &b.config.FloppyConfig,
|
||||
Datastore: b.config.Datastore,
|
||||
},
|
||||
&StepConfigParams{
|
||||
Config: &b.config.ConfigParamsConfig,
|
||||
},
|
||||
)
|
||||
|
||||
if b.config.Comm.Type != "none" {
|
||||
|
|
|
@ -22,6 +22,7 @@ type Config struct {
|
|||
CreateConfig `mapstructure:",squash"`
|
||||
CDRomConfig `mapstructure:",squash"`
|
||||
FloppyConfig `mapstructure:",squash"`
|
||||
ConfigParamsConfig `mapstructure:",squash"`
|
||||
|
||||
ctx interpolate.Context
|
||||
}
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
package iso
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/packer/packer"
|
||||
"github.com/jetbrains-infra/packer-builder-vsphere/driver"
|
||||
"github.com/mitchellh/multistep"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type ConfigParamsConfig struct {
|
||||
ConfigParams map[string]string `mapstructure:"configuration_parameters"`
|
||||
}
|
||||
|
||||
func (c *ConfigParamsConfig) Prepare() []error {
|
||||
return nil
|
||||
}
|
||||
|
||||
type StepConfigParams struct {
|
||||
Config *ConfigParamsConfig
|
||||
}
|
||||
|
||||
func (s *StepConfigParams) Run(state multistep.StateBag) multistep.StepAction {
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
vm := state.Get("vm").(*driver.VirtualMachine)
|
||||
|
||||
ui.Say("Adding configuration parameters...")
|
||||
|
||||
if err := vm.AddConfigParams(s.Config.ConfigParams); err != nil {
|
||||
state.Put("error", fmt.Errorf("error adding configuration parameters: %v", err))
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
|
||||
return multistep.ActionContinue
|
||||
}
|
||||
|
||||
func (s *StepConfigParams) Cleanup(state multistep.StateBag) {}
|
Loading…
Reference in New Issue