-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from jafurlan/main
Grendel v0.0.10
- Loading branch information
Showing
42 changed files
with
2,436 additions
and
1,774 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package bmc | ||
|
||
import ( | ||
"github.com/spf13/viper" | ||
"github.com/stmcginnis/gofish" | ||
) | ||
|
||
type Redfish struct { | ||
config gofish.ClientConfig | ||
client *gofish.APIClient | ||
service *gofish.Service | ||
} | ||
|
||
type System struct { | ||
Name string `json:"name"` | ||
BIOSVersion string `json:"bios_version"` | ||
SerialNumber string `json:"serial_number"` | ||
Manufacturer string `json:"manufacturer"` | ||
PowerStatus string `json:"power_status"` | ||
Health string `json:"health"` | ||
TotalMemory float32 `json:"total_memory"` | ||
ProcessorCount int `json:"processor_count"` | ||
BootNext string `json:"boot_next"` | ||
BootOrder []string `json:"boot_order"` | ||
} | ||
|
||
func NewRedfishClient(ip string) (*Redfish, error) { | ||
user := viper.GetString("bmc.user") | ||
pass := viper.GetString("bmc.password") | ||
viper.SetDefault("bmc.insecure", true) | ||
insecure := viper.GetBool("bmc.insecure") | ||
|
||
endpoint := "https://" + ip | ||
|
||
config := gofish.ClientConfig{ | ||
Endpoint: endpoint, | ||
Username: user, | ||
Password: pass, | ||
Insecure: insecure, | ||
} | ||
|
||
client, err := gofish.Connect(config) | ||
if err != nil { | ||
e := ParseRedfishError(err) | ||
// Try with default credentials | ||
if e.Code == "401" { | ||
config.Username = "root" | ||
config.Password = "calvin" | ||
client, err = gofish.Connect(config) | ||
if err != nil { | ||
log.Debug("default credentials failed") | ||
return nil, err | ||
} | ||
} else { | ||
return nil, err | ||
} | ||
} | ||
|
||
return &Redfish{ | ||
config: config, | ||
client: client, | ||
service: client.GetService(), | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package bmc | ||
|
||
import ( | ||
"encoding/json" | ||
"regexp" | ||
"strings" | ||
) | ||
|
||
type RedfishError struct { | ||
Code string | ||
Error struct { | ||
MessageExtendedInfo []struct { | ||
Message string | ||
MessageArgs []string //? | ||
MessageArgsCount int `json:"MessageArgs.@odata.count"` | ||
MessageId string | ||
RelatedProperties []string //? | ||
RelatedPropertiesCount int `json:"RelatedProperties.@odata.count"` | ||
Resolution string | ||
Severity string | ||
} `json:"@Message.ExtendedInfo"` | ||
Code string `json:"code"` | ||
Message string `json:"message"` | ||
} `json:"error"` | ||
} | ||
|
||
func ParseRedfishError(err error) RedfishError { | ||
var e RedfishError | ||
if err == nil { | ||
return e | ||
} | ||
|
||
reg := regexp.MustCompile(`^[0-9]{3}`) | ||
e.Code = reg.FindString(err.Error()) | ||
if e.Code != "" { | ||
test, _ := strings.CutPrefix(err.Error(), e.Code+":") | ||
|
||
json.Unmarshal([]byte(test), &e) | ||
} | ||
|
||
return e | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.