-
Notifications
You must be signed in to change notification settings - Fork 20
/
delete_volume.go
56 lines (47 loc) · 1.75 KB
/
delete_volume.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
/*******************************************************************************
* IBM Confidential
* OCO Source Materials
* IBM Cloud Container Service, 5737-D43
* (C) Copyright IBM Corp. 2018, 2019 All Rights Reserved.
* The source code for this program is not published or otherwise divested of
* its trade secrets, irrespective of what has been deposited with
* the U.S. Copyright Office.
******************************************************************************/
package provider
import (
"github.com/IBM/ibmcloud-storage-volume-lib/lib/provider"
userError "github.com/IBM/ibmcloud-storage-volume-lib/volume-providers/vpc/messages"
"go.uber.org/zap"
)
// DeleteVolume deletes the volume
func (vpcs *VPCSession) DeleteVolume(volume *provider.Volume) (err error) {
vpcs.Logger.Debug("Entry of DeleteVolume method...")
defer vpcs.Logger.Debug("Exit from DeleteVolume method...")
vpcs.Logger.Info("Validating basic inputs for DeleteVolume method...", zap.Reflect("VolumeDetails", volume))
err = validateVolume(volume)
if err != nil {
return err
}
vpcs.Logger.Info("Deleting volume from VPC provider...")
err = retry(vpcs.Logger, func() error {
err = vpcs.Apiclient.VolumeService().DeleteVolume(volume.VolumeID, vpcs.Logger)
return err
})
if err != nil {
return userError.GetUserError("FailedToDeleteVolume", err, volume.VolumeID)
}
vpcs.Logger.Info("Successfully deleted volume from VPC provider")
return err
}
// validateVolume validating volume ID
func validateVolume(volume *provider.Volume) (err error) {
if volume == nil {
err = userError.GetUserError("InvalidVolumeID", nil, nil)
return
}
if IsValidVolumeIDFormat(volume.VolumeID) {
return nil
}
err = userError.GetUserError("InvalidVolumeID", nil, volume.VolumeID)
return
}