Skip to content

Commit

Permalink
listmodelsummaries api client
Browse files Browse the repository at this point in the history
  • Loading branch information
ale8k committed Jun 18, 2024
1 parent 071bc86 commit 91082c3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
8 changes: 8 additions & 0 deletions internal/jimmtest/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 10 additions & 0 deletions internal/jujuclient/modelmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions internal/jujuclient/modelmanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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("[email protected]").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()

Expand Down

0 comments on commit 91082c3

Please sign in to comment.