Skip to content

Commit

Permalink
EFS VolumeGet implementation (#6076)
Browse files Browse the repository at this point in the history
* EFS volume get

* Wrap the error

* Use only range iterator
  • Loading branch information
Hakan Memisoglu authored and Ilya Kislenko committed Jul 18, 2019
1 parent 9e2f836 commit d4267a9
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
27 changes: 26 additions & 1 deletion pkg/blockstorage/awsefs/awsefs.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ func (e *efs) VolumeDelete(context.Context, *blockstorage.Volume) error {
}

func (e *efs) VolumeGet(ctx context.Context, id string, zone string) (*blockstorage.Volume, error) {
return nil, errors.New("Not implemented")
desc, err := e.getFileSystemDescriptionWithID(ctx, id)
if err != nil {
return nil, errors.Wrap(err, "Failed to get EFS volume")
}
return volumeFromEFSDescription(desc, zone), nil
}

func (e *efs) SnapshotCopy(ctx context.Context, from blockstorage.Snapshot, to blockstorage.Snapshot) (*blockstorage.Snapshot, error) {
Expand Down Expand Up @@ -107,3 +111,24 @@ func (e *efs) VolumesList(ctx context.Context, tags map[string]string, zone stri
func (e *efs) SnapshotsList(ctx context.Context, tags map[string]string) ([]*blockstorage.Snapshot, error) {
return nil, errors.New("Not implemented")
}

func (e *efs) getFileSystemDescriptionWithID(ctx context.Context, id string) (*awsefs.FileSystemDescription, error) {
req := &awsefs.DescribeFileSystemsInput{}
req.SetFileSystemId(id)

descs, err := e.DescribeFileSystemsWithContext(ctx, req)
if err != nil {
return nil, errors.Wrap(err, "Failed to get filesystem description")
}
availables := filterAvailable(descs.FileSystems)
var desc *awsefs.FileSystemDescription
switch len(availables) {
case 0:
return nil, errors.New("Failed to find volume")
case 1:
desc = descs.FileSystems[0]
default:
return nil, errors.New("Unexpected condition, multiple filesystems with same ID")
}
return desc, nil
}
15 changes: 15 additions & 0 deletions pkg/blockstorage/awsefs/filter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package awsefs

import (
awsefs "github.com/aws/aws-sdk-go/service/efs"
)

func filterAvailable(descriptions []*awsefs.FileSystemDescription) []*awsefs.FileSystemDescription {
result := make([]*awsefs.FileSystemDescription, 0)
for _, desc := range descriptions {
if *desc.LifeCycleState == awsefs.LifeCycleStateAvailable {
result = append(result, desc)
}
}
return result
}

0 comments on commit d4267a9

Please sign in to comment.