diff --git a/README.md b/README.md index 48c028c..beb27a3 100644 --- a/README.md +++ b/README.md @@ -39,17 +39,17 @@ versions of Go may work, the project has only been tested with v1.20. ## Usage 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`: ```bash ./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 -be set such as `host` to add additional hosts to scan, `timeout` to set how long -to wait for a responds from the BMC node, or `threads` to set the number of requests +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 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 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` to find the `hms-smd` API. +Note: If `db.path` is not set, `magellan` will use /tmp/magellan.db by default. + ## TODO List of things left to fix, do, or ideas... diff --git a/cmd/collect.go b/cmd/collect.go index c528057..185aa14 100644 --- a/cmd/collect.go +++ b/cmd/collect.go @@ -37,6 +37,12 @@ var collectCmd = &cobra.Command{ WithSecureTLS: withSecureTLS, } 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) + } }, } diff --git a/internal/api/dora/dora.go b/internal/api/dora/dora.go index eba8548..b3f2dbd 100644 --- a/internal/api/dora/dora.go +++ b/internal/api/dora/dora.go @@ -1,7 +1,7 @@ package dora import ( - "davidallendj/magellan/api" + "davidallendj/magellan/internal/api" "encoding/json" "fmt" diff --git a/internal/collect.go b/internal/collect.go index 23427f3..896bd28 100644 --- a/internal/collect.go +++ b/internal/collect.go @@ -113,6 +113,7 @@ func NewClient(l *Logger, q *QueryParams) (*bmclib.Client, error) { } func CollectInfo(probeStates *[]BMCProbeResult, l *Logger, q *QueryParams) error { + // check for available probe states if probeStates == nil { 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) chanProbeState := make(chan BMCProbeResult, q.Threads+1) - // + // collect bmc information asynchronously var wg sync.WaitGroup wg.Add(q.Threads) 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) } - // confirm the inventories were added - err = smd.GetRedfishEndpoints() - if err != nil { - l.Log.Errorf("could not get redfish endpoints: %v", err) - } - // users // user, err := magellan.QueryUsers(client, l, &q) // if err != nil { @@ -239,6 +234,7 @@ func CollectInfo(probeStates *[]BMCProbeResult, l *Logger, q *QueryParams) error chanProbeState <- ps } + // handle goroutine paths go func() { select { 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) { - // discover.ScanAndConnect(url, user, pass, clientOpts) - // open BMC session and update driver registry ctx, ctxCancel := context.WithTimeout(context.Background(), time.Second*time.Duration(q.Timeout)) 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) { - // 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) @@ -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) { 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) if err != nil { - + return nil, fmt.Errorf("could not connect to bmc: %v", err) } - redfish.ListReferencedEthernetInterfaces(c, "") - return []byte{}, nil + interfaces, err := redfish.ListReferencedEthernetInterfaces(c, "") + 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) { @@ -423,7 +423,7 @@ func QueryChassis(q *QueryParams) ([]byte, error) { Username: q.User, Password: q.Pass, Insecure: !q.WithSecureTLS, - TLSHandshakeTimeout: 30, + TLSHandshakeTimeout: q.Timeout, } c, err := gofish.Connect(config) if err != nil {