forked from stmcginnis/gofish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
manager.go
466 lines (418 loc) · 17.9 KB
/
manager.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
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
//
// SPDX-License-Identifier: BSD-3-Clause
//
package redfish
import (
"encoding/json"
"fmt"
"reflect"
"github.com/stmcginnis/gofish/common"
)
// CommandConnectTypesSupported is the command connection type.
type CommandConnectTypesSupported string
const (
// SSHCommandConnectTypesSupported The controller supports a Command
// Shell connection using the SSH protocol.
SSHCommandConnectTypesSupported CommandConnectTypesSupported = "SSH"
// TelnetCommandConnectTypesSupported The controller supports a Command
// Shell connection using the Telnet protocol.
TelnetCommandConnectTypesSupported CommandConnectTypesSupported = "Telnet"
// IPMICommandConnectTypesSupported The controller supports a Command
// Shell connection using the IPMI Serial-over-LAN (SOL) protocol.
IPMICommandConnectTypesSupported CommandConnectTypesSupported = "IPMI"
// OemCommandConnectTypesSupported The controller supports a Command
// Shell connection using an OEM-specific protocol.
OemCommandConnectTypesSupported CommandConnectTypesSupported = "Oem"
)
// GraphicalConnectTypesSupported is graphical connection type.
type GraphicalConnectTypesSupported string
const (
// KVMIPGraphicalConnectTypesSupported The controller supports a
// Graphical Console connection using a KVM-IP (redirection of Keyboard,
// Video, Mouse over IP) protocol.
KVMIPGraphicalConnectTypesSupported GraphicalConnectTypesSupported = "KVMIP"
// OemGraphicalConnectTypesSupported The controller supports a Graphical
// Console connection using an OEM-specific protocol.
OemGraphicalConnectTypesSupported GraphicalConnectTypesSupported = "Oem"
)
// UIConsoleInfo contains information about GUI services.
type UIConsoleInfo struct {
ServiceEnabled bool
MaxConcurrentSessions uint
ConnectTypesSupported []string
}
// SerialConsole shall describe a Serial Console service of a manager.
type SerialConsole struct {
// ConnectTypesSupported shall be an array of the enumerations provided
// here. SSH shall be included if the Secure Shell (SSH) protocol is
// supported. Telnet shall be included if the Telnet protocol is supported.
// IPMI shall be included if the IPMI (Serial-over-LAN) protocol is supported.
ConnectTypesSupported []SerialConnectTypesSupported
// MaxConcurrentSessions shall contain the
// maximum number of concurrent service sessions supported by the
// implementation.
MaxConcurrentSessions int
// ServiceEnabled is used for the service. The value shall be true if
// enabled and false if disabled.
ServiceEnabled bool
}
// ManagerType shall describe the function of this manager. The value
// EnclosureManager shall be used if this manager controls one or more services
// through aggregation. The value BMC shall be used if this manager represents a
// traditional server management controller. The value ManagementController
// shall be used if none of the other enumerations apply.
type ManagerType string
const (
// ManagementControllerManagerType A controller used primarily to monitor
// or manage the operation of a device or system.
ManagementControllerManagerType ManagerType = "ManagementController"
// EnclosureManagerManagerType A controller which provides management
// functions for a chassis or group of devices or systems.
EnclosureManagerManagerType ManagerType = "EnclosureManager"
// BMCManagerType A controller which provides management functions for a
// single computer system.
BMCManagerType ManagerType = "BMC"
// RackManagerManagerType A controller which provides management
// functions for a whole or part of a rack.
RackManagerManagerType ManagerType = "RackManager"
// AuxiliaryControllerManagerType A controller which provides management
// functions for a particular subsystem or group of devices.
AuxiliaryControllerManagerType ManagerType = "AuxiliaryController"
// ServiceManagerType A software-based service which provides management
// functions.
ServiceManagerType ManagerType = "Service"
)
// ResetToDefaultsType is the default to set on reset.
type ResetToDefaultsType string
const (
// ResetAllResetToDefaultsType Reset all settings to factory defaults.
ResetAllResetToDefaultsType ResetToDefaultsType = "ResetAll"
// PreserveNetworkAndUsersResetToDefaultsType Reset all settings except
// network and local user names/passwords to factory defaults.
PreserveNetworkAndUsersResetToDefaultsType ResetToDefaultsType = "PreserveNetworkAndUsers"
// PreserveNetworkResetToDefaultsType Reset all settings except network
// settings to factory defaults.
PreserveNetworkResetToDefaultsType ResetToDefaultsType = "PreserveNetwork"
)
// SerialConnectTypesSupported is serial connection type.
type SerialConnectTypesSupported string
const (
// SSHSerialConnectTypesSupported The controller supports a Serial
// Console connection using the SSH protocol.
SSHSerialConnectTypesSupported SerialConnectTypesSupported = "SSH"
// TelnetSerialConnectTypesSupported The controller supports a Serial
// Console connection using the Telnet protocol.
TelnetSerialConnectTypesSupported SerialConnectTypesSupported = "Telnet"
// IPMISerialConnectTypesSupported The controller supports a Serial
// Console connection using the IPMI Serial-over-LAN (SOL) protocol.
IPMISerialConnectTypesSupported SerialConnectTypesSupported = "IPMI"
// OemSerialConnectTypesSupported The controller supports a Serial
// Console connection using an OEM-specific protocol.
OemSerialConnectTypesSupported SerialConnectTypesSupported = "Oem"
)
// CommandShell shall describe a Command Shell service of a manager.
type CommandShell struct {
// ConnectTypesSupported shall be an array of the enumerations provided here.
// SSH shall be included if the Secure Shell (SSH) protocol is supported.
// Telnet shall be included if the Telnet protocol is supported. IPMI shall
// be included if the IPMI (Serial-over-LAN) protocol is supported.
ConnectTypesSupported []CommandConnectTypesSupported
// MaxConcurrentSessions shall contain the maximum number of concurrent
// service sessions supported by the implementation.
MaxConcurrentSessions uint32
// ServiceEnabled is used for the service. The value shall be true if
// enabled and false if disabled.
ServiceEnabled bool
}
// GraphicalConsole shall describe a Graphical Console service of a manager.
type GraphicalConsole struct {
// ConnectTypesSupported shall be an array of the enumerations provided here.
// RDP shall be included if the Remote Desktop (RDP) protocol is supported.
// KVMIP shall be included if a vendor-define KVM-IP protocol is supported.
ConnectTypesSupported []GraphicalConnectTypesSupported
// MaxConcurrentSessions shall contain the maximum number of concurrent
// service sessions supported by the implementation.
MaxConcurrentSessions uint32
// ServiceEnabled is used for the service. The value shall be true if
// enabled and false if disabled.
ServiceEnabled bool
}
// Manager is a management subsystem. Examples of managers are BMCs, Enclosure
// Managers, Management Controllers and other subsystems assigned manageability
// functions.
type Manager struct {
common.Entity
// ODataContext is the odata context.
ODataContext string `json:"@odata.context"`
// ODataType is the odata type.
ODataType string `json:"@odata.type"`
// AutoDSTEnabled shall contain the enabled status of the automatic Daylight
// Saving Time (DST) adjustment of the manager's DateTime. It shall be true
// if Automatic DST adjustment is enabled and false if disabled.
AutoDSTEnabled bool
// CommandShell shall contain information
// about the Command Shell service of this manager.
CommandShell CommandShell
// DateTime shall represent the current DateTime value for the manager, with
// offset from UTC, in Redfish Timestamp format.
DateTime string
// DateTimeLocalOffset is The value is property shall represent the offset
// from UTC time that the current value of DataTime property contains.
DateTimeLocalOffset string
// Description provides a description of this resource.
Description string
// ethernetInterfaces shall be a link to a collection of type
// EthernetInterfaceCollection.
ethernetInterfaces string
// FirmwareVersion shall contain the firmware version as defined by the
// manufacturer for the associated manager.
FirmwareVersion string
// GraphicalConsole shall contain the information about the Graphical
// Console (KVM-IP) service of this manager.
GraphicalConsole GraphicalConsole
// hostInterfaces shall be a link to a collection of type
// HostInterfaceCollection.
hostInterfaces string
// logServices shall contain a reference to a collection of type
// LogServiceCollection which are for the use of this manager.
logServices string
// ManagerType is used if this manager controls one or more services
// through aggregation. The value BMC shall be used if this manager
// represents a traditional server management controller. The value
// ManagementController shall be used if none of the other enumerations
// apply.
ManagerType ManagerType
// Manufacturer shall contain the name of the organization responsible for
// producing the manager. This organization might be the entity from whom
// the manager is purchased, but this is not necessarily true.
Manufacturer string
// Model shall contain the information about how the manufacturer references
// this manager.
Model string
// networkProtocol shall contain a reference to a resource of type
// ManagerNetworkProtocol which represents the network services for this
// manager.
networkProtocol string
// OEMData are all OEM data under top level manager section
OEMData map[string]interface{}
// OEMLinks are all OEM data under link section
OEMLinks map[string]interface{}
// PartNumber shall contain a part number assigned by the organization that
// is responsible for producing or manufacturing the manager.
PartNumber string
// PowerState shall contain the power state of the Manager.
PowerState PowerState
// Redundancy is used to show how this manager is grouped with other
// managers for form redundancy sets.
Redundancy []Redundancy
// RedundancyCount is the number of Redundancy objects.
RedundancyCount int `json:"Redundancy@odata.count"`
// remoteAccountService shall contain a reference to the
// AccountService resource for the remote Manager represented by this
// resource. This property shall only be present when providing
// aggregation of Redfish services.
remoteAccountService string
// RemoteRedfishServiceURI shall contain the URI of the
// Redfish Service Root for the remote Manager represented by this
// resource. This property shall only be present when providing
// aggregation of Redfish services.
RemoteRedfishServiceURI string `json:"RemoteRedfishServiceUri"`
// SerialConsole shall contain information about the Serial Console service
// of this manager.
SerialConsole SerialConsole
// serialInterfaces shall be a link to a collection of type
// SerialInterfaceCollection which are for the use of this manager.
serialInterfaces string
// SerialNumber shall contain a manufacturer-allocated number that
// identifies the manager.
SerialNumber string
// ServiceEntryPointUUID shall contain the UUID of the Redfish Service
// provided by this manager. Each Manager providing an Entry Point to the
// same Redfish Service shall report the same UUID value (even though the
// name of the property may imply otherwise). This property shall not be
// present if this manager does not provide a Redfish Service Entry Point.
ServiceEntryPointUUID string
// Status shall contain any status or health properties
// of the resource.
Status common.Status
// UUID shall contain the universal unique
// identifier number for the manager.
UUID string
// virtualMedia shall contain a reference to a collection of type
// VirtualMediaCollection which are for the use of this manager.
virtualMedia string
// managerForChassis shall contain an array of references to Chassis
// resources of which this Manager instance has control.
managerForChassis []string
// ManagerForChassisCount is the number of Chassis being managed.
ManagerForChassisCount int
// managerForServers shall contain an array of references to ComputerSystem
// resources of which this Manager instance has control.
managerForServers []string
// ManagerForServersCount is the number of Servers being managed.
ManagerForServersCount int
// managerForSwitches shall contain an array of references to Switch
// resources of which this Manager instance has control.
managerForSwitches []string
// ManagerForSwitchesCount is the number of Switches being managed.
ManagerForSwitchesCount int
// managerInChassis shall contain a reference to the chassis that this
// manager is located in.
managerInChassis string
// resetTarget is the internal URL to send reset targets to.
resetTarget string
// SupportedResetTypes, if provided, is the reset types this system supports.
SupportedResetTypes []ResetType
// rawData holds the original serialized JSON so we can compare updates.
rawData []byte
}
// UnmarshalJSON unmarshals a Manager object from the raw JSON.
func (manager *Manager) UnmarshalJSON(b []byte) error {
type temp Manager
type actions struct {
Reset struct {
AllowedResetTypes []ResetType `json:"ResetType@Redfish.AllowableValues"`
Target string
} `json:"#Manager.Reset"`
}
type linkReference struct {
ManagerForChassis common.Links
ManagerForChassisCount int `json:"ManagerForChassis@odata.count"`
ManagerForServers common.Links
ManagerForServersCount int `json:"ManagerForServers@odata.count"`
ManagerForSwitches common.Links
ManagerForSwitchesCount int `json:"ManagerForSwitches@odata.count"`
ManagerInChassis common.Link
OEM map[string]interface{} `json:"Oem"`
}
var t struct {
temp
EthernetInterfaces common.Link
LogServices common.Link
NetworkProtocol common.Link
RemoteAccountService common.Link
SerialInterfaces common.Link
VirtualMedia common.Link
Links linkReference
Actions actions
OEM map[string]interface{} `json:"Oem"`
}
err := json.Unmarshal(b, &t)
if err != nil {
return err
}
// Extract the links to other entities
*manager = Manager(t.temp)
manager.ethernetInterfaces = string(t.EthernetInterfaces)
manager.logServices = string(t.LogServices)
manager.networkProtocol = string(t.NetworkProtocol)
manager.OEMData = t.OEM
manager.OEMLinks = t.Links.OEM
manager.remoteAccountService = string(t.RemoteAccountService)
manager.serialInterfaces = string(t.SerialInterfaces)
manager.virtualMedia = string(t.VirtualMedia)
manager.managerForServers = t.Links.ManagerForServers.ToStrings()
manager.ManagerForServersCount = t.Links.ManagerForServersCount
manager.managerForChassis = t.Links.ManagerForChassis.ToStrings()
manager.ManagerForChassisCount = t.Links.ManagerForChassisCount
manager.ManagerForSwitchesCount = t.Links.ManagerForSwitchesCount
manager.managerForSwitches = t.Links.ManagerForSwitches.ToStrings()
manager.managerInChassis = string(t.Links.ManagerInChassis)
manager.SupportedResetTypes = t.Actions.Reset.AllowedResetTypes
manager.resetTarget = t.Actions.Reset.Target
// This is a read/write object, so we need to save the raw object data for later
manager.rawData = b
return nil
}
// Update commits updates to this object's properties to the running system.
func (manager *Manager) Update() error {
// Get a representation of the object's original state so we can find what
// to update.
original := new(Manager)
original.UnmarshalJSON(manager.rawData)
readWriteFields := []string{
"AutoDSTEnabled",
"DateTime",
"DateTimeLocalOffset",
}
originalElement := reflect.ValueOf(original).Elem()
currentElement := reflect.ValueOf(manager).Elem()
return manager.Entity.Update(originalElement, currentElement, readWriteFields)
}
// GetManager will get a Manager instance from the Swordfish service.
func GetManager(c common.Client, uri string) (*Manager, error) {
resp, err := c.Get(uri)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var manager Manager
err = json.NewDecoder(resp.Body).Decode(&manager)
if err != nil {
return nil, err
}
manager.SetClient(c)
return &manager, nil
}
// ListReferencedManagers gets the collection of Managers
func ListReferencedManagers(c common.Client, link string) ([]*Manager, error) {
var result []*Manager
links, err := common.GetCollection(c, link)
if err != nil {
return result, err
}
for _, managerLink := range links.ItemLinks {
manager, err := GetManager(c, managerLink)
if err != nil {
return result, err
}
result = append(result, manager)
}
return result, nil
}
// Reset shall perform a reset of the manager.
func (manager *Manager) Reset(resetType ResetType) error {
if len(manager.SupportedResetTypes) == 0 {
// reset directly without reset type. HPE server has the behavior
type temp struct {
Action string
}
t := temp{
Action: "Manager.Reset",
}
_, err := manager.Client.Post(manager.resetTarget, t)
return err
}
// Make sure the requested reset type is supported by the manager.
valid := false
for _, allowed := range manager.SupportedResetTypes {
if resetType == allowed {
valid = true
break
}
}
if !valid {
return fmt.Errorf("reset type '%s' is not supported by this manager",
resetType)
}
type temp struct {
ResetType ResetType
}
t := temp{
ResetType: resetType,
}
_, err := manager.Client.Post(manager.resetTarget, t)
return err
}
// EthernetInterfaces get this system's ethernet interfaces.
func (manager *Manager) EthernetInterfaces() ([]*EthernetInterface, error) {
return ListReferencedEthernetInterfaces(manager.Client, manager.ethernetInterfaces)
}
// LogServices get this manager's log services on this system.
func (manager *Manager) LogServices() ([]*LogService, error) {
return ListReferencedLogServices(manager.Client, manager.logServices)
}
// VirtualMedia gets the virtual media associated with this manager.
func (manager *Manager) VirtualMedia() ([]*VirtualMedia, error) {
return ListReferencedVirtualMedias(manager.Client, manager.virtualMedia)
}