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')
* [ ] Confirm loading different components into `hms-smd`
* [ ] 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
inventories := [][]byte{}
// users := [][]byte{}
users := [][]byte{}
for _, ps := range probeStates {
if !ps.State {
continue
@ -65,17 +65,17 @@ var collectCmd = &cobra.Command{
inventories = append(inventories, inventory)
// users
// user, err := magellan.QueryUsers(client, &logger, &q)
// if err != nil {
// l.Errorf("could not query users: %v\n", err)
// }
user, err := magellan.QueryUsers(client, &logger, &q)
if err != nil {
l.Errorf("could not query users: %v\n", err)
}
users = append(users, user)
// // bios
// _, err = magellan.QueryBios(client, &logger, &q)
// if err != nil {
// l.Errorf("could not query bios: %v\n", err)
// }
// users = append(users, user)
_, err = magellan.QueryBios(client, &logger, &q)
if err != nil {
l.Errorf("could not query bios: %v\n", err)
}
}
// add all endpoints to smd

View file

@ -17,7 +17,9 @@ var listCmd = &cobra.Command{
if err != nil {
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

@ -17,8 +17,9 @@ var (
certPoolFile string
user string
pass string
dbpath string
dbpath string
drivers []string
ipmitoolPath string
)
// TODO: discover bmc's on network (dora)
@ -26,9 +27,9 @@ var (
// TODO: send bmc component information to smd
var rootCmd = &cobra.Command{
Use: "magellan",
Use: "magellan",
Short: "Tool for BMC discovery",
Long: "",
Long: "",
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
cmd.Help()
@ -37,14 +38,14 @@ var rootCmd = &cobra.Command{
},
}
func Execute(){
func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
func init(){
func init() {
rootCmd.PersistentFlags().StringVar(&user, "user", "", "set the BMC user")
rootCmd.PersistentFlags().StringVar(&pass, "pass", "", "set the BMC pass")
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().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(&ipmitoolPath, "ipmitool", "/usr/bin/ipmitool", "set the path for ipmitool")
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")
}
}

View file

@ -16,7 +16,7 @@ var (
var scanCmd = &cobra.Command{
Use: "scan",
Short: "Scan for BMCs",
Short: "Scan for BMC nodes on a network",
Run: func(cmd *cobra.Command, args []string) {
// set hosts to use for scanning
hostsToScan := []string{}
@ -49,7 +49,7 @@ var scanCmd = &cobra.Command{
func init() {
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().StringSliceVar(&subnets, "subnet", []string{"127.0.0.0"}, "set additional subnets")
scanCmd.Flags().StringSliceVar(&subnets, "subnet", []string{}, "set additional subnets")
rootCmd.AddCommand(scanCmd)
}

View file

@ -39,10 +39,12 @@ type QueryParams struct {
User string
Pass string
Drivers []string
Preferred string
Timeout int
WithSecureTLS bool
CertPoolFile string
Verbose bool
IpmitoolPath string
}
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.WithRedfishPort(fmt.Sprint(q.Port)),
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
@ -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 := ""
if q.WithSecureTLS {
url = "https://"
} else {
url = "http://"
}
// if q.WithSecureTLS {
// url = "https://"
// } else {
// url = "http://"
// }
if q.User != "" && q.Pass != "" {
if q.User == "" && q.Pass == "" {
url += fmt.Sprintf("%s:%s@%s", q.User, q.Pass, q.Host)
} else {
url += fmt.Sprintf("%s", q.Host)
url += q.Host
}
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) {
// 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
ctx, ctxCancel := context.WithTimeout(context.Background(), time.Second*time.Duration(q.Timeout))
client.Registry.FilterForCompatible(ctx)
err := client.Open(ctx)
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) {
// 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
ctx, ctxCancel := context.WithTimeout(context.Background(), time.Second*time.Duration(q.Timeout))
// client.Registry.FilterForCompatible(ctx)
err := client.Open(ctx)
client.Registry.FilterForCompatible(ctx)
err := client.PreferProvider(q.Preferred).Open(ctx)
if err != nil {
ctxCancel()
return nil, fmt.Errorf("could not open client: %v", err)