@@ -30,32 +30,23 @@ import (
3030
3131func (c * client ) GetSnapshotByID (ctx context.Context , snapshotID string ) (* Snapshot , error ) {
3232 logger := klog .FromContext (ctx )
33- p := c .Snapshot .NewListSnapshotsParams ()
34- p .SetId (snapshotID )
35- logger .V (2 ).Info ("CloudStack API call" , "command" , "ListSnapshots" , "params" , map [string ]string {
33+ logger .V (2 ).Info ("CloudStack API call" , "command" , "GetSnapshotByID" , "params" , map [string ]string {
3634 "id" : snapshotID ,
3735 })
38- l , err := c .Snapshot .ListSnapshots (p )
36+
37+ snapshot , _ , err := c .Snapshot .GetSnapshotByID (snapshotID )
3938 if err != nil {
4039 return nil , err
4140 }
42- if l .Count == 0 {
43- return nil , ErrNotFound
44- }
45- if l .Count > 1 {
46- return nil , ErrTooManyResults
47- }
48- snapshot := l .Snapshots [0 ]
49- s := Snapshot {
41+
42+ return & Snapshot {
5043 ID : snapshot .Id ,
5144 Name : snapshot .Name ,
5245 DomainID : snapshot .Domainid ,
5346 ProjectID : snapshot .Projectid ,
5447 ZoneID : snapshot .Zoneid ,
5548 VolumeID : snapshot .Volumeid ,
56- }
57-
58- return & s , nil
49+ }, nil
5950}
6051
6152func (c * client ) CreateSnapshot (ctx context.Context , volumeID , name string ) (* Snapshot , error ) {
@@ -72,7 +63,7 @@ func (c *client) CreateSnapshot(ctx context.Context, volumeID, name string) (*Sn
7263 return nil , status .Errorf (codes .Internal , "Error %v" , err )
7364 }
7465
75- snap := Snapshot {
66+ return & Snapshot {
7667 ID : snapshot .Id ,
7768 Name : snapshot .Name ,
7869 Size : snapshot .Virtualsize ,
@@ -81,9 +72,7 @@ func (c *client) CreateSnapshot(ctx context.Context, volumeID, name string) (*Sn
8172 ZoneID : snapshot .Zoneid ,
8273 VolumeID : snapshot .Volumeid ,
8374 CreatedAt : snapshot .Created ,
84- }
85-
86- return & snap , nil
75+ }, nil
8776}
8877
8978func (c * client ) DeleteSnapshot (_ context.Context , snapshotID string ) error {
@@ -99,39 +88,28 @@ func (c *client) DeleteSnapshot(_ context.Context, snapshotID string) error {
9988
10089func (c * client ) GetSnapshotByName (ctx context.Context , name string ) (* Snapshot , error ) {
10190 logger := klog .FromContext (ctx )
102- p := c .Snapshot .NewListSnapshotsParams ()
103- p .SetName (name )
104- logger .V (2 ).Info ("CloudStack API call" , "command" , "ListSnapshots" , "params" , map [string ]string {
91+ logger .V (2 ).Info ("CloudStack API call" , "command" , "GetSnapshotByName" , "params" , map [string ]string {
10592 "name" : name ,
10693 })
107- l , err := c .Snapshot .ListSnapshots ( p )
94+ snapshot , _ , err := c .Snapshot .GetSnapshotByName ( name )
10895 if err != nil {
10996 return nil , err
11097 }
111- if l .Count == 0 {
112- return nil , ErrNotFound
113- }
114- if l .Count > 1 {
115- return nil , ErrTooManyResults
116- }
117- snapshot := l .Snapshots [0 ]
118- s := Snapshot {
98+
99+ return & Snapshot {
119100 ID : snapshot .Id ,
120101 Name : snapshot .Name ,
121102 DomainID : snapshot .Domainid ,
122103 ProjectID : snapshot .Projectid ,
123104 ZoneID : snapshot .Zoneid ,
124105 VolumeID : snapshot .Volumeid ,
125106 CreatedAt : snapshot .Created ,
126- }
127-
128- return & s , nil
107+ }, nil
129108}
130109
131110func (c * client ) ListSnapshots (ctx context.Context , volumeID , snapshotID string ) ([]* Snapshot , error ) {
132111 logger := klog .FromContext (ctx )
133112 p := c .Snapshot .NewListSnapshotsParams ()
134-
135113 // snapshotID is optional: csi.ListSnapshotsRequest
136114 if snapshotID != "" {
137115 p .SetId (snapshotID )
@@ -141,6 +119,11 @@ func (c *client) ListSnapshots(ctx context.Context, volumeID, snapshotID string)
141119 p .SetVolumeid (volumeID )
142120 }
143121
122+ // There is no list function that uses the client default project id
123+ if c .projectID != "" {
124+ p .SetProjectid (c .projectID )
125+ }
126+
144127 logger .V (2 ).Info ("CloudStack API call" , "command" , "ListSnapshots" , "params" , map [string ]string {
145128 "id" : snapshotID ,
146129 "volumeid" : volumeID ,
0 commit comments