mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2024-11-22 00:08:11 +00:00
Merge pull request #342 from elezar/add-spec-dirs-to-cdi-list
Add spec-dir flag to nvidia-ctk cdi list command
This commit is contained in:
commit
e96edb3f36
@ -1,5 +1,7 @@
|
|||||||
# NVIDIA Container Toolkit Changelog
|
# NVIDIA Container Toolkit Changelog
|
||||||
|
|
||||||
|
* Add a `--spec-dir` option to the `nvidia-ctk cdi generate` command. This allows specs outside of `/etc/cdi` and `/var/run/cdi` to be processed.
|
||||||
|
|
||||||
## v1.15.0-rc.3
|
## v1.15.0-rc.3
|
||||||
* Fix bug in `nvidia-ctk hook update-ldcache` where default `--ldconfig-path` value was not applied.
|
* Fix bug in `nvidia-ctk hook update-ldcache` where default `--ldconfig-path` value was not applied.
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
package list
|
package list
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
@ -29,7 +30,9 @@ type command struct {
|
|||||||
logger logger.Interface
|
logger logger.Interface
|
||||||
}
|
}
|
||||||
|
|
||||||
type config struct{}
|
type config struct {
|
||||||
|
cdiSpecDirs cli.StringSlice
|
||||||
|
}
|
||||||
|
|
||||||
// NewCommand constructs a cdi list command with the specified logger
|
// NewCommand constructs a cdi list command with the specified logger
|
||||||
func NewCommand(logger logger.Interface) *cli.Command {
|
func NewCommand(logger logger.Interface) *cli.Command {
|
||||||
@ -55,30 +58,44 @@ func (m command) build() *cli.Command {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Flags = []cli.Flag{}
|
c.Flags = []cli.Flag{
|
||||||
|
&cli.StringSliceFlag{
|
||||||
|
Name: "spec-dir",
|
||||||
|
Usage: "specify the directories to scan for CDI specifications",
|
||||||
|
Value: cli.NewStringSlice(cdi.DefaultSpecDirs...),
|
||||||
|
Destination: &cfg.cdiSpecDirs,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
return &c
|
return &c
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m command) validateFlags(c *cli.Context, cfg *config) error {
|
func (m command) validateFlags(c *cli.Context, cfg *config) error {
|
||||||
|
if len(cfg.cdiSpecDirs.Value()) == 0 {
|
||||||
|
return errors.New("at least one CDI specification directory must be specified")
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m command) run(c *cli.Context, cfg *config) error {
|
func (m command) run(c *cli.Context, cfg *config) error {
|
||||||
registry, err := cdi.NewCache(
|
registry, err := cdi.NewCache(
|
||||||
cdi.WithAutoRefresh(false),
|
cdi.WithAutoRefresh(false),
|
||||||
cdi.WithSpecDirs(cdi.DefaultSpecDirs...),
|
cdi.WithSpecDirs(cfg.cdiSpecDirs.Value()...),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to create CDI cache: %v", err)
|
return fmt.Errorf("failed to create CDI cache: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
refreshErr := registry.Refresh()
|
_ = registry.Refresh()
|
||||||
|
if errors := registry.GetErrors(); len(errors) > 0 {
|
||||||
|
m.logger.Warningf("The following registry errors were reported:")
|
||||||
|
for k, err := range errors {
|
||||||
|
m.logger.Warningf("%v: %v", k, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
devices := registry.ListDevices()
|
devices := registry.ListDevices()
|
||||||
m.logger.Infof("Found %d CDI devices", len(devices))
|
m.logger.Infof("Found %d CDI devices", len(devices))
|
||||||
if refreshErr != nil {
|
|
||||||
m.logger.Warningf("Refreshing the CDI registry returned the following error(s): %v", refreshErr)
|
|
||||||
}
|
|
||||||
for _, device := range devices {
|
for _, device := range devices {
|
||||||
fmt.Printf("%s\n", device)
|
fmt.Printf("%s\n", device)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user