provider/vsphere: Add support for memory reservation (#6036)
This commit is contained in:
parent
243e5c84eb
commit
a9a607d67f
|
@ -58,6 +58,10 @@ type cdrom struct {
|
||||||
path string
|
path string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type memoryAllocation struct {
|
||||||
|
reservation int64
|
||||||
|
}
|
||||||
|
|
||||||
type virtualMachine struct {
|
type virtualMachine struct {
|
||||||
name string
|
name string
|
||||||
folder string
|
folder string
|
||||||
|
@ -67,6 +71,7 @@ type virtualMachine struct {
|
||||||
datastore string
|
datastore string
|
||||||
vcpu int
|
vcpu int
|
||||||
memoryMb int64
|
memoryMb int64
|
||||||
|
memoryAllocation memoryAllocation
|
||||||
template string
|
template string
|
||||||
networkInterfaces []networkInterface
|
networkInterfaces []networkInterface
|
||||||
hardDisks []hardDisk
|
hardDisks []hardDisk
|
||||||
|
@ -124,6 +129,13 @@ func resourceVSphereVirtualMachine() *schema.Resource {
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"memory_reservation": &schema.Schema{
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Optional: true,
|
||||||
|
Default: 0,
|
||||||
|
ForceNew: true,
|
||||||
|
},
|
||||||
|
|
||||||
"datacenter": &schema.Schema{
|
"datacenter": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
|
@ -371,6 +383,9 @@ func resourceVSphereVirtualMachineCreate(d *schema.ResourceData, meta interface{
|
||||||
name: d.Get("name").(string),
|
name: d.Get("name").(string),
|
||||||
vcpu: d.Get("vcpu").(int),
|
vcpu: d.Get("vcpu").(int),
|
||||||
memoryMb: int64(d.Get("memory").(int)),
|
memoryMb: int64(d.Get("memory").(int)),
|
||||||
|
memoryAllocation: memoryAllocation{
|
||||||
|
reservation: int64(d.Get("memory_reservation").(int)),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
if v, ok := d.GetOk("folder"); ok {
|
if v, ok := d.GetOk("folder"); ok {
|
||||||
|
@ -672,6 +687,7 @@ func resourceVSphereVirtualMachineRead(d *schema.ResourceData, meta interface{})
|
||||||
|
|
||||||
d.Set("datacenter", dc)
|
d.Set("datacenter", dc)
|
||||||
d.Set("memory", mvm.Summary.Config.MemorySizeMB)
|
d.Set("memory", mvm.Summary.Config.MemorySizeMB)
|
||||||
|
d.Set("memory_reservation", mvm.Summary.Config.MemoryReservation)
|
||||||
d.Set("cpu", mvm.Summary.Config.NumCpu)
|
d.Set("cpu", mvm.Summary.Config.NumCpu)
|
||||||
d.Set("datastore", rootDatastore)
|
d.Set("datastore", rootDatastore)
|
||||||
|
|
||||||
|
@ -1104,7 +1120,10 @@ func (vm *virtualMachine) createVirtualMachine(c *govmomi.Client) error {
|
||||||
NumCPUs: vm.vcpu,
|
NumCPUs: vm.vcpu,
|
||||||
NumCoresPerSocket: 1,
|
NumCoresPerSocket: 1,
|
||||||
MemoryMB: vm.memoryMb,
|
MemoryMB: vm.memoryMb,
|
||||||
DeviceChange: networkDevices,
|
MemoryAllocation: &types.ResourceAllocationInfo{
|
||||||
|
Reservation: vm.memoryAllocation.reservation,
|
||||||
|
},
|
||||||
|
DeviceChange: networkDevices,
|
||||||
}
|
}
|
||||||
log.Printf("[DEBUG] virtual machine config spec: %v", configSpec)
|
log.Printf("[DEBUG] virtual machine config spec: %v", configSpec)
|
||||||
|
|
||||||
|
|
|
@ -61,6 +61,8 @@ func TestAccVSphereVirtualMachine_basic(t *testing.T) {
|
||||||
"vsphere_virtual_machine.foo", "vcpu", "2"),
|
"vsphere_virtual_machine.foo", "vcpu", "2"),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"vsphere_virtual_machine.foo", "memory", "4096"),
|
"vsphere_virtual_machine.foo", "memory", "4096"),
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"vsphere_virtual_machine.foo", "memory_reservation", "4096"),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"vsphere_virtual_machine.foo", "disk.#", "2"),
|
"vsphere_virtual_machine.foo", "disk.#", "2"),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
|
@ -632,6 +634,7 @@ resource "vsphere_virtual_machine" "foo" {
|
||||||
%s
|
%s
|
||||||
vcpu = 2
|
vcpu = 2
|
||||||
memory = 4096
|
memory = 4096
|
||||||
|
memory_reservation = 4096
|
||||||
gateway = "%s"
|
gateway = "%s"
|
||||||
network_interface {
|
network_interface {
|
||||||
label = "%s"
|
label = "%s"
|
||||||
|
|
|
@ -64,6 +64,7 @@ The following arguments are supported:
|
||||||
* `name` - (Required) The virtual machine name
|
* `name` - (Required) The virtual machine name
|
||||||
* `vcpu` - (Required) The number of virtual CPUs to allocate to the virtual machine
|
* `vcpu` - (Required) The number of virtual CPUs to allocate to the virtual machine
|
||||||
* `memory` - (Required) The amount of RAM (in MB) to allocate to the virtual machine
|
* `memory` - (Required) The amount of RAM (in MB) to allocate to the virtual machine
|
||||||
|
* `memory_reservation` - (Optional) The amount of RAM (in MB) to reserve physical memory resource; defaults to 0 (means not to reserve)
|
||||||
* `datacenter` - (Optional) The name of a Datacenter in which to launch the virtual machine
|
* `datacenter` - (Optional) The name of a Datacenter in which to launch the virtual machine
|
||||||
* `cluster` - (Optional) Name of a Cluster in which to launch the virtual machine
|
* `cluster` - (Optional) Name of a Cluster in which to launch the virtual machine
|
||||||
* `resource_pool` (Optional) The name of a Resource Pool in which to launch the virtual machine. Requires full path (see cluster example).
|
* `resource_pool` (Optional) The name of a Resource Pool in which to launch the virtual machine. Requires full path (see cluster example).
|
||||||
|
|
Loading…
Reference in New Issue