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
|
|
@ -1,31 +1,32 @@
|
|||
package dora
|
||||
|
||||
import (
|
||||
"davidallendj/magellan/internal/api"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/bikeshack/magellan/internal/api"
|
||||
|
||||
"github.com/jmoiron/sqlx"
|
||||
)
|
||||
|
||||
const (
|
||||
Host = "http://localhost"
|
||||
DbType = "sqlite3"
|
||||
DbPath = "../data/assets.db"
|
||||
Host = "http://localhost"
|
||||
DbType = "sqlite3"
|
||||
DbPath = "../data/assets.db"
|
||||
BaseEndpoint = "/v1"
|
||||
Port = 8000
|
||||
Port = 8000
|
||||
)
|
||||
|
||||
type ScannedResult struct {
|
||||
id string
|
||||
site any
|
||||
cidr string
|
||||
ip string
|
||||
port int
|
||||
id string
|
||||
site any
|
||||
cidr string
|
||||
ip string
|
||||
port int
|
||||
protocol string
|
||||
scanner string
|
||||
state string
|
||||
updated string
|
||||
scanner string
|
||||
state string
|
||||
updated string
|
||||
}
|
||||
|
||||
func makeEndpointUrl(endpoint string) string {
|
||||
|
|
@ -67,8 +68,8 @@ func LoadScannedPortsFromDB(dbPath string, dbType string) {
|
|||
for rows.Next() {
|
||||
var r ScannedResult
|
||||
rows.Scan(
|
||||
&r.id, &r.site, &r.cidr, &r.ip, &r.port, &r.protocol, &r.scanner,
|
||||
&r.id, &r.site, &r.cidr, &r.ip, &r.port, &r.protocol, &r.scanner,
|
||||
&r.state, &r.updated,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,18 +4,18 @@ package smd
|
|||
// https://github.com/Cray-HPE/hms-smd/blob/master/docs/examples.adoc
|
||||
// https://github.com/alexlovelltroy/hms-smd
|
||||
import (
|
||||
"davidallendj/magellan/internal/api"
|
||||
"fmt"
|
||||
|
||||
"github.com/bikeshack/magellan/internal/api"
|
||||
// hms "github.com/alexlovelltroy/hms-smd"
|
||||
)
|
||||
|
||||
var (
|
||||
Host = "http://localhost"
|
||||
Host = "http://localhost"
|
||||
BaseEndpoint = "/hsm/v2"
|
||||
Port = 27779
|
||||
Port = 27779
|
||||
)
|
||||
|
||||
|
||||
func makeEndpointUrl(endpoint string) string {
|
||||
return Host + ":" + fmt.Sprint(Port) + BaseEndpoint + endpoint
|
||||
}
|
||||
|
|
@ -49,7 +49,7 @@ func AddRedfishEndpoint(data []byte, headers map[string]string) error {
|
|||
|
||||
// var ep hms.RedfishEP
|
||||
// _ = ep
|
||||
// Add redfish endpoint via POST `/hsm/v2/Inventory/RedfishEndpoints` endpoint
|
||||
// Add redfish endpoint via POST `/hsm/v2/Inventory/RedfishEndpoints` endpoint
|
||||
url := makeEndpointUrl("/Inventory/RedfishEndpoints")
|
||||
res, body, _ := api.MakeRequest(url, "POST", data, headers)
|
||||
fmt.Println("smd url: ", url)
|
||||
|
|
@ -60,4 +60,4 @@ func AddRedfishEndpoint(data []byte, headers map[string]string) error {
|
|||
|
||||
func UpdateRedfishEndpoint() {
|
||||
// Update redfish endpoint via PUT `/hsm/v2/Inventory/RedfishEndpoints` endpoint
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package sqlite
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
magellan "davidallendj/magellan/internal"
|
||||
magellan "github.com/bikeshack/magellan/internal"
|
||||
|
||||
"github.com/jmoiron/sqlx"
|
||||
)
|
||||
|
|
@ -58,4 +58,4 @@ func GetProbeResults(path string) ([]magellan.BMCProbeResult, error) {
|
|||
return nil, fmt.Errorf("could not retrieve probes: %v", err)
|
||||
}
|
||||
return results, nil
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue