Skip to content

Commit 8b3aa9e

Browse files
Mengyao ChenMaxrovr
authored andcommitted
Added - Support for Compute: GPU Memory Fabric API Update - availableHostCount
1 parent 0197505 commit 8b3aa9e

6 files changed

+48
-2
lines changed

internal/integrationtest/core_compute_gpu_memory_fabric_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ func TestCoreComputeGpuMemoryFabricResource_basic(t *testing.T) {
6868
"oci_core_compute_gpu_memory_fabric", "test_compute_gpu_memory_fabric", acctest.Required, acctest.Create, CoreComputeGpuMemoryFabricSingularDataSourceRepresentation),
6969
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
7070
resource.TestCheckResourceAttrSet(singularDatasourceName, "compute_gpu_memory_fabric_id"),
71+
resource.TestCheckResourceAttrSet(singularDatasourceName, "available_host_count"),
7172
resource.TestCheckResourceAttr(singularDatasourceName, "compartment_id", compartmentId),
7273
resource.TestCheckResourceAttrSet(singularDatasourceName, "compute_local_block_id"),
7374
resource.TestCheckResourceAttrSet(singularDatasourceName, "display_name"),

internal/service/core/core_compute_gpu_memory_fabric_data_source.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ package core
55

66
import (
77
"context"
8+
"encoding/json"
9+
"log"
810
"strconv"
911

1012
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -67,7 +69,11 @@ func (s *CoreComputeGpuMemoryFabricDataSourceCrud) SetData() error {
6769

6870
s.D.SetId(*s.Res.Id)
6971

70-
s.D.Set("additional_data", s.Res.AdditionalData)
72+
s.D.Set("additional_data", flattenAdditionalData(s.Res.AdditionalData))
73+
74+
if s.Res.AvailableHostCount != nil {
75+
s.D.Set("available_host_count", strconv.FormatInt(*s.Res.AvailableHostCount, 10))
76+
}
7177

7278
s.D.Set("compute_gpu_memory_fabric_id", *s.Res.Id)
7379

@@ -119,3 +125,23 @@ func (s *CoreComputeGpuMemoryFabricDataSourceCrud) SetData() error {
119125

120126
return nil
121127
}
128+
129+
func flattenAdditionalData(input map[string]interface{}) map[string]interface{} {
130+
flatMap := make(map[string]interface{})
131+
132+
for k, v := range input {
133+
if strVal, ok := v.(string); ok {
134+
flatMap[k] = strVal
135+
} else {
136+
jsonStrVal, err := json.Marshal(v)
137+
if err != nil {
138+
log.Printf("[ERROR] Failed to marshal additional_data[%q]: %v", k, err)
139+
flatMap[k] = "" // Optional fallback
140+
} else {
141+
flatMap[k] = string(jsonStrVal)
142+
}
143+
}
144+
}
145+
146+
return flatMap
147+
}

internal/service/core/core_compute_gpu_memory_fabric_resource.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ func CoreComputeGpuMemoryFabricResource() *schema.Resource {
6565
Computed: true,
6666
Elem: schema.TypeString,
6767
},
68+
"available_host_count": {
69+
Type: schema.TypeString,
70+
Computed: true,
71+
},
6872
"compute_hpc_island_id": {
6973
Type: schema.TypeString,
7074
Computed: true,
@@ -286,7 +290,11 @@ func (s *CoreComputeGpuMemoryFabricResourceCrud) Update() error {
286290
}
287291

288292
func (s *CoreComputeGpuMemoryFabricResourceCrud) SetData() error {
289-
s.D.Set("additional_data", s.Res.AdditionalData)
293+
s.D.Set("additional_data", flattenAdditionalData(s.Res.AdditionalData))
294+
295+
if s.Res.AvailableHostCount != nil {
296+
s.D.Set("available_host_count", strconv.FormatInt(*s.Res.AvailableHostCount, 10))
297+
}
290298

291299
s.D.Set("compute_gpu_memory_fabric_id", *s.Res.Id)
292300

@@ -342,6 +350,10 @@ func (s *CoreComputeGpuMemoryFabricResourceCrud) SetData() error {
342350
func ComputeGpuMemoryFabricSummaryToMap(obj oci_core.ComputeGpuMemoryFabricSummary) map[string]interface{} {
343351
result := map[string]interface{}{}
344352

353+
if obj.AvailableHostCount != nil {
354+
result["available_host_count"] = strconv.FormatInt(*obj.AvailableHostCount, 10)
355+
}
356+
345357
if obj.CompartmentId != nil {
346358
result["compartment_id"] = string(*obj.CompartmentId)
347359
}
@@ -370,6 +382,10 @@ func ComputeGpuMemoryFabricSummaryToMap(obj oci_core.ComputeGpuMemoryFabricSumma
370382

371383
result["freeform_tags"] = obj.FreeformTags
372384

385+
if obj.HealthyHostCount != nil {
386+
result["healthy_host_count"] = strconv.FormatInt(*obj.HealthyHostCount, 10)
387+
}
388+
373389
if obj.Id != nil {
374390
result["id"] = string(*obj.Id)
375391
}

website/docs/d/core_compute_gpu_memory_fabric.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ The following arguments are supported:
3434
The following attributes are exported:
3535

3636
* `additional_data` - Additional data that can be exposed to the customer. Right now it will include the switch tray ids.
37+
* `available_host_count` - The total number of available bare metal hosts located in this compute GPU memory fabric.
3738
* `compartment_id` - The [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) for the compartment. This should always be the root compartment.
3839
* `compute_hpc_island_id` - The [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) for Customer-unique HPC Island
3940
* `compute_local_block_id` - The [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) for Customer-unique Local Block

website/docs/d/core_compute_gpu_memory_fabrics.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ The following attributes are exported:
5555
The following attributes are exported:
5656

5757
* `additional_data` - Additional data that can be exposed to the customer. Right now it will include the switch tray ids.
58+
* `available_host_count` - The total number of available bare metal hosts located in this compute GPU memory fabric.
5859
* `compartment_id` - The [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) for the compartment. This should always be the root compartment.
5960
* `compute_hpc_island_id` - The [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) for Customer-unique HPC Island
6061
* `compute_local_block_id` - The [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) for Customer-unique Local Block

website/docs/r/core_compute_gpu_memory_fabric.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Any change to a property that does not support update will force the destruction
4646
The following attributes are exported:
4747

4848
* `additional_data` - Additional data that can be exposed to the customer. Right now it will include the switch tray ids.
49+
* `available_host_count` - The total number of available bare metal hosts located in this compute GPU memory fabric.
4950
* `compartment_id` - The [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) for the compartment. This should always be the root compartment.
5051
* `compute_hpc_island_id` - The [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) for Customer-unique HPC Island
5152
* `compute_local_block_id` - The [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) for Customer-unique Local Block

0 commit comments

Comments
 (0)