本文整理汇总了Golang中github.com/juju/juju/api/modelmanager.NewClient函数的典型用法代码示例。如果您正苦于以下问题:Golang NewClient函数的具体用法?Golang NewClient怎么用?Golang NewClient使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewClient函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestDumpModelDB
func (s *dumpModelSuite) TestDumpModelDB(c *gc.C) {
expected := map[string]interface{}{
"models": []map[string]interface{}{{
"name": "admin",
"uuid": "some-uuid",
}},
"machines": []map[string]interface{}{{
"id": "0",
"life": 0,
}},
}
results := params.MapResults{Results: []params.MapResult{{
Result: expected,
}}}
apiCaller := basetesting.APICallerFunc(
func(objType string, version int, id, request string, args, result interface{}) error {
c.Check(objType, gc.Equals, "ModelManager")
c.Check(request, gc.Equals, "DumpModelsDB")
in, ok := args.(params.Entities)
c.Assert(ok, jc.IsTrue)
c.Assert(in, gc.DeepEquals, params.Entities{[]params.Entity{{testing.ModelTag.String()}}})
res, ok := result.(*params.MapResults)
c.Assert(ok, jc.IsTrue)
*res = results
return nil
})
client := modelmanager.NewClient(apiCaller)
out, err := client.DumpModelDB(testing.ModelTag)
c.Assert(err, jc.ErrorIsNil)
c.Assert(out, jc.DeepEquals, expected)
}
示例2: newAPIClientImpl
func newAPIClientImpl(c *showBudgetCommand) (APIClient, error) {
root, err := c.NewAPIRoot()
if err != nil {
return nil, errors.Trace(err)
}
return modelmanager.NewClient(root), nil
}
示例3: TestUnsetModelDefaults
func (s *modelmanagerSuite) TestUnsetModelDefaults(c *gc.C) {
called := false
apiCaller := basetesting.APICallerFunc(
func(objType string,
version int,
id, request string,
a, result interface{},
) error {
c.Check(objType, gc.Equals, "ModelManager")
c.Check(id, gc.Equals, "")
c.Check(request, gc.Equals, "UnsetModelDefaults")
c.Check(a, jc.DeepEquals, params.UnsetModelDefaults{
Keys: []params.ModelUnsetKeys{{
CloudTag: "cloud-mycloud",
CloudRegion: "region",
Keys: []string{"foo", "bar"},
}}})
c.Assert(result, gc.FitsTypeOf, ¶ms.ErrorResults{})
*(result.(*params.ErrorResults)) = params.ErrorResults{
Results: []params.ErrorResult{{Error: nil}},
}
called = true
return nil
},
)
client := modelmanager.NewClient(apiCaller)
err := client.UnsetModelDefaults("mycloud", "region", "foo", "bar")
c.Assert(err, jc.ErrorIsNil)
c.Assert(called, jc.IsTrue)
}
示例4: TestModelDefaults
func (s *modelmanagerSuite) TestModelDefaults(c *gc.C) {
apiCaller := basetesting.APICallerFunc(
func(objType string,
version int,
id, request string,
a, result interface{},
) error {
c.Check(objType, gc.Equals, "ModelManager")
c.Check(id, gc.Equals, "")
c.Check(request, gc.Equals, "ModelDefaults")
c.Check(a, gc.IsNil)
c.Assert(result, gc.FitsTypeOf, ¶ms.ModelDefaultsResult{})
results := result.(*params.ModelDefaultsResult)
results.Config = map[string]params.ModelDefaults{
"foo": {"bar", "model", []params.RegionDefaults{{
"dummy-region",
"dummy-value"}}},
}
return nil
},
)
client := modelmanager.NewClient(apiCaller)
result, err := client.ModelDefaults()
c.Assert(err, jc.ErrorIsNil)
c.Assert(result, jc.DeepEquals, config.ModelDefaultAttributes{
"foo": {"bar", "model", []config.RegionDefaultValue{{
"dummy-region",
"dummy-value"}}},
})
}
示例5: NewModelManagerAPIClient
// NewModelManagerAPIClient returns an API client for the
// ModelManager on the current controller using the current credentials.
func (c *ControllerCommandBase) NewModelManagerAPIClient() (*modelmanager.Client, error) {
root, err := c.NewAPIRoot()
if err != nil {
return nil, errors.Trace(err)
}
return modelmanager.NewClient(root), nil
}
示例6: createModelAdminUser
func (s *cmdControllerSuite) createModelAdminUser(c *gc.C, modelname string, isServer bool) {
modelManager := modelmanager.NewClient(s.APIState)
_, err := modelManager.CreateModel(s.AdminUserTag(c).Id(), nil, map[string]interface{}{
"name": modelname,
"controller": isServer,
})
c.Assert(err, jc.ErrorIsNil)
}
示例7: listModels
func (c *registerCommand) listModels(store jujuclient.ClientStore, controllerName, userName string) ([]base.UserModel, error) {
api, err := c.NewAPIRoot(store, controllerName, "")
if err != nil {
return nil, errors.Trace(err)
}
defer api.Close()
mm := modelmanager.NewClient(api)
return mm.ListModels(userName)
}
示例8: NewAddModelCommand
// NewAddModelCommand returns a command to add a model.
func NewAddModelCommand() cmd.Command {
return modelcmd.WrapController(&addModelCommand{
newAddModelAPI: func(caller base.APICallCloser) AddModelAPI {
return modelmanager.NewClient(caller)
},
newCloudAPI: func(caller base.APICallCloser) CloudAPI {
return cloudapi.NewClient(caller)
},
})
}
示例9: getAPI
func (c *showModelCommand) getAPI() (ShowModelAPI, error) {
if c.api != nil {
return c.api, nil
}
api, err := c.NewAPIRoot()
if err != nil {
return nil, errors.Trace(err)
}
return modelmanager.NewClient(api), nil
}
示例10: getAPI
func (c *destroyCommand) getAPI() (DestroyModelAPI, error) {
if c.api != nil {
return c.api, nil
}
root, err := c.NewControllerAPIRoot()
if err != nil {
return nil, errors.Trace(err)
}
return modelmanager.NewClient(root), nil
}
示例11: modelAPI
func (c *JujuCommandBase) modelAPI(store jujuclient.ClientStore, controllerName string) (ModelAPI, error) {
if c.modelAPI_ != nil {
return c.modelAPI_, nil
}
conn, err := c.NewAPIRoot(store, controllerName, "")
if err != nil {
return nil, errors.Trace(err)
}
c.modelAPI_ = modelmanager.NewClient(conn)
return c.modelAPI_, nil
}
示例12: createModelAdminUser
func (s *cmdControllerSuite) createModelAdminUser(c *gc.C, modelname string, isServer bool) base.ModelInfo {
modelManager := modelmanager.NewClient(s.OpenControllerAPI(c))
defer modelManager.Close()
model, err := modelManager.CreateModel(
modelname, s.AdminUserTag(c).Id(), "", "", names.CloudCredentialTag{}, map[string]interface{}{
"controller": isServer,
},
)
c.Assert(err, jc.ErrorIsNil)
return model
}
示例13: NewDefaultsCommand
// NewDefaultsCommand wraps defaultsCommand with sane model settings.
func NewDefaultsCommand() cmd.Command {
defaultsCmd := &defaultsCommand{
newCloudAPI: func(caller base.APICallCloser) cloudAPI {
return cloudapi.NewClient(caller)
},
newDefaultsAPI: func(caller base.APICallCloser) defaultsCommandAPI {
return modelmanager.NewClient(caller)
},
}
defaultsCmd.newAPIRoot = defaultsCmd.NewAPIRoot
return modelcmd.WrapController(defaultsCmd)
}
示例14: createEnv
func (s *cmdControllerSuite) createEnv(c *gc.C, envname string, isServer bool) {
conn, err := juju.NewAPIState(s.AdminUserTag(c), s.Environ, api.DialOpts{})
c.Assert(err, jc.ErrorIsNil)
s.AddCleanup(func(*gc.C) { conn.Close() })
modelManager := modelmanager.NewClient(conn)
_, err = modelManager.CreateModel(s.AdminUserTag(c).Id(), nil, map[string]interface{}{
"name": envname,
"authorized-keys": "ssh-key",
"controller": isServer,
})
c.Assert(err, jc.ErrorIsNil)
}
示例15: createModelNormalUser
func (s *cmdControllerSuite) createModelNormalUser(c *gc.C, modelname string, isServer bool) {
s.run(c, "add-user", "test")
modelManager := modelmanager.NewClient(s.OpenControllerAPI(c))
defer modelManager.Close()
_, err := modelManager.CreateModel(
modelname, names.NewLocalUserTag("test").Id(), "", "", names.CloudCredentialTag{}, map[string]interface{}{
"authorized-keys": "ssh-key",
"controller": isServer,
},
)
c.Assert(err, jc.ErrorIsNil)
}