本文整理汇总了Golang中github.com/juju/juju/api/controller.NewClient函数的典型用法代码示例。如果您正苦于以下问题:Golang NewClient函数的具体用法?Golang NewClient怎么用?Golang NewClient使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewClient函数的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: NewControllerAPIClient
// NewControllerAPIClient returns an API client for the Controller on
// the current controller using the current credentials.
func (c *ControllerCommandBase) NewControllerAPIClient() (*controller.Client, error) {
root, err := c.NewAPIRoot()
if err != nil {
return nil, errors.Trace(err)
}
return controller.NewClient(root), nil
}
开发者ID:exekias,项目名称:juju,代码行数:9,代码来源:controller.go
示例2: getControllerAPI
// getControllerAPI returns a block api for block manipulation.
func getControllerAPI(c newControllerAPIRoot) (*controller.Client, error) {
root, err := c.NewControllerAPIRoot()
if err != nil {
return nil, errors.Trace(err)
}
return controller.NewClient(root), nil
}
开发者ID:bac,项目名称:juju,代码行数:8,代码来源:list.go
示例3: withHTTPClient
// withHTTPClient sets up a fixture with the given address and handle, then
// runs the given test and checks that the HTTP handler has been called with
// the given method.
func withHTTPClient(c *gc.C, address, expectMethod string, handle func(http.ResponseWriter, *http.Request), test func(*controller.Client)) {
fix := newHTTPFixture(address, handle)
stub := fix.run(c, func(ac base.APICallCloser) {
client := controller.NewClient(ac)
test(client)
})
stub.CheckCalls(c, []testing.StubCall{{expectMethod, nil}})
}
开发者ID:bac,项目名称:juju,代码行数:11,代码来源:gui_test.go
示例4: TestHostedModelConfigs_FormatResults
func (s *Suite) TestHostedModelConfigs_FormatResults(c *gc.C) {
apiCaller := apitesting.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error {
c.Assert(objType, gc.Equals, "Controller")
c.Assert(request, gc.Equals, "HostedModelConfigs")
c.Assert(arg, gc.IsNil)
out := result.(*params.HostedModelConfigsResults)
c.Assert(out, gc.NotNil)
*out = params.HostedModelConfigsResults{
Models: []params.HostedModelConfig{
{
Name: "first",
OwnerTag: "[email protected]",
Config: map[string]interface{}{
"name": "first",
},
CloudSpec: ¶ms.CloudSpec{
Type: "magic",
Name: "first",
},
}, {
Name: "second",
OwnerTag: "bad-tag",
}, {
Name: "third",
OwnerTag: "[email protected]",
Config: map[string]interface{}{
"name": "third",
},
CloudSpec: ¶ms.CloudSpec{
Name: "third",
},
},
},
}
return nil
})
client := controller.NewClient(apiCaller)
config, err := client.HostedModelConfigs()
c.Assert(config, gc.HasLen, 3)
c.Assert(err, jc.ErrorIsNil)
first := config[0]
c.Assert(first.Name, gc.Equals, "first")
c.Assert(first.Owner, gc.Equals, names.NewUserTag("[email protected]"))
c.Assert(first.Config, gc.DeepEquals, map[string]interface{}{
"name": "first",
})
c.Assert(first.CloudSpec, gc.DeepEquals, environs.CloudSpec{
Type: "magic",
Name: "first",
})
second := config[1]
c.Assert(second.Name, gc.Equals, "second")
c.Assert(second.Error.Error(), gc.Equals, `"bad-tag" is not a valid tag`)
third := config[2]
c.Assert(third.Name, gc.Equals, "third")
c.Assert(third.Error.Error(), gc.Equals, "validating CloudSpec: empty Type not valid")
}
开发者ID:bac,项目名称:juju,代码行数:57,代码来源:controller_test.go
示例5: TestHostedModelConfigs_CallError
func (s *Suite) TestHostedModelConfigs_CallError(c *gc.C) {
apiCaller := apitesting.APICallerFunc(func(string, int, string, string, interface{}, interface{}) error {
return errors.New("boom")
})
client := controller.NewClient(apiCaller)
config, err := client.HostedModelConfigs()
c.Check(config, gc.HasLen, 0)
c.Check(err, gc.ErrorMatches, "boom")
}
开发者ID:bac,项目名称:juju,代码行数:9,代码来源:controller_test.go
示例6: TestInitiateMigrationCallError
func (s *Suite) TestInitiateMigrationCallError(c *gc.C) {
apiCaller := apitesting.APICallerFunc(func(string, int, string, string, interface{}, interface{}) error {
return errors.New("boom")
})
client := controller.NewClient(apiCaller)
id, err := client.InitiateMigration(makeSpec())
c.Check(id, gc.Equals, "")
c.Check(err, gc.ErrorMatches, "boom")
}
开发者ID:bac,项目名称:juju,代码行数:9,代码来源:controller_test.go
示例7: getControllerAPI
func (c *destroyCommandBase) getControllerAPI() (destroyControllerAPI, error) {
if c.api != nil {
return c.api, c.apierr
}
root, err := c.NewAPIRoot()
if err != nil {
return nil, errors.Trace(err)
}
return controller.NewClient(root), nil
}
开发者ID:imoapps,项目名称:juju,代码行数:10,代码来源:destroy.go
示例8: getAPI
func (c *showControllerCommand) getAPI(controllerName string) (ControllerAccessAPI, error) {
if c.api != nil {
return c.api(controllerName), nil
}
api, err := c.NewAPIRoot(c.store, controllerName, "")
if err != nil {
return nil, errors.Annotate(err, "opening API connection")
}
return controller.NewClient(api), nil
}
开发者ID:bac,项目名称:juju,代码行数:10,代码来源:showcontroller.go
示例9: getAPI
func (c *getConfigCommand) getAPI() (controllerAPI, error) {
if c.api != nil {
return c.api, nil
}
root, err := c.NewAPIRoot()
if err != nil {
return nil, errors.Trace(err)
}
return apicontroller.NewClient(root), nil
}
开发者ID:bac,项目名称:juju,代码行数:10,代码来源:getconfig.go
示例10: makeClient
func makeClient(results params.InitiateMigrationResults) (
*controller.Client, *jujutesting.Stub,
) {
var stub jujutesting.Stub
apiCaller := apitesting.APICallerFunc(
func(objType string, version int, id, request string, arg, result interface{}) error {
stub.AddCall(objType+"."+request, arg)
out := result.(*params.InitiateMigrationResults)
*out = results
return nil
},
)
client := controller.NewClient(apiCaller)
return client, &stub
}
开发者ID:bac,项目名称:juju,代码行数:15,代码来源:controller_test.go
示例11: main
func main() {
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "jujuwatchall [flags] [<controller>|<model>|[<controller>]:[<model>]]\n")
fmt.Fprintf(os.Stderr, `
jujuwatchall -a
- watches all models on the current controller
jujuwatchall :modelname
- watches the named model on the current controller.
jujuwatchall :
- watches the current model on the current controller
jujuwatchall controllername:
- watches all models on the named controller.
jujuwatchall controllername:modelname
- watches the named model on the named controller
`)
os.Exit(2)
}
flag.Parse()
if *jsonFlag {
json.MarshalIndent = stdjson.MarshalIndent
json.Marshal = stdjson.Marshal
json.Unmarshal = stdjson.Unmarshal
}
controllerName, modelName := "", ""
if flag.NArg() > 0 {
split := strings.Split(flag.Arg(0), ":")
switch len(split) {
case 1:
if *allFlag {
controllerName = split[0]
} else {
modelName = split[0]
}
case 2:
controllerName, modelName = split[0], split[1]
default:
flag.Usage()
}
}
var w *api.AllWatcher
if *allFlag {
conn, err := jujuconn.DialController(controllerName)
if err != nil {
log.Fatalf("cannot dial controller: %v", err)
}
w, err = apicontroller.NewClient(conn).WatchAllModels()
if err != nil {
log.Fatalf("cannot watch all models: %v", err)
}
} else {
conn, err := jujuconn.DialModel(controllerName, modelName)
if err != nil {
log.Fatalf("cannot dial model: %v", err)
}
w, err = conn.Client().WatchAll()
if err != nil {
log.Fatalf("cannot watch models: %v", err)
}
}
entities := make(map[multiwatcher.EntityId]map[string]interface{})
for {
deltas, err := w.Next()
if err != nil {
log.Fatalf("Next error: %v", err)
}
for _, d := range deltas {
id := d.Entity.EntityId()
if d.Removed {
fmt.Printf("- %s %v\n", id.Kind, id.Id)
delete(entities, id)
continue
}
oldFields := entities[id]
if oldFields == nil {
data, _ := json.MarshalIndent(d.Entity, "", "\t")
var fields map[string]interface{}
if err := json.Unmarshal(data, &fields); err != nil {
panic("cannot re-unmrshal json")
}
entities[id] = fields
fmt.Printf("+ %s %v %v %s\n", id.Kind, id.Id, id.ModelUUID, data)
continue
}
data, _ := json.Marshal(d.Entity)
var fields map[string]interface{}
if err := json.Unmarshal(data, &fields); err != nil {
panic("cannot re-unmrshal json")
}
names := make(map[string]bool)
for name := range oldFields {
names[name] = true
}
for name := range fields {
names[name] = true
}
changedFields := make(map[string]interface{})
for name := range names {
if !reflect.DeepEqual(fields[name], oldFields[name]) {
changedFields[name] = fields[name]
//.........这里部分代码省略.........
开发者ID:rogpeppe,项目名称:misc,代码行数:101,代码来源:juju-watchall.go
示例12: OpenAPI
func (s *controllerSuite) OpenAPI(c *gc.C) *controller.Client {
conn, err := juju.NewAPIState(s.AdminUserTag(c), s.Environ, api.DialOpts{})
c.Assert(err, jc.ErrorIsNil)
s.AddCleanup(func(*gc.C) { conn.Close() })
return controller.NewClient(conn)
}
开发者ID:pmatulis,项目名称:juju,代码行数:6,代码来源:controller_test.go
示例13: Run
}
var getModelConfigAPI = func(c *upgradeJujuCommand) (modelConfigAPI, error) {
api, err := c.NewAPIRoot()
if err != nil {
return nil, errors.Trace(err)
}
return modelconfig.NewClient(api), nil
}
var getControllerAPI = func(c *upgradeJujuCommand) (controllerAPI, error) {
api, err := c.NewControllerAPIRoot()
if err != nil {
return nil, errors.Trace(err)
}
return controller.NewClient(api), nil
}
// Run changes the version proposed for the juju envtools.
func (c *upgradeJujuCommand) Run(ctx *cmd.Context) (err error) {
client, err := getUpgradeJujuAPI(c)
if err != nil {
return err
}
defer client.Close()
modelConfigClient, err := getModelConfigAPI(c)
if err != nil {
return err
}
defer modelConfigClient.Close()
开发者ID:bac,项目名称:juju,代码行数:31,代码来源:upgradejuju.go
示例14: OpenAPI
func (s *controllerSuite) OpenAPI(c *gc.C) *controller.Client {
return controller.NewClient(s.APIState)
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:3,代码来源:controller_test.go
示例15: OpenAPI
func (s *legacySuite) OpenAPI(c *gc.C) *controller.Client {
return controller.NewClient(s.OpenControllerAPI(c))
}
开发者ID:kat-co,项目名称:juju,代码行数:3,代码来源:legacy_test.go
示例16: TestAPIServerCanShutdownWithOutstandingNext
func (s *legacySuite) TestAPIServerCanShutdownWithOutstandingNext(c *gc.C) {
lis, err := net.Listen("tcp", "localhost:0")
c.Assert(err, jc.ErrorIsNil)
srv, err := apiserver.NewServer(s.State, lis, apiserver.ServerConfig{
Clock: clock.WallClock,
Cert: []byte(testing.ServerCert),
Key: []byte(testing.ServerKey),
Tag: names.NewMachineTag("0"),
DataDir: c.MkDir(),
LogDir: c.MkDir(),
NewObserver: func() observer.Observer { return &fakeobserver.Instance{} },
})
c.Assert(err, gc.IsNil)
// Connect to the API server we've just started.
apiInfo := s.APIInfo(c)
apiInfo.Addrs = []string{lis.Addr().String()}
apiInfo.ModelTag = names.ModelTag{}
apiState, err := api.Open(apiInfo, api.DialOpts{})
sysManager := controller.NewClient(apiState)
defer sysManager.Close()
w, err := sysManager.WatchAllModels()
c.Assert(err, jc.ErrorIsNil)
defer w.Stop()
deltasC := make(chan struct{}, 2)
go func() {
defer close(deltasC)
for {
_, err := w.Next()
if err != nil {
return
}
deltasC <- struct{}{}
}
}()
// Read the first event.
select {
case <-deltasC:
case <-time.After(testing.LongWait):
c.Fatal("timed out")
}
// Wait a little while for the Next call to actually arrive.
time.Sleep(testing.ShortWait)
// We should be able to close the server instance
// even when there's an outstanding Next call.
srvStopped := make(chan struct{})
go func() {
srv.Stop()
close(srvStopped)
}()
select {
case <-srvStopped:
case <-time.After(testing.LongWait):
c.Fatal("timed out waiting for server to stop")
}
// Check that the Next call has returned too.
select {
case _, ok := <-deltasC:
if ok {
c.Fatalf("got unexpected event from deltasC")
}
case <-time.After(testing.LongWait):
c.Fatal("timed out")
}
}
开发者ID:kat-co,项目名称:juju,代码行数:72,代码来源:legacy_test.go
注:本文中的github.com/juju/juju/api/controller.NewClient函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论