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

Numa node addition to Instances and Dedicated hosts #159

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
68 changes: 67 additions & 1 deletion ibm/service/vpc/data_source_ibm_is_dedicated_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,39 @@ func DataSourceIbmIsDedicatedHost() *schema.Resource {
Computed: true,
Description: "The total amount of memory in gibibytes for this host.",
},
"numa": {
Type: schema.TypeList,
Computed: true,
Description: "The dedicated host NUMA configuration",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"count": {
Type: schema.TypeInt,
Computed: true,
Description: "The total number of NUMA nodes for this dedicated host",
},
"nodes": {
Type: schema.TypeList,
Computed: true,
Description: "The NUMA nodes for this dedicated host.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"available_vcpu": {
Type: schema.TypeInt,
Computed: true,
Description: "The available VCPU for this NUMA node.",
},
"vcpu": {
Type: schema.TypeInt,
Computed: true,
Description: "The total VCPU capacity for this NUMA node.",
},
},
},
},
},
},
},
"profile": {
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -430,7 +463,11 @@ func dataSourceIbmIsDedicatedHostRead(context context.Context, d *schema.Resourc
if err = d.Set("name", dedicatedHost.Name); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting name: %s", err))
}

if dedicatedHost.Numa != nil {
if err = d.Set("numa", dataSourceDedicatedHostFlattenNumaNodes(*dedicatedHost.Numa)); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting numa nodes: %s", err))
}
}
if dedicatedHost.Profile != nil {
err = d.Set("profile", dataSourceDedicatedHostFlattenProfile(*dedicatedHost.Profile))
if err != nil {
Expand Down Expand Up @@ -603,6 +640,35 @@ func dataSourceDedicatedHostInstancesDeletedToMap(deletedItem vpcv1.InstanceRefe
return deletedMap
}

func dataSourceDedicatedHostFlattenNumaNodes(nodeItem vpcv1.DedicatedHostNuma) (numaNodes []map[string]interface{}) {
numaNodeMap := map[string]interface{}{}

if nodeItem.Count != nil {
numaNodeMap["count"] = *nodeItem.Count
}
if nodeItem.Nodes != nil {
nodesList := []map[string]interface{}{}
for _, nodeItem := range nodeItem.Nodes {
nodesList = append(nodesList, dataSourceDedicatedHostNodesToMap(nodeItem))
}
numaNodeMap["nodes"] = nodesList
}
numaNodes = append(numaNodes, numaNodeMap)
return numaNodes
}

func dataSourceDedicatedHostNodesToMap(nodes vpcv1.DedicatedHostNumaNode) (node map[string]interface{}) {
node = map[string]interface{}{}

if nodes.AvailableVcpu != nil {
node["available_vcpu"] = nodes.AvailableVcpu
}
if nodes.Vcpu != nil {
node["vcpu"] = nodes.Vcpu
}
return node
}

func dataSourceDedicatedHostFlattenProfile(result vpcv1.DedicatedHostProfileReference) (finalList []map[string]interface{}) {
finalList = []map[string]interface{}{}
finalMap := dataSourceDedicatedHostProfileToMap(result)
Expand Down
9 changes: 8 additions & 1 deletion ibm/service/vpc/data_source_ibm_is_dedicated_host_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,11 @@ func DataSourceIbmIsDedicatedHostProfile() *schema.Resource {
},
},
},
"status": {
Type: schema.TypeString,
Computed: true,
Description: "The status of the dedicated host profile.",
},
"vcpu_architecture": {
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -354,7 +359,9 @@ func dataSourceIbmIsDedicatedHostProfileRead(context context.Context, d *schema.
return diag.FromErr(fmt.Errorf("[ERROR] Error setting disks %s", err))
}
}

if dedicatedHostProfile.Status != nil {
d.Set("status", dedicatedHostProfile.Status)
}
if err = d.Set("family", dedicatedHostProfile.Family); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting family: %s", err))
}
Expand Down
8 changes: 8 additions & 0 deletions ibm/service/vpc/data_source_ibm_is_dedicated_host_profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,11 @@ func DataSourceIbmIsDedicatedHostProfiles() *schema.Resource {
},
},
},
"status": {
Type: schema.TypeString,
Computed: true,
Description: "The status of the dedicated host profile.",
},
"vcpu_architecture": {
Type: schema.TypeList,

Expand Down Expand Up @@ -467,6 +472,9 @@ func dataSourceDedicatedHostProfileCollectionProfilesToMap(profilesItem vpcv1.De
socketCountList = append(socketCountList, socketCountMap)
profilesMap["socket_count"] = socketCountList
}
if profilesItem.Status != nil {
profilesMap["status"] = *profilesItem.Status
}
if profilesItem.SupportedInstanceProfiles != nil {
supportedInstanceProfilesList := []map[string]interface{}{}
for _, supportedInstanceProfilesItem := range profilesItem.SupportedInstanceProfiles {
Expand Down
36 changes: 36 additions & 0 deletions ibm/service/vpc/data_source_ibm_is_dedicated_hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,39 @@ func DataSourceIbmIsDedicatedHosts() *schema.Resource {
Computed: true,
Description: "The unique user-defined name for this dedicated host. If unspecified, the name will be a hyphenated list of randomly-selected words.",
},
"numa": {
Type: schema.TypeList,
Computed: true,
Description: "The dedicated host NUMA configuration",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"count": {
Type: schema.TypeInt,
Computed: true,
Description: "The total number of NUMA nodes for this dedicated host",
},
"nodes": {
Type: schema.TypeList,
Computed: true,
Description: "The NUMA nodes for this dedicated host.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"available_vcpu": {
Type: schema.TypeInt,
Computed: true,
Description: "The available VCPU for this NUMA node.",
},
"vcpu": {
Type: schema.TypeInt,
Computed: true,
Description: "The total VCPU capacity for this NUMA node.",
},
},
},
},
},
},
},
"profile": {
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -509,6 +542,9 @@ func dataSourceDedicatedHostCollectionDedicatedHostsToMap(dedicatedHostsItem vpc
if dedicatedHostsItem.Name != nil {
dedicatedHostsMap["name"] = dedicatedHostsItem.Name
}
if dedicatedHostsItem.Numa != nil {
dedicatedHostsMap["numa"] = dataSourceDedicatedHostFlattenNumaNodes(*dedicatedHostsItem.Numa)
}
if dedicatedHostsItem.Profile != nil {
profileList := []map[string]interface{}{}
profileMap := dataSourceDedicatedHostCollectionDedicatedHostsProfileToMap(*dedicatedHostsItem.Profile)
Expand Down
10 changes: 9 additions & 1 deletion ibm/service/vpc/data_source_ibm_is_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,12 @@ func DataSourceIBMISInstance() *schema.Resource {
Description: "Instance memory",
},

"numa_count": {
Type: schema.TypeInt,
Computed: true,
Description: "The number of NUMA nodes this virtual server instance is provisioned on. This property may be absent if the instance's `status` is not `running`.",
},

isInstanceStatus: {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -779,7 +785,9 @@ func instanceGetByName(d *schema.ResourceData, meta interface{}, name string) er
}

d.Set(isInstanceMemory, *instance.Memory)

if instance.NumaCount != nil {
d.Set("numa_count", *instance.NumaCount)
}
gpuList := make([]map[string]interface{}, 0)
if instance.Gpu != nil {
currentGpu := map[string]interface{}{}
Expand Down
53 changes: 53 additions & 0 deletions ibm/service/vpc/data_source_ibm_is_instance_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,24 @@ func DataSourceIBMISInstanceProfile() *schema.Resource {
},
},
},
"numa_count": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"type": {
Type: schema.TypeString,
Computed: true,
Description: "The type for this profile field.",
},
"value": {
Type: schema.TypeInt,
Computed: true,
Description: "The value for this profile field.",
},
},
},
},
"port_speed": {
Type: schema.TypeList,
Computed: true,
Expand All @@ -504,6 +522,11 @@ func DataSourceIBMISInstanceProfile() *schema.Resource {
},
},
},
"status": {
Type: schema.TypeString,
Computed: true,
Description: "The status of the instance profile.",
},
isInstanceVCPUArchitecture: &schema.Schema{
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -638,6 +661,9 @@ func instanceProfileGet(d *schema.ResourceData, meta interface{}, name string) e
}

}
if profile.Status != nil {
d.Set("status", profile.Status)
}
if profile.Bandwidth != nil {
err = d.Set("bandwidth", dataSourceInstanceProfileFlattenBandwidth(*profile.Bandwidth.(*vpcv1.InstanceProfileBandwidth)))
if err != nil {
Expand Down Expand Up @@ -696,6 +722,12 @@ func instanceProfileGet(d *schema.ResourceData, meta interface{}, name string) e
return err
}
}
if profile.NumaCount != nil {
err = d.Set("numa_count", dataSourceInstanceProfileFlattenNumaCount(*profile.NumaCount.(*vpcv1.InstanceProfileNumaCount)))
if err != nil {
return err
}
}
if profile.PortSpeed != nil {
err = d.Set("port_speed", dataSourceInstanceProfileFlattenPortSpeed(*profile.PortSpeed.(*vpcv1.InstanceProfilePortSpeed)))
if err != nil {
Expand Down Expand Up @@ -1182,3 +1214,24 @@ func dataSourceInstanceProfileTotalVolumeBandwidthToMap(bandwidthItem vpcv1.Inst

return bandwidthMap
}

func dataSourceInstanceProfileFlattenNumaCount(result vpcv1.InstanceProfileNumaCount) (finalList []map[string]interface{}) {
finalList = []map[string]interface{}{}
finalMap := dataSourceInstanceProfileNumaCountToMap(result)
finalList = append(finalList, finalMap)

return finalList
}

func dataSourceInstanceProfileNumaCountToMap(numaItem vpcv1.InstanceProfileNumaCount) (numaMap map[string]interface{}) {
numaMap = map[string]interface{}{}

if numaItem.Type != nil {
numaMap["type"] = numaItem.Type
}
if numaItem.Value != nil {
numaMap["value"] = numaItem.Value
}

return numaMap
}
32 changes: 32 additions & 0 deletions ibm/service/vpc/data_source_ibm_is_instance_profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,24 @@ func DataSourceIBMISInstanceProfiles() *schema.Resource {
},
},
},
"numa_count": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"type": {
Type: schema.TypeString,
Computed: true,
Description: "The type for this profile field.",
},
"value": {
Type: schema.TypeInt,
Computed: true,
Description: "The value for this profile field.",
},
},
},
},
"port_speed": {
Type: schema.TypeList,
Computed: true,
Expand All @@ -505,6 +523,11 @@ func DataSourceIBMISInstanceProfiles() *schema.Resource {
},
},
},
"status": {
Type: schema.TypeString,
Computed: true,
Description: "The status of the instance profile.",
},
"vcpu_architecture": {
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -640,6 +663,9 @@ func instanceProfilesList(d *schema.ResourceData, meta interface{}) error {
l["architecture_values"] = profile.OsArchitecture.Values
}
}
if profile.Status != nil {
l["status"] = *profile.Status
}
if profile.Bandwidth != nil {
bandwidthList := []map[string]interface{}{}
bandwidthMap := dataSourceInstanceProfileBandwidthToMap(*profile.Bandwidth.(*vpcv1.InstanceProfileBandwidth))
Expand Down Expand Up @@ -689,6 +715,12 @@ func instanceProfilesList(d *schema.ResourceData, meta interface{}) error {
networkInterfaceCountList = append(networkInterfaceCountList, networkInterfaceCountMap)
l["network_interface_count"] = networkInterfaceCountList
}
if profile.NumaCount != nil {
numaCountList := []map[string]interface{}{}
numaCountMap := dataSourceInstanceProfileNumaCountToMap(*profile.NumaCount.(*vpcv1.InstanceProfileNumaCount))
numaCountList = append(numaCountList, numaCountMap)
l["numa_count"] = numaCountList
}
if profile.PortSpeed != nil {
portSpeedList := []map[string]interface{}{}
portSpeedMap := dataSourceInstanceProfilePortSpeedToMap(*profile.PortSpeed.(*vpcv1.InstanceProfilePortSpeed))
Expand Down
8 changes: 8 additions & 0 deletions ibm/service/vpc/data_source_ibm_is_instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ func DataSourceIBMISInstances() *schema.Resource {
Computed: true,
Description: "Instance memory",
},
"numa_count": {
Type: schema.TypeInt,
Computed: true,
Description: "The number of NUMA nodes this virtual server instance is provisioned on. This property may be absent if the instance's `status` is not `running`.",
},
isInstanceMetadataServiceEnabled: {
Type: schema.TypeBool,
Computed: true,
Expand Down Expand Up @@ -835,6 +840,9 @@ func instancesList(d *schema.ResourceData, meta interface{}) error {
l["crn"] = *instance.CRN
l["name"] = *instance.Name
l["memory"] = *instance.Memory
if instance.NumaCount != nil {
l["numa_count"] = *instance.NumaCount
}
if instance.MetadataService != nil {
l[isInstanceMetadataServiceEnabled] = *instance.MetadataService.Enabled
metadataService := []map[string]interface{}{}
Expand Down
Loading