@@ -58,12 +58,21 @@ type Volume struct {
58
58
}
59
59
60
60
type Snapshot struct {
61
+ Name string
62
+ Id string
63
+ VolID string
64
+ Path string
65
+ CreationTime * timestamp.Timestamp
66
+ SizeBytes int64
67
+ ReadyToUse bool
68
+ GroupSnapshotID string
69
+ }
70
+
71
+ type GroupSnapshot struct {
61
72
Name string
62
73
Id string
63
- VolID string
64
- Path string
74
+ SnapshotIDs []string
65
75
CreationTime * timestamp.Timestamp
66
- SizeBytes int64
67
76
ReadyToUse bool
68
77
}
69
78
@@ -112,11 +121,32 @@ type State interface {
112
121
// snapshot ID. It is not an error when such a snapshot
113
122
// does not exist.
114
123
DeleteSnapshot (snapshotID string ) error
124
+
125
+ // GetGroupSnapshotByID retrieves a groupsnapshot by its unique ID or
126
+ // returns an error including that ID when not found.
127
+ GetGroupSnapshotByID (vgsID string ) (GroupSnapshot , error )
128
+
129
+ // GetGroupSnapshotByName retrieves a groupsnapshot by its name or
130
+ // returns an error including that name when not found.
131
+ GetGroupSnapshotByName (volName string ) (GroupSnapshot , error )
132
+
133
+ // GetGroupSnapshots returns all currently existing groupsnapshots.
134
+ GetGroupSnapshots () []GroupSnapshot
135
+
136
+ // UpdateGroupSnapshot updates the existing hostpath groupsnapshot,
137
+ // identified by its snapshot ID, or adds it if it does not exist yet.
138
+ UpdateGroupSnapshot (snapshot GroupSnapshot ) error
139
+
140
+ // DeleteGroupSnapshot deletes the groupsnapshot with the given
141
+ // groupsnapshot ID. It is not an error when such a groupsnapshot does
142
+ // not exist.
143
+ DeleteGroupSnapshot (groupSnapshotID string ) error
115
144
}
116
145
117
146
type resources struct {
118
- Volumes []Volume
119
- Snapshots []Snapshot
147
+ Volumes []Volume
148
+ Snapshots []Snapshot
149
+ GroupSnapshots []GroupSnapshot
120
150
}
121
151
122
152
type state struct {
@@ -257,3 +287,50 @@ func (s *state) DeleteSnapshot(snapshotID string) error {
257
287
}
258
288
return nil
259
289
}
290
+
291
+ func (s * state ) GetGroupSnapshotByID (groupSnapshotID string ) (GroupSnapshot , error ) {
292
+ for _ , groupSnapshot := range s .GroupSnapshots {
293
+ if groupSnapshot .Id == groupSnapshotID {
294
+ return groupSnapshot , nil
295
+ }
296
+ }
297
+ return GroupSnapshot {}, status .Errorf (codes .NotFound , "groupsnapshot id %s does not exist in the groupsnapshots list" , groupSnapshotID )
298
+ }
299
+
300
+ func (s * state ) GetGroupSnapshotByName (name string ) (GroupSnapshot , error ) {
301
+ for _ , groupSnapshot := range s .GroupSnapshots {
302
+ if groupSnapshot .Name == name {
303
+ return groupSnapshot , nil
304
+ }
305
+ }
306
+ return GroupSnapshot {}, status .Errorf (codes .NotFound , "groupsnapshot name %s does not exist in the groupsnapshots list" , name )
307
+ }
308
+
309
+ func (s * state ) GetGroupSnapshots () []GroupSnapshot {
310
+ groupSnapshots := make ([]GroupSnapshot , len (s .GroupSnapshots ))
311
+ for i , groupSnapshot := range s .GroupSnapshots {
312
+ groupSnapshots [i ] = groupSnapshot
313
+ }
314
+ return groupSnapshots
315
+ }
316
+
317
+ func (s * state ) UpdateGroupSnapshot (update GroupSnapshot ) error {
318
+ for i , groupSnapshot := range s .GroupSnapshots {
319
+ if groupSnapshot .Id == update .Id {
320
+ s .GroupSnapshots [i ] = update
321
+ return s .dump ()
322
+ }
323
+ }
324
+ s .GroupSnapshots = append (s .GroupSnapshots , update )
325
+ return s .dump ()
326
+ }
327
+
328
+ func (s * state ) DeleteGroupSnapshot (groupSnapshotID string ) error {
329
+ for i , groupSnapshot := range s .GroupSnapshots {
330
+ if groupSnapshot .Id == groupSnapshotID {
331
+ s .GroupSnapshots = append (s .GroupSnapshots [:i ], s .GroupSnapshots [i + 1 :]... )
332
+ return s .dump ()
333
+ }
334
+ }
335
+ return nil
336
+ }
0 commit comments