gvisor.dev/gvisor@v0.0.0-20240520182842-f9d4d51c7e0f/runsc/cmd/nvproxy/list_supported_drivers.go (about)

     1  // Copyright 2023 The gVisor Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  // Package nvproxy provides subcommands for the nvproxy command.
    16  package nvproxy
    17  
    18  import (
    19  	"context"
    20  	"fmt"
    21  
    22  	"github.com/google/subcommands"
    23  	"gvisor.dev/gvisor/pkg/sentry/devices/nvproxy"
    24  	"gvisor.dev/gvisor/runsc/flag"
    25  )
    26  
    27  // listSupportedDrivers implements subcommands.Command for the "nvproxy list-supported-drivers" command.
    28  type listSupportedDrivers struct{}
    29  
    30  // Name implements subcommands.Command.
    31  func (*listSupportedDrivers) Name() string {
    32  	return "list-supported-drivers"
    33  }
    34  
    35  // Synopsis implements subcommands.Command.
    36  func (*listSupportedDrivers) Synopsis() string {
    37  	return "list all nvidia driver versions supported by nvproxy"
    38  }
    39  
    40  // Usage implements subcommands.Command.
    41  func (*listSupportedDrivers) Usage() string {
    42  	return `list-supported-drivers - list all nvidia driver versions supported by nvproxy
    43  `
    44  }
    45  
    46  // SetFlags implements subcommands.Command.
    47  func (*listSupportedDrivers) SetFlags(*flag.FlagSet) {}
    48  
    49  // Execute implements subcommands.Command.
    50  func (*listSupportedDrivers) Execute(ctx context.Context, f *flag.FlagSet, args ...any) subcommands.ExitStatus {
    51  	if f.NArg() != 0 {
    52  		f.Usage()
    53  		return subcommands.ExitUsageError
    54  	}
    55  
    56  	nvproxy.ForEachSupportDriver(func(version nvproxy.DriverVersion, _ string) {
    57  		fmt.Println(version)
    58  	})
    59  
    60  	return subcommands.ExitSuccess
    61  }