mirror of
https://github.com/davidallendj/magellan.git
synced 2025-12-20 11:37:01 -07:00
Added protocol flag
This commit is contained in:
parent
5b390a65c2
commit
d8bd169cb7
3 changed files with 25 additions and 25 deletions
|
|
@ -33,6 +33,7 @@ var collectCmd = &cobra.Command{
|
|||
q := &magellan.QueryParams{
|
||||
User: user,
|
||||
Pass: pass,
|
||||
Protocol: protocol,
|
||||
Drivers: drivers,
|
||||
Preferred: preferredDriver,
|
||||
Timeout: timeout,
|
||||
|
|
@ -58,6 +59,7 @@ func init() {
|
|||
collectCmd.PersistentFlags().IntVarP(&smd.Port, "port", "p", smd.Port, "set the port to the smd API")
|
||||
collectCmd.PersistentFlags().StringVar(&user, "user", "", "set the BMC user")
|
||||
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().StringVar(&preferredDriver, "preferred-driver", "ipmi", "set the preferred driver to use")
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ var (
|
|||
threads int
|
||||
ports []int
|
||||
hosts []string
|
||||
protocol string
|
||||
withSecureTLS bool
|
||||
certPoolFile string
|
||||
user string
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ type BMCProbeResult struct {
|
|||
type QueryParams struct {
|
||||
Host string
|
||||
Port int
|
||||
Protocol string
|
||||
User string
|
||||
Pass string
|
||||
Drivers []string
|
||||
|
|
@ -59,9 +60,6 @@ type QueryParams struct {
|
|||
}
|
||||
|
||||
func NewClient(l *log.Logger, q *QueryParams) (*bmclib.Client, error) {
|
||||
// NOTE: bmclib.NewClient(host, port, user, pass)
|
||||
// ...seems like the `port` params doesn't work like expected depending on interface
|
||||
|
||||
tr := &http.Transport{
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||
}
|
||||
|
|
@ -83,22 +81,20 @@ func NewClient(l *log.Logger, q *QueryParams) (*bmclib.Client, error) {
|
|||
}
|
||||
|
||||
// only work if valid cert is provided
|
||||
if q.WithSecureTLS {
|
||||
var pool *x509.CertPool
|
||||
if q.CertPoolFile != "" {
|
||||
pool = x509.NewCertPool()
|
||||
if q.WithSecureTLS && q.CertPoolFile != "" {
|
||||
pool := x509.NewCertPool()
|
||||
data, err := os.ReadFile(q.CertPoolFile)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not read cert pool file: %v", err)
|
||||
}
|
||||
pool.AppendCertsFromPEM(data)
|
||||
}
|
||||
// a nil pool uses the system certs
|
||||
clientOpts = append(clientOpts, bmclib.WithSecureTLS(pool))
|
||||
}
|
||||
url := ""
|
||||
fmt.Println(url)
|
||||
if q.User != "" && q.Pass != "" {
|
||||
url += fmt.Sprintf("https://%s:%s@%s", q.User, q.Pass, q.Host)
|
||||
url += fmt.Sprintf("%s://%s:%s@%s", q.Protocol, q.User, q.Pass, q.Host)
|
||||
} else {
|
||||
url += q.Host
|
||||
}
|
||||
|
|
@ -469,7 +465,7 @@ func QueryEthernetInterfaces(client *bmclib.Client, q *QueryParams) ([]byte, err
|
|||
return nil, fmt.Errorf("could not connect to bmc: %v", err)
|
||||
}
|
||||
|
||||
interfaces, err := redfish.ListReferencedEthernetInterfaces(c, "/redfish/v1/Systems/")
|
||||
interfaces, err := redfish.ListReferencedEthernetInterfaces(c, "")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not get ethernet interfaces: %v", err)
|
||||
}
|
||||
|
|
@ -588,7 +584,7 @@ func QueryRegisteries(q *QueryParams) ([]byte, error) {
|
|||
}
|
||||
|
||||
func QueryProcessors(q *QueryParams) ([]byte, error) {
|
||||
url := baseUrl(q) + "Systems"
|
||||
url := baseRedfishUrl(q) + "/Systems"
|
||||
res, body, err := util.MakeRequest(url, "GET", nil, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("something went wrong: %v", err)
|
||||
|
|
@ -636,17 +632,19 @@ func connectGofish(q *QueryParams) (*gofish.APIClient, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if c.Service != nil {
|
||||
c.Service.ProtocolFeaturesSupported = gofish.ProtocolFeaturesSupported{
|
||||
ExpandQuery: gofish.Expand{
|
||||
ExpandAll: true,
|
||||
Links: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
return c, err
|
||||
}
|
||||
|
||||
func makeGofishConfig(q *QueryParams) gofish.ClientConfig {
|
||||
url := baseUrl(q)
|
||||
url := baseRedfishUrl(q)
|
||||
return gofish.ClientConfig{
|
||||
Endpoint: url,
|
||||
Username: q.User,
|
||||
|
|
@ -685,11 +683,10 @@ func makeJson(object any) ([]byte, error) {
|
|||
return []byte(b), nil
|
||||
}
|
||||
|
||||
func baseUrl(q *QueryParams) string {
|
||||
url := "https://"
|
||||
func baseRedfishUrl(q *QueryParams) string {
|
||||
url := fmt.Sprintf("%s://", q.Protocol)
|
||||
if q.User != "" && q.Pass != "" {
|
||||
url += fmt.Sprintf("%s:%s@", q.User, q.Pass)
|
||||
}
|
||||
url += fmt.Sprintf("%s:%d", q.Host, q.Port)
|
||||
return url + "/redfish/v1/"
|
||||
return fmt.Sprintf("%s%s:%d", url, q.Host, q.Port)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue