forked from stmcginnis/gofish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
storagereplicainfo.go
490 lines (449 loc) · 21.6 KB
/
storagereplicainfo.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
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
//
// SPDX-License-Identifier: BSD-3-Clause
//
package swordfish
import (
"encoding/json"
"github.com/stmcginnis/gofish/common"
)
// ConsistencyState is used to describe the consistency type used by the
// source and its associated target group.
type ConsistencyState string
const (
// ConsistentConsistencyState shall indicate that the source and target
// shall be consistent.
ConsistentConsistencyState ConsistencyState = "Consistent"
// InconsistentConsistencyState shall indicate that the source and target
// are not required to be consistent.
InconsistentConsistencyState ConsistencyState = "Inconsistent"
)
// ConsistencyStatus is used to indicate the current status of consistency.
// Consistency may have been disabled or may be experiencing an error condition.
type ConsistencyStatus string
const (
// ConsistentConsistencyStatus shall indicate that the source and target
// are consistent.
ConsistentConsistencyStatus ConsistencyStatus = "Consistent"
// InProgressConsistencyStatus shall indicate that the source and target
// are becoming consistent.
InProgressConsistencyStatus ConsistencyStatus = "InProgress"
// DisabledConsistencyStatus shall indicate that the source and target
// have consistency disabled.
DisabledConsistencyStatus ConsistencyStatus = "Disabled"
// InErrorConsistencyStatus shall indicate that the source and target are
// not consistent.
InErrorConsistencyStatus ConsistencyStatus = "InError"
)
// ConsistencyType is used by the source and its associated target group.
type ConsistencyType string
const (
// SequentiallyConsistentConsistencyType shall indicate that the source
// and target shall be sequentially consistent.
SequentiallyConsistentConsistencyType ConsistencyType = "SequentiallyConsistent"
)
// ReplicaPriority is used to specify the priority of background copy
// engine I/O relative to host I/O operations during a sequential
// background copy operation.
type ReplicaPriority string
const (
// LowReplicaPriority shall have a lower priority than host I/O.
LowReplicaPriority ReplicaPriority = "Low"
// SameReplicaPriority shall have the same priority as host I/O.
SameReplicaPriority ReplicaPriority = "Same"
// HighReplicaPriority shall have a higher priority than host I/O.
HighReplicaPriority ReplicaPriority = "High"
// UrgentReplicaPriority shall be performed as soon as possible.
UrgentReplicaPriority ReplicaPriority = "Urgent"
)
// ReplicaProgressStatus is used to describe the status of the session
// with respect to Replication activity.
type ReplicaProgressStatus string
const (
// CompletedReplicaProgressStatus shall indicate that the request is
// completed. Data flow is idle.
CompletedReplicaProgressStatus ReplicaProgressStatus = "Completed"
// DormantReplicaProgressStatus shall indicate that the data flow is
// inactive, suspended or quiesced.
DormantReplicaProgressStatus ReplicaProgressStatus = "Dormant"
// InitializingReplicaProgressStatus shall indicate that replication is
// in the process of establishing source/replica relationship and the
// data flow has not started.
InitializingReplicaProgressStatus ReplicaProgressStatus = "Initializing"
// PreparingReplicaProgressStatus shall indicate that replication has
// preparation in progress.
PreparingReplicaProgressStatus ReplicaProgressStatus = "Preparing"
// SynchronizingReplicaProgressStatus shall indicate that replication has
// synchronization in progress.
SynchronizingReplicaProgressStatus ReplicaProgressStatus = "Synchronizing"
// ResyncingReplicaProgressStatus shall indicate that replication has
// resynchronization in progress.
ResyncingReplicaProgressStatus ReplicaProgressStatus = "Resyncing"
// RestoringReplicaProgressStatus shall indicate that replication has a
// restore in progress.
RestoringReplicaProgressStatus ReplicaProgressStatus = "Restoring"
// FracturingReplicaProgressStatus shall indicate that replication has a
// fracture in progress.
FracturingReplicaProgressStatus ReplicaProgressStatus = "Fracturing"
// SplittingReplicaProgressStatus shall indicate that replication has a
// split in progress.
SplittingReplicaProgressStatus ReplicaProgressStatus = "Splitting"
// FailingOverReplicaProgressStatus shall indicate that replication is in
// the process of switching source and target.
FailingOverReplicaProgressStatus ReplicaProgressStatus = "FailingOver"
// FailingBackReplicaProgressStatus shall indicate that replication is
// undoing the result of failover.
FailingBackReplicaProgressStatus ReplicaProgressStatus = "FailingBack"
// DetachingReplicaProgressStatus shall indicate that replication has a
// detach in progress.
DetachingReplicaProgressStatus ReplicaProgressStatus = "Detaching"
// AbortingReplicaProgressStatus shall indicate that replication has an
// abort in progress.
AbortingReplicaProgressStatus ReplicaProgressStatus = "Aborting"
// MixedReplicaProgressStatus shall indicate that replication status is
// mixed across element pairs in a replication group. Generally, the
// individual statuses need to be examined.
MixedReplicaProgressStatus ReplicaProgressStatus = "Mixed"
// SuspendingReplicaProgressStatus shall indicate that replication has a
// copy operation in the process of being suspended.
SuspendingReplicaProgressStatus ReplicaProgressStatus = "Suspending"
// RequiresFractureReplicaProgressStatus shall indicate that the
// requested operation has completed, however, the synchronization
// relationship needs to be fractured before further copy operations can
// be issued.
RequiresFractureReplicaProgressStatus ReplicaProgressStatus = "RequiresFracture"
// RequiresResyncReplicaProgressStatus shall indicate that the requested
// operation has completed, however, the synchronization relationship
// needs to be resynced before further copy operations can be issued.
RequiresResyncReplicaProgressStatus ReplicaProgressStatus = "RequiresResync"
// RequiresActivateReplicaProgressStatus shall indicate that the
// requested operation has completed, however, the synchronization
// relationship needs to be activated before further copy operations can
// be issued.
RequiresActivateReplicaProgressStatus ReplicaProgressStatus = "RequiresActivate"
// PendingReplicaProgressStatus shall indicate that the flow of data has
// stopped momentarily due to limited bandwidth or a busy system.
PendingReplicaProgressStatus ReplicaProgressStatus = "Pending"
// RequiresDetachReplicaProgressStatus shall indicate that the requested
// operation has completed, however, the synchronization relationship
// needs to be detached before further copy operations can be issued.
RequiresDetachReplicaProgressStatus ReplicaProgressStatus = "RequiresDetach"
// TerminatingReplicaProgressStatus shall indicate that the replication
// relationship is in the process of terminating.
TerminatingReplicaProgressStatus ReplicaProgressStatus = "Terminating"
// RequiresSplitReplicaProgressStatus shall indicate that the requested
// operation has completed, however, the synchronization relationship
// needs to be split before further copy operations can be issued.
RequiresSplitReplicaProgressStatus ReplicaProgressStatus = "RequiresSplit"
// RequiresResumeReplicaProgressStatus shall indicate that the requested
// operation has completed, however, the synchronization relationship
// needs to be resumed before further copy operations can be issued.
RequiresResumeReplicaProgressStatus ReplicaProgressStatus = "RequiresResume"
)
// ReplicaReadOnlyAccess is used to specify whether the source, the
// target, or both elements are read-only to the host.
type ReplicaReadOnlyAccess string
const (
// SourceElementReplicaReadOnlyAccess shall be read-only to the host.
SourceElementReplicaReadOnlyAccess ReplicaReadOnlyAccess = "SourceElement"
// ReplicaElementReplicaReadOnlyAccess shall be read-only to the host.
ReplicaElementReplicaReadOnlyAccess ReplicaReadOnlyAccess = "ReplicaElement"
// BothReplicaReadOnlyAccess shall be read only to the host.
BothReplicaReadOnlyAccess ReplicaReadOnlyAccess = "Both"
)
// ReplicaRecoveryMode is used to specify whether the copy operation
// continues after a broken link is restored.
type ReplicaRecoveryMode string
const (
// AutomaticReplicaRecoveryMode shall resume automatically.
AutomaticReplicaRecoveryMode ReplicaRecoveryMode = "Automatic"
// ManualReplicaRecoveryMode shall be set to Suspended after the link is
// restored. It is required to issue the Resume operation to continue.
ManualReplicaRecoveryMode ReplicaRecoveryMode = "Manual"
)
// ReplicaRole is used to specify whether the resource is a source of
// replication or the target of replication.
type ReplicaRole string
const (
// SourceReplicaRole shall indicate a source element.
SourceReplicaRole ReplicaRole = "Source"
// TargetReplicaRole shall indicate target element.
TargetReplicaRole ReplicaRole = "Target"
)
// ReplicaState is used to describe the state of the relationship with
// respect to Replication activity.
type ReplicaState string
const (
// InitializedReplicaState shall indicate that the link to enable
// replication is established and source/replica elements are associated,
// but the data flow has not started.
InitializedReplicaState ReplicaState = "Initialized"
// UnsynchronizedReplicaState shall indicate that not all the source
// element data has been copied to the target element.
UnsynchronizedReplicaState ReplicaState = "Unsynchronized"
// SynchronizedReplicaState shall indicate that for Mirror, Snapshot, or
// Clone replication, the target represents a copy of the source.
SynchronizedReplicaState ReplicaState = "Synchronized"
// BrokenReplicaState shall indicate that the relationship is non-
// functional due to errors in the source, the target, the path between
// the two or space constraints.
BrokenReplicaState ReplicaState = "Broken"
// FracturedReplicaState shall indicate that the Target is split from the
// source. The target may not be consistent.
FracturedReplicaState ReplicaState = "Fractured"
// SplitReplicaState shall indicate that the target element was
// gracefully (or systematically) split from its source element --
// consistency shall be guaranteed.
SplitReplicaState ReplicaState = "Split"
// InactiveReplicaState shall indicate that data flow has stopped, writes
// to source element shall not be sent to target element.
InactiveReplicaState ReplicaState = "Inactive"
// SuspendedReplicaState shall indicate that the data flow between the
// source and target elements has stopped. Writes to source element shall
// be held until the relationship is Resumed.
SuspendedReplicaState ReplicaState = "Suspended"
// FailedoverReplicaState shall indicate that the reads and writes are
// sent to the target element. The source element may not be reachable.
FailedoverReplicaState ReplicaState = "Failedover"
// PreparedReplicaState shall indicate that initialization is completed,
// however, the data flow has not started.
PreparedReplicaState ReplicaState = "Prepared"
// AbortedReplicaState shall indicate that the copy operation is aborted
// with the Abort operation. The Resync Replica operation can be used to
// restart the copy operation.
AbortedReplicaState ReplicaState = "Aborted"
// SkewedReplicaState shall indicate that the target has been modified
// and is no longer synchronized with the source element or the point-in-
// time view.
SkewedReplicaState ReplicaState = "Skewed"
// MixedReplicaState shall indicate the ReplicaState of
// GroupSynchronized. The value indicates the StorageSynchronized
// relationships of the elements in the group have different ReplicaState
// values.
MixedReplicaState ReplicaState = "Mixed"
// PartitionedReplicaState shall indicate that the state of replication
// relationship can not be determined, for example, due to a connection
// problem.
PartitionedReplicaState ReplicaState = "Partitioned"
// InvalidReplicaState shall indicate that the storage server is unable
// to determine the state of the replication relationship, for example,
// after the connection is restored; however, either source or target
// elements have an unknown status.
InvalidReplicaState ReplicaState = "Invalid"
// RestoredReplicaState shall indicate that the source element was
// restored from the target element.
RestoredReplicaState ReplicaState = "Restored"
)
// ReplicaType is used to specify the intended outcome of the replication.
type ReplicaType string
const (
// MirrorReplicaType shall indicate that replication shall create and
// maintain a copy of the source.
MirrorReplicaType ReplicaType = "Mirror"
// SnapshotReplicaType shall indicate that replication shall create a
// point in time, virtual copy of the source.
SnapshotReplicaType ReplicaType = "Snapshot"
// CloneReplicaType shall indicate that replication shall create a point
// in time, full copy the source.
CloneReplicaType ReplicaType = "Clone"
// TokenizedCloneReplicaType shall indicate that replication shall create
// a token based clone.
TokenizedCloneReplicaType ReplicaType = "TokenizedClone"
)
// ReplicaUpdateMode is used to specify whether the target elements will
// be updated synchronously or asynchronously.
type ReplicaUpdateMode string
const (
// ActiveReplicaUpdateMode shall indicate Active-Active (i.e.
// bidirectional) synchronous updates.
ActiveReplicaUpdateMode ReplicaUpdateMode = "Active"
// SynchronousReplicaUpdateMode shall indicate Synchronous updates.
SynchronousReplicaUpdateMode ReplicaUpdateMode = "Synchronous"
// AsynchronousReplicaUpdateMode shall indicate Asynchronous updates.
AsynchronousReplicaUpdateMode ReplicaUpdateMode = "Asynchronous"
// AdaptiveReplicaUpdateMode shall indicate that an implementation may
// switch between synchronous and asynchronous modes.
AdaptiveReplicaUpdateMode ReplicaUpdateMode = "Adaptive"
)
// UndiscoveredElement is used to specify whether the source, the target,
// or both elements involved in a copy operation are undiscovered. An
// element shall be considered undiscovered if its object model is not
// known to the service performing the copy operation.
type UndiscoveredElement string
const (
// SourceElementUndiscoveredElement shall indicate that the source
// element is undiscovered.
SourceElementUndiscoveredElement UndiscoveredElement = "SourceElement"
// ReplicaElementUndiscoveredElement shall indicate that the replica
// element is undiscovered.
ReplicaElementUndiscoveredElement UndiscoveredElement = "ReplicaElement"
)
// ReplicaInfo shall define the characteristics of a replica.
type ReplicaInfo struct {
// ConsistencyEnabled is If true, consistency shall be enabled across the
// source and its associated target replica(s). The default value for
// this property is false.
ConsistencyEnabled bool
// ConsistencyState is The ConsistencyState enumeration literal shall
// indicate the current state of consistency.
ConsistencyState ConsistencyState
// ConsistencyStatus is The ConsistencyStatus enumeration literal shall
// specify the current status of consistency. Consistency may have been
// disabled or is experiencing an error condition.
ConsistencyStatus ConsistencyStatus
// ConsistencyType is used by the source and its associated target group.
ConsistencyType ConsistencyType
// dataProtectionLineOfService shall be a set of data
// protection service options. Within a class of service, one data
// protection service option shall be present for each replication
// session.
dataProtectionLineOfService []string
// FailedCopyStopsHostIO is If true, the storage array shall stop
// receiving data to the source element if copying to a remote element
// fails. The default value for this property is false.
FailedCopyStopsHostIO bool
// PercentSynced is Specifies the percent of the work completed to reach
// synchronization. Shall not be instantiated if implementation is not
// capable of providing this information. If related to a group, then
// PercentSynced shall be an average of the PercentSynced across all
// members of the group.
PercentSynced int
// Replica shall reference the resource that is the source of this replica.
replica string
// ReplicaPriority shall specify the priority
// of background copy engine I/O to be managed relative to host I/O
// operations during a sequential background copy operation.
ReplicaPriority ReplicaPriority
// ReplicaProgressStatus is The ReplicaProgressStatus enumeration literal
// shall specify the status of the session with respect to Replication
// activity.
ReplicaProgressStatus ReplicaProgressStatus
// ReplicaReadOnlyAccess shall specify whether
// the source, the target, or both elements are read only to the host.
ReplicaReadOnlyAccess ReplicaReadOnlyAccess
// ReplicaRecoveryMode shall specify whether
// the copy operation continues after a broken link is restored.
ReplicaRecoveryMode ReplicaRecoveryMode
// ReplicaSkewBytes is Applies to Adaptive mode and it describes maximum
// number of bytes the SyncedElement (target) can be out of sync. If the
// number of out-of-sync bytes exceeds the skew value, ReplicaUpdateMode
// shall be switched to synchronous.
ReplicaSkewBytes int64
// ReplicaState is The ReplicaState enumeration literal shall specify the
// state of the relationship with respect to Replication activity.
ReplicaState ReplicaState
// ReplicaType is The ReplicaType enumeration literal shall describe the
// intended outcome of the replication.
ReplicaType ReplicaType
// ReplicaUpdateMode shall specify whether the
// target elements will be updated synchronously or asynchronously.
ReplicaUpdateMode ReplicaUpdateMode
// RequestedReplicaState is The last requested or desired state for the
// relationship. The actual state of the relationship shall be
// represented by ReplicaState. When RequestedState reaches the requested
// state, this property shall be null.
RequestedReplicaState ReplicaState
// SyncMaintained is If true, Synchronization shall be maintained. The
// default value for this property is false.
SyncMaintained bool
// UndiscoveredElement shall specify whether
// the source, the target, or both elements involved in a copy operation
// are undiscovered. An element is considered undiscovered if its object
// model is not known to the service performing the copy operation.
UndiscoveredElement UndiscoveredElement
// WhenActivated shall be an ISO 8601 conformant time of day
// that specifies when the point-in-time copy was taken or when the
// replication relationship is activated, reactivated, resumed or re-
// established. This property shall be null if the implementation is not
// capable of providing this information.
WhenActivated string
// WhenDeactivated shall be an ISO 8601 conformant time of
// day that specifies when the replication relationship is deactivated.
// Do not instantiate this property if implementation is not capable of
// providing this information.
WhenDeactivated string
// WhenEstablished shall be an ISO 8601 conformant time of
// day that specifies when the replication relationship is established.
// Do not instantiate this property if implementation is not capable of
// providing this information.
WhenEstablished string
// WhenSuspended shall be an ISO 8601 conformant time of day
// that specifies when the replication relationship is suspended. Do not
// instantiate this property if implementation is not capable of
// providing this information.
WhenSuspended string
// WhenSynced shall be an ISO 8601 conformant time of day
// that specifies when the elements were synchronized.
WhenSynced string
// WhenSynchronized shall be an ISO 8601 conformant time of
// day that specifies when the replication relationship is synchronized.
// Do not instantiate this property if implementation is not capable of
// providing this information.
WhenSynchronized string
}
// UnmarshalJSON unmarshals a ReplicaInfo object from the raw JSON.
func (replicainfo *ReplicaInfo) UnmarshalJSON(b []byte) error {
type temp ReplicaInfo
var t struct {
temp
DataProtectionLineOfService common.Links
Replica common.Link
}
err := json.Unmarshal(b, &t)
if err != nil {
return err
}
// Extract the links to other entities for later
*replicainfo = ReplicaInfo(t.temp)
replicainfo.dataProtectionLineOfService = t.DataProtectionLineOfService.ToStrings()
replicainfo.replica = string(t.Replica)
return nil
}
// StorageReplicaInfo is
type StorageReplicaInfo 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"`
// Description provides a description of this resource.
Description string
}
// GetStorageReplicaInfo will get a StorageReplicaInfo instance from the service.
func GetStorageReplicaInfo(c common.Client, uri string) (*StorageReplicaInfo, error) {
resp, err := c.Get(uri)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var storagereplicainfo StorageReplicaInfo
err = json.NewDecoder(resp.Body).Decode(&storagereplicainfo)
if err != nil {
return nil, err
}
storagereplicainfo.SetClient(c)
return &storagereplicainfo, nil
}
// ListReferencedStorageReplicaInfos gets the collection of StorageReplicaInfo from
// a provided reference.
func ListReferencedStorageReplicaInfos(c common.Client, link string) ([]*StorageReplicaInfo, error) {
var result []*StorageReplicaInfo
if link == "" {
return result, nil
}
links, err := common.GetCollection(c, link)
if err != nil {
return result, err
}
for _, storagereplicainfoLink := range links.ItemLinks {
storagereplicainfo, err := GetStorageReplicaInfo(c, storagereplicainfoLink)
if err != nil {
return result, err
}
result = append(result, storagereplicainfo)
}
return result, nil
}