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

Task/m 324 check #385

Merged
merged 7 commits into from
Mar 16, 2022
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 @@ -50,6 +50,9 @@ type VMNic struct {

NetworkFunctionChainReference *Reference `json:"network_function_chain_reference,omitempty" mapstructure:"network_function_chain_reference,omitempty"`

// The number of queues for this NIC
NumQueues *int64 `json:"num_queues,omitempty" mapstructure:"num_queues,omitempty"`

// The type of this Network function NIC. Defaults to INGRESS.
NetworkFunctionNicType *string `json:"network_function_nic_type,omitempty" mapstructure:"network_function_nic_type,omitempty"`

Expand Down Expand Up @@ -368,6 +371,9 @@ type VMNicOutputStatus struct {

NetworkFunctionChainReference *Reference `json:"network_function_chain_reference,omitempty" mapstructure:"network_function_chain_reference,omitempty"`

// The number of queues for this NIC
NumQueues *int64 `json:"num_queues,omitempty" mapstructure:"num_queues,omitempty"`

// The type of this Network function NIC. Defaults to INGRESS.
NetworkFunctionNicType *string `json:"network_function_nic_type,omitempty" mapstructure:"network_function_nic_type,omitempty"`

Expand Down
8 changes: 8 additions & 0 deletions nutanix/data_source_nutanix_virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ func dataSourceNutanixVirtualMachine() *schema.Resource {
Type: schema.TypeString,
},
},
"num_queues": {
Type: schema.TypeInt,
Computed: true,
},
"subnet_uuid": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -792,6 +796,10 @@ func resourceNutanixDatasourceVirtualMachineInstanceResourceV0() *schema.Resourc
Type: schema.TypeString,
},
},
"num_queues": {
Type: schema.TypeInt,
Computed: true,
},
"subnet_uuid": {
Type: schema.TypeString,
Computed: true,
Expand Down
41 changes: 39 additions & 2 deletions nutanix/resource_nutanix_virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ func resourceNutanixVirtualMachine() *schema.Resource {
Type: schema.TypeString,
},
},
"num_queues": {
Type: schema.TypeInt,
Computed: true,
},
"subnet_uuid": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -278,6 +282,11 @@ func resourceNutanixVirtualMachine() *schema.Resource {
Type: schema.TypeString,
},
},
"num_queues": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
},
"subnet_uuid": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -1113,7 +1122,23 @@ func resourceNutanixVirtualMachineUpdate(ctx context.Context, d *schema.Resource
hotPlugChange = false
}
if d.HasChange("nic_list") {
res.NicList = expandNicList(d)
oldNics := res.NicList
newNics := expandNicList(d)

nicLoop:
for _, newNic := range newNics {
for _, oldNic := range oldNics {
if newNic == nil || oldNic == nil {
break nicLoop
}
if *newNic.UUID == *oldNic.UUID && newNic.NumQueues != oldNic.NumQueues {
hotPlugChange = false
break nicLoop
}
}
}

res.NicList = newNics
}

if d.HasChange("disk_list") {
Expand Down Expand Up @@ -1573,7 +1598,6 @@ func getVMResources(d *schema.ResourceData, vm *v3.VMResources) error {

return nil
}

func expandNicList(d *schema.ResourceData) []*v3.VMNic {
if v, ok := d.GetOk("nic_list"); ok {
n := v.([]interface{})
Expand Down Expand Up @@ -1605,6 +1629,9 @@ func expandNicList(d *schema.ResourceData) []*v3.VMNic {
v := value.(map[string]interface{})
nic.NetworkFunctionChainReference = validateRef(v)
}
if value, ok := val["num_queues"]; ok && value.(int) != 0 {
nic.NumQueues = utils.Int64Ptr(int64(value.(int)))
}
if value, ok := val["subnet_uuid"]; ok {
v := value.(string)
nic.SubnetReference = buildReference(v, "subnet")
Expand Down Expand Up @@ -1863,6 +1890,7 @@ func preFillResUpdateRequest(res *v3.VMResources, response *v3.VMIntentResponse)
SubnetReference: v.SubnetReference,
NetworkFunctionNicType: v.NetworkFunctionNicType,
NetworkFunctionChainReference: v.NetworkFunctionChainReference,
NumQueues: v.NumQueues,
IsConnected: v.IsConnected,
}
}
Expand Down Expand Up @@ -2166,6 +2194,10 @@ func resourceNutanixVirtualMachineInstanceResourceV0() *schema.Resource {
Type: schema.TypeString,
},
},
"num_queues": {
Type: schema.TypeInt,
Computed: true,
},
"subnet_uuid": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -2257,6 +2289,11 @@ func resourceNutanixVirtualMachineInstanceResourceV0() *schema.Resource {
Type: schema.TypeString,
},
},
"num_queues": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
},
"subnet_uuid": {
Type: schema.TypeString,
Optional: true,
Expand Down
80 changes: 80 additions & 0 deletions nutanix/resource_nutanix_virtual_machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,13 @@ func TestAccNutanixVirtualMachine_WithSubnet(t *testing.T) {
resource.TestCheckResourceAttrSet(resourceName, "nic_list_status.0.ip_endpoint_list.0.ip"),
),
},
{
Config: testAccNutanixVMConfigWithSubnetUpdated(r),
Check: resource.ComposeTestCheckFunc(
testAccCheckNutanixVirtualMachineExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "nic_list_status.0.num_queues", "2"),
),
},
},
})
}
Expand Down Expand Up @@ -854,6 +861,79 @@ func testAccNutanixVMConfigWithSubnet(r int) string {
`, r)
}

func testAccNutanixVMConfigWithSubnetUpdated(r int) string {
return fmt.Sprintf(`
data "nutanix_clusters" "clusters" {}

locals {
cluster1 = [
for cluster in data.nutanix_clusters.clusters.entities :
cluster.metadata.uuid if cluster.service_list[0] != "PRISM_CENTRAL"
][0]
}

resource "nutanix_subnet" "sub" {
cluster_uuid = "${local.cluster1}"

# General Information for subnet
name = "terraform-vm-with-subnet-%[1]d"
description = "Description of my unit test VLAN"
vlan_id = %[1]d
subnet_type = "VLAN"

# Provision a Managed L3 Network
# This bit is only needed if you intend to turn on AHV's IPAM
subnet_ip = "10.250.140.0"
default_gateway_ip = "10.250.140.1"
prefix_length = 24
dhcp_options = {
boot_file_name = "bootfile"
domain_name = "nutanix"
tftp_server_name = "10.250.140.200"
}
dhcp_domain_name_server_list = ["8.8.8.8", "4.2.2.2"]
dhcp_domain_search_list = ["terraform.nutanix.com", "terraform.unit.test.com"]
ip_config_pool_list_ranges = ["10.250.140.20 10.250.140.100"]
}

resource "nutanix_image" "cirros-034-disk" {
name = "test-image-dou-%[1]d"
source_uri = "http://download.cirros-cloud.net/0.4.0/cirros-0.4.0-x86_64-disk.img"
description = "heres a tiny linux image, not an iso, but a real disk!"
}

resource "nutanix_virtual_machine" "vm3" {
name = "test-dou-vm-%[1]d"

categories {
name = "Environment"
value = "Staging"
}

cluster_uuid = "${local.cluster1}"
num_vcpus_per_socket = 1
num_sockets = 1
memory_size_mib = 186

disk_list {
data_source_reference = {
kind = "image"
uuid = "${nutanix_image.cirros-034-disk.id}"
}
}

nic_list {
subnet_uuid = "${nutanix_subnet.sub.id}"
num_queues = 2
}
}

output "ip_address" {
value = "${lookup(nutanix_virtual_machine.vm3.nic_list_status.0.ip_endpoint_list[0], "ip")}"
}
`, r)
}

func testAccNutanixVMConfigWithSerialPortList(r int) string {
return fmt.Sprintf(`
data "nutanix_clusters" "clusters" {}
Expand Down
4 changes: 2 additions & 2 deletions nutanix/structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func flattenNicListStatus(nics []*v3.VMNicOutputStatus) []map[string]interface{}
}
nic["ip_endpoint_list"] = ipEndpointList
nic["network_function_chain_reference"] = flattenReferenceValues(v.NetworkFunctionChainReference)

nic["num_queues"] = utils.Int64Value(v.NumQueues)
if v.SubnetReference != nil {
nic["subnet_uuid"] = utils.StringValue(v.SubnetReference.UUID)
nic["subnet_name"] = utils.StringValue(v.SubnetReference.Name)
Expand Down Expand Up @@ -97,7 +97,7 @@ func flattenNicList(nics []*v3.VMNic) []map[string]interface{} {
}
nic["ip_endpoint_list"] = ipEndpointList
nic["network_function_chain_reference"] = flattenReferenceValues(v.NetworkFunctionChainReference)

nic["num_queues"] = utils.Int64Value(v.NumQueues)
if v.SubnetReference != nil {
nic["subnet_uuid"] = utils.StringValue(v.SubnetReference.UUID)
nic["subnet_name"] = utils.StringValue(v.SubnetReference.Name)
Expand Down
1 change: 1 addition & 0 deletions website/docs/d/virtual_machine.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ The nic_list attribute supports the following:
* `network_function_chain_reference`: - The reference to a network_function_chain.
* `subnet_uuid`: - The reference to a subnet.
* `subnet_name`: - The name of the subnet reference to.
* `num_queues` : - The number of tx/rx queue pairs for this NIC.

### Serial Port List

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 @@ -193,6 +193,7 @@ The nic_list attribute supports the following:
* `subnet_uuid`: - The reference to a subnet.
* `subnet_name`: - The name of the subnet reference to.
* `floating_ip`: - The Floating IP associated with the vnic. (Only in `nic_list_status`)
* `num_queues`: - The number of tx/rx queue pairs for this NIC.

### Serial Port List

Expand Down