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{
|
q := &magellan.QueryParams{
|
||||||
User: user,
|
User: user,
|
||||||
Pass: pass,
|
Pass: pass,
|
||||||
|
Protocol: protocol,
|
||||||
Drivers: drivers,
|
Drivers: drivers,
|
||||||
Preferred: preferredDriver,
|
Preferred: preferredDriver,
|
||||||
Timeout: timeout,
|
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().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(&user, "user", "", "set the BMC user")
|
||||||
collectCmd.PersistentFlags().StringVar(&pass, "pass", "", "set the BMC password")
|
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().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", true, "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(&preferredDriver, "preferred-driver", "ipmi", "set the preferred driver to use")
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ var (
|
||||||
threads int
|
threads int
|
||||||
ports []int
|
ports []int
|
||||||
hosts []string
|
hosts []string
|
||||||
|
protocol string
|
||||||
withSecureTLS bool
|
withSecureTLS bool
|
||||||
certPoolFile string
|
certPoolFile string
|
||||||
user string
|
user string
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,7 @@ type BMCProbeResult struct {
|
||||||
type QueryParams struct {
|
type QueryParams struct {
|
||||||
Host string
|
Host string
|
||||||
Port int
|
Port int
|
||||||
|
Protocol string
|
||||||
User string
|
User string
|
||||||
Pass string
|
Pass string
|
||||||
Drivers []string
|
Drivers []string
|
||||||
|
|
@ -59,9 +60,6 @@ type QueryParams struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewClient(l *log.Logger, q *QueryParams) (*bmclib.Client, error) {
|
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{
|
tr := &http.Transport{
|
||||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
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
|
// only work if valid cert is provided
|
||||||
if q.WithSecureTLS {
|
if q.WithSecureTLS && q.CertPoolFile != "" {
|
||||||
var pool *x509.CertPool
|
pool := x509.NewCertPool()
|
||||||
if q.CertPoolFile != "" {
|
|
||||||
pool = x509.NewCertPool()
|
|
||||||
data, err := os.ReadFile(q.CertPoolFile)
|
data, err := os.ReadFile(q.CertPoolFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("could not read cert pool file: %v", err)
|
return nil, fmt.Errorf("could not read cert pool file: %v", err)
|
||||||
}
|
}
|
||||||
pool.AppendCertsFromPEM(data)
|
pool.AppendCertsFromPEM(data)
|
||||||
}
|
|
||||||
// a nil pool uses the system certs
|
// a nil pool uses the system certs
|
||||||
clientOpts = append(clientOpts, bmclib.WithSecureTLS(pool))
|
clientOpts = append(clientOpts, bmclib.WithSecureTLS(pool))
|
||||||
}
|
}
|
||||||
url := ""
|
url := ""
|
||||||
|
fmt.Println(url)
|
||||||
if q.User != "" && q.Pass != "" {
|
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 {
|
} else {
|
||||||
url += q.Host
|
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)
|
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 {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("could not get ethernet interfaces: %v", err)
|
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) {
|
func QueryProcessors(q *QueryParams) ([]byte, error) {
|
||||||
url := baseUrl(q) + "Systems"
|
url := baseRedfishUrl(q) + "/Systems"
|
||||||
res, body, err := util.MakeRequest(url, "GET", nil, nil)
|
res, body, err := util.MakeRequest(url, "GET", nil, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("something went wrong: %v", err)
|
return nil, fmt.Errorf("something went wrong: %v", err)
|
||||||
|
|
@ -636,17 +632,19 @@ func connectGofish(q *QueryParams) (*gofish.APIClient, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if c.Service != nil {
|
||||||
c.Service.ProtocolFeaturesSupported = gofish.ProtocolFeaturesSupported{
|
c.Service.ProtocolFeaturesSupported = gofish.ProtocolFeaturesSupported{
|
||||||
ExpandQuery: gofish.Expand{
|
ExpandQuery: gofish.Expand{
|
||||||
ExpandAll: true,
|
ExpandAll: true,
|
||||||
Links: true,
|
Links: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return c, err
|
return c, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeGofishConfig(q *QueryParams) gofish.ClientConfig {
|
func makeGofishConfig(q *QueryParams) gofish.ClientConfig {
|
||||||
url := baseUrl(q)
|
url := baseRedfishUrl(q)
|
||||||
return gofish.ClientConfig{
|
return gofish.ClientConfig{
|
||||||
Endpoint: url,
|
Endpoint: url,
|
||||||
Username: q.User,
|
Username: q.User,
|
||||||
|
|
@ -685,11 +683,10 @@ func makeJson(object any) ([]byte, error) {
|
||||||
return []byte(b), nil
|
return []byte(b), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func baseUrl(q *QueryParams) string {
|
func baseRedfishUrl(q *QueryParams) string {
|
||||||
url := "https://"
|
url := fmt.Sprintf("%s://", q.Protocol)
|
||||||
if q.User != "" && q.Pass != "" {
|
if q.User != "" && q.Pass != "" {
|
||||||
url += fmt.Sprintf("%s:%s@", q.User, q.Pass)
|
url += fmt.Sprintf("%s:%s@", q.User, q.Pass)
|
||||||
}
|
}
|
||||||
url += fmt.Sprintf("%s:%d", q.Host, q.Port)
|
return fmt.Sprintf("%s%s:%d", url, q.Host, q.Port)
|
||||||
return url + "/redfish/v1/"
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue