Skip to content

Commit

Permalink
providers/supermicro: fix up redfish session init and purge unused me…
Browse files Browse the repository at this point in the history
…thods
  • Loading branch information
joelrebel committed Nov 27, 2023
1 parent b7f3de9 commit bbc734d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 48 deletions.
2 changes: 1 addition & 1 deletion providers/supermicro/floppy.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var (
)

func (c *Client) floppyImageMounted(ctx context.Context) (bool, error) {
if err := c.openRedfish(ctx); err != nil {
if err := c.serviceClient.redfishSession(ctx); err != nil {
return false, err
}

Expand Down
51 changes: 4 additions & 47 deletions providers/supermicro/supermicro.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,21 +249,6 @@ func (c *Client) bmcQueryor(ctx context.Context) (bmcQueryor, error) {
return queryor, nil
}

func (c *Client) openRedfish(ctx context.Context) error {
if c.serviceClient.redfish != nil && c.serviceClient.redfish.SessionActive() == nil {
return nil
}

rfclient := redfishwrapper.NewClient(c.serviceClient.host, "", c.serviceClient.user, c.serviceClient.pass)
if err := rfclient.Open(ctx); err != nil {
return err
}

c.serviceClient.redfish = rfclient

return nil
}

func parseToken(body []byte) string {
var key string
if bytes.Contains(body, []byte(`CSRF-TOKEN`)) {
Expand Down Expand Up @@ -380,38 +365,6 @@ func (c *Client) initScreenPreview(ctx context.Context) error {
return nil
}

// PowerSet sets the power state of a server
func (c *Client) PowerSet(ctx context.Context, state string) (ok bool, err error) {
switch strings.ToLower(state) {
case "cycle":
return c.powerCycle(ctx)
default:
return false, errors.New("action not implemented for provider")
}
}

// powerCycle using SMC XML API
//
// This method is only here for the case when firmware updates are being applied using this provider.
func (c *Client) powerCycle(ctx context.Context) (bool, error) {
payload := []byte(`op=SET_POWER_INFO.XML&r=(1,3)&_=`)

headers := map[string]string{
"Content-type": "application/x-www-form-urlencoded; charset=UTF-8",
}

body, status, err := c.serviceClient.query(ctx, "cgi/ipmi.cgi", http.MethodPost, bytes.NewBuffer(payload), headers, 0)
if err != nil {
return false, err
}

if status != http.StatusOK {
return false, unexpectedResponseErr(payload, body, status)
}

return true, nil
}

type serviceClient struct {
host string
port string
Expand All @@ -435,6 +388,10 @@ func (c *serviceClient) setCsrfToken(t string) {
}

func (c *serviceClient) redfishSession(ctx context.Context) (err error) {
if c.redfish != nil && c.redfish.SessionActive() == nil {
return nil
}

c.redfish = redfishwrapper.NewClient(c.host, "", c.user, c.pass, redfishwrapper.WithHTTPClient(c.client))
if err := c.redfish.Open(ctx); err != nil {
return err
Expand Down

0 comments on commit bbc734d

Please sign in to comment.