Add 'RAM_reserve_all' parameter
This commit is contained in:
parent
71c211fa09
commit
5987795a23
|
@ -63,6 +63,7 @@ Hardware customization:
|
|||
* `CPU_limit` - Upper limit of available CPU resources in MHz. Inherited from source VM by default, set to `-1` for reset.
|
||||
* `RAM` - Amount of RAM in megabytes. Inherited from source VM by default.
|
||||
* `RAM_reservation` - Amount of reserved RAM in MB. Inherited from source VM by default.
|
||||
* `RAM_reserve_all` - Reserve all available RAM (bool). `false` by default. Cannot be used together with `RAM_reservation`.
|
||||
|
||||
Provisioning:
|
||||
* `ssh_username` - [**mandatory**] username in guest OS.
|
||||
|
|
|
@ -81,6 +81,8 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
|
|||
errs = packer.MultiErrorAppend(errs, fmt.Errorf("vSphere host is required"))
|
||||
}
|
||||
|
||||
errs = packer.MultiErrorAppend(errs, c.HardwareConfig.Prepare()...)
|
||||
|
||||
if c.RawShutdownTimeout != "" {
|
||||
timeout, err := time.ParseDuration(c.RawShutdownTimeout)
|
||||
if err != nil {
|
||||
|
|
|
@ -21,6 +21,14 @@ func TestTimeout(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestRAMReservation(t *testing.T) {
|
||||
raw := minimalConfig()
|
||||
raw["RAM_reservation"] = 1000
|
||||
raw["RAM_reserve_all"] = true
|
||||
_, warns, err := NewConfig(raw)
|
||||
testConfigErr(t, warns, err)
|
||||
}
|
||||
|
||||
func minimalConfig() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"vcenter_server": "vcenter.domain.local",
|
||||
|
@ -36,18 +44,18 @@ func minimalConfig() map[string]interface{} {
|
|||
|
||||
func testConfigOk(t *testing.T, warns []string, err error) {
|
||||
if len(warns) > 0 {
|
||||
t.Fatalf("bad: %#v", warns)
|
||||
t.Fatalf("Should be no warnings: %#v", warns)
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("bad: %s", err)
|
||||
t.Fatalf("Unexpected error: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func testConfigErr(t *testing.T, warns []string, err error) {
|
||||
if len(warns) > 0 {
|
||||
t.Fatalf("bad: %#v", warns)
|
||||
t.Fatalf("Should be no warnings: %#v", warns)
|
||||
}
|
||||
if err == nil {
|
||||
t.Fatal("should error")
|
||||
t.Fatal("An error is not raised")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"github.com/vmware/govmomi/vim25/types"
|
||||
"context"
|
||||
"github.com/vmware/govmomi/object"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type HardwareConfig struct {
|
||||
|
@ -14,6 +15,17 @@ type HardwareConfig struct {
|
|||
CPULimit int64 `mapstructure:"CPU_limit"`
|
||||
RAM int64 `mapstructure:"RAM"`
|
||||
RAMReservation int64 `mapstructure:"RAM_reservation"`
|
||||
RAMReserveAll bool `mapstructure:"RAM_reserve_all"`
|
||||
}
|
||||
|
||||
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 {
|
||||
|
@ -41,6 +53,8 @@ func (s *StepConfigureHardware) Run(state multistep.StateBag) multistep.StepActi
|
|||
ramSpec.Reservation = s.config.RAMReservation
|
||||
confSpec.MemoryAllocation = &ramSpec
|
||||
|
||||
confSpec.MemoryReservationLockedToMax = &s.config.RAMReserveAll
|
||||
|
||||
task, err := vm.Reconfigure(ctx, confSpec)
|
||||
if err != nil {
|
||||
state.Put("error", err)
|
||||
|
|
Loading…
Reference in New Issue