File: cmd_set_power_restore_policy.go

package info (click to toggle)
golang-github-bougou-go-ipmi 0.7.8-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,880 kB
  • sloc: makefile: 38
file content (58 lines) | stat: -rw-r--r-- 1,893 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package ipmi

import (
	"context"
	"fmt"
)

// 28.8 Set Power Restore Policy Command
type SetPowerRestorePolicyRequest struct {
	PowerRestorePolicy
}

type SetPowerRestorePolicyResponse struct {
	SupportPolicyAlwaysOn  bool // chassis supports always powering up after AC/mains returns
	SupportPolicyPrevious  bool // chassis supports restoring power to state that was in effect when AC/mains was lost
	SupportPolicyAlwaysOff bool // chassis supports staying powered off after AC/mains returns
}

func (req *SetPowerRestorePolicyRequest) Pack() []byte {
	out := make([]byte, 1)
	packUint8(uint8(req.PowerRestorePolicy), out, 0)
	return out
}

func (req *SetPowerRestorePolicyRequest) Command() Command {
	return CommandSetPowerRestorePolicy
}

func (res *SetPowerRestorePolicyResponse) CompletionCodes() map[uint8]string {
	return map[uint8]string{}
}

func (res *SetPowerRestorePolicyResponse) Unpack(msg []byte) error {
	if len(msg) < 1 {
		return ErrUnpackedDataTooShortWith(len(msg), 1)
	}
	b, _, _ := unpackUint8(msg, 0)
	res.SupportPolicyAlwaysOff = isBit0Set(b)
	res.SupportPolicyPrevious = isBit1Set(b)
	res.SupportPolicyAlwaysOn = isBit2Set((b))
	return nil
}

func (res *SetPowerRestorePolicyResponse) Format() string {
	return "" +
		fmt.Sprintf("Policy always-off : %s\n", formatBool(res.SupportPolicyAlwaysOff, "supported", "unsupported")) +
		fmt.Sprintf("Policy always-on  : %s\n", formatBool(res.SupportPolicyAlwaysOn, "supported", "unsupported")) +
		fmt.Sprintf("Policy previous   : %s\n", formatBool(res.SupportPolicyPrevious, "supported", "unsupported"))
}

func (c *Client) SetPowerRestorePolicy(ctx context.Context, policy PowerRestorePolicy) (response *SetPowerRestorePolicyResponse, err error) {
	request := &SetPowerRestorePolicyRequest{
		PowerRestorePolicy: policy,
	}
	response = &SetPowerRestorePolicyResponse{}
	err = c.Exchange(ctx, request, response)
	return
}