forked from stmcginnis/gofish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstorage.go
386 lines (337 loc) · 16.6 KB
/
storage.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
//
// SPDX-License-Identifier: BSD-3-Clause
//
package redfish
import (
"encoding/json"
"reflect"
"github.com/stmcginnis/gofish/common"
)
type AutoVolumeCreate string
const (
// DisabledAutoVolumeCreate Do not automatically create volumes.
DisabledAutoVolumeCreate AutoVolumeCreate = "Disabled"
// NonRAIDAutoVolumeCreate Automatically create non-RAID volumes.
NonRAIDAutoVolumeCreate AutoVolumeCreate = "NonRAID"
// RAID0AutoVolumeCreate Automatically create RAID0 volumes.
RAID0AutoVolumeCreate AutoVolumeCreate = "RAID0"
// RAID1AutoVolumeCreate Automatically create RAID1 volumes.
RAID1AutoVolumeCreate AutoVolumeCreate = "RAID1"
)
type EncryptionMode string
const (
// DisabledEncryptionMode Encryption is disabled on the storage subsystem.
DisabledEncryptionMode EncryptionMode = "Disabled"
// UseExternalKeyEncryptionMode The storage subsystem uses one or more external keys for encryption.
UseExternalKeyEncryptionMode EncryptionMode = "UseExternalKey"
// UseLocalKeyEncryptionMode The storage subsystem uses a local key for encryption.
UseLocalKeyEncryptionMode EncryptionMode = "UseLocalKey"
)
type HotspareActivationPolicy string
const (
// OnDriveFailureHotspareActivationPolicy The hot spare drive will take over for the original drive when the
// original drive has been marked as failed by the storage domain.
OnDriveFailureHotspareActivationPolicy HotspareActivationPolicy = "OnDriveFailure"
// OnDrivePredictedFailureHotspareActivationPolicy The hot spare drive will take over for the original drive when
// the original drive has been predicted to fail in the future by the storage domain.
OnDrivePredictedFailureHotspareActivationPolicy HotspareActivationPolicy = "OnDrivePredictedFailure"
// OEMHotspareActivationPolicy The hot spare drive will take over for the original drive in an algorithm custom to
// the OEM.
OEMHotspareActivationPolicy HotspareActivationPolicy = "OEM"
)
type StorageResetToDefaultsType string
const (
// ResetAllStorageResetToDefaultsType Reset all settings to factory defaults and remove all volumes.
ResetAllStorageResetToDefaultsType StorageResetToDefaultsType = "ResetAll"
// PreserveVolumesStorageResetToDefaultsType Reset all settings to factory defaults but preserve the configured volumes on
// the controllers.
PreserveVolumesStorageResetToDefaultsType StorageResetToDefaultsType = "PreserveVolumes"
)
// CacheSummary shall contain properties which describe the cache memory for a
// storage controller.
type CacheSummary struct {
// PersistentCacheSizeMiB shall contain the amount of
// cache memory that is persistent as measured in mebibytes. This size
// shall be less than or equal to the TotalCacheSizeMib.
PersistentCacheSizeMiB int
// Status shall contain any status or health properties
// of the resource.
Status common.Status
// TotalCacheSizeMiB shall contain the amount of
// configured cache memory as measured in mebibytes.
TotalCacheSizeMiB int
}
// Rates shall contain all the rate settings available on the controller.
type Rates struct {
// ConsistencyCheckRatePercent shall contain the percentage of controller resources used for checking data
// consistency on volumes.
ConsistencyCheckRatePercent int
// RebuildRatePercent shall contain the percentage of controller resources used for rebuilding volumes.
RebuildRatePercent int
// TransformationRatePercent shall contain the percentage of controller resources used for transforming volumes.
TransformationRatePercent int
}
// Storage is used to represent resources that represent a storage
// subsystem in the Redfish specification.
type Storage struct {
common.Entity
// ODataContext is the odata context.
ODataContext string `json:"@odata.context"`
// ODataType is the odata type.
ODataType string `json:"@odata.type"`
// AutoVolumeCreate shall indicate if volumes are created automatically for each unassigned drive attached to this
// storage subsystem.
AutoVolumeCreate AutoVolumeCreate
// Connections shall contain a link to a resource collection of type ConnectionCollection. The members of this
// collection shall reference Connection resources subordinate to Fabric resources.
connections string
// ConsistencyGroups shall contain a link to a resource collection of type ConsistencyGroupCollection. The property
// shall be used when groups of volumes are treated as a single resource by an application or set of applications.
consistencyGroups string
// Controllers shall contain a link to a resource collection of type StorageControllerCollection that contains the
// set of storage controllers allocated to this storage subsystem.
controllers string
// Description provides a description of this resource.
Description string
// Drives is a collection that indicates all the drives attached to the
// storage controllers that this resource represents.
drives []string
// DrivesCount is the number of drives.
DrivesCount int `json:"[email protected]"`
// EncryptionMode shall contain the encryption mode of this storage subsystem.
EncryptionMode EncryptionMode
// EndpointGroups shall contain a link to a resource collection of type EndpointGroupCollection. This property
// shall be implemented when atomic control is needed to perform mapping, masking, and zoning operations.
endpointGroups string
// FileSystems shall contain a link to a resource collection of type FileSystemCollection. This property shall be
// used when file systems are shared or exported by the storage subsystem.
fileSystems string
// HotspareActivationPolicy shall contain the policy under which all drives operating as hot spares in this storage
// domain will activate.
HotspareActivationPolicy HotspareActivationPolicy
// Identifiers shall contain a list of all known durable names for the storage subsystem.
Identifiers []common.Identifier
// LocalEncryptionKeyIdentifier shall contain the local encryption key identifier used by the storage subsystem
// when EncryptionMode contains 'UseLocalKey'.
LocalEncryptionKeyIdentifier string
// Oem shall contain the OEM extensions. All values for properties that this object contains shall conform to the
// Redfish Specification-described requirements.
OEM json.RawMessage `json:"Oem"`
// Redundancy shall contain redundancy information for the storage subsystem.
Redundancy []Redundancy
// RedundancyCount is the number of Redundancy objects.
RedundancyCount int `json:"[email protected]"`
// Status shall contain any status or health properties of the resource.
Status common.Status
// StorageControllers is a collection that indicates all the storage
// controllers that this resource represents.
// This property has been deprecated in favor of Controllers to allow for storage controllers to be represented as their own resources.
StorageControllers []StorageController
// StorageControllersCount is the number of storage controllers.
StorageControllersCount int `json:"[email protected]"`
// StoragePools shall contain a link to a resource collection of type StoragePoolCollection. This property shall be
// used when an abstraction of media, rather than references to individual media, are used as the storage data
// source.
storagePools string
// Volumes is a collection that indicates all the volumes produced by the
// storage controllers that this resource represents.
volumes string
// rawData holds the original serialized JSON so we can compare updates.
rawData []byte
// Enclosures shall reference a resource of type Chassis that represents the
// physical containers attached to this resource.
enclosures []string
// EnclosuresCount is the number of enclosures.
EnclosuresCount int
hostingStorageSystems []string
// HostingStorageSystemsCount is the number of hosting storage systems.
HostingStorageSystemsCount int
// NVMeoFDiscoverySubsystems shall contain an array of links to resources of type Storage that represent the
// discovery subsystems that discovered this subsystem in an NVMe-oF environment.
nvmeoFDiscoverySubsystems []string
// NVMeoFDiscoverySubsystemsCount is the number of NVMeoFDiscoverySubsystems.
NVMeoFDiscoverySubsystemsCount int
// SimpleStorage shall contain a link to a resource of type SimpleStorage that represents the same storage
// subsystem as this resource.
simpleStorage string
// StorageServices shall contain an array of links to resources of type StorageService with which this storage
// subsystem is associated.
storageServices []string
// StorageServicesCount is the number of storage services.
StorageServicesCount int
// setEncryptionKeyTarget is the URL to send SetEncryptionKey requests.
setEncryptionKeyTarget string
// Oem are all OEM data under top level storage section
Oem json.RawMessage
resetToDefaultsTarget string
}
// UnmarshalJSON unmarshals a Storage object from the raw JSON.
func (storage *Storage) UnmarshalJSON(b []byte) error {
type temp Storage
type links struct {
Enclosures common.Links
EnclosuresCount int `json:"[email protected]"`
HostingStorageSystems common.Links
HostingStorageSystemsCount int `json:"[email protected]"`
NVMeoFDiscoverySubsystems common.Links
NVMeoFDiscoverySubsystemsCount int `json:"[email protected]"`
SimpleStorage common.Link
StorageServices common.Links
StorageServicesCount int `json:"[email protected]"`
}
type actions struct {
ResetToDefaults common.ActionTarget `json:"#/definitions/ResetToDefaults"`
SetEncryptionKey common.ActionTarget `json:"#Storage.SetEncryptionKey"`
}
var t struct {
temp
Links links
Connections common.Link
ConsistencyGroups common.Link
Controllers common.Link
Drives common.Links
EndpointGroups common.Link
FileSystems common.Link
StoragePools common.Link
Volumes common.Link
Actions actions
}
err := json.Unmarshal(b, &t)
if err != nil {
return err
}
*storage = Storage(t.temp)
// Extract the links to other entities for later
storage.connections = t.Connections.String()
storage.consistencyGroups = t.ConsistencyGroups.String()
storage.controllers = t.Controllers.String()
storage.drives = t.Drives.ToStrings()
storage.endpointGroups = t.EndpointGroups.String()
storage.fileSystems = t.FileSystems.String()
storage.storagePools = t.StoragePools.String()
storage.volumes = t.Volumes.String()
storage.enclosures = t.Links.Enclosures.ToStrings()
storage.EnclosuresCount = t.Links.EnclosuresCount
storage.hostingStorageSystems = t.Links.HostingStorageSystems.ToStrings()
storage.HostingStorageSystemsCount = t.Links.HostingStorageSystemsCount
storage.nvmeoFDiscoverySubsystems = t.Links.NVMeoFDiscoverySubsystems.ToStrings()
storage.NVMeoFDiscoverySubsystemsCount = t.Links.NVMeoFDiscoverySubsystemsCount
storage.simpleStorage = t.Links.SimpleStorage.String()
storage.storageServices = t.Links.StorageServices.ToStrings()
storage.StorageServicesCount = t.Links.StorageServicesCount
storage.resetToDefaultsTarget = t.Actions.ResetToDefaults.Target
storage.setEncryptionKeyTarget = t.Actions.SetEncryptionKey.Target
// This is a read/write object, so we need to save the raw object data for later
storage.rawData = b
return nil
}
// Connection gets the connections that this storage subsystem contains.
func (storage *Storage) Connections() ([]*Connection, error) {
return ListReferencedConnections(storage.GetClient(), storage.connections)
}
// ConsistencyGroups gets groups of volumes that are treated as a single resource
// by an application or set of applications.
// func (storage *Storage) ConsistencyGroups() ([]*swordfish.ConsistencyGroup, error) {
// return swordfishListReferencedConsistencyGroups(storage.GetClient(), storage.consistencyGroups)
// }
// Controllers gets the set of storage controllers allocated to this storage subsystem.
func (storage *Storage) Controllers() ([]*StorageController, error) {
return ListReferencedStorageControllers(storage.GetClient(), storage.controllers)
}
// Drives gets the drives attached to the storage controllers that this
// resource represents.
func (storage *Storage) Drives() ([]*Drive, error) {
return common.GetObjects[Drive](storage.GetClient(), storage.drives)
}
// EndpointGroups gets the set of endpoints that are used for a common purpose such as an ACL
// or logical identification, that belong to this storage subsystem.
func (storage *Storage) EndpointGroups() ([]*EndpointGroup, error) {
return ListReferencedEndpointGroups(storage.GetClient(), storage.endpointGroups)
}
// FileSystems gets the file systems that are allocated by this storage subsystem.
// func (storage *Storage) FileSystems() ([]*swordfish.FileSystem, error) {
// return swordfish.ListReferencedFileSystems(storage.GetClient(), storage.fileSystems)
// }
// Volumes gets the volumes associated with this storage subsystem.
func (storage *Storage) Volumes() ([]*Volume, error) {
return ListReferencedVolumes(storage.GetClient(), storage.volumes)
}
// Enclosures gets the physical containers attached to this resource.
func (storage *Storage) Enclosures() ([]*Chassis, error) {
return common.GetObjects[Chassis](storage.GetClient(), storage.enclosures)
}
// HostingStorageSystems gets the storage systems that host this storage subsystem.
func (storage *Storage) HostingStorageSystems() ([]*ComputerSystem, error) {
return common.GetObjects[ComputerSystem](storage.GetClient(), storage.hostingStorageSystems)
}
// NVMeoFDiscoverySubsystems gets the discovery subsystems that discovered this subsystem in an NVMe-oF environment.
func (storage *Storage) NVMeoFDiscoverySubsystems() ([]*Storage, error) {
return common.GetObjects[Storage](storage.GetClient(), storage.nvmeoFDiscoverySubsystems)
}
// SimpleStorage gets the simple storage instance that corresponds to this storage.
func (storage *Storage) SimpleStorage() (*SimpleStorage, error) {
if storage.simpleStorage == "" {
return nil, nil
}
return GetSimpleStorage(storage.GetClient(), storage.simpleStorage)
}
// // StorageServices gets the storage services that connect to this storage subsystem.
// func (storage *Storage) StorageServices() ([]*swordfish.StorageService, error) {
// return common.GetObjects[StorageService](storage.GetClient(), storage.storageServices)
// }
// ResetToDefaults resets the storage device to factory defaults. This can cause the loss of data.
func (storage *Storage) ResetToDefaults(resetType StorageResetToDefaultsType) error {
t := struct {
ResetType StorageResetToDefaultsType
}{ResetType: resetType}
return storage.Post(storage.resetToDefaultsTarget, t)
}
// SetEncryptionKey shall set the encryption key for the storage subsystem.
//
// `key` is the local encryption key to set on the storage subsystem.
//
// `currentEncryptionKey` (optional since v1.14.0) is the current local encryption key
// on the storage subsystem.
// Services may reject the action request if this parameter is not provided.
//
// `encryptionKeyIdentifier` (optional) is the local encryption key identifier used by the storage subsystem.
func (storage *Storage) SetEncryptionKey(key, currentEncryptionKey, encryptionKeyIdentifier string) error {
t := struct {
CurrentEncryptionKey string `json:",omitempty"`
EncryptionKey string
EncryptionKeyIdentifier string `json:",omitempty"`
}{
CurrentEncryptionKey: currentEncryptionKey,
EncryptionKey: key,
EncryptionKeyIdentifier: encryptionKeyIdentifier,
}
return storage.Post(storage.setEncryptionKeyTarget, t)
}
// Update commits updates to this object's properties to the running system.
func (storage *Storage) Update() error {
// Get a representation of the object's original state so we can find what
// to update.
original := new(Storage)
original.UnmarshalJSON(storage.rawData)
readWriteFields := []string{
"AutoVolumeCreate",
"EncryptionMode",
"HotspareActivationPolicy",
}
originalElement := reflect.ValueOf(original).Elem()
currentElement := reflect.ValueOf(storage).Elem()
return storage.Entity.Update(originalElement, currentElement, readWriteFields)
}
// GetStorage will get a Storage instance from the service.
func GetStorage(c common.Client, uri string) (*Storage, error) {
return common.GetObject[Storage](c, uri)
}
// ListReferencedStorages gets the collection of Storage from a provided
// reference.
func ListReferencedStorages(c common.Client, link string) ([]*Storage, error) {
return common.GetCollectionObjects[Storage](c, link)
}
// GetOperationApplyTimeValues returns the OperationApplyTime values applicable for this storage
func (storage *Storage) GetOperationApplyTimeValues() ([]common.OperationApplyTime, error) {
return AllowedVolumesUpdateApplyTimes(storage.GetClient(), storage.volumes)
}