diff --git a/core/application/errors.go b/core/application/errors.go index 139093b5..82b5aac1 100644 --- a/core/application/errors.go +++ b/core/application/errors.go @@ -8,8 +8,9 @@ import ( ) var ( - errIDRequired = errors.New("microvm id is required") - errNotImplemeted = errors.New("not implemented") + errIDRequired = errors.New("microvm id is required") + errNotImplemeted = errors.New("not implemented") + errNamespaceRequired = errors.New("namespace is required") ) type specAlreadyExistsError struct { diff --git a/core/application/query.go b/core/application/query.go index 3b4e54c6..b475bc62 100644 --- a/core/application/query.go +++ b/core/application/query.go @@ -2,8 +2,10 @@ package application import ( "context" + "fmt" "github.com/weaveworks/flintlock/core/models" + "github.com/weaveworks/flintlock/pkg/log" ) func (a *app) GetMicroVM(ctx context.Context, id, namespace string) (*models.MicroVM, error) { @@ -11,5 +13,23 @@ func (a *app) GetMicroVM(ctx context.Context, id, namespace string) (*models.Mic } func (a *app) GetAllMicroVM(ctx context.Context, namespace string) ([]*models.MicroVM, error) { - return nil, errNotImplemeted + logger := log.GetLogger(ctx).WithField("component", "app") + logger.Trace("querying all microvms in namespace: ", namespace) + + if namespace == "" { + return nil, errNamespaceRequired + } + + foundMvms, err := a.ports.Repo.GetAll(ctx, namespace) + if err != nil { + return nil, fmt.Errorf("error attempting to list microvms in namespace: %s: %w", namespace, err) + } + + if foundMvms == nil { + logger.Trace("no microvms were found in namespace: ", namespace) + + return []*models.MicroVM{}, nil + } + + return foundMvms, nil }