Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add vCPU hard pinning #307

Merged
merged 4 commits into from
Feb 10, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions client/v3/v3_structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`

Expand Down Expand Up @@ -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"`

Expand Down
9 changes: 9 additions & 0 deletions nutanix/data_source_nutanix_virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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,
Expand Down
19 changes: 19 additions & 0 deletions nutanix/resource_nutanix_virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
basraayman marked this conversation as resolved.
Show resolved Hide resolved
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))
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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)))
}
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/virtual_machine.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down