hardware step uses vSphere driver
This commit is contained in:
parent
b7d58590a7
commit
b05ba0a9a2
28
driver.go
28
driver.go
|
@ -129,3 +129,31 @@ func (d *Driver) destroyVM(vm *object.VirtualMachine) error {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *Driver) configureVM(vm *object.VirtualMachine, config *HardwareConfig) error {
|
||||
var confSpec types.VirtualMachineConfigSpec
|
||||
confSpec.NumCPUs = config.CPUs
|
||||
confSpec.MemoryMB = config.RAM
|
||||
|
||||
var cpuSpec types.ResourceAllocationInfo
|
||||
cpuSpec.Reservation = config.CPUReservation
|
||||
cpuSpec.Limit = config.CPULimit
|
||||
confSpec.CpuAllocation = &cpuSpec
|
||||
|
||||
var ramSpec types.ResourceAllocationInfo
|
||||
ramSpec.Reservation = config.RAMReservation
|
||||
confSpec.MemoryAllocation = &ramSpec
|
||||
|
||||
confSpec.MemoryReservationLockedToMax = &config.RAMReserveAll
|
||||
|
||||
task, err := vm.Reconfigure(d.ctx, confSpec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = task.WaitForResult(d.ctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package main
|
|||
import (
|
||||
"github.com/mitchellh/multistep"
|
||||
"github.com/hashicorp/packer/packer"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
"github.com/vmware/govmomi/object"
|
||||
"fmt"
|
||||
)
|
||||
|
@ -39,27 +38,7 @@ func (s *StepConfigureHardware) Run(state multistep.StateBag) multistep.StepActi
|
|||
if *s.config != (HardwareConfig{}) {
|
||||
ui.Say("Customizing hardware parameters...")
|
||||
|
||||
var confSpec types.VirtualMachineConfigSpec
|
||||
confSpec.NumCPUs = s.config.CPUs
|
||||
confSpec.MemoryMB = s.config.RAM
|
||||
|
||||
var cpuSpec types.ResourceAllocationInfo
|
||||
cpuSpec.Reservation = s.config.CPUReservation
|
||||
cpuSpec.Limit = s.config.CPULimit
|
||||
confSpec.CpuAllocation = &cpuSpec
|
||||
|
||||
var ramSpec types.ResourceAllocationInfo
|
||||
ramSpec.Reservation = s.config.RAMReservation
|
||||
confSpec.MemoryAllocation = &ramSpec
|
||||
|
||||
confSpec.MemoryReservationLockedToMax = &s.config.RAMReserveAll
|
||||
|
||||
task, err := vm.Reconfigure(d.ctx, confSpec)
|
||||
if err != nil {
|
||||
state.Put("error", err)
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
_, err = task.WaitForResult(d.ctx, nil)
|
||||
err := d.configureVM(vm, s.config)
|
||||
if err != nil {
|
||||
state.Put("error", err)
|
||||
return multistep.ActionHalt
|
||||
|
|
Loading…
Reference in New Issue