forked from stmcginnis/gofish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
volume.go
298 lines (268 loc) · 11.8 KB
/
volume.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
//
// SPDX-License-Identifier: BSD-3-Clause
//
package redfish
import (
"encoding/json"
"github.com/stmcginnis/gofish/common"
)
// RAIDType is
type RAIDType string
const (
// RAID0RAIDType A placement policy where consecutive logical blocks of
// data are uniformly distributed across a set of independent storage
// devices without offering any form of redundancy. This is commonly
// referred to as data striping. This form of RAID will encounter data
// loss with the failure of any storage device in the set.
RAID0RAIDType RAIDType = "RAID0"
// RAID1RAIDType A placement policy where each logical block of data is
// stored on more than one independent storage device. This is commonly
// referred to as mirroring. Data stored using this form of RAID is able
// to survive a single storage device failure without data loss.
RAID1RAIDType RAIDType = "RAID1"
// RAID3RAIDType A placement policy using parity-based protection where
// logical bytes of data are uniformly distributed across a set of
// independent storage devices and where the parity is stored on a
// dedicated independent storage device. Data stored using this form of
// RAID is able to survive a single storage device failure without data
// loss. If the storage devices use rotating media, they are assumed to
// be rotationally synchronized, and the data stripe size should be no
// larger than the exported block size.
RAID3RAIDType RAIDType = "RAID3"
// RAID4RAIDType A placement policy using parity-based protection where
// logical blocks of data are uniformly distributed across a set of
// independent storage devices and where the parity is stored on a
// dedicated independent storage device. Data stored using this form of
// RAID is able to survive a single storage device failure without data
// loss.
RAID4RAIDType RAIDType = "RAID4"
// RAID5RAIDType A placement policy using parity-based protection for
// storing stripes of 'n' logical blocks of data and one logical block of
// parity across a set of 'n+1' independent storage devices where the
// parity and data blocks are interleaved across the storage devices.
// Data stored using this form of RAID is able to survive a single
// storage device failure without data loss.
RAID5RAIDType RAIDType = "RAID5"
// RAID6RAIDType A placement policy using parity-based protection for
// storing stripes of 'n' logical blocks of data and two logical blocks
// of independent parity across a set of 'n+2' independent storage
// devices where the parity and data blocks are interleaved across the
// storage devices. Data stored using this form of RAID is able to
// survive any two independent storage device failures without data loss.
RAID6RAIDType RAIDType = "RAID6"
// RAID10RAIDType A placement policy that creates a striped device (RAID
// 0) over a set of mirrored devices (RAID 1). This is commonly referred
// to as RAID 1/0. Data stored using this form of RAID is able to survive
// storage device failures in each RAID 1 set without data loss.
RAID10RAIDType RAIDType = "RAID10"
// RAID01RAIDType A data placement policy that creates a mirrored device
// (RAID 1) over a set of striped devices (RAID 0). This is commonly
// referred to as RAID 0+1 or RAID 0/1. Data stored using this form of
// RAID is able to survive a single RAID 0 data set failure without data
// loss.
RAID01RAIDType RAIDType = "RAID01"
// RAID6TPRAIDType A placement policy that uses parity-based protection
// for storing stripes of 'n' logical blocks of data and three logical
// blocks of independent parity across a set of 'n+3' independent storage
// devices where the parity and data blocks are interleaved across the
// storage devices. This is commonly referred to as Triple Parity RAID.
// Data stored using this form of RAID is able to survive any three
// independent storage device failures without data loss.
RAID6TPRAIDType RAIDType = "RAID6TP"
// RAID1ERAIDType A placement policy that uses a form of mirroring
// implemented over a set of independent storage devices where logical
// blocks are duplicated on a pair of independent storage devices so that
// data is uniformly distributed across the storage devices. This is
// commonly referred to as RAID 1 Enhanced. Data stored using this form
// of RAID is able to survive a single storage device failure without
// data loss.
RAID1ERAIDType RAIDType = "RAID1E"
// RAID50RAIDType A placement policy that uses a RAID 0 stripe set over
// two or more RAID 5 sets of independent storage devices. Data stored
// using this form of RAID is able to survive a single storage device
// failure within each RAID 5 set without data loss.
RAID50RAIDType RAIDType = "RAID50"
// RAID60RAIDType A placement policy that uses a RAID 0 stripe set over
// two or more RAID 6 sets of independent storage devices. Data stored
// using this form of RAID is able to survive two device failures within
// each RAID 6 set without data loss.
RAID60RAIDType RAIDType = "RAID60"
// RAID00RAIDType A placement policy that creates a RAID 0 stripe set
// over two or more RAID 0 sets. This is commonly referred to as RAID
// 0+0. This form of data layout is not fault tolerant; if any storage
// device fails there will be data loss.
RAID00RAIDType RAIDType = "RAID00"
// RAID10ERAIDType A placement policy that uses a RAID 0 stripe set over
// two or more RAID 10 sets. This is commonly referred to as Enhanced
// RAID 10. Data stored using this form of RAID is able to survive a
// single device failure within each nested RAID 1 set without data loss.
RAID10ERAIDType RAIDType = "RAID10E"
// RAID1TripleRAIDType A placement policy where each logical block of
// data is mirrored three times across a set of three independent storage
// devices. This is commonly referred to as three-way mirroring. This
// form of RAID can survive two device failures without data loss.
RAID1TripleRAIDType RAIDType = "RAID1Triple"
// RAID10TripleRAIDType A placement policy that uses a striped device
// (RAID 0) over a set of triple mirrored devices (RAID 1Triple). This
// form of RAID can survive up to two failures in each triple mirror set
// without data loss.
RAID10TripleRAIDType RAIDType = "RAID10Triple"
)
// EncryptionTypes is the type of encryption used by the volume.
type EncryptionTypes string
const (
// NativeDriveEncryptionEncryptionTypes indicates the volume is is utilizing the
// native drive encryption capabilities of the drive hardware.
NativeDriveEncryptionEncryptionTypes EncryptionTypes = "NativeDriveEncryption"
// ControllerAssistedEncryptionTypes indicates the volume is is being encrypted by the
// storage controller entity.
ControllerAssistedEncryptionTypes EncryptionTypes = "ControllerAssisted"
// SoftwareAssistedEncryptionTypes indicates the volume is is being encrypted by
// software running on the system or the operating system.
SoftwareAssistedEncryptionTypes EncryptionTypes = "SoftwareAssisted"
)
// VolumeType is the type of volume.
type VolumeType string
const (
// RawDeviceVolumeType indicates the volume is is a raw physical device without any
// RAID or other virtualization applied.
RawDeviceVolumeType VolumeType = "RawDevice"
// NonRedundantVolumeType indicates the volume is is a non-redundant storage device.
NonRedundantVolumeType VolumeType = "NonRedundant"
// MirroredVolumeType indicates the volume is is a mirrored device.
MirroredVolumeType VolumeType = "Mirrored"
// StripedWithParityVolumeType indicates the volume is is a device which uses parity
// to retain redundant information.
StripedWithParityVolumeType VolumeType = "StripedWithParity"
// SpannedMirrorsVolumeType indicates the volume is is a spanned set of mirrored
// devices.
SpannedMirrorsVolumeType VolumeType = "SpannedMirrors"
// SpannedStripesWithParityVolumeType indicates the volume is is a spanned set of
// devices which uses parity to retain redundant information.
SpannedStripesWithParityVolumeType VolumeType = "SpannedStripesWithParity"
)
// Volume is used to represent a volume, virtual disk, logical disk, LUN,
// or other logical storage for a Redfish implementation.
type Volume struct {
common.Entity
// ODataContext is the odata context.
ODataContext string `json:"@odata.context"`
// ODataType is the odata type.
ODataType string `json:"@odata.type"`
// Description provides a description of this resource.
Description string
// Status is
Status common.Status
// CapacityBytes shall contain the size in bytes of the associated volume.
CapacityBytes int
// VolumeType shall contain the type of the associated Volume.
VolumeType VolumeType
// Encrypted shall contain a boolean indicator if the Volume is currently
// utilizing encryption or not.
Encrypted bool
// EncryptionTypes is used by this Volume.
EncryptionTypes []EncryptionTypes
// Identifiers shall contain a list of all known durable names for the
// associated volume.
Identifiers []common.Identifier
// BlockSizeBytes shall contain size of the smallest addressable unit of the
// associated volume.
BlockSizeBytes int
// Operations shall contain a list of all currently running on the Volume.
Operations []common.Operations
// OptimumIOSizeBytes shall contain the optimum IO size to use when
// performing IO on this volume. For logical disks, this is the stripe size.
// For physical disks, this describes the physical sector size.
OptimumIOSizeBytes int
// DrivesCount is the number of associated drives.
DrivesCount int
// drives contains references to associated drives.
drives []string
}
// UnmarshalJSON unmarshals a Volume object from the raw JSON.
func (volume *Volume) UnmarshalJSON(b []byte) error {
type temp Volume
type links struct {
DriveCount int `json:"Drives@odata.count"`
Drives common.Links
}
var t struct {
temp
Links links
}
err := json.Unmarshal(b, &t)
if err != nil {
return err
}
*volume = Volume(t.temp)
// Extract the links to other entities for later
volume.DrivesCount = t.DrivesCount
volume.drives = t.Links.Drives.ToStrings()
return nil
}
// GetVolume will get a Volume instance from the service.
func GetVolume(c common.Client, uri string) (*Volume, error) {
resp, err := c.Get(uri)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var volume Volume
err = json.NewDecoder(resp.Body).Decode(&volume)
if err != nil {
return nil, err
}
volume.SetClient(c)
return &volume, nil
}
// ListReferencedVolumes gets the collection of Volumes from a provided reference.
func ListReferencedVolumes(c common.Client, link string) ([]*Volume, error) {
var result []*Volume
if link == "" {
return result, nil
}
links, err := common.GetCollection(c, link)
if err != nil {
return result, err
}
for _, volumeLink := range links.ItemLinks {
volume, err := GetVolume(c, volumeLink)
if err != nil {
return result, err
}
result = append(result, volume)
}
return result, nil
}
// Drives references the Drives that this volume is associated with.
func (volume *Volume) Drives() ([]*Drive, error) {
var result []*Drive
for _, driveLink := range volume.drives {
drive, err := GetDrive(volume.Client, driveLink)
if err != nil {
return result, err
}
result = append(result, drive)
}
return result, nil
}
// AllowedVolumesUpdateApplyTimes returns the set of allowed apply times to request when setting the volumes values
func AllowedVolumesUpdateApplyTimes(c common.Client, link string) ([]common.OperationApplyTime, error) {
resp, err := c.Get(link)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var temp struct {
OperationApplyTimeSupport common.OperationApplyTimeSupport `json:"@Redfish.OperationApplyTimeSupport"`
}
err = json.NewDecoder(resp.Body).Decode(&temp)
if err != nil {
return nil, err
}
var applyTimes []common.OperationApplyTime
for _, v := range temp.OperationApplyTimeSupport.SupportedValues {
applyTimes = append(applyTimes, v)
}
return applyTimes, nil
}