mirror of
https://github.com/davidallendj/magellan.git
synced 2025-12-20 03:27:03 -07:00
inital release refactor
This commit is contained in:
parent
34367f830a
commit
3351de48a6
12 changed files with 215 additions and 84 deletions
|
|
@ -3,13 +3,14 @@ package magellan
|
|||
import (
|
||||
"context"
|
||||
"crypto/x509"
|
||||
"davidallendj/magellan/internal/api/smd"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/bikeshack/magellan/internal/api/smd"
|
||||
|
||||
"github.com/Cray-HPE/hms-xname/xnames"
|
||||
bmclib "github.com/bmc-toolbox/bmclib/v2"
|
||||
"github.com/jacobweinstock/registrar"
|
||||
|
|
@ -42,13 +43,13 @@ type QueryParams struct {
|
|||
User string
|
||||
Pass string
|
||||
Drivers []string
|
||||
Threads int
|
||||
Preferred string
|
||||
Threads int
|
||||
Preferred string
|
||||
Timeout int
|
||||
WithSecureTLS bool
|
||||
CertPoolFile string
|
||||
Verbose bool
|
||||
IpmitoolPath string
|
||||
IpmitoolPath string
|
||||
}
|
||||
|
||||
func NewClient(l *Logger, q *QueryParams) (*bmclib.Client, error) {
|
||||
|
|
@ -120,18 +121,18 @@ func CollectInfo(probeStates *[]BMCProbeResult, l *Logger, q *QueryParams) error
|
|||
if len(*probeStates) <= 0 {
|
||||
return fmt.Errorf("no probe states found")
|
||||
}
|
||||
|
||||
|
||||
// generate custom xnames for bmcs
|
||||
node := xnames.Node{
|
||||
Cabinet: 1000,
|
||||
Chassis: 1,
|
||||
ComputeModule: 7,
|
||||
NodeBMC: -1,
|
||||
Cabinet: 1000,
|
||||
Chassis: 1,
|
||||
ComputeModule: 7,
|
||||
NodeBMC: -1,
|
||||
}
|
||||
|
||||
found := make([]string, 0, len(*probeStates))
|
||||
done := make(chan struct{}, q.Threads+1)
|
||||
chanProbeState := make(chan BMCProbeResult, q.Threads+1)
|
||||
found := make([]string, 0, len(*probeStates))
|
||||
done := make(chan struct{}, q.Threads+1)
|
||||
chanProbeState := make(chan BMCProbeResult, q.Threads+1)
|
||||
|
||||
// collect bmc information asynchronously
|
||||
var wg sync.WaitGroup
|
||||
|
|
@ -139,7 +140,7 @@ func CollectInfo(probeStates *[]BMCProbeResult, l *Logger, q *QueryParams) error
|
|||
for i := 0; i < q.Threads; i++ {
|
||||
go func() {
|
||||
for {
|
||||
ps, ok := <- chanProbeState
|
||||
ps, ok := <-chanProbeState
|
||||
if !ok {
|
||||
wg.Done()
|
||||
return
|
||||
|
|
@ -152,7 +153,7 @@ func CollectInfo(probeStates *[]BMCProbeResult, l *Logger, q *QueryParams) error
|
|||
client, err := NewClient(l, q)
|
||||
if err != nil {
|
||||
l.Log.Errorf("could not make client: %v", err)
|
||||
continue
|
||||
continue
|
||||
}
|
||||
|
||||
// metadata
|
||||
|
|
@ -164,7 +165,7 @@ func CollectInfo(probeStates *[]BMCProbeResult, l *Logger, q *QueryParams) error
|
|||
// inventories
|
||||
inventory, err := QueryInventory(client, l, q)
|
||||
if err != nil {
|
||||
l.Log.Errorf("could not query inventory: %v", err)
|
||||
l.Log.Errorf("could not query inventory: %v", err)
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
@ -181,13 +182,13 @@ func CollectInfo(probeStates *[]BMCProbeResult, l *Logger, q *QueryParams) error
|
|||
headers["Content-Type"] = "application/json"
|
||||
|
||||
data := make(map[string]any)
|
||||
data["ID"] = fmt.Sprintf("%v", node.String()[:len(node.String())-2])
|
||||
data["Type"] = ""
|
||||
data["Name"] = ""
|
||||
data["FQDN"] = ps.Host
|
||||
data["RediscoverOnUpdate"] = false
|
||||
data["Inventory"] = inventory
|
||||
data["Chassis"] = chassis
|
||||
data["ID"] = fmt.Sprintf("%v", node.String()[:len(node.String())-2])
|
||||
data["Type"] = ""
|
||||
data["Name"] = ""
|
||||
data["FQDN"] = ps.Host
|
||||
data["RediscoverOnUpdate"] = false
|
||||
data["Inventory"] = inventory
|
||||
data["Chassis"] = chassis
|
||||
|
||||
b, err := json.MarshalIndent(data, "", " ")
|
||||
if err != nil {
|
||||
|
|
@ -228,7 +229,7 @@ func CollectInfo(probeStates *[]BMCProbeResult, l *Logger, q *QueryParams) error
|
|||
for _, ps := range *probeStates {
|
||||
// skip if found info from host
|
||||
foundHost := slices.Index(found, ps.Host)
|
||||
if !ps.State || foundHost >= 0{
|
||||
if !ps.State || foundHost >= 0 {
|
||||
continue
|
||||
}
|
||||
chanProbeState <- ps
|
||||
|
|
@ -394,11 +395,11 @@ 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,
|
||||
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 {
|
||||
|
|
@ -418,12 +419,12 @@ 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,
|
||||
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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue