diff --git a/cmd/collect.go b/cmd/collect.go index bcefa56..7c26c32 100644 --- a/cmd/collect.go +++ b/cmd/collect.go @@ -2,6 +2,7 @@ package cmd import ( "fmt" + "os/user" magellan "github.com/OpenCHAMI/magellan/internal" "github.com/OpenCHAMI/magellan/internal/api/smd" @@ -44,17 +45,15 @@ var collectCmd = &cobra.Command{ } // - if threads <= 0 { - threads = mathutil.Clamp(len(probeStates), 1, 255) + if concurrency <= 0 { + concurrency = mathutil.Clamp(len(probeStates), 1, 255) } q := &magellan.QueryParams{ User: username, Pass: password, Protocol: protocol, - Drivers: drivers, - Preferred: preferredDriver, Timeout: timeout, - Threads: threads, + Concurrency: concurrency, Verbose: verbose, CaCertPath: cacertPath, OutputPath: outputPath, @@ -72,16 +71,14 @@ var collectCmd = &cobra.Command{ } func init() { - collectCmd.PersistentFlags().StringSliceVar(&drivers, "driver", []string{"redfish"}, "set the driver(s) and fallback drivers to use") - collectCmd.PersistentFlags().StringVar(&smd.Host, "host", smd.Host, "set the host to the smd API") - collectCmd.PersistentFlags().IntVarP(&smd.Port, "port", "p", smd.Port, "set the port to the smd API") + currentUser, _ = user.Current() + collectCmd.PersistentFlags().StringVar(&smd.Host, "host", smd.Host, "set the host to the SMD API") + collectCmd.PersistentFlags().IntVarP(&smd.Port, "port", "p", smd.Port, "set the port to the SMD API") collectCmd.PersistentFlags().StringVar(&username, "user", "", "set the BMC user") collectCmd.PersistentFlags().StringVar(&password, "pass", "", "set the BMC password") collectCmd.PersistentFlags().StringVar(&protocol, "protocol", "https", "set the protocol used to query") - collectCmd.PersistentFlags().StringVarP(&outputPath, "output", "o", "/tmp/magellan/data/", "set the path to store collection data") - collectCmd.PersistentFlags().BoolVar(&forceUpdate, "force-update", false, "set flag to force update data sent to SMD ") - collectCmd.PersistentFlags().StringVar(&preferredDriver, "preferred-driver", "ipmi", "set the preferred driver to use") - collectCmd.PersistentFlags().StringVar(&ipmitoolPath, "ipmitool.path", "/usr/bin/ipmitool", "set the path for ipmitool") + collectCmd.PersistentFlags().StringVarP(&outputPath, "output", "o", fmt.Sprintf("/tmp/%smagellan/data/", currentUser.Username), "set the path to store collection data") + collectCmd.PersistentFlags().BoolVar(&forceUpdate, "force-update", false, "set flag to force update data sent to SMD") collectCmd.PersistentFlags().StringVar(&cacertPath, "ca-cert", "", "path to CA cert. (defaults to system CAs)") viper.BindPFlag("collect.driver", collectCmd.Flags().Lookup("driver")) @@ -92,10 +89,8 @@ func init() { viper.BindPFlag("collect.protocol", collectCmd.Flags().Lookup("protocol")) viper.BindPFlag("collect.output", collectCmd.Flags().Lookup("output")) viper.BindPFlag("collect.force-update", collectCmd.Flags().Lookup("force-update")) - viper.BindPFlag("collect.preferred-driver", collectCmd.Flags().Lookup("preferred-driver")) - viper.BindPFlag("collect.ipmitool.path", collectCmd.Flags().Lookup("ipmitool.path")) - viper.BindPFlag("collect.secure-tls", collectCmd.Flags().Lookup("secure-tls")) - viper.BindPFlag("collect.cert-pool", collectCmd.Flags().Lookup("cert-pool")) + viper.BindPFlag("collect.ca-cert", collectCmd.Flags().Lookup("secure-tls")) + viper.BindPFlags(collectCmd.Flags()) rootCmd.AddCommand(collectCmd) } diff --git a/cmd/root.go b/cmd/root.go index cccc69a..41b0d20 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -13,22 +13,20 @@ import ( ) var ( - accessToken string - timeout int - threads int - ports []int - hosts []string - protocol string - cacertPath string - username string - password string - dbpath string - drivers []string - preferredDriver string - ipmitoolPath string - outputPath string - configPath string - verbose bool + currentUser *user.User + accessToken string + timeout int + concurrency int + ports []int + hosts []string + protocol string + cacertPath string + username string + password string + dbpath string + outputPath string + configPath string + verbose bool ) // TODO: discover bmc's on network (dora) @@ -77,28 +75,26 @@ func LoadAccessToken() (string, error) { } func init() { - // get the current user - currentUser, _ := user.Current() + currentUser, _ = user.Current() cobra.OnInitialize(InitializeConfig) - rootCmd.PersistentFlags().IntVar(&threads, "threads", -1, "set the number of threads") + rootCmd.PersistentFlags().IntVar(&concurrency, "concurrency", -1, "set the number of concurrent processes") rootCmd.PersistentFlags().IntVar(&timeout, "timeout", 30, "set the timeout") rootCmd.PersistentFlags().StringVarP(&configPath, "config", "c", "", "set the config file path") - rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "set verbose flag") + rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "set output verbosity") rootCmd.PersistentFlags().StringVar(&accessToken, "access-token", "", "set the access token") - rootCmd.PersistentFlags().StringVar(&dbpath, "db.path", fmt.Sprintf("/tmp/%smagellan/magellan.db", currentUser.Name+"/"), "set the probe storage path") + rootCmd.PersistentFlags().StringVar(&dbpath, "db.path", fmt.Sprintf("/tmp/%smagellan/magellan.db", currentUser.Username+"/"), "set the probe storage path") // bind viper config flags with cobra - viper.BindPFlag("threads", rootCmd.Flags().Lookup("threads")) + viper.BindPFlag("concurrency", rootCmd.Flags().Lookup("concurrency")) viper.BindPFlag("timeout", rootCmd.Flags().Lookup("timeout")) viper.BindPFlag("verbose", rootCmd.Flags().Lookup("verbose")) viper.BindPFlag("db.path", rootCmd.Flags().Lookup("db.path")) - // viper.BindPFlags(rootCmd.Flags()) + viper.BindPFlags(rootCmd.Flags()) } func InitializeConfig() { if configPath != "" { magellan.LoadConfig(configPath) - fmt.Printf("subnets: %v\n", viper.Get("scan.subnets")) } } diff --git a/cmd/scan.go b/cmd/scan.go index 50534a2..e114749 100644 --- a/cmd/scan.go +++ b/cmd/scan.go @@ -54,10 +54,10 @@ var scanCmd = &cobra.Command{ } // scan and store probe data in dbPath - if threads <= 0 { - threads = mathutil.Clamp(len(hostsToScan), 1, 255) + if concurrency <= 0 { + concurrency = mathutil.Clamp(len(hostsToScan), 1, 255) } - probeStates := magellan.ScanForAssets(hostsToScan, portsToScan, threads, timeout, disableProbing, verbose) + probeStates := magellan.ScanForAssets(hostsToScan, portsToScan, concurrency, timeout, disableProbing, verbose) if verbose { for _, r := range probeStates { fmt.Printf("%s:%d (%s)\n", r.Host, r.Port, r.Protocol)