provider/vsphere: Add support for memory reservation (#6036)

This commit is contained in:
Takaaki Furukawa 2016-04-25 20:15:37 +09:00 committed by Paul Stack
parent 243e5c84eb
commit a9a607d67f
3 changed files with 24 additions and 1 deletions

View File

@ -58,6 +58,10 @@ type cdrom struct {
path string
}
type memoryAllocation struct {
reservation int64
}
type virtualMachine struct {
name string
folder string
@ -67,6 +71,7 @@ type virtualMachine struct {
datastore string
vcpu int
memoryMb int64
memoryAllocation memoryAllocation
template string
networkInterfaces []networkInterface
hardDisks []hardDisk
@ -124,6 +129,13 @@ func resourceVSphereVirtualMachine() *schema.Resource {
ForceNew: true,
},
"memory_reservation": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
Default: 0,
ForceNew: true,
},
"datacenter": &schema.Schema{
Type: schema.TypeString,
Optional: true,
@ -371,6 +383,9 @@ func resourceVSphereVirtualMachineCreate(d *schema.ResourceData, meta interface{
name: d.Get("name").(string),
vcpu: d.Get("vcpu").(int),
memoryMb: int64(d.Get("memory").(int)),
memoryAllocation: memoryAllocation{
reservation: int64(d.Get("memory_reservation").(int)),
},
}
if v, ok := d.GetOk("folder"); ok {
@ -672,6 +687,7 @@ func resourceVSphereVirtualMachineRead(d *schema.ResourceData, meta interface{})
d.Set("datacenter", dc)
d.Set("memory", mvm.Summary.Config.MemorySizeMB)
d.Set("memory_reservation", mvm.Summary.Config.MemoryReservation)
d.Set("cpu", mvm.Summary.Config.NumCpu)
d.Set("datastore", rootDatastore)
@ -1104,7 +1120,10 @@ func (vm *virtualMachine) createVirtualMachine(c *govmomi.Client) error {
NumCPUs: vm.vcpu,
NumCoresPerSocket: 1,
MemoryMB: vm.memoryMb,
DeviceChange: networkDevices,
MemoryAllocation: &types.ResourceAllocationInfo{
Reservation: vm.memoryAllocation.reservation,
},
DeviceChange: networkDevices,
}
log.Printf("[DEBUG] virtual machine config spec: %v", configSpec)

View File

@ -61,6 +61,8 @@ func TestAccVSphereVirtualMachine_basic(t *testing.T) {
"vsphere_virtual_machine.foo", "vcpu", "2"),
resource.TestCheckResourceAttr(
"vsphere_virtual_machine.foo", "memory", "4096"),
resource.TestCheckResourceAttr(
"vsphere_virtual_machine.foo", "memory_reservation", "4096"),
resource.TestCheckResourceAttr(
"vsphere_virtual_machine.foo", "disk.#", "2"),
resource.TestCheckResourceAttr(
@ -632,6 +634,7 @@ resource "vsphere_virtual_machine" "foo" {
%s
vcpu = 2
memory = 4096
memory_reservation = 4096
gateway = "%s"
network_interface {
label = "%s"

View File

@ -64,6 +64,7 @@ The following arguments are supported:
* `name` - (Required) The virtual machine name
* `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_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
* `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).