diff --git a/client/v3/v3_structs.go b/client/v3/v3_structs.go index f543d3d74..e9e73cb09 100644 --- a/client/v3/v3_structs.go +++ b/client/v3/v3_structs.go @@ -286,6 +286,9 @@ type VMResources struct { // Indicates whether to passthrough the host’s CPU features to the guest. Enabling this will disable live migration of the VM. EnableCPUPassthrough *bool `json:"enable_cpu_passthrough,omitempty" mapstructure:"enable_cpu_passthrough,omitempty"` + // Indicates whether a VMs cores are getting pinned on either CPU1, CPU2, CPU3 or CPU4. By default, the Linux Scheduler in AHV will pin all cores wherever they are best available. + EnableCPUPinning *bool `json:"is_vcpu_hard_pinned,omitempty" mapstructure:"is_vcpu_hard_pinned,omitempty"` + // Information regarding vNUMA configuration. VMVnumaConfig *VMVnumaConfig `json:"vnuma_config,omitempty" mapstructure:"vnuma_config,omitempty"` @@ -516,6 +519,9 @@ type VMResourcesDefStatus struct { // Indicates whether to passthrough the host’s CPU features to the guest. Enabling this will disable live migration of the VM. EnableCPUPassthrough *bool `json:"enable_cpu_passthrough,omitempty" mapstructure:"enable_cpu_passthrough,omitempty"` + // Indicates whether a VMs cores are getting pinned on either CPU1, CPU2, CPU3 or CPU4. By default, the Linux Scheduler in AHV will pin all cores wherever they are best available. + EnableCPUPinning *bool `json:"is_vcpu_hard_pinned,omitempty" mapstructure:"is_vcpu_hard_pinned,omitempty"` + // Information regarding vNUMA configuration. VnumaConfig *VMVnumaConfig `json:"vnuma_config,omitempty" mapstructure:"vnuma_config,omitempty"` diff --git a/nutanix/data_source_nutanix_virtual_machine.go b/nutanix/data_source_nutanix_virtual_machine.go index c4806ea66..cb84ca9e7 100644 --- a/nutanix/data_source_nutanix_virtual_machine.go +++ b/nutanix/data_source_nutanix_virtual_machine.go @@ -198,6 +198,10 @@ func dataSourceNutanixVirtualMachine() *schema.Resource { Type: schema.TypeBool, Computed: true, }, + "is_vcpu_hard_pinned": { + Type: schema.TypeBool, + Computed: true, + }, "num_vnuma_nodes": { Type: schema.TypeInt, Computed: true, @@ -802,6 +806,7 @@ func dataSourceNutanixVirtualMachineRead(d *schema.ResourceData, meta interface{ d.Set("description", utils.StringValue(resp.Status.Description)) d.Set("state", utils.StringValue(resp.Status.State)) d.Set("enable_cpu_passthrough", utils.BoolValue(resp.Status.Resources.EnableCPUPassthrough)) + d.Set("is_vcpu_hard_pinned", utils.BoolValue(resp.Status.Resources.EnableCPUPinning)) d.Set("num_vnuma_nodes", utils.Int64Value(resp.Status.Resources.VnumaConfig.NumVnumaNodes)) d.Set("guest_os_id", utils.StringValue(resp.Status.Resources.GuestOsID)) d.Set("power_state", utils.StringValue(resp.Status.Resources.PowerState)) @@ -1007,6 +1012,10 @@ func resourceNutanixDatasourceVirtualMachineInstanceResourceV0() *schema.Resourc Type: schema.TypeBool, Computed: true, }, + "is_vcpu_hard_pinned": { + Type: schema.TypeBool, + Computed: true, + }, "num_vnuma_nodes": { Type: schema.TypeInt, Computed: true, diff --git a/nutanix/resource_nutanix_virtual_machine.go b/nutanix/resource_nutanix_virtual_machine.go index 5d5264d2a..9c73cf53b 100644 --- a/nutanix/resource_nutanix_virtual_machine.go +++ b/nutanix/resource_nutanix_virtual_machine.go @@ -292,6 +292,11 @@ func resourceNutanixVirtualMachine() *schema.Resource { Optional: true, Default: false, }, + "is_vcpu_hard_pinned": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, "use_hot_add": { Type: schema.TypeBool, Optional: true, @@ -1085,6 +1090,7 @@ func resourceNutanixVirtualMachineRead(d *schema.ResourceData, meta interface{}) } d.Set("enable_cpu_passthrough", resp.Status.Resources.EnableCPUPassthrough) + d.Set("is_vcpu_hard_pinned", resp.Status.Resources.EnableCPUPinning) d.Set("guest_customization_cloud_init_user_data", cloudInitUser) d.Set("guest_customization_cloud_init_meta_data", cloudInitMeta) d.Set("hardware_clock_timezone", utils.StringValue(resp.Status.Resources.HardwareClockTimezone)) @@ -1197,6 +1203,11 @@ func resourceNutanixVirtualMachineUpdate(d *schema.ResourceData, meta interface{ // TODO: Is this correct? hotPlugChange = false } + if d.HasChange("is_vcpu_hard_pinned") { + _, n := d.GetChange("is_vcpu_hard_pinned") + res.EnableCPUPinning = utils.BoolPtr(n.(bool)) + hotPlugChange = false + } if d.HasChange("num_vnuma_nodes") { _, n := d.GetChange("num_vnuma_nodes") res.VMVnumaConfig = &v3.VMVnumaConfig{ @@ -1646,6 +1657,9 @@ func getVMResources(d *schema.ResourceData, vm *v3.VMResources) error { if v, ok := d.GetOk("enable_cpu_passthrough"); ok { vm.EnableCPUPassthrough = utils.BoolPtr(v.(bool)) } + if v, ok := d.GetOk("is_vcpu_hard_pinned"); ok { + vm.EnableCPUPinning = utils.BoolPtr(v.(bool)) + } if v, ok := d.GetOk("num_sockets"); ok { vm.NumSockets = utils.Int64Ptr(int64(v.(int))) } @@ -2485,6 +2499,11 @@ func resourceNutanixVirtualMachineInstanceResourceV0() *schema.Resource { Optional: true, Default: false, }, + "is_vcpu_hard_pinned": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, "num_vnuma_nodes": { Type: schema.TypeInt, Optional: true, diff --git a/website/docs/r/virtual_machine.html.markdown b/website/docs/r/virtual_machine.html.markdown index 5773b01fb..e7a40267f 100644 --- a/website/docs/r/virtual_machine.html.markdown +++ b/website/docs/r/virtual_machine.html.markdown @@ -100,6 +100,7 @@ The following arguments are supported: * `use_hot_add`: - (Optional) Use Hot Add when modifying VM resources. Passing value false will result in VM reboots. Default value is `true`. * `num_threads_per_core`: - (Optional) Number of threads per core. * `enable_cpu_passthrough`: - (Optional) Add true to enable CPU passthrough. +* `is_vcpu_hard_pinned`: - (Optional) Add true to enable CPU pinning. ### Disk List