forked from juju/juju
-
Notifications
You must be signed in to change notification settings - Fork 0
/
storage.go
122 lines (99 loc) · 3.07 KB
/
storage.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
// Copyright 2018 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package oci
import (
"github.com/juju/clock"
"github.com/juju/errors"
"github.com/DavinZhang/juju/storage"
)
type poolType string
const (
ociStorageProviderType = storage.ProviderType("oci")
// maxVolumeSizeInGB represents the maximum size in GiB for
// a single volume. For more information please see:
// https://docs.oracle.com/cloud/latest/stcomputecs/STCSA/op-storage-volume--post.html#request
maxVolumeSizeInGB = 16000
// minVolumeSizeInGB represents the minimum size in GiB for
// a single volume. For more information please see:
// https://docs.oracle.com/cloud/latest/stcomputecs/STCSA/op-storage-volume--post.html#request
minVolumeSizeInGB = 50
iscsiPool poolType = "iscsi"
ociVolumeType string = "volume-type"
)
var poolTypeMap map[string]poolType = map[string]poolType{
"iscsi": iscsiPool,
}
type StorageAPI interface{}
type storageProvider struct {
env *Environ
api StorageClient
}
var _ storage.Provider = (*storageProvider)(nil)
func (s *storageProvider) VolumeSource(cfg *storage.Config) (storage.VolumeSource, error) {
envConfig := s.env.Config()
name := envConfig.Name()
uuid := envConfig.UUID()
return &volumeSource{
env: s.env,
envName: name,
modelUUID: uuid,
storageAPI: s.env.Storage,
computeAPI: s.env.Compute,
clock: clock.WallClock,
}, nil
}
func (s *storageProvider) FilesystemSource(cfg *storage.Config) (storage.FilesystemSource, error) {
return nil, errors.NotSupportedf("filesystemsource")
}
func (s *storageProvider) Supports(kind storage.StorageKind) bool {
return kind == storage.StorageKindBlock
}
func (s *storageProvider) Scope() storage.Scope {
return storage.ScopeEnviron
}
func (s *storageProvider) Dynamic() bool {
return true
}
func (s *storageProvider) Releasable() bool {
// TODO (gsamfira): add support
return false
}
func (s *storageProvider) DefaultPools() []*storage.Config {
pool, _ := storage.NewConfig("iscsi", ociStorageProviderType, map[string]interface{}{
ociVolumeType: iscsiPool,
})
return []*storage.Config{pool}
}
func (s *storageProvider) ValidateConfig(cfg *storage.Config) error {
attrs := cfg.Attrs()
var pool string
if volType, ok := attrs[ociVolumeType]; ok {
switch kind := volType.(type) {
case string:
pool = volType.(string)
case poolType:
pool = string(volType.(poolType))
default:
return errors.Errorf("invalid volume-type %T", kind)
}
if _, ok := poolTypeMap[pool]; !ok {
return errors.Errorf("invalid volume-type %q", volType)
}
return nil
}
return nil
}
// StorageProviderTypes implements storage.ProviderRegistry.
func (e *Environ) StorageProviderTypes() ([]storage.ProviderType, error) {
return []storage.ProviderType{ociStorageProviderType}, nil
}
// StorageProvider implements storage.ProviderRegistry.
func (e *Environ) StorageProvider(t storage.ProviderType) (storage.Provider, error) {
if t == ociStorageProviderType {
return &storageProvider{
env: e,
api: e.Storage,
}, nil
}
return nil, errors.NotFoundf("storage provider %q", t)
}