mirror of
https://github.com/davidallendj/magellan.git
synced 2025-12-20 03:27:03 -07:00
Merge pull request #13 from davidallendj/tidy-code
Tidy code and other minor changes and bug fixes
This commit is contained in:
commit
994bf07716
4 changed files with 52 additions and 48 deletions
|
|
@ -61,7 +61,7 @@ func init() {
|
|||
collectCmd.PersistentFlags().StringVar(&pass, "pass", "", "set the BMC password")
|
||||
collectCmd.PersistentFlags().StringVar(&protocol, "protocol", "https", "set the Redfish protocol")
|
||||
collectCmd.PersistentFlags().StringVarP(&outputPath, "output", "o", "/tmp/magellan/data/", "set the path to store collection data")
|
||||
collectCmd.PersistentFlags().BoolVar(&forceUpdate, "force-update", true, "set flag to force update data sent to SMD ")
|
||||
collectCmd.PersistentFlags().BoolVar(&forceUpdate, "force-update", false, "set flag to force update data sent to SMD ")
|
||||
collectCmd.PersistentFlags().StringVar(&preferredDriver, "preferred-driver", "ipmi", "set the preferred driver to use")
|
||||
collectCmd.PersistentFlags().StringVar(&ipmitoolPath, "ipmitool.path", "/usr/bin/ipmitool", "set the path for ipmitool")
|
||||
collectCmd.PersistentFlags().BoolVar(&withSecureTLS, "secure-tls", false, "enable secure TLS")
|
||||
|
|
|
|||
|
|
@ -51,11 +51,11 @@ func AddRedfishEndpoint(data []byte, headers map[string]string) error {
|
|||
// Add redfish endpoint via POST `/hsm/v2/Inventory/RedfishEndpoints` endpoint
|
||||
url := makeEndpointUrl("/Inventory/RedfishEndpoints")
|
||||
res, body, err := util.MakeRequest(url, "POST", data, headers)
|
||||
fmt.Printf("%v (%v)\n%s\n", url, res.Status, string(body))
|
||||
if res != nil {
|
||||
if res.StatusCode != http.StatusOK {
|
||||
return fmt.Errorf("could not add redfish endpoint")
|
||||
}
|
||||
fmt.Printf("%v (%v)\n%s\n", url, res.Status, string(body))
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -153,16 +153,16 @@ func CollectInfo(probeStates *[]ScannedResult, l *log.Logger, q *QueryParams) er
|
|||
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])
|
||||
data["Type"] = ""
|
||||
data["Name"] = ""
|
||||
data["FQDN"] = ps.Host
|
||||
data["User"] = q.User
|
||||
data["Password"] = q.Pass
|
||||
data["IPAddr"] = ""
|
||||
data["MACAddr"] = ""
|
||||
data["RediscoverOnUpdate"] = false
|
||||
data := map[string]any{
|
||||
"ID": fmt.Sprintf("%v", node.String()[:len(node.String())-2]),
|
||||
"Type": "",
|
||||
"Name": "",
|
||||
"FQDN": ps.Host,
|
||||
"User": q.User,
|
||||
"Password": q.Pass,
|
||||
"MACRequired": true,
|
||||
"RediscoverOnUpdate": false,
|
||||
}
|
||||
|
||||
// unmarshal json to send in correct format
|
||||
var rm map[string]json.RawMessage
|
||||
|
|
@ -185,24 +185,13 @@ func CollectInfo(probeStates *[]ScannedResult, l *log.Logger, q *QueryParams) er
|
|||
data["Chassis"] = rm["Chassis"]
|
||||
|
||||
// ethernet interfaces
|
||||
interfaces, err := QueryEthernetInterfaces(client, q)
|
||||
if err != nil {
|
||||
l.Log.Errorf("could not query ethernet interfaces: %v", err)
|
||||
continue
|
||||
}
|
||||
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"]
|
||||
}
|
||||
}
|
||||
// interfaces, err := QueryEthernetInterfaces(client, q)
|
||||
// if err != nil {
|
||||
// l.Log.Errorf("could not query ethernet interfaces: %v", err)
|
||||
// continue
|
||||
// }
|
||||
// json.Unmarshal(interfaces, &rm)
|
||||
// data["Interfaces"] = rm["Interfaces"]
|
||||
|
||||
// storage
|
||||
// storage, err := QueryStorage(q)
|
||||
|
|
@ -214,16 +203,16 @@ func CollectInfo(probeStates *[]ScannedResult, l *log.Logger, q *QueryParams) er
|
|||
// 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"]
|
||||
// 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)
|
||||
systems, err := QuerySystems(client, q)
|
||||
if err != nil {
|
||||
l.Log.Errorf("could not query systems: %v", err)
|
||||
}
|
||||
|
|
@ -453,7 +442,7 @@ func QueryBios(client *bmclib.Client, q *QueryParams) ([]byte, error) {
|
|||
return b, err
|
||||
}
|
||||
|
||||
func QueryEthernetInterfaces(client *bmclib.Client, q *QueryParams) ([]byte, error) {
|
||||
func QueryEthernetInterfaces(client *bmclib.Client, q *QueryParams, systemID string) ([]byte, error) {
|
||||
c, err := connectGofish(q)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not connect to bmc: %v", err)
|
||||
|
|
@ -477,15 +466,15 @@ func QueryEthernetInterfaces(client *bmclib.Client, q *QueryParams) ([]byte, err
|
|||
return nil, fmt.Errorf("could not get ethernet interfaces: %v", err)
|
||||
}
|
||||
|
||||
data := map[string]any{"Interfaces": interfaces}
|
||||
data := map[string]any{"EthernetInterfaces": interfaces}
|
||||
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))
|
||||
}
|
||||
// if q.Verbose {
|
||||
// fmt.Printf("%v\n", string(b))
|
||||
// }
|
||||
return b, nil
|
||||
}
|
||||
|
||||
|
|
@ -544,7 +533,7 @@ func QueryStorage(q *QueryParams) ([]byte, error) {
|
|||
return b, nil
|
||||
}
|
||||
|
||||
func QuerySystems(q *QueryParams) ([]byte, error) {
|
||||
func QuerySystems(client *bmclib.Client, q *QueryParams) ([]byte, error) {
|
||||
c, err := connectGofish(q)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not connect to bmc (%v:%v): %v", q.Host, q.Port, err)
|
||||
|
|
@ -552,10 +541,25 @@ func QuerySystems(q *QueryParams) ([]byte, error) {
|
|||
|
||||
systems, err := c.Service.Systems()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not query storage systems (%v:%v): %v", q.Host, q.Port, err)
|
||||
return nil, fmt.Errorf("could not query systems (%v:%v): %v", q.Host, q.Port, err)
|
||||
}
|
||||
|
||||
data := map[string]any{"Systems": systems }
|
||||
// query the system's ethernet interfaces
|
||||
var temp []map[string]any
|
||||
for _, system := range systems {
|
||||
interfaces, err := QueryEthernetInterfaces(client, q, system.ID)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
var i map[string]any
|
||||
json.Unmarshal(interfaces, &i)
|
||||
temp = append(temp, map[string]any{
|
||||
"Data": system,
|
||||
"EthernetInterfaces": i["EthernetInterfaces"],
|
||||
})
|
||||
}
|
||||
|
||||
data := map[string]any{"Systems": temp }
|
||||
b, err := json.MarshalIndent(data, "", " ")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not marshal JSON: %v", err)
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ func CreateProbeResultsIfNotExists(path string) (*sqlx.DB, error) {
|
|||
return db, nil
|
||||
}
|
||||
|
||||
func InsertProbeResults(path string, states *[]magellan.BMCProbeResult) error {
|
||||
func InsertProbeResults(path string, states *[]magellan.ScannedResult) error {
|
||||
if states == nil {
|
||||
return fmt.Errorf("states == nil")
|
||||
}
|
||||
|
|
@ -54,7 +54,7 @@ func InsertProbeResults(path string, states *[]magellan.BMCProbeResult) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func DeleteProbeResults(path string, results *[]magellan.BMCProbeResult) error {
|
||||
func DeleteProbeResults(path string, results *[]magellan.ScannedResult) error {
|
||||
if results == nil {
|
||||
return fmt.Errorf("no probe results found")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue