本文整理汇总了Golang中github.com/juju/juju/api/modelmanager.NewClient函数的典型用法代码示例。如果您正苦于以下问题:Golang NewClient函数的具体用法?Golang NewClient怎么用?Golang NewClient使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewClient函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
}
开发者ID:bac,项目名称:juju,代码行数:31,代码来源:modelmanager_test.go
示例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
}
开发者ID:alesstimec,项目名称:romulus-1,代码行数:7,代码来源:show_budget.go
示例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)
}
开发者ID:bac,项目名称:juju,代码行数:30,代码来源:modelmanager_test.go
示例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"}}},
})
}
开发者ID:bac,项目名称:juju,代码行数:31,代码来源:modelmanager_test.go
示例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
}
开发者ID:exekias,项目名称:juju,代码行数:9,代码来源:controller.go
示例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)
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:8,代码来源:cmd_juju_controller_test.go
示例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)
}
开发者ID:bac,项目名称:juju,代码行数:9,代码来源:register.go
示例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)
},
})
}
开发者ID:kat-co,项目名称:juju,代码行数:11,代码来源:addmodel.go
示例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
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:10,代码来源:show.go
示例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
}
开发者ID:kat-co,项目名称:juju,代码行数:10,代码来源:destroy.go
示例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
}
开发者ID:bac,项目名称:juju,代码行数:11,代码来源:base.go
示例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
}
开发者ID:kat-co,项目名称:juju,代码行数:11,代码来源:cmd_juju_controller_test.go
示例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)
}
开发者ID:bac,项目名称:juju,代码行数:13,代码来源:defaultscommand.go
示例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)
}
开发者ID:exekias,项目名称:juju,代码行数:12,代码来源:cmd_juju_controller_test.go
示例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)
}
开发者ID:kat-co,项目名称:juju,代码行数:12,代码来源:cmd_juju_controller_test.go
示例16: getAPI
// getAPI sets the api on the command. This allows passing in a test
// ModelDefaultsAPI implementation.
func (c *defaultsCommand) getAPI() (defaultsCommandAPI, error) {
if c.api != nil {
return c.api, nil
}
api, err := c.NewAPIRoot()
if err != nil {
return nil, errors.Annotate(err, "opening API connection")
}
client := modelmanager.NewClient(api)
return client, nil
}
开发者ID:kat-co,项目名称:juju,代码行数:15,代码来源:defaultscommand.go
示例17: TestInvalidResultCount
func (s *accessSuite) TestInvalidResultCount(c *gc.C) {
apiCaller := basetesting.APICallerFunc(
func(objType string, version int, id, request string, a, result interface{}) error {
checkCall(c, objType, id, request)
assertRequest(c, a)
resp := assertResponse(c, result)
*resp = params.ErrorResults{Results: nil}
return nil
})
client := modelmanager.NewClient(apiCaller)
err := client.GrantModel("bob", "write", someModelUUID, someModelUUID)
c.Assert(err, gc.ErrorMatches, "expected 2 results, got 0")
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:15,代码来源:access_test.go
示例18: TestGrantModel
func (s *apiEnvironmentSuite) TestGrantModel(c *gc.C) {
username := "[email protected]"
model, err := s.State.Model()
c.Assert(err, jc.ErrorIsNil)
mm := modelmanager.NewClient(s.APIState)
err = mm.GrantModel(username, "read", model.UUID())
c.Assert(err, jc.ErrorIsNil)
user := names.NewUserTag(username)
modelUser, err := s.State.ModelUser(user)
c.Assert(err, jc.ErrorIsNil)
c.Assert(modelUser.UserName(), gc.Equals, user.Canonical())
lastConn, err := modelUser.LastConnection()
c.Assert(err, jc.Satisfies, state.IsNeverConnectedError)
c.Assert(lastConn.IsZero(), jc.IsTrue)
}
开发者ID:makyo,项目名称:juju,代码行数:16,代码来源:api_model_test.go
示例19: TestInvalidResultCount
func (s *modelInfoSuite) TestInvalidResultCount(c *gc.C) {
apiCaller := basetesting.APICallerFunc(
func(objType string, version int, id, request string, a, result interface{}) error {
s.checkCall(c, objType, id, request)
c.Assert(a, jc.DeepEquals, params.Entities{
Entities: []params.Entity{{testing.ModelTag.String()}, {testing.ModelTag.String()}},
})
resp := s.assertResponse(c, result)
*resp = params.ModelInfoResults{Results: []params.ModelInfoResult{{}}}
return nil
},
)
client := modelmanager.NewClient(apiCaller)
_, err := client.ModelInfo([]names.ModelTag{testing.ModelTag, testing.ModelTag})
c.Assert(err, gc.ErrorMatches, "expected 2 result\\(s\\), got 1")
}
开发者ID:bac,项目名称:juju,代码行数:16,代码来源:modelinfo_test.go
示例20: TestDumpModelDBError
func (s *dumpModelSuite) TestDumpModelDBError(c *gc.C) {
results := params.MapResults{Results: []params.MapResult{{
Error: ¶ms.Error{Message: "fake error"},
}}}
apiCaller := basetesting.APICallerFunc(
func(objType string, version int, id, request string, args, result interface{}) error {
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, gc.ErrorMatches, "fake error")
c.Assert(out, gc.IsNil)
}
开发者ID:bac,项目名称:juju,代码行数:16,代码来源:modelmanager_test.go
注:本文中的github.com/juju/juju/api/modelmanager.NewClient函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论