github.com/emc-advanced-dev/unik@v0.0.0-20190717152701-a58d3e8e33b7/pkg/providers/common/get_volume.go (about) 1 package common 2 3 import ( 4 "github.com/emc-advanced-dev/pkg/errors" 5 "github.com/solo-io/unik/pkg/providers" 6 "github.com/solo-io/unik/pkg/types" 7 "strings" 8 ) 9 10 func GetVolume(p providers.Provider, nameOrIdPrefix string) (*types.Volume, error) { 11 volumes, err := p.ListVolumes() 12 if err != nil { 13 return nil, errors.New("retrieving volume list", err) 14 } 15 for _, volume := range volumes { 16 if strings.Contains(volume.Id, nameOrIdPrefix) || strings.Contains(volume.Name, nameOrIdPrefix) { 17 return volume, nil 18 } 19 } 20 return nil, errors.New("volume with name or id containing '"+nameOrIdPrefix+"' not found", nil) 21 }