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

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

View file

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