forked from stmcginnis/gofish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfacility.go
313 lines (285 loc) · 13.9 KB
/
facility.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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
//
// SPDX-License-Identifier: BSD-3-Clause
//
package redfish
import (
"encoding/json"
"github.com/stmcginnis/gofish/common"
)
type FacilityType string
const (
// RoomFacilityType A room inside of a building or floor.
RoomFacilityType FacilityType = "Room"
// FloorFacilityType A floor inside of a building.
FloorFacilityType FacilityType = "Floor"
// BuildingFacilityType A structure with a roof and walls.
BuildingFacilityType FacilityType = "Building"
// SiteFacilityType A small area consisting of several buildings.
SiteFacilityType FacilityType = "Site"
)
// Facility shall be used to represent a location containing equipment, such as a room, building, or campus, for a
// Redfish implementation.
type Facility 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"`
// AmbientMetrics shall contain a link to a resource of type EnvironmentMetrics that specifies the outdoor
// environment metrics for this facility.
AmbientMetrics string
// Description provides a description of this resource.
Description string
// EnvironmentMetrics shall contain a link to a resource of type EnvironmentMetrics that specifies the environment
// metrics for this facility.
environmentMetrics string
// FacilityType shall contain the type of location this resource represents.
FacilityType FacilityType
// Location shall contain the location information of the associated facility.
Location common.Location
// PowerDomains shall contain a link to a resource collection of type PowerDomainCollection that contains the power
// domains associated with this facility.
powerDomains string
// Status shall contain any status or health properties of the resource.
Status common.Status
// CDUs shall contain an array of links to resources of type CoolingUnit that represent the coolant distribution
// units in this facility.
cdus []string
// CDUCount is the number of coolant distribution units in this facility.
CDUsCount int
// ContainedByFacility shall contain a link to a resource of type Facility that represents the facility that
// contains this facility.
containedByFacility string
// ContainsChassis shall be an array of links to resources of type Chassis that represent the outermost chassis
// that this facility contains. This array shall only contain chassis instances that do not include a ContainedBy
// property within the Links property. That is, only chassis instances that are not contained by another chassis.
containsChassis []string
// ContainsChassisCount is the number of Chassis that this facility contains.
ContainsChassisCount int
// ContainsFacilities shall be an array of links to resources of type Facility that represent the facilities that
// this facility contains.
containsFacilities []string
// ContainsFacilitiesCount is the number of facilities that this facility contains.
ContainsFacilitiesCount int
// CoolingLoops shall contain an array of links to resources of type CoolingLoop that represent the cooling loops
// in this facility.
coolingLoops []string
// CoolingLoopsCount is the number of cooling loops in this facility.
CoolingLoopsCount int
// ElectricalBuses shall contain an array of links to resources of type PowerDistribution that represent the
// electrical buses in this facility.
electricalBuses []string
// ElectricalBusesCount is the number of electrical buses in this facility.
ElectricalBusesCount int
// FloorPDUs shall be an array of links to resources of type PowerDistribution that represent the floor power
// distribution units in this facility.
floorPDUs []string
// FloorPDUs@odataCount is the number of floor power distribution units in this facility.
FloorPDUsCount int
// ImmersionUnits shall contain an array of links to resources of type CoolingUnit that represent the immersion
// cooling units in this facility.
immersionUnits []string
// ImmersionUnitsCount is the number of immersion cooling units in this facility.
ImmersionUnitsCount int
// ManagedBy shall be an array of links to resources of type Manager that represent the managers that manager this
// facility.
managedBy []string
// ManagedByCount is the number of Managers that manage this facility.
ManagedByCount int
// PowerShelves shall be an array of links to resources of type PowerDistribution that represent the power shelves
// in this facility.
powerShelves []string
// PowerShelvesCount is the number of power shelves in this facility.
PowerShelvesCount int
// RackPDUs shall be an array of links to resources of type PowerDistribution that represent the rack-level power
// distribution units in this facility.
rackPDUs []string
// RackPDUsCount is the number of rack-level power distribution units in this facility.
RackPDUsCount int
// Switchgear shall be an array of links to resources of type PowerDistribution that represent the switchgear in
// this facility.
switchgear []string
// SwitchgearCount is the number of switch gear in this facility.
SwitchgearCount int
// TransferSwitches shall be an array of links to resources of type PowerDistribution that represent the transfer
// switches in this facility.
transferSwitches []string
// TransferSwitchesCount is the number of transfer switches in this community.
TransferSwitchesCount int
}
type facilityLinks struct {
// CDUs shall contain an array of links to resources of type CoolingUnit that represent the coolant distribution
// units in this facility.
CDUs common.Links
CDUsCount int `json:"[email protected]"`
// ContainedByFacility shall contain a link to a resource of type Facility that represents the facility that
// contains this facility.
ContainedByFacility common.Link
// ContainsChassis shall be an array of links to resources of type Chassis that represent the outermost chassis
// that this facility contains. This array shall only contain chassis instances that do not include a ContainedBy
// property within the Links property. That is, only chassis instances that are not contained by another chassis.
ContainsChassis common.Links
ContainsChassisCount int `json:"[email protected]"`
// ContainsFacilities shall be an array of links to resources of type Facility that represent the facilities that
// this facility contains.
ContainsFacilities common.Links
ContainsFacilitiesCount int `json:"[email protected]"`
// CoolingLoops shall contain an array of links to resources of type CoolingLoop that represent the cooling loops
// in this facility.
CoolingLoops common.Links
CoolingLoopsCount int `json:"[email protected]"`
// ElectricalBuses shall contain an array of links to resources of type PowerDistribution that represent the
// electrical buses in this facility.
ElectricalBuses common.Links
ElectricalBusesCount int `json:"[email protected]"`
// FloorPDUs shall be an array of links to resources of type PowerDistribution that represent the floor power
// distribution units in this facility.
FloorPDUs common.Links
FloorPDUsCount int `json:"[email protected]"`
// ImmersionUnits shall contain an array of links to resources of type CoolingUnit that represent the immersion
// cooling units in this facility.
ImmersionUnits common.Links
ImmersionUnitsCount int `json:"[email protected]"`
// ManagedBy shall be an array of links to resources of type Manager that represent the managers that manager this
// facility.
ManagedBy common.Links
ManagedByCount int `json:"[email protected]"`
// PowerShelves shall be an array of links to resources of type PowerDistribution that represent the power shelves
// in this facility.
PowerShelves common.Links
PowerShelvesCount int `json:"[email protected]"`
// RackPDUs shall be an array of links to resources of type PowerDistribution that represent the rack-level power
// distribution units in this facility.
RackPDUs common.Links
RackPDUsCount int `json:"[email protected]"`
// Switchgear shall be an array of links to resources of type PowerDistribution that represent the switchgear in
// this facility.
Switchgear common.Links
SwitchgearCount int `json:"[email protected]"`
// TransferSwitches shall be an array of links to resources of type PowerDistribution that represent the transfer
// switches in this facility.
TransferSwitches common.Links
TransferSwitchesCount int `json:"[email protected]"`
}
// UnmarshalJSON unmarshals a Facility object from the raw JSON.
func (facility *Facility) UnmarshalJSON(b []byte) error {
type temp Facility
var t struct {
temp
EnvironmentMetrics common.Link
PowerDomains common.Link
Links facilityLinks
}
err := json.Unmarshal(b, &t)
if err != nil {
return err
}
*facility = Facility(t.temp)
// Extract the links to other entities for later
facility.environmentMetrics = t.EnvironmentMetrics.String()
facility.powerDomains = t.PowerDomains.String()
facility.cdus = t.Links.CDUs.ToStrings()
facility.CDUsCount = t.Links.CDUsCount
facility.containedByFacility = t.Links.ContainedByFacility.String()
facility.containsChassis = t.Links.ContainsChassis.ToStrings()
facility.ContainsChassisCount = t.Links.ContainsChassisCount
facility.containsFacilities = t.Links.ContainsFacilities.ToStrings()
facility.ContainsFacilitiesCount = t.Links.ContainsFacilitiesCount
facility.coolingLoops = t.Links.CoolingLoops.ToStrings()
facility.CoolingLoopsCount = t.Links.CoolingLoopsCount
facility.electricalBuses = t.Links.ElectricalBuses.ToStrings()
facility.ElectricalBusesCount = t.Links.ElectricalBusesCount
facility.floorPDUs = t.Links.FloorPDUs.ToStrings()
facility.FloorPDUsCount = t.Links.FloorPDUsCount
facility.immersionUnits = t.Links.ImmersionUnits.ToStrings()
facility.ImmersionUnitsCount = t.Links.ImmersionUnitsCount
facility.managedBy = t.Links.ManagedBy.ToStrings()
facility.ManagedByCount = t.Links.ManagedByCount
facility.powerShelves = t.Links.PowerShelves.ToStrings()
facility.PowerShelvesCount = t.Links.PowerShelvesCount
facility.rackPDUs = t.Links.RackPDUs.ToStrings()
facility.RackPDUsCount = t.Links.RackPDUsCount
facility.switchgear = t.Links.Switchgear.ToStrings()
facility.SwitchgearCount = t.Links.SwitchgearCount
facility.transferSwitches = t.Links.TransferSwitches.ToStrings()
facility.TransferSwitchesCount = t.Links.TransferSwitchesCount
return nil
}
// CDUs get the cooling distribution units associated with this facility.
func (facility *Facility) CDUs() ([]*CoolingUnit, error) {
return common.GetObjects[CoolingUnit](facility.GetClient(), facility.cdus)
}
// ContainedByFacility get facility that contains this facility.
func (facility *Facility) ContainedByFacility() (*Facility, error) {
if facility.containedByFacility == "" {
return nil, nil
}
return GetFacility(facility.GetClient(), facility.containedByFacility)
}
// ContainsChassis get the chassis within this facility.
func (facility *Facility) ContainsChassis() ([]*Chassis, error) {
return common.GetObjects[Chassis](facility.GetClient(), facility.containsChassis)
}
// ContainsFacilities get facilities within this facility.
func (facility *Facility) ContainsFacilities() ([]*Facility, error) {
return common.GetObjects[Facility](facility.GetClient(), facility.containsFacilities)
}
// CoolingLoops get cooling loops within this facility.
func (facility *Facility) CoolingLoops() ([]*CoolingLoop, error) {
return common.GetObjects[CoolingLoop](facility.GetClient(), facility.coolingLoops)
}
// ElectricalBuses get electrical buses within this facility.
func (facility *Facility) ElectricalBuses() ([]*PowerDistribution, error) {
return common.GetObjects[PowerDistribution](facility.GetClient(), facility.electricalBuses)
}
// FloorPDUs get floor power distribution units within this facility.
func (facility *Facility) FloorPDUs() ([]*PowerDistribution, error) {
return common.GetObjects[PowerDistribution](facility.GetClient(), facility.floorPDUs)
}
// ImmersionUnits get immersion cooling units within this facility.
func (facility *Facility) ImmersionUnits() ([]*CoolingUnit, error) {
return common.GetObjects[CoolingUnit](facility.GetClient(), facility.immersionUnits)
}
// ManagedBy gets the managers of this facility.
func (facility *Facility) ManagedBy() ([]*Manager, error) {
return common.GetObjects[Manager](facility.GetClient(), facility.managedBy)
}
// PowerShelves get power shelves within this facility.
func (facility *Facility) PowerShelves() ([]*PowerDistribution, error) {
return common.GetObjects[PowerDistribution](facility.GetClient(), facility.powerShelves)
}
// RackPDUs get rack power distribution units within this facility.
func (facility *Facility) RackPDUs() ([]*PowerDistribution, error) {
return common.GetObjects[PowerDistribution](facility.GetClient(), facility.rackPDUs)
}
// Switchgear get switchgear power distribution units within this facility.
func (facility *Facility) Switchgear() ([]*PowerDistribution, error) {
return common.GetObjects[PowerDistribution](facility.GetClient(), facility.switchgear)
}
// TransferSwitches get transfer switches within this facility.
func (facility *Facility) TransferSwitches() ([]*PowerDistribution, error) {
return common.GetObjects[PowerDistribution](facility.GetClient(), facility.transferSwitches)
}
// GetFacility will get a Facility instance from the service.
func GetFacility(c common.Client, uri string) (*Facility, error) {
return common.GetObject[Facility](c, uri)
}
// ListReferencedFacilities gets the collection of Facility from
// a provided reference.
func ListReferencedFacilities(c common.Client, link string) ([]*Facility, error) {
return common.GetCollectionObjects[Facility](c, link)
}