-
Notifications
You must be signed in to change notification settings - Fork 4
/
rfcomponents-assembly.go
295 lines (254 loc) · 10.2 KB
/
rfcomponents-assembly.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
// MIT License
//
// (C) Copyright [2019-2021] Hewlett Packard Enterprise Development LP
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
package rf
import (
"encoding/json"
"fmt"
base "github.com/Cray-HPE/hms-base"
)
/////////////////////////////////////////////////////////////////////////////
// Chassis - Assembly
/////////////////////////////////////////////////////////////////////////////
// This is the top-level Assembly object for a particular Chassis.
type EpAssembly struct {
// Embedded struct: id, type, odataID and associated RfEndpointID.
ComponentDescription
BaseOdataID string `json:"BaseOdataID"`
InventoryData
AssemblyURL string `json:"assemblyURL"` // Full URL to this RF Assembly obj
ParentOID string `json:"parentOID"` // odata.id for parent
ParentType string `json:"parentType"` // Chassis
LastStatus string `json:"LastStatus"`
AssemblyRF Assembly `json:"AssemblyRF"`
AssemblyRaw *json.RawMessage
systemRF *EpSystem // Backpointer to associated system.
epRF *RedfishEP // Backpointer to RF EP, for connection details, etc.
}
// Initializes EpAssembly struct with minimal information needed to
// pass along to its children.
func NewEpAssembly(s *EpSystem, odataID ResourceID, pOID, pType string) *EpAssembly {
a := new(EpAssembly)
a.OdataID = odataID.Oid
a.Type = AssemblyType
a.BaseOdataID = odataID.Basename()
a.RedfishType = AssemblyType
a.RfEndpointID = s.epRF.ID
a.AssemblyURL = s.epRF.FQDN + odataID.Oid
a.ParentOID = pOID
a.ParentType = pType
a.LastStatus = NotYetQueried
a.systemRF = s
a.epRF = s.epRF
return a
}
// Makes contact with redfish endpoint to discover information about
// the Assembly object under a Chassis. Note that the
// EpAssembly should be created with the appropriate constructor first.
func (a *EpAssembly) discoverRemotePhase1() {
path := a.OdataID
url := a.epRF.FQDN + path
assemblyJSON, err := a.epRF.GETRelative(path)
if err != nil || assemblyJSON == nil {
a.LastStatus = HTTPsGetFailed
return
}
if rfDebug > 0 {
errlog.Printf("%s: %s\n", url, assemblyJSON)
}
a.AssemblyRaw = &assemblyJSON
a.LastStatus = HTTPsGetOk
if err := json.Unmarshal(assemblyJSON, &a.AssemblyRF); err != nil {
if IsUnmarshalTypeError(err) {
errlog.Printf("bad field(s) skipped: %s: %s\n", url, err)
} else {
errlog.Printf("ERROR: json decode failed: %s: %s\n", url, err)
a.LastStatus = EPResponseFailedDecode
return
}
}
if rfVerbose > 0 {
jout, _ := json.MarshalIndent(a, "", " ")
errlog.Printf("%s: %s\n", url, jout)
}
a.LastStatus = VerifyingData
}
/////////////////////////////////////////////////////////////////////////////
// Chassis - NodeAccelRisers
/////////////////////////////////////////////////////////////////////////////
// Set of EpNodeAccelRiser, each representing a GPUSubsystem baseboard "NodeAccelRiser"
// listed under a Redfish Chassis.
type EpNodeAccelRisers struct {
Num int `json:"num"`
OIDs map[string]*EpNodeAccelRiser `json:"oids"`
}
// This is one of possibly several NodeAccelRiser cards for a particular
// EpChassis (Redfish "Chassis").
type EpNodeAccelRiser struct {
// Embedded struct: id, type, odataID and associated RfEndpointID.
ComponentDescription
BaseOdataID string `json:"BaseOdataID"`
// Embedded struct - Locational/FRU, state, and status info
InventoryData
NodeAccelRiserURL string `json:"nodeAccelRiserURL"` // Full URL to this RF PowerSupply obj
ParentOID string `json:"parentOID"` // odata.id for parent
ParentType string `json:"parentType"` // Chassis
LastStatus string `json:"LastStatus"`
NodeAccelRiserRF *NodeAccelRiser `json:"NodeAccelRiserRF"`
nodeAccelRiserRaw *json.RawMessage
epRF *RedfishEP // Backpointer to RF EP, for connection details, etc.
systemRF *EpSystem // Backpointer to associated system.
assemblyRF *EpAssembly // Backpointer to parent Assembly obj.
}
// Initializes EpNodeAccelRiser struct with minimal information needed to
// discover it, i.e. endpoint info and the odataID of the NodeAccelRiser to
// look at. This should be the only way this struct is created for
// NodeAccelRiser cards under a chassis.
func NewEpNodeAccelRiser(assembly *EpAssembly, odataID ResourceID, rawOrdinal int) *EpNodeAccelRiser {
ar := new(EpNodeAccelRiser)
ar.OdataID = odataID.Oid
ar.Type = NodeAccelRiserType
ar.BaseOdataID = odataID.Basename()
ar.RedfishType = NodeAccelRiserType
ar.RfEndpointID = assembly.epRF.ID
ar.NodeAccelRiserURL = assembly.epRF.FQDN + odataID.Oid
ar.ParentOID = assembly.OdataID
ar.ParentType = assembly.Type
ar.Ordinal = -1
ar.RawOrdinal = rawOrdinal
ar.LastStatus = NotYetQueried
ar.epRF = assembly.epRF
ar.systemRF = assembly.systemRF
ar.assemblyRF = assembly
return ar
}
// Examines parent Assembly redfish endpoint to discover information about
// all NodeAccelRisers for a given Redfish Chassis. EpNodeAccel entries
// should be created with the appropriate constructor first.
func (rs *EpNodeAccelRisers) discoverRemotePhase1() {
for _, r := range rs.OIDs {
r.discoverRemotePhase1()
}
}
// Retrieves the NodeAccelRF from the parent Assembly.Assemblies array.
func (r *EpNodeAccelRiser) discoverRemotePhase1() {
//Since the parent Assembly obj already has the array of NodeAccelRiser objects
//the NodeAccelRiserRF field for this NodeAccelRiser just needs to be pulled from there
//instead of retrieving it using an HTTP call
if r.assemblyRF.AssemblyRF.Assemblies == nil {
//this is a lookup error
errlog.Printf("%s: No Assemblies array found in Parent.\n", r.OdataID)
r.LastStatus = HTTPsGetFailed
return
}
//If we got this far, then the EpAssembly call to discoverRemotePhase1 was successful
r.LastStatus = HTTPsGetOk
if rfDebug > 0 {
errlog.Printf("%s: %s\n", r.ParentOID, r.assemblyRF.AssemblyRaw)
}
//use r.RawOrdinal as the index to retrieve the NodeAccelRiser entry from the parent Assembly.Assemblies array,
//and assign it to r.NodeAccelRiserRF
if (len(r.assemblyRF.AssemblyRF.Assemblies) > r.RawOrdinal) && (r.assemblyRF.AssemblyRF.Assemblies[r.RawOrdinal] != nil) {
r.NodeAccelRiserRF = r.assemblyRF.AssemblyRF.Assemblies[r.RawOrdinal]
} else {
//this is a lookup error
errlog.Printf("%s: failure retrieving NodeAccelRiser from Assembly.Assemblies[%d].\n", r.OdataID, r.RawOrdinal)
r.LastStatus = HTTPsGetFailed
return
}
r.RedfishSubtype = NodeAccelRiserType
if rfVerbose > 0 {
jout, _ := json.MarshalIndent(r, "", " ")
errlog.Printf("%s: %s\n", r.NodeAccelRiserURL, jout)
}
r.LastStatus = VerifyingData
}
// This is the second discovery phase, after all information from
// the parent system has been gathered. This is not intended to
// be run as a separate step; it is separate because certain discovery
// activities may require that information is gathered for all components
// under the chassis first, so that it is available during later steps.
func (rs *EpNodeAccelRisers) discoverLocalPhase2() error {
var savedError error
for i, r := range rs.OIDs {
r.discoverLocalPhase2()
if r.LastStatus == RedfishSubtypeNoSupport {
errlog.Printf("Key %s: RF NodeAccelRiser type not supported: %s",
i, r.RedfishSubtype)
} else if r.LastStatus != DiscoverOK {
err := fmt.Errorf("Key %s: %s", i, r.LastStatus)
errlog.Printf("NodeAccelRisers discoverLocalPhase2: saw error: %s", err)
savedError = err
}
}
return savedError
}
// Phase2 discovery for an individual NodeAccelRiser. Now that all information
// has been gathered, we can set the remaining fields needed to provide
// HMS with information about where the NodeAccelRiser is located
func (r *EpNodeAccelRiser) discoverLocalPhase2() {
// Should never happen
if r.epRF == nil {
errlog.Printf("Error: RedfishEP == nil for odataID: %s\n",
r.OdataID)
r.LastStatus = EndpointInvalid
return
}
if r.LastStatus != VerifyingData {
return
}
r.Ordinal = r.epRF.getNodeAccelRiserOrdinal(r)
r.Type = r.epRF.getNodeAccelRiserHMSType(r)
r.ID = r.epRF.getNodeAccelRiserHMSID(r, r.Type, r.Ordinal)
if r.NodeAccelRiserRF.Status.State != "Absent" {
r.Status = "Populated"
r.State = base.StatePopulated.String()
r.Flag = base.FlagOK.String()
generatedFRUID, err := GetNodeAccelRiserFRUID(r)
if err != nil {
errlog.Printf("FRUID Error: %s\n", err.Error())
errlog.Printf("Using untrackable FRUID: %s\n", generatedFRUID)
}
r.FRUID = generatedFRUID
} else {
r.Status = "Empty"
r.State = base.StateEmpty.String()
//the state of the component is known (empty), it is not locked, does not have an alert or warning, so therefore Flag defaults to OK.
r.Flag = base.FlagOK.String()
}
// Check if we have something valid to insert into the data store
if (base.GetHMSType(r.ID) == base.NodeAccelRiser) && (r.Type == base.NodeAccelRiser.String()) {
errlog.Printf("NodeAccelRiser discoverLocalPhase2: VALID xname ID ('%s') and Type ('%s') for: %s\n",
r.ID, r.Type, r.NodeAccelRiserURL)
} else {
errlog.Printf("Error: Bad xname ID ('%s') or Type ('%s') for: %s\n",
r.ID, r.Type, r.NodeAccelRiserURL)
r.LastStatus = VerificationFailed
return
}
if rfVerbose > 0 {
jout, _ := json.MarshalIndent(r, "", " ")
errlog.Printf("%s\n", jout)
errlog.Printf("NodeAccelRiser ID: %s\n", r.ID)
errlog.Printf("NodeAccelRiser FRUID: %s\n", r.FRUID)
}
r.LastStatus = DiscoverOK
}