Use cdi parser package

Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
Evan Lezar 2023-08-25 16:15:30 +02:00
parent 12dc12ce09
commit f2c9937ca8
4 changed files with 10 additions and 6 deletions

View File

@ -28,7 +28,7 @@ import (
"github.com/NVIDIA/nvidia-container-toolkit/pkg/nvcdi" "github.com/NVIDIA/nvidia-container-toolkit/pkg/nvcdi"
"github.com/NVIDIA/nvidia-container-toolkit/pkg/nvcdi/spec" "github.com/NVIDIA/nvidia-container-toolkit/pkg/nvcdi/spec"
"github.com/NVIDIA/nvidia-container-toolkit/pkg/nvcdi/transform" "github.com/NVIDIA/nvidia-container-toolkit/pkg/nvcdi/transform"
"github.com/container-orchestrated-devices/container-device-interface/pkg/cdi" cdi "github.com/container-orchestrated-devices/container-device-interface/pkg/parser"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
) )

View File

@ -22,6 +22,7 @@ import (
"github.com/NVIDIA/nvidia-container-toolkit/pkg/nvcdi/transform" "github.com/NVIDIA/nvidia-container-toolkit/pkg/nvcdi/transform"
"github.com/container-orchestrated-devices/container-device-interface/pkg/cdi" "github.com/container-orchestrated-devices/container-device-interface/pkg/cdi"
"github.com/container-orchestrated-devices/container-device-interface/pkg/parser"
"github.com/container-orchestrated-devices/container-device-interface/specs-go" "github.com/container-orchestrated-devices/container-device-interface/specs-go"
) )
@ -47,7 +48,7 @@ func newBuilder(opts ...Option) *builder {
} }
if s.raw != nil { if s.raw != nil {
s.noSimplify = true s.noSimplify = true
vendor, class := cdi.ParseQualifier(s.raw.Kind) vendor, class := parser.ParseQualifier(s.raw.Kind)
s.vendor = vendor s.vendor = vendor
s.class = class s.class = class
} }

View File

@ -20,7 +20,9 @@ import (
"fmt" "fmt"
"github.com/NVIDIA/nvidia-container-toolkit/internal/edits" "github.com/NVIDIA/nvidia-container-toolkit/internal/edits"
"github.com/container-orchestrated-devices/container-device-interface/pkg/cdi" "github.com/container-orchestrated-devices/container-device-interface/pkg/cdi"
"github.com/container-orchestrated-devices/container-device-interface/pkg/parser"
"github.com/container-orchestrated-devices/container-device-interface/specs-go" "github.com/container-orchestrated-devices/container-device-interface/specs-go"
) )
@ -64,7 +66,7 @@ func NewMergedDevice(opts ...MergedDeviceOption) (Transformer, error) {
} }
m.simplifier = NewSimplifier() m.simplifier = NewSimplifier()
if err := cdi.ValidateDeviceName(m.name); err != nil { if err := parser.ValidateDeviceName(m.name); err != nil {
return nil, fmt.Errorf("invalid device name %q: %v", m.name, err) return nil, fmt.Errorf("invalid device name %q: %v", m.name, err)
} }

View File

@ -27,6 +27,7 @@ import (
"github.com/NVIDIA/nvidia-container-toolkit/pkg/nvcdi" "github.com/NVIDIA/nvidia-container-toolkit/pkg/nvcdi"
"github.com/NVIDIA/nvidia-container-toolkit/pkg/nvcdi/transform" "github.com/NVIDIA/nvidia-container-toolkit/pkg/nvcdi/transform"
"github.com/container-orchestrated-devices/container-device-interface/pkg/cdi" "github.com/container-orchestrated-devices/container-device-interface/pkg/cdi"
"github.com/container-orchestrated-devices/container-device-interface/pkg/parser"
toml "github.com/pelletier/go-toml" toml "github.com/pelletier/go-toml"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
@ -238,11 +239,11 @@ func validateOptions(c *cli.Context, opts *options) error {
return fmt.Errorf("invalid --toolkit-root option: %v", opts.toolkitRoot) return fmt.Errorf("invalid --toolkit-root option: %v", opts.toolkitRoot)
} }
vendor, class := cdi.ParseQualifier(opts.cdiKind) vendor, class := parser.ParseQualifier(opts.cdiKind)
if err := cdi.ValidateVendorName(vendor); err != nil { if err := parser.ValidateVendorName(vendor); err != nil {
return fmt.Errorf("invalid CDI vendor name: %v", err) return fmt.Errorf("invalid CDI vendor name: %v", err)
} }
if err := cdi.ValidateClassName(class); err != nil { if err := parser.ValidateClassName(class); err != nil {
return fmt.Errorf("invalid CDI class name: %v", err) return fmt.Errorf("invalid CDI class name: %v", err)
} }
opts.cdiVendor = vendor opts.cdiVendor = vendor