-
Notifications
You must be signed in to change notification settings - Fork 3
/
rfservices.go
369 lines (320 loc) · 11.3 KB
/
rfservices.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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
// 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 (
//"bytes"
"encoding/json"
//base "github.com/Cray-HPE/hms-base"
//"io/ioutil"
//"path"
//"strings"
//"time"
)
/////////////////////////////////////////////////////////////////////////////
//
// Redfish service discovery
//
/////////////////////////////////////////////////////////////////////////////
// Struct to be embedded in Redfish service objects. These are the
// key fields in the storage schema.
type ServiceDescription struct {
RfEndpointID string `json:"RedfishEndpointID"` // Key
RedfishType string `json:"RedfishType"` // Key
RedfishSubtype string `json:"RedfishSubtype,omitempty"`
UUID string `json:"UUID"`
OdataID string `json:"OdataID"`
}
// This is the AccountService for the corresponding RedfishEP
type EpAccountService struct {
// Embedded struct: id, type, odataID and associated RfEndpointID.
ServiceDescription
AccountServiceURL string `json:"accountServiceURL"` // Full URL to this svc
RootFQDN string `json:"rootFQDN"` // i.e. for epRF
RootHostname string `json:"rootHostname"`
RootDomain string `json:"rootDomain"`
LastStatus string `json:"lastStatus"`
AccountServiceRF AccountService `json:"accountServiceRF"`
accountServiceURLRaw *json.RawMessage // `json:"AccountServiceURLRaw"`
epRF *RedfishEP // Backpointer, for connection details, etc.
}
// Create new struct to discover the AccountService for this RedfishEP
func NewEpAccountService(epRF *RedfishEP, odataID string) *EpAccountService {
s := new(EpAccountService)
s.OdataID = odataID
s.RfEndpointID = epRF.ID
s.RedfishType = AccountServiceType
s.LastStatus = NotYetQueried
s.epRF = epRF
return s
}
// Contact RedfishEP and discover properties of the AccountService
func (s *EpAccountService) discoverRemotePhase1() {
// Should never happen
if s.epRF == nil {
errlog.Printf("Error: RedfishEP == nil for AccountService odataID: %s\n",
s.OdataID)
s.LastStatus = EndpointInvalid
return
}
s.AccountServiceURL = s.epRF.FQDN + s.OdataID
s.RootFQDN = s.epRF.FQDN
s.RootHostname = s.epRF.Hostname
s.RootDomain = s.epRF.Domain
path := s.OdataID
svcURLJSON, err := s.epRF.GETRelative(path)
if err != nil || svcURLJSON == nil {
errlog.Println(err)
s.LastStatus = HTTPsGetFailed
return
}
if rfDebug > 0 {
errlog.Printf("%s: %s\n", s.epRF.FQDN+path, svcURLJSON)
}
s.accountServiceURLRaw = &svcURLJSON
s.LastStatus = HTTPsGetOk
// Decode Raw JSON into AccountService Go struct
if err := json.Unmarshal(svcURLJSON, &s.AccountServiceRF); err != nil {
errlog.Printf("Bad Decode: %s: %s\n", s.RootFQDN+path, err)
s.LastStatus = EPResponseFailedDecode
return
}
}
// This is the SessionService for the corresponding RedfishEP
type EpSessionService struct {
// Embedded struct: id, type, odataID and associated RfEndpointID.
ServiceDescription
SessionServiceURL string `json:"sessionServiceURL"` // Full URL to this svc
RootFQDN string `json:"rootFQDN"` // i.e. for epRF
RootHostname string `json:"rootHostname"`
RootDomain string `json:"rootDomain"`
LastStatus string `json:"lastStatus"`
SessionServiceRF SessionService `json:"sessionServiceRF"`
sessionServiceURLRaw *json.RawMessage // `json:"sessionServiceURLRaw"`
epRF *RedfishEP // Backpointer, for connection details, etc.
}
// Create new struct to discover the SessionService for this RedfishEP
func NewEpSessionService(epRF *RedfishEP, odataID string) *EpSessionService {
s := new(EpSessionService)
s.OdataID = odataID
s.RfEndpointID = epRF.ID
s.RedfishType = SessionServiceType
s.LastStatus = NotYetQueried
s.epRF = epRF
return s
}
// Contact RedfishEP and discover properties of the SessionService
func (s *EpSessionService) discoverRemotePhase1() {
// Should never happen
if s.epRF == nil {
errlog.Printf("Error: RedfishEP == nil for SessionService odataID: %s\n",
s.OdataID)
s.LastStatus = EndpointInvalid
return
}
s.SessionServiceURL = s.epRF.FQDN + s.OdataID
s.RootFQDN = s.epRF.FQDN
s.RootHostname = s.epRF.Hostname
s.RootDomain = s.epRF.Domain
path := s.OdataID
svcURLJSON, err := s.epRF.GETRelative(path)
if err != nil || svcURLJSON == nil {
errlog.Println(err)
s.LastStatus = HTTPsGetFailed
return
}
if rfDebug > 0 {
errlog.Printf("%s: %s\n", s.epRF.FQDN+path, svcURLJSON)
}
s.sessionServiceURLRaw = &svcURLJSON
s.LastStatus = HTTPsGetOk
// Decode Raw JSON into AccountService Go struct
if err := json.Unmarshal(svcURLJSON, &s.SessionServiceRF); err != nil {
errlog.Printf("Bad Decode: %s: %s\n", s.RootFQDN+path, err)
s.LastStatus = EPResponseFailedDecode
return
}
}
// This is the EventService for the corresponding RedfishEP
type EpEventService struct {
// Embedded struct: id, type, odataID and associated RfEndpointID.
ServiceDescription
EventServiceURL string `json:"eventServiceURL"` // Full URL to this svc
RootFQDN string `json:"rootFQDN"` // i.e. for epRF
RootHostname string `json:"rootHostname"`
RootDomain string `json:"rootDomain"`
LastStatus string `json:"lastStatus"`
EventServiceRF EventService `json:"eventServiceRF"`
eventServiceURLRaw *json.RawMessage // `json:"eventServiceURLRaw"`
epRF *RedfishEP // Backpointer, for connection details, etc.
}
// Create new struct to discover the EventService for this RedfishEP
func NewEpEventService(epRF *RedfishEP, odataID string) *EpEventService {
s := new(EpEventService)
s.OdataID = odataID
s.RfEndpointID = epRF.ID
s.RedfishType = EventServiceType
s.LastStatus = NotYetQueried
s.epRF = epRF
return s
}
// Contact RedfishEP and discover properties of the EventService
func (s *EpEventService) discoverRemotePhase1() {
// Should never happen
if s.epRF == nil {
errlog.Printf("Error: RedfishEP == nil for EventService odataID: %s\n",
s.OdataID)
s.LastStatus = EndpointInvalid
return
}
s.EventServiceURL = s.epRF.FQDN + s.OdataID
s.RootFQDN = s.epRF.FQDN
s.RootHostname = s.epRF.Hostname
s.RootDomain = s.epRF.Domain
path := s.OdataID
svcURLJSON, err := s.epRF.GETRelative(path)
if err != nil || svcURLJSON == nil {
errlog.Println(err)
s.LastStatus = HTTPsGetFailed
return
}
if rfDebug > 0 {
errlog.Printf("%s: %s\n", s.epRF.FQDN+path, svcURLJSON)
}
s.eventServiceURLRaw = &svcURLJSON
s.LastStatus = HTTPsGetOk
// Decode Raw JSON into AccountService Go struct
if err := json.Unmarshal(svcURLJSON, &s.EventServiceRF); err != nil {
errlog.Printf("Bad Decode: %s: %s\n", s.RootFQDN+path, err)
s.LastStatus = EPResponseFailedDecode
return
}
}
// This is the TaskService for the corresponding RedfishEP
type EpTaskService struct {
// Embedded struct: id, type, odataID and associated RfEndpointID.
ServiceDescription
TaskServiceURL string `json:"taskServiceURL"` // Full URL to this svc
RootFQDN string `json:"rootFQDN"` // i.e. for epRF
RootHostname string `json:"rootHostname"`
RootDomain string `json:"rootDomain"`
LastStatus string `json:"lastStatus"`
TaskServiceRF TaskService `json:"taskServiceRF"`
taskServiceURLRaw *json.RawMessage // `json:"taskServiceURLRaw"`
epRF *RedfishEP // Backpointer, for connection details, etc.
}
// Create new struct to discover the TaskService for this RedfishEP
func NewEpTaskService(epRF *RedfishEP, odataID string) *EpTaskService {
s := new(EpTaskService)
s.OdataID = odataID
s.RfEndpointID = epRF.ID
s.RedfishType = TaskServiceType
s.LastStatus = NotYetQueried
s.epRF = epRF
return s
}
// Contact RedfishEP and discover properties of the TaskService
func (s *EpTaskService) discoverRemotePhase1() {
// Should never happen
if s.epRF == nil {
errlog.Printf("Error: RedfishEP == nil for TaskService odataID: %s\n",
s.OdataID)
s.LastStatus = EndpointInvalid
return
}
s.TaskServiceURL = s.epRF.FQDN + s.OdataID
s.RootFQDN = s.epRF.FQDN
s.RootHostname = s.epRF.Hostname
s.RootDomain = s.epRF.Domain
path := s.OdataID
svcURLJSON, err := s.epRF.GETRelative(path)
if err != nil || svcURLJSON == nil {
errlog.Println(err)
s.LastStatus = HTTPsGetFailed
return
}
if rfDebug > 0 {
errlog.Printf("%s: %s\n", s.epRF.FQDN+path, svcURLJSON)
}
s.taskServiceURLRaw = &svcURLJSON
s.LastStatus = HTTPsGetOk
// Decode Raw JSON into AccountService Go struct
if err := json.Unmarshal(svcURLJSON, &s.TaskServiceRF); err != nil {
errlog.Printf("Bad Decode: %s: %s\n", s.RootFQDN+path, err)
s.LastStatus = EPResponseFailedDecode
return
}
}
// This is the UpdateService for the corresponding RedfishEP
type EpUpdateService struct {
// Embedded struct: id, type, odataID and associated RfEndpointID.
ServiceDescription
UpdateServiceURL string `json:"updateServiceURL"` // Full URL to this svc
RootFQDN string `json:"rootFQDN"` // i.e. for epRF
RootHostname string `json:"rootHostname"`
RootDomain string `json:"rootDomain"`
LastStatus string `json:"lastStatus"`
UpdateServiceRF UpdateService `json:"updateServiceRF"`
updateServiceURLRaw *json.RawMessage // `json:"eventServiceURLRaw"`
epRF *RedfishEP // Backpointer, for connection details, etc.
}
// Create new struct to discover the UpdateService for this RedfishEP
func NewEpUpdateService(epRF *RedfishEP, odataID string) *EpUpdateService {
s := new(EpUpdateService)
s.OdataID = odataID
s.RfEndpointID = epRF.ID
s.RedfishType = UpdateServiceType
s.LastStatus = NotYetQueried
s.epRF = epRF
return s
}
// Contact RedfishEP and discover properties of the UpdateService
func (s *EpUpdateService) discoverRemotePhase1() {
// Should never happen
if s.epRF == nil {
errlog.Printf("Error: RedfishEP == nil for UpdateService odataID: %s\n",
s.OdataID)
s.LastStatus = EndpointInvalid
return
}
s.UpdateServiceURL = s.epRF.FQDN + s.OdataID
s.RootFQDN = s.epRF.FQDN
s.RootHostname = s.epRF.Hostname
s.RootDomain = s.epRF.Domain
path := s.OdataID
svcURLJSON, err := s.epRF.GETRelative(path)
if err != nil || svcURLJSON == nil {
errlog.Println(err)
s.LastStatus = HTTPsGetFailed
return
}
if rfDebug > 0 {
errlog.Printf("%s: %s\n", s.epRF.FQDN+path, svcURLJSON)
}
s.updateServiceURLRaw = &svcURLJSON
s.LastStatus = HTTPsGetOk
// Decode Raw JSON into UpdateService Go struct
if err := json.Unmarshal(svcURLJSON, &s.UpdateServiceRF); err != nil {
errlog.Printf("Bad Decode: %s: %s\n", s.RootFQDN+path, err)
s.LastStatus = EPResponseFailedDecode
return
}
}