-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimgo_lsmplugin.go
383 lines (304 loc) · 10.8 KB
/
simgo_lsmplugin.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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
// SPDX-License-Identifier: 0BSD
package main
import (
"fmt"
"net/url"
"os"
"strings"
lsm "github.com/libstorage/libstoragemgmt-golang"
"github.com/libstorage/libstoragemgmt-golang/errors"
)
type pluginData struct {
reg lsm.PluginRegister
c *lsm.ClientConnection
tmo uint32
}
var state pluginData
func register(p *lsm.PluginRegister) error {
parsed, pE := url.Parse(p.URI)
if pE != nil {
return pE
}
values := strings.Split(parsed.RawQuery, "=")
if len(values) != 2 || values[0] != "forward" {
return &errors.LsmError{
Code: errors.InvalidArgument,
Message: fmt.Sprintf("expected query string to be 'forward=<otherplugin>' got %s", parsed.RawQuery)}
}
var cE error
state.c, cE = lsm.Client(fmt.Sprintf("%s://", values[1]), "", p.Timeout)
return cE
}
func unregister() error {
return state.c.Close()
}
func systems() ([]lsm.System, error) {
return state.c.Systems()
}
func pools(search ...string) ([]lsm.Pool, error) {
if len(search) > 0 {
return state.c.Pools(search[0], search[1])
}
return state.c.Pools()
}
func volumes(search ...string) ([]lsm.Volume, error) {
if len(search) > 0 {
return state.c.Volumes(search[0], search[1])
}
return state.c.Volumes()
}
func tmoSet(timeout uint32) error {
state.tmo = timeout
return nil
}
func tmoGet() uint32 {
return state.tmo
}
func capabilities(system *lsm.System) (*lsm.Capabilities, error) {
return state.c.Capabilities(system)
}
func jobStatus(jobID string) (*lsm.JobInfo, error) {
var item interface{}
jobStatus, jobPercent, error := state.c.JobStatus(jobID, &item)
if error != nil {
return nil, error
}
return &lsm.JobInfo{Status: jobStatus, Percent: jobPercent, Item: item}, nil
}
func jobFree(jobID string) error {
return state.c.JobFree(jobID)
}
func volCreate(pool *lsm.Pool, volumeName string, size uint64,
provisioning lsm.VolumeProvisionType) (*lsm.Volume, *string, error) {
return state.c.VolumeCreate(pool, volumeName, size, provisioning, false)
}
func volDelete(volume *lsm.Volume) (*string, error) {
return state.c.VolumeDelete(volume, false)
}
func disks() ([]lsm.Disk, error) {
return state.c.Disks()
}
func volReplicate(optionalPool *lsm.Pool, repType lsm.VolumeReplicateType,
sourceVolume *lsm.Volume, name string) (*lsm.Volume, *string, error) {
return state.c.VolumeReplicate(optionalPool, repType, sourceVolume, name, false)
}
func volReplicateRange(repType lsm.VolumeReplicateType, srcVol *lsm.Volume, dstVol *lsm.Volume,
ranges []lsm.BlockRange) (*string, error) {
return state.c.VolumeReplicateRange(repType, srcVol, dstVol, ranges, false)
}
func volRepRangeBlockSize(system *lsm.System) (uint32, error) {
return state.c.VolumeRepRangeBlkSize(system)
}
func volResize(vol *lsm.Volume, newSizeBytes uint64) (*lsm.Volume, *string, error) {
return state.c.VolumeResize(vol, newSizeBytes, false)
}
func volEnable(vol *lsm.Volume) error {
return state.c.VolumeEnable(vol)
}
func volDisable(vol *lsm.Volume) error {
return state.c.VolumeDisable(vol)
}
func accessGroups() ([]lsm.AccessGroup, error) {
return state.c.AccessGroups()
}
func accessGroupCreate(name string, initID string,
initType lsm.InitiatorType, system *lsm.System) (*lsm.AccessGroup, error) {
return state.c.AccessGroupCreate(name, initID, initType, system)
}
func accessGroupDelete(ag *lsm.AccessGroup) error {
return state.c.AccessGroupDelete(ag)
}
func accessGroupInitAdd(ag *lsm.AccessGroup,
initID string, initType lsm.InitiatorType) (*lsm.AccessGroup, error) {
return state.c.AccessGroupInitAdd(ag, initID, initType)
}
func accessGroupInitDelete(ag *lsm.AccessGroup,
initID string, initType lsm.InitiatorType) (*lsm.AccessGroup, error) {
return state.c.AccessGroupInitDelete(ag, initID, initType)
}
func volumeMask(vol *lsm.Volume, ag *lsm.AccessGroup) error {
return state.c.VolumeMask(vol, ag)
}
func volumeUnMask(vol *lsm.Volume, ag *lsm.AccessGroup) error {
return state.c.VolumeUnMask(vol, ag)
}
func volsMaskedToAg(ag *lsm.AccessGroup) ([]lsm.Volume, error) {
return state.c.VolsMaskedToAg(ag)
}
func agsGrantedToVol(vol *lsm.Volume) ([]lsm.AccessGroup, error) {
return state.c.AgsGrantedToVol(vol)
}
func iscsiChapAuthSet(initID string, inUser *string, inPassword *string, outUser *string, outPassword *string) error {
return state.c.IscsiChapAuthSet(initID, inUser, inPassword, outUser, outPassword)
}
func volHasChildDep(vol *lsm.Volume) (bool, error) {
return state.c.VolHasChildDep(vol)
}
func volChildDepRm(vol *lsm.Volume) (*string, error) {
return state.c.VolChildDepRm(vol, false)
}
func targetPorts() ([]lsm.TargetPort, error) {
return state.c.TargetPorts()
}
func volIdentLedOn(vol *lsm.Volume) error {
return state.c.VolIdentLedOn(vol)
}
func volIdentLedOff(vol *lsm.Volume) error {
return state.c.VolIdentLedOff(vol)
}
func fileSystems(search ...string) ([]lsm.FileSystem, error) {
if len(search) > 0 {
return state.c.FileSystems(search[0], search[1])
}
return state.c.FileSystems()
}
func fileSystemCreate(pool *lsm.Pool, name string, sizeBytes uint64) (*lsm.FileSystem, *string, error) {
return state.c.FsCreate(pool, name, sizeBytes, false)
}
func fileSystemDelete(fs *lsm.FileSystem) (*string, error) {
return state.c.FsDelete(fs, false)
}
func fileSystemResize(fs *lsm.FileSystem, newSizeBytes uint64) (*lsm.FileSystem, *string, error) {
return state.c.FsResize(fs, newSizeBytes, false)
}
func fileSystemClone(srcFs *lsm.FileSystem, destName string, optionalSnapShot *lsm.FileSystemSnapShot) (*lsm.FileSystem, *string, error) {
return state.c.FsClone(srcFs, destName, optionalSnapShot, false)
}
func fileSystemFileClone(fs *lsm.FileSystem, srcFileName string, dstFileName string,
optionalSnapShot *lsm.FileSystemSnapShot) (*string, error) {
return state.c.FsFileClone(fs, srcFileName, dstFileName, optionalSnapShot, false)
}
func fileSystemSnapShotCreate(fs *lsm.FileSystem, name string) (*lsm.FileSystemSnapShot, *string, error) {
return state.c.FsSnapShotCreate(fs, name, false)
}
func fileSystemSnapShotDelete(fs *lsm.FileSystem, ss *lsm.FileSystemSnapShot) (*string, error) {
return state.c.FsSnapShotDelete(fs, ss, false)
}
func fileSystemSnapShots(fs *lsm.FileSystem) ([]lsm.FileSystemSnapShot, error) {
return state.c.FsSnapShots(fs)
}
func fileSystemSnapShotRestore(fs *lsm.FileSystem, ss *lsm.FileSystemSnapShot,
allFiles bool, files []string, restoreFiles []string) (*string, error) {
return state.c.FsSnapShotRestore(fs, ss, allFiles, files, restoreFiles, false)
}
func fileSystemHasChildDep(fs *lsm.FileSystem, files []string) (bool, error) {
return state.c.FsHasChildDep(fs, files)
}
func fileSystemChildDepRm(fs *lsm.FileSystem, files []string) (*string, error) {
return state.c.FsChildDepRm(fs, files, false)
}
func exports(search ...string) ([]lsm.NfsExport, error) {
if len(search) > 1 {
return state.c.NfsExports(search[0], search[1])
}
return state.c.NfsExports()
}
func fsExport(fs *lsm.FileSystem, exportPath *string,
access *lsm.NfsAccess, authType *string, options *string) (*lsm.NfsExport, error) {
return state.c.FsExport(fs, exportPath, access, authType, options)
}
func fsUnExport(export *lsm.NfsExport) error {
return state.c.FsUnExport(export)
}
func fsExportAuthTypes() ([]string, error) {
return state.c.NfsExportAuthTypes()
}
func volRaidCreate(name string, raidType lsm.RaidType, disks []lsm.Disk, stripSize uint32) (*lsm.Volume, error) {
return state.c.VolRaidCreate(name, raidType, disks, stripSize)
}
func volRaidCreateCapGet(sys *lsm.System) (*lsm.SupportedRaidCapability, error) {
return state.c.VolRaidCreateCapGet(sys)
}
func poolMemberInfo(pool *lsm.Pool) (*lsm.PoolMemberInfo, error) {
return state.c.PoolMemberInfo(pool)
}
func handleVolRaidInfo(vol *lsm.Volume) (*lsm.VolumeRaidInfo, error) {
return state.c.VolRaidInfo(vol)
}
func handleBatteries() ([]lsm.Battery, error) {
return state.c.Batteries()
}
func sysReadCachePctSet(system *lsm.System, readPercent uint32) error {
return state.c.SysReadCachePctSet(system, readPercent)
}
func volCacheInfo(volume *lsm.Volume) (*lsm.VolumeCacheInfo, error) {
return state.c.VolCacheInfo(volume)
}
func volPhyDiskCacheSet(volume *lsm.Volume, pdc lsm.PhysicalDiskCache) error {
return state.c.VolPhyDiskCacheSet(volume, pdc)
}
func volWriteCacheSet(volume *lsm.Volume, wcp lsm.WriteCachePolicy) error {
return state.c.VolWriteCacheSet(volume, wcp)
}
func volReadCacheSet(volume *lsm.Volume, rcp lsm.ReadCachePolicy) error {
return state.c.VolReadCacheSet(volume, rcp)
}
func main() {
var cb lsm.PluginCallBacks
cb.Mgmt.Systems = systems
cb.Mgmt.PluginRegister = register
cb.Mgmt.PluginUnregister = unregister
cb.Mgmt.Pools = pools
cb.Mgmt.TimeOutSet = tmoSet
cb.Mgmt.TimeOutGet = tmoGet
cb.Mgmt.Capabilities = capabilities
cb.Mgmt.JobStatus = jobStatus
cb.Mgmt.JobFree = jobFree
cb.San.VolumeCreate = volCreate
cb.San.VolumeDelete = volDelete
cb.San.Volumes = volumes
cb.San.Disks = disks
cb.San.VolumeReplicate = volReplicate
cb.San.VolumeReplicateRange = volReplicateRange
cb.San.VolumeRepRangeBlkSize = volRepRangeBlockSize
cb.San.VolumeResize = volResize
cb.San.VolumeEnable = volEnable
cb.San.VolumeDisable = volDisable
cb.San.VolumeMask = volumeMask
cb.San.VolumeUnMask = volumeUnMask
cb.San.VolsMaskedToAg = volsMaskedToAg
cb.San.VolHasChildDep = volHasChildDep
cb.San.VolChildDepRm = volChildDepRm
cb.San.AccessGroups = accessGroups
cb.San.AccessGroupCreate = accessGroupCreate
cb.San.AccessGroupDelete = accessGroupDelete
cb.San.AccessGroupInitAdd = accessGroupInitAdd
cb.San.AccessGroupInitDelete = accessGroupInitDelete
cb.San.AgsGrantedToVol = agsGrantedToVol
cb.San.IscsiChapAuthSet = iscsiChapAuthSet
cb.San.TargetPorts = targetPorts
cb.San.VolIdentLedOn = volIdentLedOn
cb.San.VolIdentLedOff = volIdentLedOff
cb.File.FileSystems = fileSystems
cb.File.FsCreate = fileSystemCreate
cb.File.FsDelete = fileSystemDelete
cb.File.FsResize = fileSystemResize
cb.File.FsClone = fileSystemClone
cb.File.FsFileClone = fileSystemFileClone
cb.File.FsSnapShotCreate = fileSystemSnapShotCreate
cb.File.FsSnapShotDelete = fileSystemSnapShotDelete
cb.File.FsSnapShots = fileSystemSnapShots
cb.File.FsSnapShotRestore = fileSystemSnapShotRestore
cb.File.FsHasChildDep = fileSystemHasChildDep
cb.File.FsChildDepRm = fileSystemChildDepRm
cb.Nfs.Exports = exports
cb.Nfs.FsExport = fsExport
cb.Nfs.FsUnExport = fsUnExport
cb.Nfs.ExportAuthTypes = fsExportAuthTypes
cb.Hba.VolRaidCreate = volRaidCreate
cb.Hba.VolRaidCreateCapGet = volRaidCreateCapGet
cb.Hba.PoolMemberInfo = poolMemberInfo
cb.Hba.VolRaidInfo = handleVolRaidInfo
cb.Hba.Batteries = handleBatteries
cb.Cache.SysReadCachePctSet = sysReadCachePctSet
cb.Cache.VolCacheInfo = volCacheInfo
cb.Cache.VolPhyDiskCacheSet = volPhyDiskCacheSet
cb.Cache.VolWriteCacheSet = volWriteCacheSet
cb.Cache.VolReadCacheSet = volReadCacheSet
plugin, err := lsm.PluginInit(&cb, os.Args, "golang forwarding plugin", "0.0.1")
if err != nil {
fmt.Printf("Failed to initialize plugin, exiting! (%s)\n", err)
} else {
plugin.Run()
}
}