forked from NetApp/netappdvp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eseries.go
704 lines (542 loc) · 22.2 KB
/
eseries.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
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
// Copyright 2016 NetApp, Inc. All Rights Reserved.
package eseries
import (
"bytes"
"encoding/json"
"sync"
"crypto/tls"
"io/ioutil"
"net/http"
"fmt"
"github.com/netapp/netappdvp/utils"
"strconv"
log "github.com/Sirupsen/logrus"
)
// VolumeInfo hold all the information about a constructed volume on E-Series array and Docker Host Mapping
type VolumeInfo struct {
VolumeGroupRef string
VolumeRef string
VolumeSize int64
SegmentSize int
UnitSize string
MediaType string
SecureVolume bool
IsVolumeMapped bool
LunMappingRef string
LunNumber int
}
// DriverConfig holds the configuration data for Driver objects
type DriverConfig struct {
//Web Proxy Services Info
WebProxy_Hostname string
Username string
Password string
//Array Info
Controller_A string
Controller_B string
Password_Array string
Array_Registered bool
//Host Connectivity
HostData_IP string //for iSCSI with multipathing this can be either IP on host
//Internal Config Variables
ArrayID string //Unique ID for array once added to web proxy services
Volumes map[string]*VolumeInfo
}
// Driver is the object to use for interacting with the Array
type Driver struct {
config *DriverConfig
m *sync.Mutex
}
// NewDriver is a factory method for creating a new instance
func NewDriver(config DriverConfig) *Driver {
d := &Driver{
config: &config,
m: &sync.Mutex{},
}
//Clear out internal config variables
d.config.ArrayID = ""
d.config.Volumes = make(map[string]*VolumeInfo)
return d
}
//Pass in marshaled json byte array
func (d Driver) SendMsg(data []byte, sendType string, msgType string) (*http.Response, error) {
if data == nil && d.config.ArrayID == "" {
panic("data is nil and no ArrayID set!")
}
log.Debugf("Sending data to web services proxy @ '%s' json: \n%s", d.config.WebProxy_Hostname, string(data))
//Do we want to use https?
secureConnect := false
addressPrefix := "http"
addressPort := "8080"
if secureConnect {
addressPrefix = "https"
addressPort = "8443"
}
//Set up address to web services proxy
url := addressPrefix + "://" + d.config.WebProxy_Hostname + ":" + addressPort + "/devmgr/v2/storage-systems/" + d.config.ArrayID + msgType
log.Debugf("URL:> %s", url)
//Check msg type
if sendType != "POST" && sendType != "GET" && sendType != "DELETE" {
panic("invalid msgType!")
}
req, err := http.NewRequest(sendType, url, bytes.NewBuffer(data))
req.Header.Set("Content-Type", "application/json")
req.SetBasicAuth(d.config.Username, d.config.Password)
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
client := &http.Client{Transport: tr}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
log.Debugf("response Status: %s", resp.Status)
log.Debugf("response Headers: %s", resp.Header)
return resp, err
}
// Add Arry to Web Services Proxy
func (d Driver) Connect() (response string, err error) {
//Send a login/connect request for array to web services proxy
msgConnect := MsgConnect{[]string{d.config.Controller_A, d.config.Controller_B}, d.config.Password_Array}
jsonConnect, err := json.Marshal(msgConnect)
if err != nil {
panic(err)
}
log.Debugf("jsonConnect=%s", string(jsonConnect))
//Send off the message
resp, err := d.SendMsg(jsonConnect, "POST", "")
defer resp.Body.Close()
if resp.StatusCode != GenericResponseSuccess && resp.StatusCode != GenericResponseOkay {
panic("Couldn't add storage array to web services proxy!")
}
body, _ := ioutil.ReadAll(resp.Body)
log.Debugf("response Body:\n%s", string(body))
//Next need to demarshal json data
responseData := MsgConnectResponse{}
if err := json.Unmarshal(body, &responseData); err != nil {
panic(err)
}
d.config.ArrayID = responseData.ArrayID
d.config.Array_Registered = responseData.AlreadyExists
log.Debugf("ArrayID=%s alreadyRegistered=%v", d.config.ArrayID, d.config.Array_Registered)
return d.config.ArrayID, nil
}
func (d Driver) VerifyVolumePools(mediaType string, size string) (VolumeGroupRef string, err error) {
//Verify we have a valid array id
if d.config.ArrayID == "" {
panic("ArrayID is invalid!")
}
//Do the GET to obtain volume pools
resp, err := d.SendMsg(nil, "GET", "/storage-pools")
defer resp.Body.Close()
if resp.StatusCode != GenericResponseOkay {
return "", fmt.Errorf("ESeriesStorageDriver::VerifyVolumePools - GET to obtain volume pools failed! StatusCode=%v Status=%s", resp.StatusCode, resp.Status)
}
body, _ := ioutil.ReadAll(resp.Body)
log.Debugf("response Body:\n%s", string(body))
//Next need to demarshal json data
responseJSON := make([]VolumeGroupExResponse, 0)
if err := json.Unmarshal(body, &responseJSON); err != nil {
panic(err)
}
//Create search volume group label
var volumeGroupLabel string = "netappdvp_"
if mediaType != "ssd" && mediaType != "hdd" {
return "", fmt.Errorf("ESeriesStorageDriver::VerifyVolumePools - mediaType specified is invalid! mediaType=%s", mediaType)
}
volumeGroupLabel += mediaType
//Search for correct volume group label
var volumeGroupRef string = ""
var volumeFreeSpace string = "0"
for i, e := range responseJSON {
log.Debugf("%v) label=%s freeSpace=%s", i, e.VolumeLabel, e.FreeSpace)
if e.VolumeLabel == volumeGroupLabel {
volumeGroupRef = e.VolumeGroupRef
volumeFreeSpace = e.FreeSpace
}
}
if volumeGroupRef == "" {
return "", fmt.Errorf("ESeriesStorageDriver::VerifyVolumePools - correct volume group not found for mediaType=%s!", mediaType)
}
//Verify volume group has enough space
convertedSize, convertErr := utils.ConvertSizeToBytes64(size)
if convertErr != nil {
fmt.Errorf("Cannot convert size to bytes: %v error: %v", size, convertErr)
return "", convertErr
}
lunSize, atoiErr := strconv.ParseInt(convertedSize, 10, 0)
if atoiErr != nil {
fmt.Errorf("Cannot convert size to bytes: %v error: %v", size, atoiErr)
return "", atoiErr
}
if convertedVolumeFreeSpace, _ := strconv.ParseInt(volumeFreeSpace, 10, 0); lunSize > convertedVolumeFreeSpace {
return "", fmt.Errorf("ESeriesStorageDriver::VerifyVolumePools - volume group doesn't have enough space! lunSize=%v > volumeFreeSpace=%v!", lunSize, volumeFreeSpace)
}
return volumeGroupRef, nil
}
func (d Driver) VerifyVolumeExists(name string) (err error) {
//Verify we have a valid array id
if d.config.ArrayID == "" {
panic("ArrayID is invalid!")
}
//First check if volume is already in persistant map
if _, isPresent := d.config.Volumes[name]; isPresent {
return nil
}
//If not in map then we need to query volumes on array
resp, err := d.SendMsg(nil, "GET", "/volumes")
defer resp.Body.Close()
if resp.StatusCode != GenericResponseOkay {
return fmt.Errorf("ESeriesStorageDriver::VerifyVolumeExists - GET to obtain volume failed! StatusCode=%v Status=%s", resp.StatusCode, resp.Status)
}
body, _ := ioutil.ReadAll(resp.Body)
log.Debugf("response Body:\n%s", string(body))
//Next need to demarshal json data
responseJSON := make([]MsgVolumeExResponse, 0)
if err := json.Unmarshal(body, &responseJSON); err != nil {
panic(err)
}
var foundVolume bool = false
for i, e := range responseJSON {
log.Debugf("%v) Found volume with name %s Label=%s IsMapped=%v", i, name, e.Label, e.IsMapped)
if e.Label == name {
foundVolume = true
//Create a VolumeInfo structure and add it to the map
var tmpVolumeInfo VolumeInfo
tmpVolumeInfo.VolumeGroupRef = e.VolumeGroupRef
tmpVolumeInfo.VolumeRef = e.VolumeRef
//Convert size of volume from string to int64
tmpLunSize, atoiErr := strconv.ParseInt(e.VolumeSize, 10, 0)
if atoiErr != nil {
fmt.Errorf("Cannot convert size to bytes: %v error: %v", e.VolumeSize, atoiErr)
return atoiErr
}
tmpVolumeInfo.VolumeSize = tmpLunSize
tmpVolumeInfo.SegmentSize = e.SegmentSize
tmpVolumeInfo.UnitSize = "b" //bytes
//Need to figure out mediaType (whether this volume belongs to hdd or ssd group)
volumeGroupRef, error := d.VerifyVolumePools("hdd", "1m") //1 megabyte is just a small unit to use while figuring out which media type this volume belongs to
if error != nil {
return error
}
if e.VolumeGroupRef == volumeGroupRef {
//Found it! It is a hdd volume group.
tmpVolumeInfo.MediaType = "hdd"
} else {
//Not a part of hdd volume group so see if it is part of ssd volume group
volumeGroupRef1, error1 := d.VerifyVolumePools("ssd", "1m") //1 megabyte is just a small unit to use while figuring out which media type this volume belongs to
if error != nil {
return error1
}
if e.VolumeGroupRef == volumeGroupRef1 {
//Found it! It is part of ssd volume group.
tmpVolumeInfo.MediaType = "ssd"
} else {
//It isn't part of ssd nor hdd volume group!
panic("volume is not part of ssd nor hdd volume group!")
}
}
tmpVolumeInfo.SecureVolume = false //TODO: add this capability for FDE drives
tmpVolumeInfo.IsVolumeMapped = e.IsMapped
for j, f := range e.ListOfMappings {
log.Debugf("%v) Volume with name %s has mapping reference %s", j, name, f.LunMappingRef)
tmpVolumeInfo.LunMappingRef = f.LunMappingRef //TODO - what if there are multiple mappings? Is this even possible outside 'Default Group'?
tmpVolumeInfo.LunNumber = f.LunNumber
}
//Add it to map
d.config.Volumes[name] = &tmpVolumeInfo
//Stop searching
break
}
}
if !foundVolume {
return fmt.Errorf("ESeriesStorageDriver::VerifyVolumeExists - volume with name %s not found on array! Are you sure you created a volume with this name?", name)
}
return nil
}
func (d Driver) IsVolumeAlreadyMappedToHost(name string, hostRef string) (isMapped bool, lunNumber int, err error) {
//Verify we have a valid array id
if d.config.ArrayID == "" {
panic("ArrayID is invalid!")
}
resp, err := d.SendMsg(nil, "GET", "/volume-mappings")
defer resp.Body.Close()
if resp.StatusCode != GenericResponseOkay {
return false, -1, fmt.Errorf("ESeriesStorageDriver::IsVolumeAlreadyMappedToHost - GET to obtain volume mappings failed! StatusCode=%v Status=%s", resp.StatusCode, resp.Status)
}
body, _ := ioutil.ReadAll(resp.Body)
log.Debugf("response Body:\n%s", string(body))
//Next need to demarshal json data
responseJSON := make([]LUNMapping, 0)
if err := json.Unmarshal(body, &responseJSON); err != nil {
panic(err)
}
//Need to find the correct volumeRef for the name argument and also verify that if is mapped already that it is indeed mapped to our host and not some other host
var foundVolumeMapping bool = false
//Make sure volume is already in persistant map
tmpVolumeInfo, isPresent := d.config.Volumes[name]
if !isPresent {
panic("volume is not already apart of map! Check to see if you indeed created the docker volume with this name.")
}
//tmpVolumeInfo.VolumeRef
for i, e := range responseJSON {
log.Debugf("%v) Found host mapping with volumeRef=%s mapped to LUN number %v with hostRef=%s", i, e.VolumeRef, e.LunNumber, e.HostRef)
if e.VolumeRef == tmpVolumeInfo.VolumeRef {
//We found our volume and it is indeed mapped, but is it mapped to the correct host?
foundVolumeMapping = true
if e.HostRef == hostRef {
//Yes, it is mapped to proper host
return true, e.LunNumber, nil
} else {
//No, it is mapped to different host!
return false, e.LunNumber, fmt.Errorf("ESeriesStorageDriver::IsVolumeAlreadyMappedToHost - found mapped volume with name %s but it is mapped to different host (%s) rather than requested host (%s)", name, e.HostRef, hostRef)
}
}
}
if foundVolumeMapping {
panic("Unreachable code path")
}
//The volume is not mapped to any host
return false, -1, nil
}
func (d Driver) CreateVolume(name string, volumeGroupRef string, size string, mediaType string) (volumeRef string, err error) {
//Verify we have a valid array id
if d.config.ArrayID == "" {
panic("ArrayID is invalid!")
}
//Lets create a volume message structure
var msgCreateVolume MsgVolumeEx
msgCreateVolume.VolumeGroupRef = volumeGroupRef
msgCreateVolume.Name = name
msgCreateVolume.SizeUnit = "kb" //bytes, b, kb, mb, gb, tb, pb, eb, zb, yb
msgCreateVolume.SegmentSize = 128
//Convert size string to int64
convertedSize, convertErr := utils.ConvertSizeToBytes64(size)
if convertErr != nil {
return "", fmt.Errorf("Cannot convert size to bytes: %v error: %v", size, convertErr)
}
lunSize, atoiErr := strconv.ParseInt(convertedSize, 10, 0)
if atoiErr != nil {
return "", fmt.Errorf("Cannot convert size to bytes: %v error: %v", size, atoiErr)
}
//Set lun size in kilobytes
msgCreateVolume.Size = int(lunSize / 1024) //the json request requires lunSize to be an int not an int64 so we are passing it as an int but in kilobytes
jsonCreateVolume, err := json.Marshal(msgCreateVolume)
if err != nil {
panic(err)
}
log.Debugf("jsonCreateVolume=%s", string(jsonCreateVolume))
//Send off the message
resp, err := d.SendMsg(jsonCreateVolume, "POST", "/volumes")
defer resp.Body.Close()
if resp.StatusCode == GenericResponseOkay {
//Success!
body, _ := ioutil.ReadAll(resp.Body)
log.Debugf("response Body:\n%s", string(body))
//Next need to demarshal json data
responseData := MsgVolumeExResponse{}
if err := json.Unmarshal(body, &responseData); err != nil {
panic(err)
}
log.Debugf("Label=%s VolumeRef=%s", responseData.Label, responseData.VolumeRef)
//Create a VolumeInfo structure and put it into the map
var tmpVolumeInfo VolumeInfo
tmpVolumeInfo.VolumeGroupRef = volumeGroupRef
tmpVolumeInfo.VolumeRef = responseData.VolumeRef
tmpVolumeInfo.VolumeSize = lunSize
tmpVolumeInfo.SegmentSize = msgCreateVolume.SegmentSize * 1024 //convert from kilobytes to bytes
tmpVolumeInfo.UnitSize = "b" //bytes
//Sanity check
if tmpVolumeInfo.SegmentSize != responseData.SegmentSize {
panic("Segment size specified in request doesn't equal returned volume segment size!")
}
tmpVolumeInfo.MediaType = mediaType
tmpVolumeInfo.SecureVolume = false //TODO: add this capability for FDE drives
tmpVolumeInfo.IsVolumeMapped = false
tmpVolumeInfo.LunMappingRef = ""
tmpVolumeInfo.LunNumber = -1
//Add it to map
d.config.Volumes[name] = &tmpVolumeInfo
return responseData.VolumeRef, nil
} else if resp.StatusCode == GenericResponseNotFound || resp.StatusCode == GenericResponseMalformed {
//Known Error!
body, _ := ioutil.ReadAll(resp.Body)
log.Debugf("response Body:\n%s", string(body))
//Next need to demarshal json data
responseData := CallResponseError{}
if err := json.Unmarshal(body, &responseData); err != nil {
panic(err)
}
return "", fmt.Errorf("Error - not found code - ErrorMsg=%s LocalizedMsg=%s", responseData.ErrorMsg, responseData.LocalizedMsg)
} else {
return "", fmt.Errorf("Unknown error code - StatusCode=%v!", resp.StatusCode)
}
return "", fmt.Errorf("Unreachable Code Path!")
}
func (d Driver) VerifyHostIQN(iqn string) (hostRef string, err error) {
//Verify we have a valid array id
if d.config.ArrayID == "" {
panic("ArrayID is invalid!")
}
//Do a GET to obtain hosts on array
resp, err := d.SendMsg(nil, "GET", "/hosts")
defer resp.Body.Close()
if resp.StatusCode != GenericResponseOkay {
panic("Couldn't obtain storage pools!")
}
body, _ := ioutil.ReadAll(resp.Body)
log.Debugf("response Body:\n%s", string(body))
//Next need to demarshal json data
responseJSON := make([]HostExResponse, 0)
if err := json.Unmarshal(body, &responseJSON); err != nil {
panic(err)
}
var retHostRef string = ""
for i, e := range responseJSON {
log.Debugf("%v) HostRef=%s Label=%s", i, e.HostRef, e.Label)
for j, f := range e.Initiators {
log.Debugf(" %v) Host_Label=%s interface=%s iqn=%s", j, f.Label, f.NodeName.IoInterfaceType, f.NodeName.IscsiNodeName)
if f.NodeName.IoInterfaceType == "iscsi" && f.NodeName.IscsiNodeName == iqn {
retHostRef = e.HostRef
}
}
}
//Make sure we found the correct hostRef
if retHostRef == "" {
return "", fmt.Errorf("Host reference not found on array for host IQN %s!", iqn)
}
return retHostRef, nil
}
func (d Driver) MapVolume(name string, hostRef string) (lunNumber int, err error) {
//Verify we have a valid array id
if d.config.ArrayID == "" {
panic("ArrayID is invalid!")
}
//Look up volumeRef in persistant map, and error out if it is not found
tmpVolumeInfo, isPresent := d.config.Volumes[name]
if !isPresent {
return -1, fmt.Errorf("name (%s) wasn't found in persistant map! Have you created a netappdvp volume group yet with that name?", name)
}
//Lets create a volume message structure
var msgMapVolume VolumeMappingCreateRequest
msgMapVolume.MappableObjectId = tmpVolumeInfo.VolumeRef
msgMapVolume.TargetID = hostRef
//msgMapVolume.LunNumber = 20 <--- optional parameter. Just let array choose the LUN #, and return it on response
jsonMapVolume, err := json.Marshal(msgMapVolume)
if err != nil {
panic(err)
}
log.Debugf("jsonMapVolume=%s", string(jsonMapVolume))
//Send off the message
resp, err := d.SendMsg(jsonMapVolume, "POST", "/volume-mappings")
defer resp.Body.Close()
if resp.StatusCode != GenericResponseOkay {
return -1, fmt.Errorf("Error occured while mapping volume! ReturnCode=%v name=%s volumeRef=%s hostRef=%s", resp.StatusCode, name, tmpVolumeInfo.VolumeRef, hostRef)
}
//Got back success code
body, _ := ioutil.ReadAll(resp.Body)
log.Debugf("response Body:\n%s", string(body))
//Next need to demarshal json data
responseData := LUNMapping{}
if err := json.Unmarshal(body, &responseData); err != nil {
panic(err)
}
log.Debugf("LunMappingRef=%s LunNumber=%v VolumeRef=%s", responseData.LunMappingRef, responseData.LunNumber, responseData.VolumeRef)
//Sanity check to verify that returned volumeRef matches up with the volume we sent
if tmpVolumeInfo.VolumeRef != responseData.VolumeRef {
return -1, fmt.Errorf("Extremely odd case where the returned volumeRef (%s) doesn't equal the volumeRef (%s) we sent to array to map!", responseData.VolumeRef, tmpVolumeInfo.VolumeRef)
}
//Update volumeInfo map for this volume that we are not mapped as well as setting the LunMappingRef and LUN #
if tmpVolumeInfo.IsVolumeMapped {
panic("Volume is already mapped!")
}
tmpVolumeInfo.IsVolumeMapped = true
tmpVolumeInfo.LunMappingRef = responseData.LunMappingRef
tmpVolumeInfo.LunNumber = responseData.LunNumber
return responseData.LunNumber, nil
}
func (d Driver) UnmapVolume(name string) (err error) {
//Verify we have a valid array id
if d.config.ArrayID == "" {
panic("ArrayID is invalid!")
}
//Need to lookup lunMappingRef for this volume from the volumeInfo map and do some sanity checking
tmpVolumeInfo, isPresent := d.config.Volumes[name]
if !isPresent {
//If we are in this unmap function this volume better be in the volumeInfo map!
panic("ERROR - volume wasn't found in volumeInfo map!")
}
//Sanity checks to make sure volume is mapped and have a LunMappingRef
if !tmpVolumeInfo.IsVolumeMapped {
//We are in unmap and the volume isn't even mapped!
panic("ERROR - volume was found on array but it isn't mapped!")
}
if tmpVolumeInfo.LunMappingRef == "" {
//Note: if this volume is indeed mapped it should have had its LunMappingRef filled either inside of CreateVolume function or inside of VerifyVolumeExists function!
panic("ERROR - LunMappingRef is empty!")
}
//Send a DELETE to remove this LUN mapping from storage array
resp, err := d.SendMsg(nil, "DELETE", "/volume-mappings/"+tmpVolumeInfo.LunMappingRef)
defer resp.Body.Close()
if resp.StatusCode != GenericResponseOkay && resp.StatusCode != GenericResponseNoContent {
return fmt.Errorf("Error occured while trying to remove LUN mapping for volume %s! Error Code (%v) and Status=%s", name, resp.StatusCode, resp.Status)
}
if resp.StatusCode != GenericResponseNoContent {
body, _ := ioutil.ReadAll(resp.Body)
log.Debugf("response Body:\n%s", string(body))
//Next need to demarshal json data
responseData := LUNMapping{}
if err := json.Unmarshal(body, &responseData); err != nil {
panic(err)
}
//Sanity check to verify we remove LUN mapping for correct volume
if responseData.LunMappingRef != tmpVolumeInfo.LunMappingRef {
return fmt.Errorf("Error occured while trying to remove LUN mapping for volume %s! Very odd - responseData.LunMappingRef (%s) != tmpVolumeInfo.LunMappingRef (%s)...", name, responseData.LunMappingRef, tmpVolumeInfo.LunMappingRef)
}
}
//Alter the state of the volumeInfo mapping to reflect this volume is no longer mapped
tmpVolumeInfo.IsVolumeMapped = false
tmpVolumeInfo.LunMappingRef = ""
tmpVolumeInfo.LunNumber = -1
//Return success!
return nil
}
func (d Driver) DestroyVolume(name string) (err error) {
//Verify we have a valid array id
if d.config.ArrayID == "" {
panic("ArrayID is invalid!")
}
//Make sure this volume is found in our volumeInfo map
tmpVolumeInfo, isPresent := d.config.Volumes[name]
if !isPresent {
//If we are in this destroy function this volume better be in the volumeInfo map!
panic("ERROR - volume wasn't found in volumeInfo map!")
}
//Sanity checks to make sure volume in map has a volumeRef
if tmpVolumeInfo.VolumeRef == "" {
//We are in destroy and the volume doesn't have a volumeRef!
panic("ERROR - volume was found in volumeInfo map but has invalid volumeRef!")
}
//Send a DELETE to remove this volume from storage array
resp, err := d.SendMsg(nil, "DELETE", "/volumes/"+tmpVolumeInfo.VolumeRef)
defer resp.Body.Close()
if resp.StatusCode != GenericResponseOkay && resp.StatusCode != GenericResponseNoContent {
if resp.StatusCode == GenericResponseNotFound {
body, _ := ioutil.ReadAll(resp.Body)
log.Debugf("error response Body:\n%s", string(body))
//Next need to demarshal json data
responseData := CallResponseError{}
if err := json.Unmarshal(body, &responseData); err != nil {
panic(err)
}
//Offer more information about what went wrong with request than just HTTP error information
return fmt.Errorf("Error occured while trying to remove LUN mapping for volume %s! ErrorMsg=%s LocalizedMsg=%s RetCode=%s CodeType=%s Error Code (%v) and Status=%s", name, responseData.ErrorMsg, responseData.LocalizedMsg, responseData.ReturnCode, responseData.CodeType, resp.StatusCode, resp.Status)
} else {
//Different error than NotFound
return fmt.Errorf("Error occured while trying to remove LUN mapping for volume %s! Error Code (%v) and Status=%s", name, resp.StatusCode, resp.Status)
}
}
//Remove this volume from volumeInfo map
delete(d.config.Volumes, name)
return nil
}