Merge branch 'main' into alt-releaser

This commit is contained in:
Alex Lovell-Troy 2023-09-14 17:11:18 -04:00 committed by GitHub
commit d649697859
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 41 additions and 40 deletions

View file

@ -28,7 +28,7 @@ In summary, `magellan` needs at minimum the following configured to work on each
Install Go, clone the repo, and then run the following in the project root: Install Go, clone the repo, and then run the following in the project root:
```bash ```bash
clone https://github.com/bikeshack/magellan git clone https://github.com/bikeshack/magellan
cd magellan cd magellan
go mod tidy && go build go mod tidy && go build
``` ```
@ -40,7 +40,7 @@ versions of Go may work, the project has only been tested with v1.20.
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 the port is not 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, 442 (redfish and IPMI) by default:
```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
@ -74,7 +74,7 @@ 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. Note: If the `db.path` flag is not set, `magellan` will use /tmp/magellan.db by default.
## TODO ## TODO

View file

@ -4,14 +4,14 @@ function build(){
} }
function scan() { function scan() {
./magellan scan --subnet 172.16.0.0 --db.path data/assets.db --port 443,623,5000 ./magellan scan --subnet 172.16.0.0 --port 443
} }
function list(){ function list(){
./magellan list --db.path data/assets.db ./magellan list
} }
function collect() { function collect() {
./magellan collect --db.path data/assets.db --driver redfish --timeout 30 --user admin --pass password ./magellan collect --user admin --pass password
} }

View file

@ -34,6 +34,7 @@ var collectCmd = &cobra.Command{
Threads: threads, Threads: threads,
Verbose: verbose, Verbose: verbose,
WithSecureTLS: withSecureTLS, WithSecureTLS: withSecureTLS,
} }
magellan.CollectInfo(&probeStates, l, q) magellan.CollectInfo(&probeStates, l, q)
@ -51,7 +52,6 @@ func init() {
collectCmd.PersistentFlags().IntVar(&smd.Port, "port", smd.Port, "set the port to the smd API") collectCmd.PersistentFlags().IntVar(&smd.Port, "port", smd.Port, "set the port to the smd API")
collectCmd.PersistentFlags().StringVar(&user, "user", "", "set the BMC user") collectCmd.PersistentFlags().StringVar(&user, "user", "", "set the BMC user")
collectCmd.PersistentFlags().StringVar(&pass, "pass", "", "set the BMC password") collectCmd.PersistentFlags().StringVar(&pass, "pass", "", "set the BMC password")
collectCmd.PersistentFlags().StringVar(&pass, "password", "", "set the BMC password")
collectCmd.PersistentFlags().StringVar(&preferredDriver, "preferred-driver", "ipmi", "set the preferred driver to use") 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().StringVar(&ipmitoolPath, "ipmitool.path", "/usr/bin/ipmitool", "set the path for ipmitool")
collectCmd.PersistentFlags().BoolVar(&withSecureTLS, "secure-tls", false, "enable secure TLS") collectCmd.PersistentFlags().BoolVar(&withSecureTLS, "secure-tls", false, "enable secure TLS")

View file

@ -49,7 +49,7 @@ func Execute() {
func init() { func init() {
rootCmd.PersistentFlags().IntVar(&threads, "threads", -1, "set the number of threads") rootCmd.PersistentFlags().IntVar(&threads, "threads", -1, "set the number of threads")
rootCmd.PersistentFlags().IntVar(&timeout, "timeout", 10, "set the timeout") rootCmd.PersistentFlags().IntVar(&timeout, "timeout", 30, "set the timeout")
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", true, "set verbose flag") rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", true, "set verbose flag")
rootCmd.PersistentFlags().StringVar(&dbpath, "db.path", "/tmp/magellan.db", "set the probe storage path") rootCmd.PersistentFlags().StringVar(&dbpath, "db.path", "/tmp/magellan.db", "set the probe storage path")
} }

View file

@ -2,9 +2,11 @@ package magellan
import ( import (
"context" "context"
"crypto/tls"
"crypto/x509" "crypto/x509"
"encoding/json" "encoding/json"
"fmt" "fmt"
"net/http"
"os" "os"
"sync" "sync"
"time" "time"
@ -15,7 +17,6 @@ import (
bmclib "github.com/bmc-toolbox/bmclib/v2" bmclib "github.com/bmc-toolbox/bmclib/v2"
"github.com/jacobweinstock/registrar" "github.com/jacobweinstock/registrar"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
"github.com/sirupsen/logrus"
"github.com/stmcginnis/gofish" "github.com/stmcginnis/gofish"
_ "github.com/stmcginnis/gofish" _ "github.com/stmcginnis/gofish"
"github.com/stmcginnis/gofish/redfish" "github.com/stmcginnis/gofish/redfish"
@ -26,7 +27,6 @@ const (
IPMI_PORT = 623 IPMI_PORT = 623
SSH_PORT = 22 SSH_PORT = 22
HTTPS_PORT = 443 HTTPS_PORT = 443
REDFISH_PORT = 5000
) )
type BMCProbeResult struct { type BMCProbeResult struct {
@ -56,20 +56,20 @@ func NewClient(l *Logger, q *QueryParams) (*bmclib.Client, error) {
// NOTE: bmclib.NewClient(host, port, user, pass) // NOTE: bmclib.NewClient(host, port, user, pass)
// ...seems like the `port` params doesn't work like expected depending on interface // ...seems like the `port` params doesn't work like expected depending on interface
// tr := &http.Transport{ tr := &http.Transport{
// TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
// } }
// httpClient := http.Client{ httpClient := http.Client{
// Transport: tr, Transport: tr,
// } }
// init client // init client
clientOpts := []bmclib.Option{ clientOpts := []bmclib.Option{
// bmclib.WithSecureTLS(nil), // bmclib.WithSecureTLS(nil),
// bmclib.WithHTTPClient(&httpClient), bmclib.WithHTTPClient(&httpClient),
// bmclib.WithLogger(), // bmclib.WithLogger(),
// bmclib.WithRedfishHTTPClient(&httpClient), bmclib.WithRedfishHTTPClient(&httpClient),
bmclib.WithDellRedfishUseBasicAuth(true), // bmclib.WithDellRedfishUseBasicAuth(true),
bmclib.WithRedfishPort(fmt.Sprint(q.Port)), bmclib.WithRedfishPort(fmt.Sprint(q.Port)),
bmclib.WithRedfishUseBasicAuth(true), bmclib.WithRedfishUseBasicAuth(true),
bmclib.WithIpmitoolPort(fmt.Sprint(IPMI_PORT)), bmclib.WithIpmitoolPort(fmt.Sprint(IPMI_PORT)),
@ -90,16 +90,9 @@ func NewClient(l *Logger, q *QueryParams) (*bmclib.Client, error) {
// a nil pool uses the system certs // a nil pool uses the system certs
clientOpts = append(clientOpts, bmclib.WithSecureTLS(pool)) clientOpts = append(clientOpts, bmclib.WithSecureTLS(pool))
} }
// url := fmt.Sprintf("https://%s:%s@%s", q.User, q.Pass, q.Host)
url := "" url := ""
// if q.WithSecureTLS { if q.User != "" && q.Pass != "" {
// url = "https://" url += fmt.Sprintf("https://%s:%s@%s", q.User, q.Pass, q.Host)
// } else {
// url = "http://"
// }
if q.User == "" && q.Pass == "" {
url += fmt.Sprintf("%s:%s@%s", q.User, q.Pass, q.Host)
} else { } else {
url += q.Host url += q.Host
} }
@ -147,9 +140,7 @@ func CollectInfo(probeStates *[]BMCProbeResult, l *Logger, q *QueryParams) error
} }
q.Host = ps.Host q.Host = ps.Host
q.Port = ps.Port q.Port = ps.Port
logrus.Printf("querying %v:%v (%v)\n", ps.Host, ps.Port, ps.Protocol)
client, err := NewClient(l, q) client, err := NewClient(l, q)
if err != nil { if err != nil {
l.Log.Errorf("could not make client: %v", err) l.Log.Errorf("could not make client: %v", err)
@ -190,6 +181,7 @@ func CollectInfo(probeStates *[]BMCProbeResult, l *Logger, q *QueryParams) error
data["Inventory"] = inventory data["Inventory"] = inventory
data["Chassis"] = chassis data["Chassis"] = chassis
b, err := json.MarshalIndent(data, "", " ") b, err := json.MarshalIndent(data, "", " ")
if err != nil { if err != nil {
l.Log.Errorf("could not marshal JSON: %v", err) l.Log.Errorf("could not marshal JSON: %v", err)
@ -199,6 +191,8 @@ func CollectInfo(probeStates *[]BMCProbeResult, l *Logger, q *QueryParams) error
err = smd.AddRedfishEndpoint(b, headers) err = smd.AddRedfishEndpoint(b, headers)
if err != nil { if err != nil {
l.Log.Errorf("could not add redfish endpoint: %v", err) l.Log.Errorf("could not add redfish endpoint: %v", err)
// try updating instead
} }
// users // users
@ -419,20 +413,27 @@ func QueryEthernetInterfaces(client *bmclib.Client, l *Logger, q *QueryParams) (
} }
func QueryChassis(q *QueryParams) ([]byte, error) { func QueryChassis(q *QueryParams) ([]byte, error) {
config := gofish.ClientConfig{
Endpoint: fmt.Sprintf("https://%s:%d", q.Host, q.Port), url := "https://"
Username: q.User, if q.User != "" && q.Pass != "" {
Password: q.Pass, url += fmt.Sprintf("%s:%s@", q.User, q.Pass)
Insecure: !q.WithSecureTLS, }
TLSHandshakeTimeout: q.Timeout, url += fmt.Sprintf("%s:%d", q.Host, q.Port)
config := gofish.ClientConfig {
Endpoint: url,
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) return nil, fmt.Errorf("could not connect to bmc (%v:%v): %v", q.Host, q.Port, err)
} }
chassis, err := c.Service.Chassis() chassis, err := c.Service.Chassis()
if err != nil { if err != nil {
return nil, fmt.Errorf("could not query chassis: %v", err) return nil, fmt.Errorf("could not query chassis (%v:%v): %v", q.Host, q.Port, err)
} }
b, err := json.MarshalIndent(chassis, "", " ") b, err := json.MarshalIndent(chassis, "", " ")

View file

@ -92,5 +92,5 @@ func ScanForAssets(hosts []string, ports []int, threads int, timeout int) []BMCP
} }
func GetDefaultPorts() []int { func GetDefaultPorts() []int {
return []int{SSH_PORT, HTTPS_PORT, IPMI_PORT, REDFISH_PORT} return []int{HTTPS_PORT, IPMI_PORT}
} }