/
thermalsubsystem.go
174 lines (149 loc) · 5.64 KB
/
thermalsubsystem.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
//
// SPDX-License-Identifier: BSD-3-Clause
//
package redfish
import (
"encoding/json"
"github.com/stmcginnis/gofish/common"
)
// ThermalSubsystem shall represent a thermal subsystem for a Redfish implementation.
type ThermalSubsystem struct {
common.Entity
// ODataContext is the odata context.
ODataContext string `json:"@odata.context"`
// ODataEtag is the odata etag.
ODataEtag string `json:"@odata.etag"`
// ODataType is the odata type.
ODataType string `json:"@odata.type"`
// CoolantConnectorRedundancy shall contain redundancy information for the set of coolant connectors attached to
// this equipment. The values of the RedundancyGroup array shall reference resources of type CoolantConnector.
CoolantConnectorRedundancy []RedundantGroup
// CoolantConnectors shall contain a link to a resource collection of type CoolantConnectorCollection that contains
// the coolant connectors for this equipment.
coolantConnectors string
// Description provides a description of this resource.
Description string
// FanRedundancy shall contain redundancy information for the groups of fans in this subsystem.
FanRedundancy []RedundantGroup
// Fans shall contain a link to a resource collection of type FanCollection.
fans string
// Heaters shall contain a link to a resource collection of type HeaterCollection.
heaters string
// LeakDetection shall contain a link to a resource collection of type LeakDetection.
leakDetection string
// Oem shall contain the OEM extensions. All values for properties that this object contains shall conform to the
// Redfish Specification-described requirements.
OEM json.RawMessage `json:"Oem"`
// Pumps shall contain a link to a resource collection of type PumpCollection that contains details for the pumps
// included in this equipment.
pumps string
// Status shall contain any status or health properties of the resource.
Status common.Status
// ThermalMetrics shall contain a link to a resource collection of type ThermalMetrics.
thermalMetrics string
}
// UnmarshalJSON unmarshals a ThermalSubsystem object from the raw JSON.
func (thermalsubsystem *ThermalSubsystem) UnmarshalJSON(b []byte) error {
type temp ThermalSubsystem
var t struct {
temp
CoolantConnectors common.Link
Fans common.Link
Heaters common.Link
LeakDetection common.Link
Pumps common.Link
ThermalMetrics common.Link
}
err := json.Unmarshal(b, &t)
if err != nil {
return err
}
*thermalsubsystem = ThermalSubsystem(t.temp)
// Extract the links to other entities for later
thermalsubsystem.coolantConnectors = t.CoolantConnectors.String()
thermalsubsystem.fans = t.Fans.String()
thermalsubsystem.heaters = t.Heaters.String()
thermalsubsystem.leakDetection = t.LeakDetection.String()
thermalsubsystem.pumps = t.Pumps.String()
thermalsubsystem.thermalMetrics = t.ThermalMetrics.String()
return nil
}
// CoolantConnectors gets the coolant connectors for this equipment.
func (thermalsubsystem *ThermalSubsystem) CoolantConnectors() ([]*CoolantConnector, error) {
return ListReferencedCoolantConnectors(thermalsubsystem.GetClient(), thermalsubsystem.coolantConnectors)
}
// Fans gets the fans for this equipment.
func (thermalsubsystem *ThermalSubsystem) Fans() ([]*Fan, error) {
return ListReferencedFans(thermalsubsystem.GetClient(), thermalsubsystem.fans)
}
// Heaters gets the heaters within this subsystem.
func (thermalsubsystem *ThermalSubsystem) Heaters() ([]*Heater, error) {
return ListReferencedHeaters(thermalsubsystem.GetClient(), thermalsubsystem.heaters)
}
// LeakDetection gets the leak detection system within this chassis.
func (thermalsubsystem *ThermalSubsystem) LeakDetection() ([]*LeakDetection, error) {
return ListReferencedLeakDetections(thermalsubsystem.GetClient(), thermalsubsystem.leakDetection)
}
// Pumps gets the pumps for this equipment.
func (thermalsubsystem *ThermalSubsystem) Pumps() ([]*Pump, error) {
return ListReferencedPumps(thermalsubsystem.GetClient(), thermalsubsystem.pumps)
}
// ThermalMetrics gets the summary of thermal metrics for this subsystem.
func (thermalsubsystem *ThermalSubsystem) ThermalMetrics() (*ThermalMetrics, error) {
if thermalsubsystem.thermalMetrics == "" {
return nil, nil
}
return GetThermalMetrics(thermalsubsystem.GetClient(), thermalsubsystem.thermalMetrics)
}
// GetThermalSubsystem will get a ThermalSubsystem instance from the service.
func GetThermalSubsystem(c common.Client, uri string) (*ThermalSubsystem, error) {
resp, err := c.Get(uri)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var thermalsubsystem ThermalSubsystem
err = json.NewDecoder(resp.Body).Decode(&thermalsubsystem)
if err != nil {
return nil, err
}
thermalsubsystem.SetClient(c)
return &thermalsubsystem, nil
}
// ListReferencedThermalSubsystems gets the collection of ThermalSubsystem from
// a provided reference.
func ListReferencedThermalSubsystems(c common.Client, link string) ([]*ThermalSubsystem, error) {
var result []*ThermalSubsystem
if link == "" {
return result, nil
}
type GetResult struct {
Item *ThermalSubsystem
Link string
Error error
}
ch := make(chan GetResult)
collectionError := common.NewCollectionError()
get := func(link string) {
thermalsubsystem, err := GetThermalSubsystem(c, link)
ch <- GetResult{Item: thermalsubsystem, Link: link, Error: err}
}
go func() {
err := common.CollectList(get, c, link)
if err != nil {
collectionError.Failures[link] = err
}
close(ch)
}()
for r := range ch {
if r.Error != nil {
collectionError.Failures[r.Link] = r.Error
} else {
result = append(result, r.Item)
}
}
if collectionError.Empty() {
return result, nil
}
return result, collectionError
}