forked from stmcginnis/gofish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpowersupplyunit.go
290 lines (251 loc) · 9.96 KB
/
powersupplyunit.go
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
//
// SPDX-License-Identifier: BSD-3-Clause
//
package redfish
import (
"encoding/json"
"errors"
"reflect"
"github.com/stmcginnis/gofish/common"
)
type LineInputStatus string
const (
// No power detected at line input.
LossOfInputLineInputStatus LineInputStatus = "LossOfInput"
// Line input is within normal operating range.
NormalLineInputStatus LineInputStatus = "Normal"
// Line input voltage or current is outside of normal operating range.
OutOfRangeLineInputStatus LineInputStatus = "OutOfRange"
)
type PowerSupplyUnitType string
const (
// Alternating Current (AC) power supply.
ACPowerSupplyUnitType PowerSupplyUnitType = "AC"
// The power supply supports both DC or AC.
ACorDCPowerSupplyUnitType PowerSupplyUnitType = "ACorDC"
// Direct Current (DC) power supply.
DCPowerSupplyUnitType PowerSupplyUnitType = "DC"
// (v1.5+) Direct Current (DC) voltage regulator.
DCRegulatorPowerSupplyUnitType PowerSupplyUnitType = "DCRegulator"
)
// The efficiency ratings of this power supply.
type EfficiencyRating struct {
// The rated efficiency of this power supply at the specified load.
EfficiencyPercent float32
// The electrical load for this rating.
LoadPercent float32
}
// The input ranges that the power supply can use.
type PowerSupplyInputRange struct {
// The maximum capacity of this power supply when operating in this input range.
CapacityWatts float32
// The input voltage range.
NominalVoltageType NominalVoltage
}
// The input ranges that the power supply can use.
type OutputRail struct {
// The nominal voltage of this output power rail.
NominalVoltage float32
// The area or device to which this power rail applies.
PhysicalContext common.PhysicalContext
}
// PowerSupplyUnit shall represent a power supply unit for a Redfish implementation.
// It may also represent a location, such as a slot, socket, or bay, where a unit may be installed,
// but the State property within the Status property contains Absent.
type PowerSupplyUnit struct {
common.Entity
// ODataContext is the odata context.
ODataContext string `json:"@odata.context"`
// ODataType is the odata type.
ODataType string `json:"@odata.type"`
// Description provides a description of this resource.
Description string
// The link to the assembly associated with this power supply.
assembly string
// The efficiency ratings of this power supply.
EfficiencyRatings []EfficiencyRating
// The URIs of the management interfaces
// for the upstream electrical source connections for this power supply.
ElectricalSourceManagerURIs []string
// The names of the upstream electrical sources,
// such as circuits or outlets, connected to this power supply.
ElectricalSourceNames []string
// The firmware version for this power supply.
FirmwareVersion string
// An indication of whether this device can be inserted
// or removed while the equipment is in operation.
HotPluggable bool
// The nominal voltage type of the line input to this power supply.
InputNominalVoltageType NominalVoltage
// The input ranges that the power supply can use.
InputRanges []PowerSupplyInputRange
// The status of the line input.
LineInputStatus LineInputStatus
// The location of the power supply.
Location common.Location
// An indicator allowing an operator to physically locate this resource.
LocationIndicatorActive bool
// The manufacturer of this power supply.
Manufacturer string
// The link to the power supply metrics resource associated with this power supply.
metrics string
// The model number for this power supply.
Model string
// The nominal output voltage type of this power supply.
OutputNominalVoltageType NominalVoltage
// The output power rails provided by this power supply.
OutputRails []OutputRail
// The part number for this power supply.
PartNumber string
// The number of ungrounded current-carrying conductors (phases)
// and the total number of conductors (wires)
// provided for the power supply input connector.
PhaseWiringType PhaseWiringType
// The type of plug according to NEMA, IEC, or regional standards.
PlugType PlugType
// The maximum capacity of this power supply.
PowerCapacityWatts float32
// The power supply type (AC or DC).
PowerSupplyType PowerSupplyUnitType
// The production or manufacturing date of this power supply.
ProductionDate string
// An indication of whether this component can be independently replaced
// as allowed by the vendor's replacement policy.
Replaceable bool
// The serial number for this power supply.
SerialNumber string
// The spare part number for this power supply.
SparePartNumber string
// The status and health of the resource and its subordinate or dependent resources.
Status common.Status
// The hardware version of this power supply.
Version string
// Links section
// Deprecated (v1.4): A link to the outlet connected to this power supply.
outlet string
poweringChassis []string
// PoweringChassisCount is the number of chassis that are directly powered by this power supply.
PoweringChassisCount int
powerOutlets []string
// PowerOutletsCount is the number of outlets that provide power to this power supply.
PowerOutletsCount int
// OemLinks are all OEM data under link section
OemLinks json.RawMessage
// Actions section
// This action resets the power supply.
resetTarget string
// OemActions contains all the vendor specific actions.
// It is vendor responsibility to parse this field accordingly
OemActions json.RawMessage
// rawData holds the original serialized JSON so we can compare updates.
rawData []byte
}
// UnmarshalJSON unmarshals a PowerSupplyUnit object from the raw JSON.
func (powerSupplyUnit *PowerSupplyUnit) UnmarshalJSON(b []byte) error {
type temp PowerSupplyUnit
type linkReference struct {
Outlet common.Link
PoweringChassis common.Links
PoweringChassisCount int `json:"[email protected]"`
PowerOutlets common.Links
PowerOutletsCount int `json:"[email protected]"`
Oem json.RawMessage
}
type actions struct {
Reset common.ActionTarget `json:"#PowerSupply.Reset"`
Oem json.RawMessage // OEM actions will be stored here
}
var t struct {
temp
Assembly common.Link
Metrics common.Link
Links linkReference
Actions actions
}
if err := json.Unmarshal(b, &t); err != nil {
return err
}
// Extract the links to other entities for later
*powerSupplyUnit = PowerSupplyUnit(t.temp)
powerSupplyUnit.assembly = t.Assembly.String()
powerSupplyUnit.metrics = t.Metrics.String()
powerSupplyUnit.outlet = t.Links.Outlet.String()
powerSupplyUnit.poweringChassis = t.Links.PoweringChassis.ToStrings()
powerSupplyUnit.PoweringChassisCount = t.Links.PoweringChassisCount
powerSupplyUnit.powerOutlets = t.Links.PowerOutlets.ToStrings()
powerSupplyUnit.PowerOutletsCount = t.Links.PowerOutletsCount
powerSupplyUnit.OemLinks = t.Links.Oem
powerSupplyUnit.resetTarget = t.Actions.Reset.Target
powerSupplyUnit.OemActions = t.Actions.Oem
// This is a read/write object, so we need to save the raw object data for later
powerSupplyUnit.rawData = b
return nil
}
// Update commits updates to this object's properties to the running system.
func (powerSupplyUnit *PowerSupplyUnit) Update() error {
// Get a representation of the object's original state so we can find what
// to update.
psu := new(PowerSupplyUnit)
err := psu.UnmarshalJSON(powerSupplyUnit.rawData)
if err != nil {
return err
}
readWriteFields := []string{
"ElectricalSourceManagerURIs",
"ElectricalSourceNames",
"LocationIndicatorActive",
}
originalElement := reflect.ValueOf(psu).Elem()
currentElement := reflect.ValueOf(powerSupplyUnit).Elem()
return powerSupplyUnit.Entity.Update(originalElement, currentElement, readWriteFields)
}
// GetPowerSupplyUnit will get a PowerSupplyUnit instance from the Redfish service.
func GetPowerSupplyUnit(c common.Client, uri string) (*PowerSupplyUnit, error) {
return common.GetObject[PowerSupplyUnit](c, uri)
}
// ListReferencedPowerSupplyUnits gets the collection of PowerSupplies from
// a provided reference.
func ListReferencedPowerSupplyUnits(c common.Client, link string) ([]*PowerSupplyUnit, error) {
return common.GetCollectionObjects[PowerSupplyUnit](c, link)
}
// This action shall reset a power supply. A GracefulRestart ResetType shall reset the power supply
// but shall not affect the power output. A ForceRestart ResetType can affect the power supply output.
func (powerSupplyUnit *PowerSupplyUnit) Reset(resetType ResetType) error {
if powerSupplyUnit.resetTarget == "" {
return errors.New("Reset is not supported") //nolint:golint
}
t := struct {
ResetType ResetType
}{ResetType: resetType}
return powerSupplyUnit.Post(powerSupplyUnit.resetTarget, t)
}
// Assembly gets the containing assembly for this power supply.
func (powerSupplyUnit *PowerSupplyUnit) Assembly() (*Assembly, error) {
if powerSupplyUnit.assembly == "" {
return nil, nil
}
return GetAssembly(powerSupplyUnit.GetClient(), powerSupplyUnit.assembly)
}
// Metrics gets the metrics associated with this power supply.
func (powerSupplyUnit *PowerSupplyUnit) Metrics() (*PowerSupplyUnitMetrics, error) {
if powerSupplyUnit.metrics == "" {
return nil, nil
}
return GetPowerSupplyUnitMetrics(powerSupplyUnit.GetClient(), powerSupplyUnit.metrics)
}
// Outlet get the outlet connected to this power supply.
// Deprecated (v1.4)
func (powerSupplyUnit *PowerSupplyUnit) Outlet() (*Outlet, error) {
if powerSupplyUnit.metrics == "" {
return nil, nil
}
return GetOutlet(powerSupplyUnit.GetClient(), powerSupplyUnit.outlet)
}
// PowerOutlets gets the outlets that supply power to this power supply.
func (powerSupplyUnit *PowerSupplyUnit) PowerOutlets() ([]*Outlet, error) {
return common.GetObjects[Outlet](powerSupplyUnit.GetClient(), powerSupplyUnit.powerOutlets)
}
// PoweringChassis gets the collection of the chassis directly powered by this power supply.
func (powerSupplyUnit *PowerSupplyUnit) PoweringChassis() ([]*Chassis, error) {
return common.GetObjects[Chassis](powerSupplyUnit.GetClient(), powerSupplyUnit.poweringChassis)
}