当前位置: 首页>>代码示例>>Golang>>正文


Golang api.Close函数代码示例

本文整理汇总了Golang中github.com/juju/juju/api.Close函数的典型用法代码示例。如果您正苦于以下问题:Golang Close函数的具体用法?Golang Close怎么用?Golang Close使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Close函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestControllerLoginCommand

func (s *cmdControllerSuite) TestControllerLoginCommand(c *gc.C) {
	user := s.Factory.MakeUser(c, &factory.UserParams{
		NoEnvUser: true,
		Password:  "super-secret",
	})
	apiInfo := s.APIInfo(c)
	serverFile := envcmd.ServerFile{
		Addresses: apiInfo.Addrs,
		CACert:    apiInfo.CACert,
		Username:  user.Name(),
		Password:  "super-secret",
	}
	serverFilePath := filepath.Join(c.MkDir(), "server.yaml")
	content, err := goyaml.Marshal(serverFile)
	c.Assert(err, jc.ErrorIsNil)
	err = ioutil.WriteFile(serverFilePath, []byte(content), 0644)
	c.Assert(err, jc.ErrorIsNil)

	s.run(c, "login", "--server", serverFilePath, "just-a-controller")

	// Make sure that the saved server details are sufficient to connect
	// to the api server.
	api, err := juju.NewAPIFromName("just-a-controller", nil)
	c.Assert(err, jc.ErrorIsNil)
	api.Close()
}
开发者ID:imoapps,项目名称:juju,代码行数:26,代码来源:cmd_juju_controller_test.go

示例2: RunPost

// RunPost sends credentials obtained during the call to RunPre to the controller.
func (r *RegisterMeteredCharm) RunPost(state api.Connection, bakeryClient *httpbakery.Client, ctx *cmd.Context, deployInfo DeploymentInfo, prevErr error) error {
	if prevErr != nil {
		return nil
	}
	if r.credentials == nil {
		return nil
	}
	api, cerr := getMetricCredentialsAPI(state)
	if cerr != nil {
		logger.Infof("failed to get the metrics credentials setter: %v", cerr)
		return cerr
	}
	defer api.Close()

	err := api.SetMetricCredentials(deployInfo.ServiceName, r.credentials)
	if err != nil {
		logger.Warningf("failed to set metric credentials: %v", err)
		return errors.Trace(err)
	}

	err = r.AllocateBudget.RunPost(state, bakeryClient, ctx, deployInfo, prevErr)
	if err != nil {
		logger.Warningf("failed to allocate budget: %v", err)
		return errors.Trace(err)
	}

	return nil
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:29,代码来源:register.go

示例3: registerMeteredCharm

func registerMeteredCharm(registrationURL string, state *api.State, jar *cookiejar.Jar, charmURL string, serviceName, environmentUUID string) error {
	charmsClient := charms.NewClient(state)
	defer charmsClient.Close()
	metered, err := charmsClient.IsMetered(charmURL)
	if err != nil {
		return err
	}
	if metered {
		httpClient := httpbakery.NewHTTPClient()
		httpClient.Jar = jar
		credentials, err := registerMetrics(registrationURL, environmentUUID, charmURL, serviceName, httpClient, openWebBrowser)
		if err != nil {
			logger.Infof("failed to register metrics: %v", err)
			return err
		}

		api, cerr := getMetricCredentialsAPI(state)
		if cerr != nil {
			logger.Infof("failed to get the metrics credentials setter: %v", cerr)
		}
		err = api.SetMetricCredentials(serviceName, credentials)
		if err != nil {
			logger.Infof("failed to set metric credentials: %v", err)
			return err
		}
		api.Close()
	}
	return nil
}
开发者ID:Pankov404,项目名称:juju,代码行数:29,代码来源:register.go

示例4: testAddModel

func (s *cmdControllerSuite) testAddModel(c *gc.C, args ...string) {
	// The JujuConnSuite doesn't set up an ssh key in the fake home dir,
	// so fake one on the command line.  The dummy provider also expects
	// a config value for 'controller'.
	args = append([]string{"add-model", "new-model"}, args...)
	args = append(args,
		"--config", "authorized-keys=fake-key",
		"--config", "controller=false",
	)
	context := s.run(c, args...)
	c.Check(testing.Stdout(context), gc.Equals, "")
	c.Check(testing.Stderr(context), gc.Equals, `
Added 'new-model' model on dummy/dummy-region with credential 'cred' for user 'admin'
`[1:])

	// Make sure that the saved server details are sufficient to connect
	// to the api server.
	accountDetails, err := s.ControllerStore.AccountDetails("kontroll")
	c.Assert(err, jc.ErrorIsNil)
	modelDetails, err := s.ControllerStore.ModelByName("kontroll", "[email protected]/new-model")
	c.Assert(err, jc.ErrorIsNil)
	api, err := juju.NewAPIConnection(juju.NewAPIConnectionParams{
		Store:          s.ControllerStore,
		ControllerName: "kontroll",
		AccountDetails: accountDetails,
		ModelUUID:      modelDetails.ModelUUID,
		DialOpts:       api.DefaultDialOpts(),
		OpenAPI:        api.Open,
	})
	c.Assert(err, jc.ErrorIsNil)
	api.Close()
}
开发者ID:kat-co,项目名称:juju,代码行数:32,代码来源:cmd_juju_controller_test.go

示例5: RunWithAPI

func (c *SpaceCommandBase) RunWithAPI(ctx *cmd.Context, toRun RunOnAPI) error {
	api, err := c.NewAPI()
	if err != nil {
		return errors.Annotate(err, "cannot connect to the API server")
	}
	defer api.Close()
	return toRun(api, ctx)
}
开发者ID:makyo,项目名称:juju,代码行数:8,代码来源:space.go

示例6: 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

示例7: TestAddUserAndRegister

func (s *cmdRegistrationSuite) TestAddUserAndRegister(c *gc.C) {
	// First, add user "bob", and record the "juju register" command
	// that is printed out.
	context := s.run(c, nil, "add-user", "bob", "Bob Dobbs")
	c.Check(testing.Stderr(context), gc.Equals, "")
	stdout := testing.Stdout(context)
	c.Check(stdout, gc.Matches, `
User "Bob Dobbs \(bob\)" added
Please send this command to bob:
    juju register .*

"Bob Dobbs \(bob\)" has not been granted access to any models(.|\n)*
`[1:])
	jujuRegisterCommand := strings.Fields(strings.TrimSpace(
		strings.SplitN(stdout[strings.Index(stdout, "juju register"):], "\n", 2)[0],
	))
	c.Logf("%q", jujuRegisterCommand)

	// Now run the "juju register" command. We need to pass the
	// controller name and password to set.
	stdin := strings.NewReader("bob-controller\nhunter2\nhunter2\n")
	args := jujuRegisterCommand[1:] // drop the "juju"
	context = s.run(c, stdin, args...)
	c.Check(testing.Stdout(context), gc.Equals, "")
	c.Check(testing.Stderr(context), gc.Equals, `
Please set a name for this controller: 
Enter password: 
Confirm password: 

Welcome, bob. You are now logged into "bob-controller".

There are no models available. You can create models with
"juju create-model", or you can ask an administrator or owner
of a model to grant access to that model with "juju grant".

`[1:])

	// Make sure that the saved server details are sufficient to connect
	// to the api server.
	accountDetails, err := s.ControllerStore.AccountByName("bob-controller", "[email protected]")
	c.Assert(err, jc.ErrorIsNil)
	api, err := juju.NewAPIConnection(juju.NewAPIConnectionParams{
		Store:           s.ControllerStore,
		ControllerName:  "bob-controller",
		AccountDetails:  accountDetails,
		BootstrapConfig: noBootstrapConfig,
		DialOpts:        api.DefaultDialOpts(),
	})
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(api.Close(), jc.ErrorIsNil)
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:51,代码来源:cmd_juju_register_test.go

示例8: killSystemViaClient

// killSystemViaClient attempts to kill the system using the client
// endpoint for older juju systems which do not implement systemmanager.DestroySystem
func (c *killCommand) killSystemViaClient(ctx *cmd.Context, info configstore.EnvironInfo, systemEnviron environs.Environ, store configstore.Storage) error {
	api, err := c.getClientAPI()
	if err != nil {
		defer api.Close()
	}

	if api != nil {
		err = api.DestroyEnvironment()
		if err != nil {
			ctx.Infof("Unable to destroy system through the API: %s.  Destroying through provider.", err)
		}
	}

	return environs.Destroy(systemEnviron, store)
}
开发者ID:snailwalker,项目名称:juju,代码行数:17,代码来源:kill.go

示例9: listForModel

func (c *listCommand) listForModel(ctx *cmd.Context) (err error) {
	api, err := c.apiFunc(c)
	if err != nil {
		return errors.Trace(err)
	}
	defer api.Close()

	result, err := api.List()
	if err != nil {
		return errors.Trace(err)
	}
	if len(result) == 0 && c.out.Name() == "tabular" {
		ctx.Infof(noBlocks)
		return nil
	}
	return c.out.Write(ctx, formatBlockInfo(result))
}
开发者ID:bac,项目名称:juju,代码行数:17,代码来源:list.go

示例10: TestCreateEnvironment

func (s *cmdControllerSuite) TestCreateEnvironment(c *gc.C) {
	c.Assert(envcmd.WriteCurrentController("dummyenv"), jc.ErrorIsNil)
	// The JujuConnSuite doesn't set up an ssh key in the fake home dir,
	// so fake one on the command line.  The dummy provider also expects
	// a config value for 'state-server'.
	context := s.run(c, "create-environment", "new-env", "authorized-keys=fake-key", "state-server=false")
	c.Check(testing.Stdout(context), gc.Equals, "")
	c.Check(testing.Stderr(context), gc.Equals, `
created environment "new-env"
dummyenv (controller) -> new-env
`[1:])

	// Make sure that the saved server details are sufficient to connect
	// to the api server.
	api, err := juju.NewAPIFromName("new-env", nil)
	c.Assert(err, jc.ErrorIsNil)
	api.Close()
}
开发者ID:imoapps,项目名称:juju,代码行数:18,代码来源:cmd_juju_controller_test.go

示例11: getTargetControllerMacaroons

func (c *migrateCommand) getTargetControllerMacaroons() ([]macaroon.Slice, error) {
	apiContext, err := c.APIContext()
	if err != nil {
		return nil, errors.Trace(err)
	}

	// Connect to the target controller, ensuring up-to-date macaroons,
	// and return the macaroons in the cookie jar for the controller.
	//
	// TODO(axw,mjs) add a controller API that returns a macaroon that
	// may be used for the sole purpose of migration.
	api, err := c.newAPIRoot(c.ClientStore(), c.targetController, "")
	if err != nil {
		return nil, errors.Annotate(err, "connecting to target controller")
	}
	defer api.Close()
	return httpbakery.MacaroonsForURL(apiContext.Jar, api.CookieURL()), nil
}
开发者ID:bac,项目名称:juju,代码行数:18,代码来源:migrate.go

示例12: Open

func (t *timeoutOpener) Open(store jujuclient.ClientStore, controllerName, modelName string) (api.Connection, error) {
	// Make the channels buffered so the created goroutine is guaranteed
	// not go get blocked trying to send down the channel.
	apic := make(chan api.Connection, 1)
	errc := make(chan error, 1)
	go func() {
		api, dialErr := t.opener.Open(store, controllerName, modelName)
		if dialErr != nil {
			errc <- dialErr
			return
		}

		select {
		case apic <- api:
			// sent fine
		default:
			// couldn't send, was blocked by the dummy value, must have timed out.
			api.Close()
		}
	}()

	var apiRoot api.Connection
	select {
	case err := <-errc:
		return nil, err
	case apiRoot = <-apic:
	case <-t.clock.After(t.timeout):
		select {
		case apic <- nil:
			// Fill up the buffer on the apic to indicate to the other goroutine
			// that we have timed out.
		case apiRoot = <-apic:
			// We hit that weird edge case where we have both timed out and
			// returned a viable apiRoot at exactly the same time, and the other
			// goroutine managed to send back the apiRoot before we pushed the
			// dummy value.  If this is the case, then we are good, return the
			// apiRoot
			return apiRoot, nil
		}
		return nil, ErrConnTimedOut
	}

	return apiRoot, nil
}
开发者ID:bac,项目名称:juju,代码行数:44,代码来源:apiopener.go

示例13: RunPost

// RunPost sends credentials obtained during the call to RunPre to the controller.
func (r *RegisterMeteredCharm) RunPost(state api.Connection, client *http.Client, deployInfo DeploymentInfo) error {
	if r.credentials == nil {
		return nil
	}
	api, cerr := getMetricCredentialsAPI(state)
	if cerr != nil {
		logger.Infof("failed to get the metrics credentials setter: %v", cerr)
		return cerr
	}
	defer api.Close()

	err := api.SetMetricCredentials(deployInfo.ServiceName, r.credentials)
	if err != nil {
		logger.Infof("failed to set metric credentials: %v", err)
		return err
	}

	return nil
}
开发者ID:pmatulis,项目名称:juju,代码行数:20,代码来源:register.go

示例14: recordMacaroon

func (c *changePasswordCommand) recordMacaroon(user, password string) error {
	accountDetails := &jujuclient.AccountDetails{User: user}
	args, err := c.NewAPIConnectionParams(
		c.ClientStore(), c.ControllerName(), "", accountDetails,
	)
	if err != nil {
		return errors.Trace(err)
	}
	args.DialOpts.BakeryClient.WebPageVisitor = httpbakery.NewMultiVisitor(
		authentication.NewVisitor(accountDetails.User, func(string) (string, error) {
			return password, nil
		}),
		args.DialOpts.BakeryClient.WebPageVisitor,
	)
	api, err := c.newAPIConnection(args)
	if err != nil {
		return errors.Annotate(err, "connecting to API")
	}
	return api.Close()
}
开发者ID:bac,项目名称:juju,代码行数:20,代码来源:change_password.go

示例15: listForController

func (c *listCommand) listForController(ctx *cmd.Context) (err error) {
	api, err := c.controllerAPIFunc(c)
	if err != nil {
		return errors.Trace(err)
	}
	defer api.Close()

	result, err := api.ListBlockedModels()
	if err != nil {
		return errors.Trace(err)
	}
	if len(result) == 0 && c.out.Name() == "tabular" {
		ctx.Infof(noBlocks)
		return nil
	}
	info, err := FormatModelBlockInfo(result)
	if err != nil {
		return errors.Trace(err)
	}
	return c.out.Write(ctx, info)
}
开发者ID:bac,项目名称:juju,代码行数:21,代码来源:list.go


注:本文中的github.com/juju/juju/api.Close函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。