Minor tweaks and updated README.md

This commit is contained in:
David Allen 2023-09-14 09:44:12 -06:00
parent 4de7803167
commit 34367f830a
4 changed files with 33 additions and 25 deletions

View file

@ -39,17 +39,17 @@ versions of Go may work, the project has only been tested with v1.20.
## Usage ## Usage
There are three main commands to use with the tool: `scan`, `list`, and `collect`. There are three main commands to use with the tool: `scan`, `list`, and `collect`.
To scan a network for BMC nodes, use the `scan` command. If not port is specified, To scan a network for BMC nodes, use the `scan` command. If the port is not specified,
`magellan` will probe ports 623, 22, 442, and 5000 by default similar to `dora`: `magellan` will probe ports 623, 22, 442, and 5000 by default similar to `dora`:
```bash ```bash
./magellan scan --subnet 192.168.0.0 --db.path data/assets.db --port 623 ./magellan scan --subnet 192.168.0.0 --db.path data/assets.db --port 623
``` ```
This with scan the `192.168.0.0` network returning the found nodes for port 623 This will scan the `192.168.0.0` subnet returning the host and port that return a response
and store the results in database with path `data/assets.db`. Additional flags can and store the results in database with path `data/assets.db`. Additional flags can
be set such as `host` to add additional hosts to scan, `timeout` to set how long be set such as `host` to add more hosts to scan not included on the subnet, `timeout` to set how long
to wait for a responds from the BMC node, or `threads` to set the number of requests to wait for a response from the BMC node, or `threads` to set the number of requests
to make concurrently. Try using `./magellan help scan` for a complete set of options. to make concurrently. Try using `./magellan help scan` for a complete set of options.
To see the available BMC nodes found from the scan, use the `list` command. Make To see the available BMC nodes found from the scan, use the `list` command. Make
@ -74,6 +74,8 @@ and `pass/password` flag to be set to use `ipmitool` (which must installed as we
Additionally, it may be necessary to set the `host` and `port` flags for `magellan` Additionally, it may be necessary to set the `host` and `port` flags for `magellan`
to find the `hms-smd` API. to find the `hms-smd` API.
Note: If `db.path` is not set, `magellan` will use /tmp/magellan.db by default.
## TODO ## TODO
List of things left to fix, do, or ideas... List of things left to fix, do, or ideas...

View file

@ -37,6 +37,12 @@ var collectCmd = &cobra.Command{
WithSecureTLS: withSecureTLS, WithSecureTLS: withSecureTLS,
} }
magellan.CollectInfo(&probeStates, l, q) magellan.CollectInfo(&probeStates, l, q)
// confirm the inventories were added
err = smd.GetRedfishEndpoints()
if err != nil {
l.Log.Errorf("could not get redfish endpoints: %v", err)
}
}, },
} }

View file

@ -1,7 +1,7 @@
package dora package dora
import ( import (
"davidallendj/magellan/api" "davidallendj/magellan/internal/api"
"encoding/json" "encoding/json"
"fmt" "fmt"

View file

@ -113,6 +113,7 @@ func NewClient(l *Logger, q *QueryParams) (*bmclib.Client, error) {
} }
func CollectInfo(probeStates *[]BMCProbeResult, l *Logger, q *QueryParams) error { func CollectInfo(probeStates *[]BMCProbeResult, l *Logger, q *QueryParams) error {
// check for available probe states
if probeStates == nil { if probeStates == nil {
return fmt.Errorf("no probe states found") return fmt.Errorf("no probe states found")
} }
@ -132,7 +133,7 @@ func CollectInfo(probeStates *[]BMCProbeResult, l *Logger, q *QueryParams) error
done := make(chan struct{}, q.Threads+1) done := make(chan struct{}, q.Threads+1)
chanProbeState := make(chan BMCProbeResult, q.Threads+1) chanProbeState := make(chan BMCProbeResult, q.Threads+1)
// // collect bmc information asynchronously
var wg sync.WaitGroup var wg sync.WaitGroup
wg.Add(q.Threads) wg.Add(q.Threads)
for i := 0; i < q.Threads; i++ { for i := 0; i < q.Threads; i++ {
@ -199,12 +200,6 @@ func CollectInfo(probeStates *[]BMCProbeResult, l *Logger, q *QueryParams) error
l.Log.Errorf("could not add redfish endpoint: %v", err) l.Log.Errorf("could not add redfish endpoint: %v", err)
} }
// confirm the inventories were added
err = smd.GetRedfishEndpoints()
if err != nil {
l.Log.Errorf("could not get redfish endpoints: %v", err)
}
// users // users
// user, err := magellan.QueryUsers(client, l, &q) // user, err := magellan.QueryUsers(client, l, &q)
// if err != nil { // if err != nil {
@ -239,6 +234,7 @@ func CollectInfo(probeStates *[]BMCProbeResult, l *Logger, q *QueryParams) error
chanProbeState <- ps chanProbeState <- ps
} }
// handle goroutine paths
go func() { go func() {
select { select {
case <-done: case <-done:
@ -290,8 +286,6 @@ func QueryMetadata(client *bmclib.Client, l *Logger, q *QueryParams) ([]byte, er
} }
func QueryInventory(client *bmclib.Client, l *Logger, q *QueryParams) ([]byte, error) { func QueryInventory(client *bmclib.Client, l *Logger, q *QueryParams) ([]byte, error) {
// discover.ScanAndConnect(url, user, pass, clientOpts)
// 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)
@ -354,12 +348,6 @@ func QueryPowerState(client *bmclib.Client, l *Logger, q *QueryParams) ([]byte,
} }
func QueryUsers(client *bmclib.Client, l *Logger, q *QueryParams) ([]byte, error) { func QueryUsers(client *bmclib.Client, l *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 // 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)
@ -406,15 +394,27 @@ func QueryBios(client *bmclib.Client, l *Logger, q *QueryParams) ([]byte, error)
func QueryEthernetInterfaces(client *bmclib.Client, l *Logger, q *QueryParams) ([]byte, error) { func QueryEthernetInterfaces(client *bmclib.Client, l *Logger, q *QueryParams) ([]byte, error) {
config := gofish.ClientConfig{ config := gofish.ClientConfig{
Endpoint: fmt.Sprintf("https://%s:%d", q.Host, q.Port),
Username: q.User,
Password: q.Pass,
Insecure: !q.WithSecureTLS,
TLSHandshakeTimeout: q.Timeout,
} }
c, err := gofish.Connect(config) c, err := gofish.Connect(config)
if err != nil { if err != nil {
return nil, fmt.Errorf("could not connect to bmc: %v", err)
} }
redfish.ListReferencedEthernetInterfaces(c, "") interfaces, err := redfish.ListReferencedEthernetInterfaces(c, "")
return []byte{}, nil if err != nil {
return nil, fmt.Errorf("could not get ethernet interfaces: %v", err)
}
b, err := json.MarshalIndent(interfaces, "", " ")
if err != nil {
return nil, fmt.Errorf("could not marshal JSON: %v", err)
}
return b, nil
} }
func QueryChassis(q *QueryParams) ([]byte, error) { func QueryChassis(q *QueryParams) ([]byte, error) {
@ -423,7 +423,7 @@ func QueryChassis(q *QueryParams) ([]byte, error) {
Username: q.User, Username: q.User,
Password: q.Pass, Password: q.Pass,
Insecure: !q.WithSecureTLS, Insecure: !q.WithSecureTLS,
TLSHandshakeTimeout: 30, TLSHandshakeTimeout: q.Timeout,
} }
c, err := gofish.Connect(config) c, err := gofish.Connect(config)
if err != nil { if err != nil {