mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2025-06-26 18:18:24 +00:00
Return nvcdi.spec.Interface from GetSpec
Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
@@ -17,12 +17,17 @@
|
||||
package nvcdi
|
||||
|
||||
import (
|
||||
"github.com/NVIDIA/nvidia-container-toolkit/pkg/nvcdi/spec"
|
||||
"github.com/sirupsen/logrus"
|
||||
"gitlab.com/nvidia/cloud-native/go-nvlib/pkg/nvlib/device"
|
||||
"gitlab.com/nvidia/cloud-native/go-nvlib/pkg/nvlib/info"
|
||||
"gitlab.com/nvidia/cloud-native/go-nvlib/pkg/nvml"
|
||||
)
|
||||
|
||||
type wrapper struct {
|
||||
Interface
|
||||
}
|
||||
|
||||
type nvcdilib struct {
|
||||
logger *logrus.Logger
|
||||
nvmllib nvml.Interface
|
||||
@@ -60,6 +65,7 @@ func New(opts ...Option) Interface {
|
||||
l.infolib = info.New()
|
||||
}
|
||||
|
||||
var lib Interface
|
||||
switch l.resolveMode() {
|
||||
case ModeNvml:
|
||||
if l.nvmllib == nil {
|
||||
@@ -69,13 +75,30 @@ func New(opts ...Option) Interface {
|
||||
l.devicelib = device.New(device.WithNvml(l.nvmllib))
|
||||
}
|
||||
|
||||
return (*nvmllib)(l)
|
||||
lib = (*nvmllib)(l)
|
||||
case ModeWsl:
|
||||
return (*wsllib)(l)
|
||||
lib = (*wsllib)(l)
|
||||
default:
|
||||
// TODO: We would like to return an error here instead of panicking
|
||||
panic("Unknown mode")
|
||||
}
|
||||
|
||||
// TODO: We want an error here.
|
||||
return nil
|
||||
return &wrapper{Interface: lib}
|
||||
}
|
||||
|
||||
// GetSpec combines the device specs and common edits from the wrapped Interface to a single spec.Interface.
|
||||
func (l *wrapper) GetSpec() (spec.Interface, error) {
|
||||
deviceSpecs, err := l.GetAllDeviceSpecs()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
edits, err := l.GetCommonEdits()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return spec.New(deviceSpecs, *edits.ContainerEdits)
|
||||
}
|
||||
|
||||
// resolveMode resolves the mode for CDI spec generation based on the current system.
|
||||
|
||||
Reference in New Issue
Block a user