forked from stmcginnis/gofish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheater.go
203 lines (178 loc) · 7.69 KB
/
heater.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
//
// SPDX-License-Identifier: BSD-3-Clause
//
package redfish
import (
"encoding/json"
"reflect"
"github.com/stmcginnis/gofish/common"
)
// Heater shall represent the management properties for monitoring and management of heaters for a Redfish
// implementation.
type Heater 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"`
// Assembly shall contain a link to a resource of type Assembly.
assembly string
// Description provides a description of this resource.
Description string
// HotPluggable shall indicate whether the device can be inserted or removed while the underlying equipment
// otherwise remains in its current operational state. Hot-pluggable devices can become operable without altering
// the operational state of the underlying equipment. Devices that cannot be inserted or removed from equipment in
// operation, or devices that cannot become operable without affecting the operational state of that equipment,
// shall not be hot-pluggable.
HotPluggable bool
// Location shall contain the location information of this heater.
Location common.Location
// LocationIndicatorActive shall contain the state of the indicator used to physically identify or locate this
// resource.
LocationIndicatorActive bool
// Manufacturer shall contain the name of the organization responsible for producing the heater. This organization
// may be the entity from whom the heater is purchased, but this is not necessarily true.
Manufacturer string
// Metrics shall contain a link to a resource of type HeaterMetrics.
metrics string
// Model shall contain the model information as defined by the manufacturer for this heater.
Model 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"`
// PartNumber shall contain the part number as defined by the manufacturer for this heater.
PartNumber string
// PhysicalContext shall contain a description of the affected device or region within the chassis with which this
// heater is associated.
PhysicalContext PhysicalContext
// SerialNumber shall contain the serial number as defined by the manufacturer for this heater.
SerialNumber string
// SparePartNumber shall contain the spare or replacement part number as defined by the manufacturer for this
// heater.
SparePartNumber string
// Status shall contain any status or health properties of the resource.
Status common.Status
// rawData holds the original serialized JSON so we can compare updates.
rawData []byte
managers []string
// ManagersCount gets the number of managers for this heater.
ManagersCount int
memory []string
// MemoryCount gets the number of memory units associated with this heater.
MemoryCount int
networkAdapters []string
// NetworkAdaptersCount gets the number of network adapters associated with this heater.
NetworkAdaptersCount int
processors []string
// ProcessorsCount gets the number of processors associated with this heater.
ProcessorsCount int
storageControllers []string
// StorageControllersCount gets the number of storage controllers associated with this heater.
StorageControllersCount int
}
// UnmarshalJSON unmarshals a Heater object from the raw JSON.
func (heater *Heater) UnmarshalJSON(b []byte) error {
type temp Heater
type Links struct {
// Managers shall contain an array of links to the managers which this heater heats.
Managers common.Links
ManagersCount int `json:"[email protected]"`
// Memory shall contain an array of links to the memory devices which this heater heats.
Memory common.Links
MemoryCount int `json:"[email protected]"`
// NetworkAdapters shall contain an array of links to the network adapters which this heater heats.
NetworkAdapters common.Links
NetworkAdaptersCount int `json:"[email protected]"`
// Processors shall contain an array of links to the processors which this heater heats.
Processors common.Links
ProcessorsCount int `json:"[email protected]"`
// StorageControllers shall contain an array of links to the storage controllers which this heater heats.
StorageControllers common.Links
StorageControllersCount int `json:"[email protected]"`
}
var t struct {
temp
Assembly common.Link
Metrics common.Link
Links Links
}
err := json.Unmarshal(b, &t)
if err != nil {
return err
}
*heater = Heater(t.temp)
// Extract the links to other entities for later
heater.assembly = t.Assembly.String()
heater.metrics = t.Metrics.String()
heater.managers = t.Links.Managers.ToStrings()
heater.ManagersCount = t.Links.ManagersCount
heater.memory = t.Links.Memory.ToStrings()
heater.MemoryCount = t.Links.MemoryCount
heater.networkAdapters = t.Links.NetworkAdapters.ToStrings()
heater.NetworkAdaptersCount = t.Links.NetworkAdaptersCount
heater.processors = t.Links.Processors.ToStrings()
heater.ProcessorsCount = t.Links.ProcessorsCount
heater.storageControllers = t.Links.StorageControllers.ToStrings()
heater.StorageControllersCount = t.Links.StorageControllersCount
// This is a read/write object, so we need to save the raw object data for later
heater.rawData = b
return nil
}
// Assembly gets the assembly for this heater.
func (heater *Heater) Assembly() (*Assembly, error) {
if heater.assembly == "" {
return nil, nil
}
return GetAssembly(heater.GetClient(), heater.assembly)
}
// Managers gets the managers for this heater.
func (heater *Heater) Managers() ([]*Manager, error) {
return common.GetObjects[Manager](heater.GetClient(), heater.managers)
}
// Memory gets the memory associated with this heater.
func (heater *Heater) Memory() ([]*Memory, error) {
return common.GetObjects[Memory](heater.GetClient(), heater.memory)
}
// NetworkAdapters gets the network adapters associated with this heater.
func (heater *Heater) NetworkAdapters() ([]*NetworkAdapter, error) {
return common.GetObjects[NetworkAdapter](heater.GetClient(), heater.networkAdapters)
}
// Processors gets this heater's processors.
func (heater *Heater) Processors() ([]*Processor, error) {
return common.GetObjects[Processor](heater.GetClient(), heater.processors)
}
// StorageControllers gets the storage controllers associated with this heater.
func (heater *Heater) StorageControllers() ([]*StorageController, error) {
return common.GetObjects[StorageController](heater.GetClient(), heater.storageControllers)
}
// Metrics gets the heater metrics for this heater.
func (heater *Heater) Metrics() (*HeaterMetrics, error) {
if heater.metrics == "" {
return nil, nil
}
return GetHeaterMetrics(heater.GetClient(), heater.metrics)
}
// Update commits updates to this object's properties to the running system.
func (heater *Heater) Update() error {
// Get a representation of the object's original state so we can find what
// to update.
original := new(Heater)
original.UnmarshalJSON(heater.rawData)
readWriteFields := []string{
"LocationIndicatorActive",
}
originalElement := reflect.ValueOf(original).Elem()
currentElement := reflect.ValueOf(heater).Elem()
return heater.Entity.Update(originalElement, currentElement, readWriteFields)
}
// GetHeater will get a Heater instance from the service.
func GetHeater(c common.Client, uri string) (*Heater, error) {
return common.GetObject[Heater](c, uri)
}
// ListReferencedHeaters gets the collection of Heater from
// a provided reference.
func ListReferencedHeaters(c common.Client, link string) ([]*Heater, error) {
return common.GetCollectionObjects[Heater](c, link)
}