From 91082c34f958bd418850744d5b9ee5e9e9b04aa8 Mon Sep 17 00:00:00 2001 From: ale8k Date: Tue, 18 Jun 2024 14:02:20 +0100 Subject: [PATCH] listmodelsummaries api client --- internal/jimmtest/api.go | 8 ++++++++ internal/jujuclient/modelmanager.go | 10 ++++++++++ internal/jujuclient/modelmanager_test.go | 19 +++++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/internal/jimmtest/api.go b/internal/jimmtest/api.go index 07dc0c28b..774b0fdf8 100644 --- a/internal/jimmtest/api.go +++ b/internal/jimmtest/api.go @@ -167,6 +167,14 @@ type API struct { ListFilesystems_ func(ctx context.Context, machines []string) ([]jujuparams.FilesystemDetailsListResult, error) ListVolumes_ func(ctx context.Context, machines []string) ([]jujuparams.VolumeDetailsListResult, error) ListStorageDetails_ func(ctx context.Context) ([]jujuparams.StorageDetails, error) + ListModelSummaries_ func(ctx context.Context, args *jujuparams.ModelSummariesRequest, out *jujuparams.ModelSummaryResults) error +} + +func (a *API) ListModelSummaries(ctx context.Context, args *jujuparams.ModelSummariesRequest, out *jujuparams.ModelSummaryResults) error { + if a.ListModelSummaries_ == nil { + return errors.E(errors.CodeNotImplemented) + } + return a.ListModelSummaries_(ctx, args, out) } func (a *API) AddCloud(ctx context.Context, tag names.CloudTag, cld jujuparams.Cloud, force bool) error { diff --git a/internal/jujuclient/modelmanager.go b/internal/jujuclient/modelmanager.go index 39140c66e..e08f5ab3b 100644 --- a/internal/jujuclient/modelmanager.go +++ b/internal/jujuclient/modelmanager.go @@ -13,6 +13,16 @@ import ( "github.com/canonical/jimm/internal/errors" ) +func (c Connection) ListModelSummaries(ctx context.Context, args *jujuparams.ModelSummariesRequest, out *jujuparams.ModelSummaryResults) error { + const op = errors.Op("jujuclient.ListModelSummaries") + + if err := c.Call(ctx, "ModelManager", 9, "", "ListModelSummaries", args, out); err != nil { + return errors.E(op, jujuerrors.Cause(err)) + } + + return nil +} + // CreateModel creates a new model as specified by the given model // specification. If the model is created successfully then the model // document passed in will be updated with the model information returned diff --git a/internal/jujuclient/modelmanager_test.go b/internal/jujuclient/modelmanager_test.go index a745eb016..0e72b4cf7 100644 --- a/internal/jujuclient/modelmanager_test.go +++ b/internal/jujuclient/modelmanager_test.go @@ -25,6 +25,25 @@ type modelmanagerSuite struct { var _ = gc.Suite(&modelmanagerSuite{}) +func (s *modelmanagerSuite) TestListModelSummaries(c *gc.C) { + ctx := context.Background() + + var info jujuparams.ModelInfo + err := s.API.CreateModel(ctx, &jujuparams.ModelCreateArgs{ + Name: "test-model", + OwnerTag: names.NewUserTag("test-user@canonical.com").String(), + }, &info) + c.Assert(err, gc.Equals, nil) + + in := jujuparams.ModelSummariesRequest{UserTag: names.NewUserTag("admin").String(), All: true} + out := jujuparams.ModelSummaryResults{} + err = s.API.ListModelSummaries(ctx, &in, &out) + c.Assert(err, gc.Equals, nil) + // Check just our two models names, and expect juju to return correctly + c.Assert(out.Results[0].Result.Name, gc.Equals, "controller") + c.Assert(out.Results[1].Result.Name, gc.Equals, "test-model") +} + func (s *modelmanagerSuite) TestCreateModel(c *gc.C) { ctx := context.Background()