From 6dbbbd2b722d1f2695bba7704a1efeb06b7a3539 Mon Sep 17 00:00:00 2001 From: bhatipradeep Date: Fri, 25 Mar 2022 13:31:09 +0530 Subject: [PATCH 1/4] Add ipmi netmask and gateway for bare metal nodes --- client/foundation/foundation_structs.go | 6 ++- ...resource_nutanix_foundation_image_nodes.go | 39 +++++++++++++++++-- 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/client/foundation/foundation_structs.go b/client/foundation/foundation_structs.go index c88b47af4..3badef02c 100644 --- a/client/foundation/foundation_structs.go +++ b/client/foundation/foundation_structs.go @@ -36,8 +36,8 @@ type ImageNodesInput struct { HypervisorGateway string `json:"hypervisor_gateway"` NosPackage string `json:"nos_package"` //will be null for cluster creation UcsmUser string `json:"ucsm_user,omitempty"` - // IPMINetmask string `json:"ipmi_netmask,omitempty"` - // IPMIGateway string `json:"ipmi_gateway,omitempty"` + IPMINetmask string `json:"ipmi_netmask,omitempty"` + IPMIGateway string `json:"ipmi_gateway,omitempty"` } //Specific hypervisor definition for imaging @@ -113,6 +113,8 @@ type Vswitches struct { //Single node definition type Node struct { + IPMINetmask string `json:"ipmi_netmask,omitempty"` + IPMIGateway string `json:"ipmi_gateway,omitempty"` Ipv6Address string `json:"ipv6_address,omitempty"` NodePosition string `json:"node_position"` ImageDelay *int64 `json:"image_delay,omitempty"` diff --git a/nutanix/resource_nutanix_foundation_image_nodes.go b/nutanix/resource_nutanix_foundation_image_nodes.go index 0b55f078a..b45d51db8 100644 --- a/nutanix/resource_nutanix_foundation_image_nodes.go +++ b/nutanix/resource_nutanix_foundation_image_nodes.go @@ -35,6 +35,16 @@ func resourceFoundationImageNodes() *schema.Resource { Optional: true, ForceNew: true, }, + "ipmi_netmask": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + "ipmi_gateway": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, "ipmi_password": { Type: schema.TypeString, Optional: true, @@ -379,6 +389,16 @@ func resourceFoundationImageNodes() *schema.Resource { ForceNew: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ + "ipmi_netmask": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + "ipmi_gateway": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, "ipv6_address": { Type: schema.TypeString, Optional: true, @@ -709,7 +729,12 @@ func resourceFoundationImageNodesCreate(ctx context.Context, d *schema.ResourceD if ok { request.IpmiPassword = ipmiPass.(string) } - + if ipmiNetmask, ok := d.GetOk("ipmi_netmask"); ok { + request.IPMINetmask = ipmiNetmask.(string) + } + if ipmiGateway, ok := d.GetOk("ipmi_gateway"); ok { + request.IPMIGateway = ipmiGateway.(string) + } cvmGateway, cvmgok := d.GetOk("cvm_gateway") if cvmgok { request.CvmGateway = (cvmGateway.(string)) @@ -1140,8 +1165,14 @@ func expandNodes(pr interface{}) []*foundation.Node { for i, p := range nodesList { node := p.(map[string]interface{}) nodeList := &foundation.Node{} + if ipmiNetmask, ok := node["ipmi_netmask"]; ok { + nodeList.IPMINetmask = ipmiNetmask.(string) + } + if ipmiGateway, ok := node["ipmi_gateway"]; ok { + nodeList.IPMIGateway = ipmiGateway.(string) + } if ipv6, ipv6ok := node["ipv6_address"]; ipv6ok { - nodeList.BondLacpRate = (ipv6.(string)) + nodeList.Ipv6Address = (ipv6.(string)) } if np, npok := node["node_position"]; npok { nodeList.NodePosition = (np.(string)) @@ -1200,10 +1231,10 @@ func expandNodes(pr interface{}) []*foundation.Node { nodeList.IpmiMac = (ipmimac.(string)) } if clsid, clsidok := node["rdma_mac_addr"]; clsidok { - nodeList.ClusterID = (clsid.(string)) + nodeList.RdmaMacAddr = (clsid.(string)) } if ucsmns, ucsmnsok := node["current_network_interface"]; ucsmnsok { - nodeList.UcsmNodeSerial = (ucsmns.(string)) + nodeList.CurrentNetworkInterface = (ucsmns.(string)) } if hypervip, hypervipok := node["hypervisor_ip"]; hypervipok { nodeList.HypervisorIP = (hypervip.(string)) From 64527842893343dd7a10236c65a95362592ba1ba Mon Sep 17 00:00:00 2001 From: bhatipradeep Date: Fri, 25 Mar 2022 13:35:19 +0530 Subject: [PATCH 2/4] Minor typos --- nutanix/resource_nutanix_foundation_image_nodes.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/nutanix/resource_nutanix_foundation_image_nodes.go b/nutanix/resource_nutanix_foundation_image_nodes.go index b45d51db8..1d3bd04bb 100644 --- a/nutanix/resource_nutanix_foundation_image_nodes.go +++ b/nutanix/resource_nutanix_foundation_image_nodes.go @@ -1230,11 +1230,11 @@ func expandNodes(pr interface{}) []*foundation.Node { if ipmimac, ipmimacok := node["ipmi_mac"]; ipmimacok { nodeList.IpmiMac = (ipmimac.(string)) } - if clsid, clsidok := node["rdma_mac_addr"]; clsidok { - nodeList.RdmaMacAddr = (clsid.(string)) + if rma, rmaok := node["rdma_mac_addr"]; rmaok { + nodeList.RdmaMacAddr = (rma.(string)) } - if ucsmns, ucsmnsok := node["current_network_interface"]; ucsmnsok { - nodeList.CurrentNetworkInterface = (ucsmns.(string)) + if cni, cniok := node["current_network_interface"]; cniok { + nodeList.CurrentNetworkInterface = (cni.(string)) } if hypervip, hypervipok := node["hypervisor_ip"]; hypervipok { nodeList.HypervisorIP = (hypervip.(string)) From 058391671af4bbc4678401e86a67c537e03596d2 Mon Sep 17 00:00:00 2001 From: bhatipradeep Date: Fri, 25 Mar 2022 14:09:38 +0530 Subject: [PATCH 3/4] Resolve lint errors. Change datatypes for cluster_id and cvm_vlan_tags --- nutanix/data_source_foundation_discover_nodes.go | 13 +++++++------ nutanix/resource_nutanix_foundation_image_nodes.go | 10 +++++----- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/nutanix/data_source_foundation_discover_nodes.go b/nutanix/data_source_foundation_discover_nodes.go index ca23a81f7..4a414debd 100644 --- a/nutanix/data_source_foundation_discover_nodes.go +++ b/nutanix/data_source_foundation_discover_nodes.go @@ -2,6 +2,7 @@ package nutanix import ( "context" + "strconv" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" @@ -69,11 +70,11 @@ func dataSourceFoundationDiscoverNodes() *schema.Resource { Computed: true, }, "cluster_id": { - Type: schema.TypeInt, + Type: schema.TypeString, Computed: true, }, "current_cvm_vlan_tag": { - Type: schema.TypeInt, + Type: schema.TypeString, Computed: true, }, "hypervisor_version": { @@ -150,16 +151,16 @@ func flattenDiscoveredNodes(nodesList []foundation.DiscoveredNode) []map[string] //ClusterID is of interface{} type so making sure we only accept integer values if val, ok := v.ClusterID.(float64); ok { - node["cluster_id"] = int64(val) + node["cluster_id"] = strconv.FormatInt(int64(val), 10) } else { - node["cluster_id"] = int64(-1) + node["cluster_id"] = "" } //CurrentCvmVlanTag is of interface{} type so making sure we only accept integer values if val, ok := v.CurrentCvmVlanTag.(float64); ok { - node["current_cvm_vlan_tag"] = int64(val) + node["current_cvm_vlan_tag"] = strconv.FormatInt(int64(val), 10) } else { - node["current_cvm_vlan_tag"] = int64(-1) + node["current_cvm_vlan_tag"] = "" } node["hypervisor_version"] = v.HypervisorVersion diff --git a/nutanix/resource_nutanix_foundation_image_nodes.go b/nutanix/resource_nutanix_foundation_image_nodes.go index 1d3bd04bb..bd50c2f1b 100644 --- a/nutanix/resource_nutanix_foundation_image_nodes.go +++ b/nutanix/resource_nutanix_foundation_image_nodes.go @@ -952,11 +952,11 @@ func expandEosMetadata(d *schema.ResourceData) (*foundation.EosMetadata, error) if acname, ok := eosmeta["account_name"]; ok { ac := acname.([]interface{}) - acc_names := make([]string, len(ac)) + accNames := make([]string, len(ac)) for a := range ac { - acc_names[a] = ac[a].(string) + accNames[a] = ac[a].(string) } - eosMeta.AccountName = acc_names + eosMeta.AccountName = accNames } if email, ok := eosmeta["email"]; ok { @@ -1165,10 +1165,10 @@ func expandNodes(pr interface{}) []*foundation.Node { for i, p := range nodesList { node := p.(map[string]interface{}) nodeList := &foundation.Node{} - if ipmiNetmask, ok := node["ipmi_netmask"]; ok { + if ipmiNetmask, ipmiNetOk := node["ipmi_netmask"]; ipmiNetOk { nodeList.IPMINetmask = ipmiNetmask.(string) } - if ipmiGateway, ok := node["ipmi_gateway"]; ok { + if ipmiGateway, ipmiGateOk := node["ipmi_gateway"]; ipmiGateOk { nodeList.IPMIGateway = ipmiGateway.(string) } if ipv6, ipv6ok := node["ipv6_address"]; ipv6ok { From f057882aee75e3022d32cde70568d52040b1c665 Mon Sep 17 00:00:00 2001 From: bhatipradeep Date: Fri, 25 Mar 2022 14:14:33 +0530 Subject: [PATCH 4/4] resolve lint errrors --- nutanix/resource_nutanix_foundation_image_nodes.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nutanix/resource_nutanix_foundation_image_nodes.go b/nutanix/resource_nutanix_foundation_image_nodes.go index bd50c2f1b..d735392ea 100644 --- a/nutanix/resource_nutanix_foundation_image_nodes.go +++ b/nutanix/resource_nutanix_foundation_image_nodes.go @@ -729,10 +729,10 @@ func resourceFoundationImageNodesCreate(ctx context.Context, d *schema.ResourceD if ok { request.IpmiPassword = ipmiPass.(string) } - if ipmiNetmask, ok := d.GetOk("ipmi_netmask"); ok { + if ipmiNetmask, ipmiNetOk := d.GetOk("ipmi_netmask"); ipmiNetOk { request.IPMINetmask = ipmiNetmask.(string) } - if ipmiGateway, ok := d.GetOk("ipmi_gateway"); ok { + if ipmiGateway, ipmiGateOk := d.GetOk("ipmi_gateway"); ipmiGateOk { request.IPMIGateway = ipmiGateway.(string) } cvmGateway, cvmgok := d.GetOk("cvm_gateway")