/
resources.go
362 lines (303 loc) · 9.63 KB
/
resources.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
/**
* Copyright 2017 IBM Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package resources
import (
"fmt"
"github.com/jinzhu/gorm"
)
const (
SpectrumScale string = "spectrum-scale"
SpectrumScaleNFS string = "spectrum-scale-nfs"
SoftlayerNFS string = "softlayer-nfs"
SCBE string = "scbe"
ScbeInterfaceName string = "Enabler for Containers"
)
type UbiquityServerConfig struct {
Port int
LogPath string
ConfigPath string
SpectrumScaleConfig SpectrumScaleConfig
ScbeConfig ScbeConfig
BrokerConfig BrokerConfig
DefaultBackend string
LogLevel string
}
// TODO we should consider to move dedicated backend structs to the backend resource file instead of this one.
type SpectrumScaleConfig struct {
DefaultFilesystemName string
NfsServerAddr string
RestConfig RestConfig
ForceDelete bool
}
type CredentialInfo struct {
UserName string `json:"username"`
Password string `json:"password"`
Group string `json:"group"`
}
type ConnectionInfo struct {
CredentialInfo CredentialInfo
Port int
ManagementIP string
}
type ScbeConfig struct {
ConfigPath string // TODO consider to remove later
ConnectionInfo ConnectionInfo
DefaultService string // SCBE storage service to be used by default if not mentioned by plugin
DefaultVolumeSize string // The default volume size in case not specified by user
UbiquityInstanceName string // Prefix for the volume name in the storage side (max length 15 char)
DefaultFilesystemType string // The default filesystem type to create on new provisioned volume during attachment to the host
}
const UbiquityInstanceNameMaxSize = 15
const DefaultForScbeConfigParamDefaultVolumeSize = "1" // if customer don't mention size, then the default is 1gb
const DefaultForScbeConfigParamDefaultFilesystem = "ext4" // if customer don't mention fstype, then the default is ext4
const PathToMountUbiquityBlockDevices = "/ubiquity/%s" // %s is the WWN of the volume # TODO this should be moved to docker plugin side
const OptionNameForVolumeFsType = "fstype" // the option name of the fstype and also the key in the volumeConfig
const ScbeKeyVolAttachToHost = "attach-to" // the key in map for volume to host attachments
const ScbeKeyVolAttachLunNumToHost = "LunNumber" // the key in map for volume lun number to host attachments
const ScbeDefaultPort = 8440 // the default port for SCBE management
const SslModeRequire = "require"
const SslModeVerifyFull = "verify-full"
const KeySslMode = "UBIQUITY_PLUGIN_SSL_MODE"
const KeyScbeSslMode = "SCBE_SSL_MODE"
const DefaultDbSslMode = SslModeVerifyFull
const DefaultScbeSslMode = SslModeVerifyFull
const DefaultPluginsSslMode = SslModeVerifyFull
const SpectrumscaleDefaultPort = 443 // the default port for SPECTRUM SCALE management
const SpectrumScaleParamPrefix = "SPECTRUMSCALE_"
const KeySpectrumScaleSslMode = SpectrumScaleParamPrefix + "SSL_MODE"
const DefaultSpectrumScaleSslMode = SslModeVerifyFull
type SshConfig struct {
User string
Host string
Port string
}
type RestConfig struct {
Port int
ManagementIP string
User string
Password string
Hostname string
}
type SpectrumNfsRemoteConfig struct {
ClientConfig string
}
type BrokerConfig struct {
ConfigPath string
Port int //for CF Service broker
}
type UbiquityPluginConfig struct {
DockerPlugin UbiquityDockerPluginConfig
LogPath string
LogRotateMaxSize int
UbiquityServer UbiquityServerConnectionInfo
SpectrumNfsRemoteConfig SpectrumNfsRemoteConfig
Backends []string
LogLevel string
CredentialInfo CredentialInfo
SslConfig UbiquityPluginSslConfig
}
type UbiquityDockerPluginConfig struct {
//Address string
Port int
PluginsDirectory string
}
type UbiquityServerConnectionInfo struct {
Address string
Port int
}
type UbiquityPluginSslConfig struct {
UseSsl bool
SslMode string
VerifyCa string
}
//go:generate counterfeiter -o ../fakes/fake_storage_client.go . StorageClient
type StorageClient interface {
Activate(activateRequest ActivateRequest) error
CreateVolume(createVolumeRequest CreateVolumeRequest) error
RemoveVolume(removeVolumeRequest RemoveVolumeRequest) error
ListVolumes(listVolumeRequest ListVolumesRequest) ([]Volume, error)
GetVolume(getVolumeRequest GetVolumeRequest) (Volume, error)
GetVolumeConfig(getVolumeConfigRequest GetVolumeConfigRequest) (map[string]interface{}, error)
Attach(attachRequest AttachRequest) (string, error)
Detach(detachRequest DetachRequest) error
}
// volumeNotFoundError error for Attach, Detach, GetVolume, GetVolumeConfig, RemoveVolume interfaces if volume not found in Ubiquity DB
const VolumeNotFoundErrorMsg = "volume was not found in Ubiqutiy database."
type VolumeNotFoundError struct {
VolName string
}
func (e *VolumeNotFoundError) Error() string {
return fmt.Sprintf("[%s] "+VolumeNotFoundErrorMsg, e.VolName)
}
// volAlreadyExistsError error for Create interface if volume is already exist in the Ubiquity DB
type VolAlreadyExistsError struct {
VolName string
}
func (e *VolAlreadyExistsError) Error() string {
return fmt.Sprintf("Volume [%s] already exists.", e.VolName)
}
type BackendInitializationError struct {
BackendName string
Err error
}
func (e *BackendInitializationError) Error() string {
return fmt.Sprintf("Error while initializing %s client:[%s]", e.BackendName, e.Err.Error())
}
const ClientInitializationErrorStr = "Check backend configuration - SpectrumScale ManagementIP or SpectrumConnect managmentIP is mandatory in the ubiqutiy-configmap."
//go:generate counterfeiter -o ../fakes/fake_mounter.go . Mounter
type Mounter interface {
Mount(mountRequest MountRequest) (string, error)
Unmount(unmountRequest UnmountRequest) error
ActionAfterDetach(request AfterDetachRequest) error
}
type VolumeConfigGetter interface {
GetVolumeConfig() map[string]interface{}
}
type ActivateRequest struct {
CredentialInfo CredentialInfo
Backends []string
Opts map[string]string
Context RequestContext
}
type CreateVolumeRequest struct {
CredentialInfo CredentialInfo
Name string
Backend string
Opts map[string]interface{}
Context RequestContext
}
type RemoveVolumeRequest struct {
CredentialInfo CredentialInfo
Name string
Context RequestContext
}
type ListVolumesRequest struct {
CredentialInfo CredentialInfo
//TODO add filter
Backends []string
Context RequestContext
}
type AttachRequest struct {
CredentialInfo CredentialInfo
Name string
Host string
Context RequestContext
}
type DetachRequest struct {
CredentialInfo CredentialInfo
Name string
Host string
Context RequestContext
}
type GetVolumeRequest struct {
CredentialInfo CredentialInfo
Name string
Context RequestContext
}
type GetVolumeConfigRequest struct {
CredentialInfo CredentialInfo
Name string
Context RequestContext
}
type ActivateResponse struct {
Implements []string
Err string
}
type GenericResponse struct {
Err string
}
type MountRequest struct {
Mountpoint string
VolumeConfig map[string]interface{}
Context RequestContext
}
func (r *MountRequest) GetVolumeConfig() map[string]interface{} {
return r.VolumeConfig
}
var _ VolumeConfigGetter = &MountRequest{}
type UnmountRequest struct {
// TODO missing Mountpoint string
VolumeConfig map[string]interface{}
Context RequestContext
}
type AfterDetachRequest struct {
VolumeConfig map[string]interface{}
Context RequestContext
}
func (r *AfterDetachRequest) GetVolumeConfig() map[string]interface{} {
return r.VolumeConfig
}
var _ VolumeConfigGetter = &AfterDetachRequest{}
type AttachResponse struct {
Mountpoint string
Err string
}
type MountResponse struct {
Mountpoint string
Err string
}
type GetResponse struct {
Volume Volume
Err string
}
type DockerGetResponse struct {
Volume map[string]interface{}
Err string
}
type Volume struct {
gorm.Model
Name string
Backend string
Mountpoint string
}
type GetConfigResponse struct {
VolumeConfig map[string]interface{}
Err string
}
type ListResponse struct {
Volumes []Volume
Err string
}
type FlexVolumeResponse struct {
Status string `json:"status"`
Message string `json:"message"`
Device string `json:"device"`
}
type FlexVolumeMountRequest struct {
MountPath string `json:"mountPath"`
MountDevice string `json:"name"`
Opts map[string]interface{} `json:"opts"`
}
type FlexVolumeUnmountRequest struct {
MountPath string `json:"mountPath"`
}
type FlexVolumeAttachRequest struct {
Name string `json:"name"`
Host string `json:"host"`
Opts map[string]string `json:"opts"`
}
type FlexVolumeDetachRequest struct {
Name string `json:"name"`
Host string `json:"host"`
}
type RequestContext struct {
Id string
ActionName string
}
type VolumeMountProperties struct {
WWN string
LunNumber int
}