Minor changes and fixes

This commit is contained in:
David J. Allen 2023-08-30 14:43:13 -06:00
parent 488e6f8131
commit 118c12fa14
9 changed files with 40 additions and 38 deletions

View file

@ -55,3 +55,4 @@ List of things left to fix or do...
* [ ] Test using different `bmclib` supported drivers (mainly 'redfish') * [ ] Test using different `bmclib` supported drivers (mainly 'redfish')
* [ ] Confirm loading different components into `hms-smd` * [ ] Confirm loading different components into `hms-smd`
* [ ] Add unit tests * [ ] Add unit tests
* [ ] Code clean up and tidying

1
bin/collect.sh Normal file
View file

@ -0,0 +1 @@
./magellan collect --dbpath data/assets.db --driver ipmi --timeout 5

1
bin/list.sh Normal file
View file

@ -0,0 +1 @@
./magellan list --dbpath data/assets.db

1
bin/scan.sh Normal file
View file

@ -0,0 +1 @@
./magellan scan --subnet 172.16.0.0 --dbpath data/assets.db --driver ipmi --port 623

View file

@ -27,7 +27,7 @@ var collectCmd = &cobra.Command{
// use the found results to query bmc information // use the found results to query bmc information
inventories := [][]byte{} inventories := [][]byte{}
// users := [][]byte{} users := [][]byte{}
for _, ps := range probeStates { for _, ps := range probeStates {
if !ps.State { if !ps.State {
continue continue
@ -65,17 +65,17 @@ var collectCmd = &cobra.Command{
inventories = append(inventories, inventory) inventories = append(inventories, inventory)
// users // users
// user, err := magellan.QueryUsers(client, &logger, &q) user, err := magellan.QueryUsers(client, &logger, &q)
// if err != nil { if err != nil {
// l.Errorf("could not query users: %v\n", err) l.Errorf("could not query users: %v\n", err)
// } }
users = append(users, user)
// // bios // // bios
// _, err = magellan.QueryBios(client, &logger, &q) _, err = magellan.QueryBios(client, &logger, &q)
// if err != nil { if err != nil {
// l.Errorf("could not query bios: %v\n", err) l.Errorf("could not query bios: %v\n", err)
// } }
// users = append(users, user)
} }
// add all endpoints to smd // add all endpoints to smd

View file

@ -17,7 +17,9 @@ var listCmd = &cobra.Command{
if err != nil { if err != nil {
logrus.Errorf("could not get probe results: %v\n", err) logrus.Errorf("could not get probe results: %v\n", err)
} }
fmt.Printf("%v\n", probeResults) for _, r := range probeResults {
fmt.Printf("%s:%d (%s)\n", r.Host, r.Port, r.Protocol)
}
}, },
} }

View file

@ -19,6 +19,7 @@ var (
pass string pass string
dbpath string dbpath string
drivers []string drivers []string
ipmitoolPath string
) )
// TODO: discover bmc's on network (dora) // TODO: discover bmc's on network (dora)
@ -37,14 +38,14 @@ var rootCmd = &cobra.Command{
}, },
} }
func Execute(){ func Execute() {
if err := rootCmd.Execute(); err != nil { if err := rootCmd.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err) fmt.Fprintln(os.Stderr, err)
os.Exit(1) os.Exit(1)
} }
} }
func init(){ func init() {
rootCmd.PersistentFlags().StringVar(&user, "user", "", "set the BMC user") rootCmd.PersistentFlags().StringVar(&user, "user", "", "set the BMC user")
rootCmd.PersistentFlags().StringVar(&pass, "pass", "", "set the BMC pass") rootCmd.PersistentFlags().StringVar(&pass, "pass", "", "set the BMC pass")
rootCmd.PersistentFlags().StringSliceVar(&hosts, "host", []string{}, "set additional hosts") rootCmd.PersistentFlags().StringSliceVar(&hosts, "host", []string{}, "set additional hosts")
@ -54,6 +55,7 @@ func init(){
rootCmd.PersistentFlags().IntSliceVar(&ports, "port", []int{}, "set the ports to scan") rootCmd.PersistentFlags().IntSliceVar(&ports, "port", []int{}, "set the ports to scan")
rootCmd.PersistentFlags().StringSliceVar(&drivers, "driver", []string{"redfish"}, "set the BMC driver to use") rootCmd.PersistentFlags().StringSliceVar(&drivers, "driver", []string{"redfish"}, "set the BMC driver to use")
rootCmd.PersistentFlags().StringVar(&dbpath, "dbpath", ":memory:", "set the probe storage path") rootCmd.PersistentFlags().StringVar(&dbpath, "dbpath", ":memory:", "set the probe storage path")
rootCmd.PersistentFlags().StringVar(&ipmitoolPath, "ipmitool", "/usr/bin/ipmitool", "set the path for ipmitool")
rootCmd.PersistentFlags().BoolVar(&withSecureTLS, "secure-tls", false, "enable secure TLS") rootCmd.PersistentFlags().BoolVar(&withSecureTLS, "secure-tls", false, "enable secure TLS")
rootCmd.PersistentFlags().StringVar(&certPoolFile, "cert-pool", "", "path to an file containing x509 CAs. An empty string uses the system CAs. Only takes effect when --secure-tls=true") rootCmd.PersistentFlags().StringVar(&certPoolFile, "cert-pool", "", "path to an file containing x509 CAs. An empty string uses the system CAs. Only takes effect when --secure-tls=true")
} }

View file

@ -16,7 +16,7 @@ var (
var scanCmd = &cobra.Command{ var scanCmd = &cobra.Command{
Use: "scan", Use: "scan",
Short: "Scan for BMCs", Short: "Scan for BMC nodes on a network",
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
// set hosts to use for scanning // set hosts to use for scanning
hostsToScan := []string{} hostsToScan := []string{}
@ -49,7 +49,7 @@ var scanCmd = &cobra.Command{
func init() { func init() {
scanCmd.Flags().Uint8Var(&begin, "begin", 0, "set the starting point for range of IP addresses") scanCmd.Flags().Uint8Var(&begin, "begin", 0, "set the starting point for range of IP addresses")
scanCmd.Flags().Uint8Var(&end, "end", 255, "set the ending point for range of IP addresses") scanCmd.Flags().Uint8Var(&end, "end", 255, "set the ending point for range of IP addresses")
scanCmd.Flags().StringSliceVar(&subnets, "subnet", []string{"127.0.0.0"}, "set additional subnets") scanCmd.Flags().StringSliceVar(&subnets, "subnet", []string{}, "set additional subnets")
rootCmd.AddCommand(scanCmd) rootCmd.AddCommand(scanCmd)
} }

View file

@ -39,10 +39,12 @@ type QueryParams struct {
User string User string
Pass string Pass string
Drivers []string Drivers []string
Preferred string
Timeout int Timeout int
WithSecureTLS bool WithSecureTLS bool
CertPoolFile string CertPoolFile string
Verbose bool Verbose bool
IpmitoolPath string
} }
func rawConnect(host string, ports []int, timeout int, keepOpenOnly bool) []bmcProbeResult { func rawConnect(host string, ports []int, timeout int, keepOpenOnly bool) []bmcProbeResult {
@ -201,7 +203,8 @@ func NewClient(l *logr.Logger, q *QueryParams) (*bmclib.Client, error) {
// bmclib.WithRedfishHTTPClient(&httpClient), // bmclib.WithRedfishHTTPClient(&httpClient),
bmclib.WithRedfishPort(fmt.Sprint(q.Port)), bmclib.WithRedfishPort(fmt.Sprint(q.Port)),
bmclib.WithRedfishUseBasicAuth(true), bmclib.WithRedfishUseBasicAuth(true),
bmclib.WithIpmitoolPort(fmt.Sprint(q.Port)), bmclib.WithIpmitoolPort(fmt.Sprint(IPMI_PORT)),
bmclib.WithIpmitoolPath(q.IpmitoolPath),
} }
// only work if valid cert is provided // only work if valid cert is provided
@ -220,16 +223,16 @@ func NewClient(l *logr.Logger, q *QueryParams) (*bmclib.Client, error) {
} }
// url := fmt.Sprintf("https://%s:%s@%s", q.User, q.Pass, q.Host) // url := fmt.Sprintf("https://%s:%s@%s", q.User, q.Pass, q.Host)
url := "" url := ""
if q.WithSecureTLS { // if q.WithSecureTLS {
url = "https://" // url = "https://"
} else { // } else {
url = "http://" // url = "http://"
} // }
if q.User != "" && q.Pass != "" { if q.User == "" && q.Pass == "" {
url += fmt.Sprintf("%s:%s@%s", q.User, q.Pass, q.Host) url += fmt.Sprintf("%s:%s@%s", q.User, q.Pass, q.Host)
} else { } else {
url += fmt.Sprintf("%s", q.Host) url += q.Host
} }
client := bmclib.NewClient(url, q.User, q.Pass, clientOpts...) client := bmclib.NewClient(url, q.User, q.Pass, clientOpts...)
@ -244,13 +247,9 @@ func NewClient(l *logr.Logger, q *QueryParams) (*bmclib.Client, error) {
func QueryMetadata(client *bmclib.Client, l *logr.Logger, q *QueryParams) ([]byte, error) { func QueryMetadata(client *bmclib.Client, l *logr.Logger, q *QueryParams) ([]byte, error) {
// client, err := NewClient(l, q) // client, err := NewClient(l, q)
// if err != nil {
// return nil, fmt.Errorf("could not make query: %v", err)
// }
// open BMC session and update driver registry // open BMC session and update driver registry
ctx, ctxCancel := context.WithTimeout(context.Background(), time.Second*time.Duration(q.Timeout)) ctx, ctxCancel := context.WithTimeout(context.Background(), time.Second*time.Duration(q.Timeout))
client.Registry.FilterForCompatible(ctx) client.Registry.FilterForCompatible(ctx)
err := client.Open(ctx) err := client.Open(ctx)
if err != nil { if err != nil {
@ -282,16 +281,11 @@ func QueryMetadata(client *bmclib.Client, l *logr.Logger, q *QueryParams) ([]byt
func QueryInventory(client *bmclib.Client, l *logr.Logger, q *QueryParams) ([]byte, error) { func QueryInventory(client *bmclib.Client, l *logr.Logger, q *QueryParams) ([]byte, error) {
// discover.ScanAndConnect(url, user, pass, clientOpts) // discover.ScanAndConnect(url, user, pass, clientOpts)
// client, err := NewClient(l, q)
// if err != nil {
// return nil, fmt.Errorf("could not make query: %v", err)
// }
// open BMC session and update driver registry // open BMC session and update driver registry
ctx, ctxCancel := context.WithTimeout(context.Background(), time.Second*time.Duration(q.Timeout)) ctx, ctxCancel := context.WithTimeout(context.Background(), time.Second*time.Duration(q.Timeout))
client.Registry.FilterForCompatible(ctx)
// client.Registry.FilterForCompatible(ctx) err := client.PreferProvider(q.Preferred).Open(ctx)
err := client.Open(ctx)
if err != nil { if err != nil {
ctxCancel() ctxCancel()
return nil, fmt.Errorf("could not open client: %v", err) return nil, fmt.Errorf("could not open client: %v", err)