-
Notifications
You must be signed in to change notification settings - Fork 218
/
storage_pool.go
67 lines (57 loc) · 1.88 KB
/
storage_pool.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
// Copyright 2018 NetApp, Inc. All Rights Reserved.
package storage
import (
"sort"
sa "github.com/netapp/trident/storage_attribute"
)
type Pool struct {
Name string
// A Trident storage pool can potentially satisfy more than one storage class.
StorageClasses []string
Backend *Backend
Attributes map[string]sa.Offer // These attributes are used to match storage classes
InternalAttributes map[string]string // These attributes are defined & used internally by storage drivers
}
func NewStoragePool(backend *Backend, name string) *Pool {
return &Pool{
Name: name,
StorageClasses: make([]string, 0),
Backend: backend,
Attributes: make(map[string]sa.Offer),
InternalAttributes: make(map[string]string),
}
}
func (pool *Pool) AddStorageClass(class string) {
// Note that this function should get called once per storage class
// affecting the volume; thus, we don't need to check for duplicates.
pool.StorageClasses = append(pool.StorageClasses, class)
}
func (pool *Pool) RemoveStorageClass(class string) bool {
found := false
for i, name := range pool.StorageClasses {
if name == class {
pool.StorageClasses = append(pool.StorageClasses[:i],
pool.StorageClasses[i+1:]...)
found = true
break
}
}
return found
}
type PoolExternal struct {
Name string `json:"name"`
StorageClasses []string `json:"storageClasses"`
//TODO: can't have an interface here for unmarshalling
Attributes map[string]sa.Offer `json:"storageAttributes"`
}
func (pool *Pool) ConstructExternal() *PoolExternal {
external := &PoolExternal{
Name: pool.Name,
StorageClasses: pool.StorageClasses,
Attributes: pool.Attributes,
}
// We want to sort these so that the output remains consistent;
// there are cases where the order won't always be the same.
sort.Strings(external.StorageClasses)
return external
}