-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathtypes.go
More file actions
59 lines (52 loc) · 1.66 KB
/
Copy pathtypes.go
File metadata and controls
59 lines (52 loc) · 1.66 KB
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
package snapshot
import (
"time"
"github.com/kernel/hypeman/lib/hypervisor"
"github.com/kernel/hypeman/lib/tags"
)
// SnapshotKind determines how snapshot data is captured and restored.
type SnapshotKind string
const (
// SnapshotKindStandby captures snapshot-based standby state (memory/device/disk).
SnapshotKindStandby SnapshotKind = "Standby"
// SnapshotKindStopped captures stopped-state disk+metadata only.
SnapshotKindStopped SnapshotKind = "Stopped"
)
// Snapshot is a centrally stored immutable snapshot resource.
type Snapshot struct {
Id string `json:"id"`
Name string `json:"name"`
Kind SnapshotKind `json:"kind"`
Tags tags.Tags `json:"tags,omitempty"`
SourceInstanceID string `json:"source_instance_id"`
SourceName string `json:"source_instance_name"`
SourceHypervisor hypervisor.Type
CreatedAt time.Time `json:"created_at"`
SizeBytes int64 `json:"size_bytes"`
}
// ListSnapshotsFilter contains optional filters for listing snapshots.
type ListSnapshotsFilter struct {
SourceInstanceID *string
Kind *SnapshotKind
Name *string
Tags tags.Tags
}
// Matches returns true if the given snapshot satisfies all filter criteria.
func (f *ListSnapshotsFilter) Matches(snapshot *Snapshot) bool {
if f == nil {
return true
}
if f.SourceInstanceID != nil && snapshot.SourceInstanceID != *f.SourceInstanceID {
return false
}
if f.Kind != nil && snapshot.Kind != *f.Kind {
return false
}
if f.Name != nil && snapshot.Name != *f.Name {
return false
}
if !tags.Matches(snapshot.Tags, f.Tags) {
return false
}
return true
}