github.com/emc-advanced-dev/unik@v0.0.0-20190717152701-a58d3e8e33b7/pkg/providers/common/get_instance.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 GetInstance(p providers.Provider, nameOrIdPrefix string) (*types.Instance, error) { 11 instances, err := p.ListInstances() 12 if err != nil { 13 return nil, errors.New("retrieving instance list", err) 14 } 15 for _, instance := range instances { 16 if strings.Contains(instance.Id, nameOrIdPrefix) || strings.Contains(instance.Name, nameOrIdPrefix) { 17 return instance, nil 18 } 19 } 20 return nil, errors.New("instance with name or id containing '"+nameOrIdPrefix+"' not found", nil) 21 }