mirror of
https://github.com/davidallendj/magellan.git
synced 2025-12-20 03:27:03 -07:00
Fixed invalid xnames
Signed-off-by: David J. Allen <davidallendj@gmail.com>
This commit is contained in:
parent
63a8e2a058
commit
4de7803167
2 changed files with 32 additions and 137 deletions
148
cmd/collect.go
148
cmd/collect.go
|
|
@ -15,136 +15,28 @@ var collectCmd = &cobra.Command{
|
||||||
Use: "collect",
|
Use: "collect",
|
||||||
Short: "Query information about BMC",
|
Short: "Query information about BMC",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
// make application logger
|
||||||
// make application logger
|
l := magellan.NewLogger(logrus.New(), logrus.DebugLevel)
|
||||||
l := magellan.NewLogger(logrus.New(), logrus.DebugLevel)
|
|
||||||
|
|
||||||
// get probe states stored in db from scan
|
// get probe states stored in db from scan
|
||||||
probeStates, err := sqlite.GetProbeResults(dbpath)
|
probeStates, err := sqlite.GetProbeResults(dbpath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.Log.Errorf("could not get states: %v", err)
|
l.Log.Errorf("could not get states: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if threads <= 0 {
|
if threads <= 0 {
|
||||||
threads = mathutil.Clamp(len(probeStates), 1, 255)
|
threads = mathutil.Clamp(len(probeStates), 1, 255)
|
||||||
}
|
}
|
||||||
q := &magellan.QueryParams{
|
q := &magellan.QueryParams{
|
||||||
User: user,
|
User: user,
|
||||||
Pass: pass,
|
Pass: pass,
|
||||||
Drivers: drivers,
|
Drivers: drivers,
|
||||||
Timeout: timeout,
|
Timeout: timeout,
|
||||||
Threads: threads,
|
Threads: threads,
|
||||||
Verbose: verbose,
|
Verbose: verbose,
|
||||||
WithSecureTLS: withSecureTLS,
|
WithSecureTLS: withSecureTLS,
|
||||||
}
|
}
|
||||||
magellan.CollectInfo(&probeStates, l, q)
|
magellan.CollectInfo(&probeStates, l, q)
|
||||||
|
|
||||||
// generate custom xnames for bmcs
|
|
||||||
// node := xnames.Node{
|
|
||||||
// Cabinet: 1000,
|
|
||||||
// Chassis: 1,
|
|
||||||
// ComputeModule: 7,
|
|
||||||
// NodeBMC: 1,
|
|
||||||
// Node: 0,
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // use the found results to query bmc information
|
|
||||||
// // users := [][]byte{}
|
|
||||||
// probedHosts := []string{}
|
|
||||||
// for _, ps := range probeStates {
|
|
||||||
|
|
||||||
// // skip if found info from host
|
|
||||||
// foundHost := slices.Index(probedHosts, ps.Host)
|
|
||||||
// if !ps.State || foundHost >= 0{
|
|
||||||
// continue
|
|
||||||
// }
|
|
||||||
|
|
||||||
// logrus.Printf("querying %v:%v (%v)\n", ps.Host, ps.Port, ps.Protocol)
|
|
||||||
|
|
||||||
|
|
||||||
// client, err := magellan.NewClient(l, q)
|
|
||||||
// if err != nil {
|
|
||||||
// l.Log.Errorf("could not make client: %v", err)
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // metadata
|
|
||||||
// // _, err = magellan.QueryMetadata(client, l, &q)
|
|
||||||
// // if err != nil {
|
|
||||||
// // l.Log.Errorf("could not query metadata: %v\n", err)
|
|
||||||
// // }
|
|
||||||
|
|
||||||
// // inventories
|
|
||||||
// inventory, err := magellan.QueryInventory(client, l, q)
|
|
||||||
// if err != nil {
|
|
||||||
// l.Log.Errorf("could not query inventory: %v\n", err)
|
|
||||||
// continue
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // chassis
|
|
||||||
// _, err = magellan.QueryChassis(client, l, q)
|
|
||||||
// if err != nil {
|
|
||||||
// l.Log.Errorf("could not query chassis: %v\n", err)
|
|
||||||
// continue
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // got host information, so add to list of already probed hosts
|
|
||||||
// probedHosts = append(probedHosts, ps.Host)
|
|
||||||
|
|
||||||
// node.NodeBMC += 1
|
|
||||||
|
|
||||||
// headers := make(map[string]string)
|
|
||||||
// headers["Content-Type"] = "application/json"
|
|
||||||
|
|
||||||
// data := make(map[string]any)
|
|
||||||
// data["ID"] = fmt.Sprintf("%v", node)
|
|
||||||
// data["Type"] = ""
|
|
||||||
// data["Name"] = ""
|
|
||||||
// data["FQDN"] = ps.Host
|
|
||||||
// data["RediscoverOnUpdate"] = false
|
|
||||||
// data["Inventory"] = inventory
|
|
||||||
|
|
||||||
|
|
||||||
// b, err := json.MarshalIndent(data, "", " ")
|
|
||||||
// if err != nil {
|
|
||||||
// l.Log.Errorf("could not marshal JSON: %v\n", err)
|
|
||||||
// continue
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // add all endpoints to smd
|
|
||||||
// err = smd.AddRedfishEndpoint(b, headers)
|
|
||||||
// if err != nil {
|
|
||||||
// logrus.Errorf("could not add redfish endpoint: %v", err)
|
|
||||||
// continue
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // confirm the inventories were added
|
|
||||||
// err = smd.GetRedfishEndpoints()
|
|
||||||
// if err != nil {
|
|
||||||
// logrus.Errorf("could not get redfish endpoints: %v\n", err)
|
|
||||||
// continue
|
|
||||||
// }
|
|
||||||
|
|
||||||
// users
|
|
||||||
// user, err := magellan.QueryUsers(client, l, &q)
|
|
||||||
// if err != nil {
|
|
||||||
// l.Log.Errorf("could not query users: %v\n", err)
|
|
||||||
// }
|
|
||||||
// users = append(users, user)
|
|
||||||
|
|
||||||
// // bios
|
|
||||||
// _, err = magellan.QueryBios(client, l, &q)
|
|
||||||
// if err != nil {
|
|
||||||
// l.Log.Errorf("could not query bios: %v\n", err)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// _, err = magellan.QueryPowerState(client, l, &q)
|
|
||||||
// if err != nil {
|
|
||||||
// l.Log.Errorf("could not query power state: %v\n", err)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// }
|
|
||||||
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -125,8 +125,7 @@ func CollectInfo(probeStates *[]BMCProbeResult, l *Logger, q *QueryParams) error
|
||||||
Cabinet: 1000,
|
Cabinet: 1000,
|
||||||
Chassis: 1,
|
Chassis: 1,
|
||||||
ComputeModule: 7,
|
ComputeModule: 7,
|
||||||
NodeBMC: 1,
|
NodeBMC: -1,
|
||||||
Node: 0,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
found := make([]string, 0, len(*probeStates))
|
found := make([]string, 0, len(*probeStates))
|
||||||
|
|
@ -165,12 +164,14 @@ func CollectInfo(probeStates *[]BMCProbeResult, l *Logger, q *QueryParams) error
|
||||||
inventory, err := QueryInventory(client, l, q)
|
inventory, err := QueryInventory(client, l, q)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.Log.Errorf("could not query inventory: %v", err)
|
l.Log.Errorf("could not query inventory: %v", err)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// chassis
|
// chassis
|
||||||
_, err = QueryChassis(client, l, q)
|
chassis, err := QueryChassis(q)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.Log.Errorf("could not query chassis: %v", err)
|
l.Log.Errorf("could not query chassis: %v", err)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
node.NodeBMC += 1
|
node.NodeBMC += 1
|
||||||
|
|
@ -179,12 +180,13 @@ func CollectInfo(probeStates *[]BMCProbeResult, l *Logger, q *QueryParams) error
|
||||||
headers["Content-Type"] = "application/json"
|
headers["Content-Type"] = "application/json"
|
||||||
|
|
||||||
data := make(map[string]any)
|
data := make(map[string]any)
|
||||||
data["ID"] = fmt.Sprintf("%v", node)
|
data["ID"] = fmt.Sprintf("%v", node.String()[:len(node.String())-2])
|
||||||
data["Type"] = ""
|
data["Type"] = ""
|
||||||
data["Name"] = ""
|
data["Name"] = ""
|
||||||
data["FQDN"] = ps.Host
|
data["FQDN"] = ps.Host
|
||||||
data["RediscoverOnUpdate"] = false
|
data["RediscoverOnUpdate"] = false
|
||||||
data["Inventory"] = inventory
|
data["Inventory"] = inventory
|
||||||
|
data["Chassis"] = chassis
|
||||||
|
|
||||||
b, err := json.MarshalIndent(data, "", " ")
|
b, err := json.MarshalIndent(data, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -415,12 +417,13 @@ func QueryEthernetInterfaces(client *bmclib.Client, l *Logger, q *QueryParams) (
|
||||||
return []byte{}, nil
|
return []byte{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func QueryChassis(client *bmclib.Client, l *Logger, q *QueryParams) ([]byte, error) {
|
func QueryChassis(q *QueryParams) ([]byte, error) {
|
||||||
config := gofish.ClientConfig {
|
config := gofish.ClientConfig {
|
||||||
Endpoint: "https://" + q.Host,
|
Endpoint: fmt.Sprintf("https://%s:%d", q.Host, q.Port),
|
||||||
Username: q.User,
|
Username: q.User,
|
||||||
Password: q.Pass,
|
Password: q.Pass,
|
||||||
Insecure: q.WithSecureTLS,
|
Insecure: !q.WithSecureTLS,
|
||||||
|
TLSHandshakeTimeout: 30,
|
||||||
}
|
}
|
||||||
c, err := gofish.Connect(config)
|
c, err := gofish.Connect(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue