mirror of
https://github.com/davidallendj/magellan.git
synced 2025-12-20 03:27:03 -07:00
Added ability to update endpoint when conflicting with existing + processor info
Signed-off-by: David J. Allen <allend@lanl.gov>
This commit is contained in:
parent
2bfc42a064
commit
54dde2dda6
4 changed files with 130 additions and 37 deletions
|
|
@ -55,6 +55,7 @@ type QueryParams struct {
|
|||
Verbose bool
|
||||
IpmitoolPath string
|
||||
OutputPath string
|
||||
ForceUpdate bool
|
||||
}
|
||||
|
||||
func NewClient(l *log.Logger, q *QueryParams) (*bmclib.Client, error) {
|
||||
|
|
@ -120,14 +121,6 @@ func CollectInfo(probeStates *[]BMCProbeResult, l *log.Logger, q *QueryParams) e
|
|||
return fmt.Errorf("no probe states found")
|
||||
}
|
||||
|
||||
// generate custom xnames for bmcs
|
||||
node := xnames.Node{
|
||||
Cabinet: 1000,
|
||||
Chassis: 1,
|
||||
ComputeModule: 7,
|
||||
NodeBMC: -1,
|
||||
}
|
||||
|
||||
// make the output directory to store files
|
||||
outputPath := path.Clean(q.OutputPath)
|
||||
outputPath, err := util.MakeOutputDirectory(outputPath)
|
||||
|
|
@ -139,6 +132,14 @@ func CollectInfo(probeStates *[]BMCProbeResult, l *log.Logger, q *QueryParams) e
|
|||
done := make(chan struct{}, q.Threads+1)
|
||||
chanProbeState := make(chan BMCProbeResult, q.Threads+1)
|
||||
|
||||
// generate custom xnames for bmcs
|
||||
node := xnames.Node{
|
||||
Cabinet: 1000,
|
||||
Chassis: 1,
|
||||
ComputeModule: 7,
|
||||
NodeBMC: -1,
|
||||
}
|
||||
|
||||
// collect bmc information asynchronously
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(q.Threads)
|
||||
|
|
@ -159,6 +160,8 @@ func CollectInfo(probeStates *[]BMCProbeResult, l *log.Logger, q *QueryParams) e
|
|||
continue
|
||||
}
|
||||
|
||||
node.NodeBMC += 1
|
||||
|
||||
// data to be sent to smd
|
||||
data := make(map[string]any)
|
||||
data["ID"] = fmt.Sprintf("%v", node.String()[:len(node.String())-2])
|
||||
|
|
@ -167,6 +170,8 @@ func CollectInfo(probeStates *[]BMCProbeResult, l *log.Logger, q *QueryParams) e
|
|||
data["FQDN"] = ps.Host
|
||||
data["User"] = q.User
|
||||
data["Password"] = q.Pass
|
||||
data["IPAddr"] = ""
|
||||
data["MACAddr"] = ""
|
||||
data["RediscoverOnUpdate"] = false
|
||||
|
||||
// unmarshal json to send in correct format
|
||||
|
|
@ -198,6 +203,17 @@ func CollectInfo(probeStates *[]BMCProbeResult, l *log.Logger, q *QueryParams) e
|
|||
json.Unmarshal(interfaces, &rm)
|
||||
data["Interface"] = rm["Interface"]
|
||||
|
||||
// get MAC address of first interface (for now...)
|
||||
if len(rm["Interface"]) > 0 {
|
||||
var i map[string]interface{}
|
||||
json.Unmarshal(rm["Interface"], &i)
|
||||
data["MACAddr"] = i["MACAddress"]
|
||||
data["IPAddr"] = i["IPAddress"]
|
||||
if i["FQDN"] != "" {
|
||||
data["FQDN"] = rm["FQDN"]
|
||||
}
|
||||
}
|
||||
|
||||
// storage
|
||||
// storage, err := QueryStorage(q)
|
||||
// if err != nil {
|
||||
|
|
@ -207,6 +223,15 @@ func CollectInfo(probeStates *[]BMCProbeResult, l *log.Logger, q *QueryParams) e
|
|||
// json.Unmarshal(storage, &rm)
|
||||
// data["Storage"] = rm["Storage"]
|
||||
|
||||
// get specific processor info
|
||||
procs, err := QueryProcessors(q)
|
||||
if err != nil {
|
||||
l.Log.Errorf("could not query processors: %v", err)
|
||||
}
|
||||
var p map[string]interface{}
|
||||
json.Unmarshal(procs, &p)
|
||||
data["Processors"] = rm["Processors"]
|
||||
|
||||
// systems
|
||||
systems, err := QuerySystems(q)
|
||||
if err != nil {
|
||||
|
|
@ -215,6 +240,15 @@ func CollectInfo(probeStates *[]BMCProbeResult, l *log.Logger, q *QueryParams) e
|
|||
json.Unmarshal(systems, &rm)
|
||||
data["Systems"] = rm["Systems"]
|
||||
|
||||
// add other fields from systems
|
||||
if len(rm["Systems"]) > 0 {
|
||||
var s map[string][]interface{}
|
||||
json.Unmarshal(rm["Systems"], &s)
|
||||
data["Name"] = s["Name"]
|
||||
}
|
||||
|
||||
// data["Type"] = rm[""]
|
||||
|
||||
// registries
|
||||
// registries, err := QueryRegisteries(q)
|
||||
// if err != nil {
|
||||
|
|
@ -223,8 +257,6 @@ func CollectInfo(probeStates *[]BMCProbeResult, l *log.Logger, q *QueryParams) e
|
|||
// json.Unmarshal(registries, &rm)
|
||||
// data["Registries"] = rm["Registries"]
|
||||
|
||||
node.NodeBMC += 1
|
||||
|
||||
headers := make(map[string]string)
|
||||
headers["Content-Type"] = "application/json"
|
||||
|
||||
|
|
@ -242,29 +274,17 @@ func CollectInfo(probeStates *[]BMCProbeResult, l *log.Logger, q *QueryParams) e
|
|||
// add all endpoints to smd
|
||||
err = smd.AddRedfishEndpoint(b, headers)
|
||||
if err != nil {
|
||||
l.Log.Errorf("could not add redfish endpoint: %v", err)
|
||||
l.Log.Error(err)
|
||||
|
||||
// try updating instead
|
||||
if q.ForceUpdate {
|
||||
err = smd.UpdateRedfishEndpoint(data["ID"].(string), b, headers)
|
||||
if err != nil {
|
||||
l.Log.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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)
|
||||
// }
|
||||
|
||||
// got host information, so add to list of already probed hosts
|
||||
found = append(found, ps.Host)
|
||||
}
|
||||
|
|
@ -567,6 +587,54 @@ func QueryRegisteries(q *QueryParams) ([]byte, error) {
|
|||
return b, nil
|
||||
}
|
||||
|
||||
func QueryProcessors(q *QueryParams) ([]byte, error) {
|
||||
baseUrl := "https://"
|
||||
if q.User != "" && q.Pass != "" {
|
||||
baseUrl += fmt.Sprintf("%s:%s@", q.User, q.Pass)
|
||||
}
|
||||
baseUrl += fmt.Sprintf("%s:%d", q.Host, q.Port)
|
||||
url := baseUrl + "/redfish/v1/Systems"
|
||||
res, body, err := util.MakeRequest(url, "GET", nil, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("something went wrong: %v", err)
|
||||
} else if res == nil {
|
||||
return nil, fmt.Errorf("no response returned (url: %s)", url)
|
||||
} else if res.StatusCode != http.StatusOK {
|
||||
return nil, fmt.Errorf("returned status code %d", res.StatusCode)
|
||||
}
|
||||
|
||||
// convert to not get base64 string
|
||||
var procs map[string]json.RawMessage
|
||||
var members []map[string]any
|
||||
json.Unmarshal(body, &procs)
|
||||
json.Unmarshal(procs["Members"], &members)
|
||||
|
||||
// request data about each processor member on node
|
||||
for _, member := range members {
|
||||
var oid = member["@odata.id"].(string)
|
||||
var infoUrl = baseUrl + oid
|
||||
res, _, err := util.MakeRequest(infoUrl, "GET", nil, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("something went wrong: %v", err)
|
||||
} else if res == nil {
|
||||
return nil, fmt.Errorf("no response returned (url: %s)", url)
|
||||
} else if res.StatusCode != http.StatusOK {
|
||||
return nil, fmt.Errorf("returned status code %d", res.StatusCode)
|
||||
}
|
||||
}
|
||||
|
||||
data := map[string]any{"Processors": procs }
|
||||
b, err := json.MarshalIndent(data, "", " ")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not marshal JSON: %v", err)
|
||||
}
|
||||
|
||||
if q.Verbose {
|
||||
fmt.Printf("%v\n", string(b))
|
||||
}
|
||||
return b, nil
|
||||
}
|
||||
|
||||
func connectGofish(q *QueryParams) (*gofish.APIClient, error) {
|
||||
config := makeGofishConfig(q)
|
||||
c, err := gofish.Connect(config)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue