mirror of https://github.com/hashicorp/packer
parent
0b4729c9e4
commit
c44221a800
@ -1,43 +0,0 @@
|
||||
package clone
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/packer/packer"
|
||||
"github.com/jetbrains-infra/packer-builder-vsphere/common"
|
||||
"github.com/jetbrains-infra/packer-builder-vsphere/driver"
|
||||
"github.com/hashicorp/packer/helper/multistep"
|
||||
"context"
|
||||
)
|
||||
|
||||
type StepConfigureHardware struct {
|
||||
config *common.HardwareConfig
|
||||
}
|
||||
|
||||
func (s *StepConfigureHardware) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
vm := state.Get("vm").(*driver.VirtualMachine)
|
||||
|
||||
if *s.config != (common.HardwareConfig{}) {
|
||||
ui.Say("Customizing hardware parameters...")
|
||||
|
||||
err := vm.Configure(&driver.HardwareConfig{
|
||||
CPUs: s.config.CPUs,
|
||||
CPUReservation: s.config.CPUReservation,
|
||||
CPULimit: s.config.CPULimit,
|
||||
RAM: s.config.RAM,
|
||||
RAMReservation: s.config.RAMReservation,
|
||||
RAMReserveAll: s.config.RAMReserveAll,
|
||||
DiskSize: s.config.DiskSize,
|
||||
NestedHV: s.config.NestedHV,
|
||||
CpuHotAddEnabled: s.config.CpuHotAddEnabled,
|
||||
MemoryHotAddEnabled: s.config.MemoryHotAddEnabled,
|
||||
})
|
||||
if err != nil {
|
||||
state.Put("error", err)
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
}
|
||||
|
||||
return multistep.ActionContinue
|
||||
}
|
||||
|
||||
func (s *StepConfigureHardware) Cleanup(multistep.StateBag) {}
|
||||
@ -1,44 +0,0 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/jetbrains-infra/packer-builder-vsphere/driver"
|
||||
)
|
||||
|
||||
type HardwareConfig struct {
|
||||
CPUs int32 `mapstructure:"CPUs"`
|
||||
CPUReservation int64 `mapstructure:"CPU_reservation"`
|
||||
CPULimit int64 `mapstructure:"CPU_limit"`
|
||||
RAM int64 `mapstructure:"RAM"`
|
||||
RAMReservation int64 `mapstructure:"RAM_reservation"`
|
||||
RAMReserveAll bool `mapstructure:"RAM_reserve_all"`
|
||||
DiskSize int64 `mapstructure:"disk_size"`
|
||||
NestedHV bool `mapstructure:"NestedHV"`
|
||||
CpuHotAddEnabled bool `mapstructure:"CPU_hot_plug"`
|
||||
MemoryHotAddEnabled bool `mapstructure:"RAM_hot_plug"`
|
||||
}
|
||||
|
||||
func (c *HardwareConfig) Prepare() []error {
|
||||
var errs []error
|
||||
|
||||
if c.RAMReservation > 0 && c.RAMReserveAll != false {
|
||||
errs = append(errs, fmt.Errorf("'RAM_reservation' and 'RAM_reserve_all' cannot be used together"))
|
||||
}
|
||||
|
||||
return errs
|
||||
}
|
||||
|
||||
func (c *HardwareConfig) ToDriverHardwareConfig() driver.HardwareConfig {
|
||||
return driver.HardwareConfig{
|
||||
CPUs: c.CPUs,
|
||||
CPUReservation: c.CPUReservation,
|
||||
CPULimit: c.CPULimit,
|
||||
RAM: c.RAM,
|
||||
RAMReservation: c.RAMReservation,
|
||||
RAMReserveAll: c.RAMReserveAll,
|
||||
DiskSize: c.DiskSize,
|
||||
NestedHV: c.NestedHV,
|
||||
CpuHotAddEnabled: c.CpuHotAddEnabled,
|
||||
MemoryHotAddEnabled: c.MemoryHotAddEnabled,
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,64 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/packer/packer"
|
||||
"github.com/jetbrains-infra/packer-builder-vsphere/driver"
|
||||
"github.com/hashicorp/packer/helper/multistep"
|
||||
"context"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type HardwareConfig struct {
|
||||
CPUs int32 `mapstructure:"CPUs"`
|
||||
CPUReservation int64 `mapstructure:"CPU_reservation"`
|
||||
CPULimit int64 `mapstructure:"CPU_limit"`
|
||||
RAM int64 `mapstructure:"RAM"`
|
||||
RAMReservation int64 `mapstructure:"RAM_reservation"`
|
||||
RAMReserveAll bool `mapstructure:"RAM_reserve_all"`
|
||||
NestedHV bool `mapstructure:"NestedHV"`
|
||||
CpuHotAddEnabled bool `mapstructure:"CPU_hot_plug"`
|
||||
MemoryHotAddEnabled bool `mapstructure:"RAM_hot_plug"`
|
||||
}
|
||||
|
||||
func (c *HardwareConfig) Prepare() []error {
|
||||
var errs []error
|
||||
|
||||
if c.RAMReservation > 0 && c.RAMReserveAll != false {
|
||||
errs = append(errs, fmt.Errorf("'RAM_reservation' and 'RAM_reserve_all' cannot be used together"))
|
||||
}
|
||||
|
||||
return errs
|
||||
}
|
||||
|
||||
type StepConfigureHardware struct {
|
||||
Config *HardwareConfig
|
||||
}
|
||||
|
||||
func (s *StepConfigureHardware) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
vm := state.Get("vm").(*driver.VirtualMachine)
|
||||
|
||||
if *s.Config != (HardwareConfig{}) {
|
||||
ui.Say("Customizing hardware parameters...")
|
||||
|
||||
err := vm.Configure(&driver.HardwareConfig{
|
||||
CPUs: s.Config.CPUs,
|
||||
CPUReservation: s.Config.CPUReservation,
|
||||
CPULimit: s.Config.CPULimit,
|
||||
RAM: s.Config.RAM,
|
||||
RAMReservation: s.Config.RAMReservation,
|
||||
RAMReserveAll: s.Config.RAMReserveAll,
|
||||
NestedHV: s.Config.NestedHV,
|
||||
CpuHotAddEnabled: s.Config.CpuHotAddEnabled,
|
||||
MemoryHotAddEnabled: s.Config.MemoryHotAddEnabled,
|
||||
})
|
||||
if err != nil {
|
||||
state.Put("error", err)
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
}
|
||||
|
||||
return multistep.ActionContinue
|
||||
}
|
||||
|
||||
func (s *StepConfigureHardware) Cleanup(multistep.StateBag) {}
|
||||
Loading…
Reference in new issue