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 support for CPU passthrough #288

Merged
merged 1 commit into from
Oct 29, 2021
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -283,6 +283,9 @@ type VMResources struct {
// Indicates whether VGA console should be enabled or not.
VgaConsoleEnabled *bool `json:"vga_console_enabled,omitempty" mapstructure:"vga_console_enabled,omitempty"`

// 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"`

// Information regarding vNUMA configuration.
VMVnumaConfig *VMVnumaConfig `json:"vnuma_config,omitempty" mapstructure:"vnuma_config,omitempty"`

Expand Down Expand Up @@ -510,6 +513,9 @@ type VMResourcesDefStatus struct {
// Indicates whether VGA console has been enabled or not.
VgaConsoleEnabled *bool `json:"vga_console_enabled,omitempty" mapstructure:"vga_console_enabled,omitempty"`

// 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"`

// Information regarding vNUMA configuration.
VnumaConfig *VMVnumaConfig `json:"vnuma_config,omitempty" mapstructure:"vnuma_config,omitempty"`

Expand Down
11 changes: 9 additions & 2 deletions nutanix/data_source_nutanix_virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,10 @@ func dataSourceNutanixVirtualMachine() *schema.Resource {
},

// RESOURCES ARGUMENTS

"enable_cpu_passthrough": {
Type: schema.TypeBool,
Computed: true,
},
"num_vnuma_nodes": {
Type: schema.TypeInt,
Computed: true,
Expand Down Expand Up @@ -798,6 +801,7 @@ func dataSourceNutanixVirtualMachineRead(d *schema.ResourceData, meta interface{
d.Set("name", utils.StringValue(resp.Status.Name))
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("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 @@ -999,7 +1003,10 @@ func resourceNutanixDatasourceVirtualMachineInstanceResourceV0() *schema.Resourc
},

// RESOURCES ARGUMENTS

"enable_cpu_passthrough": {
Type: schema.TypeBool,
Computed: true,
},
"num_vnuma_nodes": {
Type: schema.TypeInt,
Computed: true,
Expand Down
20 changes: 20 additions & 0 deletions nutanix/resource_nutanix_virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,11 @@ func resourceNutanixVirtualMachine() *schema.Resource {

// RESOURCES ARGUMENTS

"enable_cpu_passthrough": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"use_hot_add": {
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -1077,6 +1082,7 @@ func resourceNutanixVirtualMachineRead(d *schema.ResourceData, meta interface{})
return fmt.Errorf("error setting guest_customization_sysprep for Virtual Machine %s: %s", d.Id(), err)
}

d.Set("enable_cpu_passthrough", resp.Status.Resources.EnableCPUPassthrough)
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 @@ -1183,6 +1189,12 @@ func resourceNutanixVirtualMachineUpdate(d *schema.ResourceData, meta interface{
res.ParentReference = validateRef(n.(map[string]interface{}))
hotPlugChange = false
}
if d.HasChange("enable_cpu_passthrough") {
_, n := d.GetChange("enable_cpu_passthrough")
res.EnableCPUPassthrough = utils.BoolPtr(n.(bool))
// TODO: Is this correct?
hotPlugChange = false
}
if d.HasChange("num_vnuma_nodes") {
_, n := d.GetChange("num_vnuma_nodes")
res.VMVnumaConfig = &v3.VMVnumaConfig{
Expand Down Expand Up @@ -1630,6 +1642,9 @@ func getVMResources(d *schema.ResourceData, vm *v3.VMResources) error {
if v, ok := d.GetOk("num_vcpus_per_socket"); ok {
vm.NumVcpusPerSocket = utils.Int64Ptr(int64(v.(int)))
}
if v, ok := d.GetOk("enable_cpu_passthrough"); ok {
vm.EnableCPUPassthrough = utils.BoolPtr(v.(bool))
}
if v, ok := d.GetOk("num_sockets"); ok {
vm.NumSockets = utils.Int64Ptr(int64(v.(int)))
}
Expand Down Expand Up @@ -2428,6 +2443,11 @@ func resourceNutanixVirtualMachineInstanceResourceV0() *schema.Resource {

// RESOURCES ARGUMENTS

"enable_cpu_passthrough": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"num_vnuma_nodes": {
Type: schema.TypeInt,
Optional: true,
Expand Down