| package commands |
| |
| import ( |
| "net/http" |
| |
| "cos-extensions/extensions/gpu" |
| |
| "github.com/golang/glog" |
| "github.com/spf13/cobra" |
| ) |
| |
| const ( |
| rootHelpTemplate = `Name: |
| cos-extensions {{with (or .Long .Short)}}{{. | trimTrailingWhitespaces}}{{end}}{{if or .Runnable .HasSubCommands}} |
| {{.UsageString}}{{end}}` |
| |
| rootUsageTemplate = `Usage:{{if .Runnable}} |
| {{.UseLine}}{{end}}{{if .HasAvailableSubCommands}} |
| {{.CommandPath}} [command] <extension> {{end}}{{if gt (len .Aliases) 0}} |
| |
| Aliases: |
| {{.NameAndAliases}}{{end}}{{if .HasExample}} |
| |
| Examples: |
| {{.Example}}{{end}}{{if .HasAvailableSubCommands}}{{$cmds := .Commands}}{{if eq (len .Groups) 0}} |
| |
| Available Commands:{{range $cmds}}{{if (or .IsAvailableCommand (eq .Name "help"))}} |
| {{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}{{else}}{{range $group := .Groups}} |
| |
| {{.Title}}{{range $cmds}}{{if (and (eq .GroupID $group.ID) (or .IsAvailableCommand (eq .Name "help")))}} |
| {{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}{{end}}{{if not .AllChildCommandsHaveGroup}} |
| |
| Additional Commands:{{range $cmds}}{{if (and (eq .GroupID "") (or .IsAvailableCommand (eq .Name "help")))}} |
| {{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}{{end}}{{end}}{{end}} |
| |
| Detailed Description: |
| Available Extensions: |
| |
| gpu Installs gpu drivers and lists the available versions. |
| |
| Extension usage: |
| cos-extensions list gpu [--gpu-installer] lists all available gpu driver verions. |
| When --gpu-installer is set, lists the |
| available cos-gpu-installer. |
| |
| cos-extensions install gpu installs gpu drivers. |
| |
| Additional Description: |
| cos-extensions install gpu -- [options] |
| |
| --version |
| The gpu extension can be invoked with --version. The possible values are |
| 'latest', 'default', 'R<major-version>' eg. 'R470', 'R535'. or |
| precise driver versions retrievable by running ${PROG_NAME} list. |
| If unspecified, the default driver version is installed. |
| |
| --force-fallback |
| This flag indicates whether to use fallback mechanism when specified |
| GPU driver is not compatible with GPU devices. In case unspecified, |
| the fallback behavior of the installer is not applicable for |
| --version=R<major-version> eg. 'R470', 'R525' or |
| --version=<precise-version> eg. '535.129.03', '525.147.05'. |
| The fallback behavior of the installer is active for --version is unset |
| or --version=default or --version=latest. |
| When fallback behavior is active, the installer will find a compatible |
| driver to install for the detected GPU on the VM. |
| |
| --prepare-build-tools |
| The gpu extension can be invoked with a --prepare-build-tools optional |
| argument that can be used to cache the toolchain for the installer. |
| Caching the toolchain carries the overhead of ~1GB disk space on the |
| stateful partition. |
| Using this command only populates the cache and does NOT install the GPU |
| drivers thus may saves time on downloading the toolchain during subsequent |
| installations. |
| |
| --clean-build-tools |
| Use this optional command to delete the cache for the toolchain present on |
| the stateful partition. |
| |
| -test |
| The gpu extension can be used to install drivers on a dev channel image with |
| this. |
| |
| -debug |
| The granularity of logging of the gpu extension can be increased by |
| specifying this. |
| {{if .HasAvailableLocalFlags}} |
| Flags: |
| {{.LocalFlags.FlagUsages | trimTrailingWhitespaces}}{{end}}{{if .HasAvailableInheritedFlags}} |
| |
| Global Flags: |
| {{.InheritedFlags.FlagUsages | trimTrailingWhitespaces}}{{end}}{{if .HasHelpSubCommands}} |
| |
| Additional help topics:{{range .Commands}}{{if .IsAdditionalHelpTopicCommand}} |
| {{rpad .CommandPath .CommandPathPadding}} {{.Short}}{{end}}{{end}}{{end}}{{if .HasAvailableSubCommands}} |
| |
| Use "{{.CommandPath}} [command] --help" for more information about a command.{{end}} |
| ` |
| |
| cmdHelpTemplate = `Name: |
| cos-extensions-{{.Use}} {{with (or .Long .Short)}}{{. | trimTrailingWhitespaces}} |
| {{end}}{{if or .Runnable .HasSubCommands}}{{.UsageString}}{{end}}` |
| |
| cmdUsageTemplate = `Usage:{{if .HasAvailableSubCommands}} |
| {{.CommandPath}} <extension> [options]{{end}}{{if gt (len .Aliases) 0}} |
| |
| Aliases: |
| {{.NameAndAliases}}{{end}}{{if .HasExample}} |
| |
| Examples: |
| {{.Example}}{{end}}{{if .HasAvailableSubCommands}}{{$cmds := .Commands}}{{if eq (len .Groups) 0}} |
| |
| Available Extensions:{{range $cmds}}{{if (or .IsAvailableCommand (eq .Name "help"))}} |
| {{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}{{else}}{{range $group := .Groups}} |
| |
| {{.Title}}{{range $cmds}}{{if (and (eq .GroupID $group.ID) (or .IsAvailableCommand (eq .Name "help")))}} |
| {{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}{{end}}{{if not .AllChildCommandsHaveGroup}} |
| |
| Additional Commands:{{range $cmds}}{{if (and (eq .GroupID "") (or .IsAvailableCommand (eq .Name "help")))}} |
| {{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}{{end}}{{end}}{{end}}{{if .HasAvailableLocalFlags}} |
| |
| Flags: |
| {{.LocalFlags.FlagUsages | trimTrailingWhitespaces}}{{end}}{{if .HasAvailableInheritedFlags}} |
| |
| Global Flags: |
| {{.InheritedFlags.FlagUsages | trimTrailingWhitespaces}}{{end}}{{if .HasHelpSubCommands}} |
| |
| Additional help topics:{{range .Commands}}{{if .IsAdditionalHelpTopicCommand}} |
| {{rpad .CommandPath .CommandPathPadding}} {{.Short}}{{end}}{{end}}{{end}}{{if .HasAvailableSubCommands}} |
| |
| Use "{{.CommandPath}} <extension> --help" for more information about an extension.{{end}} |
| ` |
| ) |
| |
| var rootCmd = &cobra.Command{ |
| Use: "cos-extensions", |
| Long: "Utility to manage COS extensions.", |
| } |
| |
| var installCmd = &cobra.Command{ |
| Use: "install", |
| Short: "Installs a COS extension.", |
| } |
| |
| var listCmd = &cobra.Command{ |
| Use: "list", |
| Short: "Lists all available COS extensions and their versions.", |
| Run: func(cmd *cobra.Command, args []string) { |
| installers, err := gpu.GetCosInstaller(&http.Client{}) |
| if err != nil { |
| glog.Exitf("Failed to set gpu installer: %v", err) |
| } |
| err = gpu.List(installers, false, []string{}) |
| if err != nil { |
| glog.Exitf("Failed to run list command: %v", err) |
| } |
| }, |
| } |
| |
| func Execute() { |
| if err := rootCmd.Execute(); err != nil { |
| glog.Exitf("Failed to run cos-extensions: %v", err) |
| } |
| } |
| |
| func init() { |
| rootCmd.CompletionOptions.DisableDefaultCmd = true |
| rootCmd.AddCommand(installCmd) |
| rootCmd.SetHelpTemplate(rootHelpTemplate) |
| rootCmd.SetUsageTemplate(rootUsageTemplate) |
| rootCmd.AddCommand(listCmd) |
| |
| installCmd.SetUsageTemplate(cmdUsageTemplate) |
| installCmd.SetHelpTemplate(cmdHelpTemplate) |
| listCmd.SetUsageTemplate(cmdUsageTemplate) |
| listCmd.SetHelpTemplate(cmdHelpTemplate) |
| } |