forked from stmcginnis/gofish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
serviceroot.go
288 lines (262 loc) · 11.2 KB
/
serviceroot.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
//
// SPDX-License-Identifier: BSD-3-Clause
//
package gofish
import (
"encoding/json"
"github.com/stmcginnis/gofish/common"
"github.com/stmcginnis/gofish/redfish"
"github.com/stmcginnis/gofish/swordfish"
)
// Expand shall contain information about the support of the $expand query
// parameter by the service.
type Expand struct {
// ExpandAll shall be a boolean indicating whether this service supports the
// use of asterisk (expand all entries) as a value for the $expand query
// parameter as described by the specification.
ExpandAll bool
// Levels shall be a boolean indicating whether this service supports the
// use of $levels as a value for the $expand query parameter as described by
// the specification.
Levels bool
// Links shall be a boolean indicating whether this service supports the use
// of tilde (expand only entries in the Links section) as a value for the
// $expand query parameter as described by the specification.
Links bool
// MaxLevels shall be the maximum value of the $levels qualifier supported
// by the service and shall only be included if the value of the Levels
// property is true.
MaxLevels int
// NoLinks shall be a boolean indicating whether this service supports the
// use of period (expand only entries not in the Links section) as a value
// for the $expand query parameter as described by the specification.
NoLinks bool
}
// ProtocolFeaturesSupported contains information about protocol features
// supported by the service.
type ProtocolFeaturesSupported struct {
// ExcerptQuery shall be a boolean indicating whether this service supports
// the use of the 'excerpt' query parameter as described by the
// specification.
ExcerptQuery bool
// ExpandQuery shall contain information about the support of the $expand
// query parameter by the service.
ExpandQuery Expand
// FilterQuery shall be a boolean indicating whether this service supports
// the use of the $filter query parameter as described by the specification.
FilterQuery bool
// OnlyMemberQuery shall be a boolean indicating whether this service
// supports the use of the 'only' query parameter as described by the
// specification.
OnlyMemberQuery bool
// SelectQuery shall be a boolean indicating whether this service supports
// the use of the $select query parameter as described by the specification.
SelectQuery bool
}
// Service represents the root Redfish service. All values for resources
// described by this schema shall comply to the requirements as described in the
// Redfish specification.
type Service struct {
common.Entity
// ODataContext is the odata context.
ODataContext string `json:"@odata.context"`
// ODataEtag is the odata etag.
ODataEtag string `json:"@odata.etag"`
// ODataID is the odata identifier.
ODataID string `json:"@odata.id"`
// ODataType is the odata type.
ODataType string `json:"@odata.type"`
// AccountService shall only contain a reference to a resource that complies
// to the AccountService schema.
accountService string
// CertificateService shall be a link to the CertificateService.
certificateService string
// Chassis shall only contain a reference to a collection of resources that
// comply to the Chassis schema.
chassis string
// CompositionService shall only contain a reference to a resource that
// complies to the CompositionService schema.
compositionService string
// Description provides a description of this resource.
Description string
// EventService shall only contain a reference to a resource that complies
// to the EventService schema.
eventService string
// Fabrics shall contain references to all Fabric instances.
fabrics string
// JobService shall only contain a reference to a resource that conforms to
// the JobService schema.
jobService string
// JsonSchemas shall only contain a reference to a collection of resources
// that comply to the SchemaFile schema where the files are Json-Schema
// files.
jsonSchemas string
// Managers shall only contain a reference to a collection of resources that
// comply to the Managers schema.
managers string
// Product shall include the name of the product represented by this Redfish
// service.
Product string
// ProtocolFeaturesSupported contains information about protocol features
// supported by the service.
ProtocolFeaturesSupported ProtocolFeaturesSupported
// RedfishVersion shall represent the version of the Redfish service. The
// format of this string shall be of the format
// majorversion.minorversion.errata in compliance with Protocol Version
// section of the Redfish specification.
RedfishVersion string
// Registries shall contain a reference to Message Registry.
registries string
// ResourceBlocks shall contain references to all Resource Block instances.
resourceBlocks string
// SessionService shall only contain a reference to a resource that complies
// to the SessionService schema.
sessionService string
// StorageServices shall contain references to all StorageService instances.
storageServices string
// StorageSystems shall contain computer systems that act as storage
// servers. The HostingRoles attribute of each such computer system shall
// have an entry for StorageServer.
storageSystems string
// Systems shall only contain a reference to a collection of resources that
// comply to the Systems schema.
systems string
// Tasks shall only contain a reference to a resource that complies to the
// TaskService schema.
tasks string
// TelemetryService shall be a link to the TelemetryService.
telemetryService string
// UUID shall be an exact match of the UUID value returned in a 200OK from
// an SSDP M-SEARCH request during discovery. RFC4122 describes methods that
// can be used to create a UUID value. The value should be considered to be
// opaque. Client software should only treat the overall value as a
// universally unique identifier and should not interpret any sub-fields
// within the UUID.
UUID string
// UpdateService shall only contain a reference to a resource that complies
// to the UpdateService schema.
updateService string
// Vendor shall include the name of the manufacturer or vendor represented
// by this Redfish service. If this property is supported, the vendor name
// shall not be included in the value of the Product property.
Vendor string
// Sessions shall contain the link to a collection of Sessions.
sessions string
}
// UnmarshalJSON unmarshals a Service object from the raw JSON.
func (serviceroot *Service) UnmarshalJSON(b []byte) error {
type temp Service
var t struct {
temp
CertificateService common.Link
Chassis common.Link
Managers common.Link
Tasks common.Link
StorageServices common.Link
StorageSystems common.Link
AccountService common.Link
EventService common.Link
Registries common.Link
Systems common.Link
CompositionService common.Link
Fabrics common.Link
JobService common.Link
JSONSchemas common.Link `json:"JsonSchemas"`
ResourceBlocks common.Link
SessionService common.Link
TelemetryService common.Link
UpdateService common.Link
Links struct {
Sessions common.Link
}
}
err := json.Unmarshal(b, &t)
if err != nil {
return err
}
// Extract the links to other entities for later
*serviceroot = Service(t.temp)
serviceroot.certificateService = string(t.CertificateService)
serviceroot.chassis = string(t.Chassis)
serviceroot.managers = string(t.Managers)
serviceroot.tasks = string(t.Tasks)
serviceroot.sessions = string(t.Links.Sessions)
serviceroot.storageServices = string(t.StorageServices)
serviceroot.storageSystems = string(t.StorageSystems)
serviceroot.accountService = string(t.AccountService)
serviceroot.eventService = string(t.EventService)
serviceroot.registries = string(t.Registries)
serviceroot.systems = string(t.Systems)
serviceroot.compositionService = string(t.CompositionService)
serviceroot.fabrics = string(t.Fabrics)
serviceroot.jobService = string(t.JobService)
serviceroot.jsonSchemas = string(t.JSONSchemas)
serviceroot.resourceBlocks = string(t.ResourceBlocks)
serviceroot.sessionService = string(t.SessionService)
serviceroot.telemetryService = string(t.TelemetryService)
serviceroot.updateService = string(t.UpdateService)
return nil
}
// ServiceRoot will get a Service instance from the service.
func ServiceRoot(c common.Client) (*Service, error) {
resp, err := c.Get(common.DefaultServiceRoot)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var serviceroot Service
err = json.NewDecoder(resp.Body).Decode(&serviceroot)
if err != nil {
return nil, err
}
serviceroot.SetClient(c)
return &serviceroot, nil
}
// Chassis gets the chassis instances managed by this service.
func (serviceroot *Service) Chassis() ([]*redfish.Chassis, error) {
return redfish.ListReferencedChassis(serviceroot.Client, serviceroot.chassis)
}
// Managers gets the manager instances of this service.
func (serviceroot *Service) Managers() ([]*redfish.Manager, error) {
return redfish.ListReferencedManagers(serviceroot.Client, serviceroot.managers)
}
// StorageSystems gets the storage system instances managed by this service.
func (serviceroot *Service) StorageSystems() ([]*swordfish.StorageSystem, error) {
return swordfish.ListReferencedStorageSystems(serviceroot.Client, serviceroot.storageSystems)
}
// StorageServices gets the Swordfish storage services
func (serviceroot *Service) StorageServices() ([]*swordfish.StorageService, error) {
return swordfish.ListReferencedStorageServices(serviceroot.Client, serviceroot.storageServices)
}
// Tasks gets the system's tasks
func (serviceroot *Service) Tasks() ([]*redfish.Task, error) {
return redfish.ListReferencedTasks(serviceroot.Client, serviceroot.tasks)
}
// CreateSession creates a new session and returns the token and id
func (serviceroot *Service) CreateSession(username string, password string) (*redfish.AuthToken, error) {
return redfish.CreateSession(serviceroot.Client, serviceroot.sessions, username, password)
}
// Sessions gets the system's active sessions
func (serviceroot *Service) Sessions() ([]*redfish.Session, error) {
return redfish.ListReferencedSessions(serviceroot.Client, serviceroot.sessions)
}
// DeleteSession logout the specified session
func (serviceroot *Service) DeleteSession(url string) error {
return redfish.DeleteSession(serviceroot.Client, url)
}
// AccountService gets the Redfish AccountService
func (serviceroot *Service) AccountService() (*redfish.AccountService, error) {
return redfish.GetAccountService(serviceroot.Client, serviceroot.accountService)
}
// EventService gets the Redfish EventService
func (serviceroot *Service) EventService() (*redfish.EventService, error) {
return redfish.GetEventService(serviceroot.Client, serviceroot.eventService)
}
// Systems get the system instances from the service
func (serviceroot *Service) Systems() ([]*redfish.ComputerSystem, error) {
return redfish.ListReferencedComputerSystems(serviceroot.Client, serviceroot.systems)
}
// CompositionService gets the composition service instance
func (serviceroot *Service) CompositionService() (*redfish.CompositionService, error) {
return redfish.GetCompositionService(serviceroot.Client, serviceroot.compositionService)
}