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

PLT-626: Added gpu_device support in libvirt. #335

Merged
merged 9 commits into from
Oct 3, 2023
Merged
14 changes: 14 additions & 0 deletions docs/resources/cluster_libvirt.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,22 @@ Required:

Optional:

- `gpu_device` (Block List) (see [below for nested schema](#nestedblock--machine_pool--placements--gpu_device))
- `network` (String)

<a id="nestedblock--machine_pool--placements--gpu_device"></a>
### Nested Schema for `machine_pool.placements.gpu_device`

Required:

- `device_model` (String) DeviceModel `device_model` is the model of GPU, for a given vendor, for eg., TU104GL [Tesla T4]
- `vendor` (String) Vendor `vendor` is the GPU vendor, for eg., NVIDIA or AMD

Optional:

- `addresses` (Map of String) Addresses is a map of PCI device entry name to its addresses.



<a id="nestedblock--machine_pool--taints"></a>
### Nested Schema for `machine_pool.taints`
Expand Down
44 changes: 44 additions & 0 deletions spectrocloud/resource_cluster_libvirt.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,32 @@ func resourceClusterLibvirt() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"gpu_device": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"device_model": {
Type: schema.TypeString,
Required: true,
Description: "DeviceModel `device_model` is the model of GPU, for a given vendor, for eg., TU104GL [Tesla T4]",
},
"vendor": {
Type: schema.TypeString,
Required: true,
Description: "Vendor `vendor` is the GPU vendor, for eg., NVIDIA or AMD",
},
"addresses": {
Type: schema.TypeMap,
Optional: true,
Description: "Addresses is a map of PCI device entry name to its addresses.",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
},
},
},
},
Expand Down Expand Up @@ -476,6 +502,7 @@ func flattenMachinePoolConfigsLibvirt(machinePools []*models.V1LibvirtMachinePoo
pj["image_storage_pool"] = p.SourceStoragePool
pj["target_storage_pool"] = p.TargetStoragePool
pj["data_storage_pool"] = p.DataStoragePool
pj["gpu_device"] = flattenGpuDevice(p.GpuDevices)
placements[j] = pj
}
oi["placements"] = placements
Expand All @@ -487,6 +514,23 @@ func flattenMachinePoolConfigsLibvirt(machinePools []*models.V1LibvirtMachinePoo
return ois
}

func flattenGpuDevice(gpus []*models.V1GPUDeviceSpec) []interface{} {
SivaanandM marked this conversation as resolved.
Show resolved Hide resolved
if gpus != nil {
dConfig := make([]interface{}, 0)
for _, d := range gpus {
if !(d.Model == "" || d.Vendor == "") {
dElem := make(map[string]interface{})
dElem["device_model"] = d.Model
dElem["vendor"] = d.Vendor
dElem["addresses"] = d.Addresses
dConfig = append(dConfig, dElem)
}
}
return dConfig
}
return make([]interface{}, 0)
}

func resourceClusterVirtUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
c := m.(*client.V1Client)

Expand Down