• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang juju.NewAPIFromName函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了NewAPIFromName函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: newKillCommand

func (s *KillSuite) newKillCommand() cmd.Command {
	return system.NewKillCommand(
		s.api,
		s.clientapi,
		s.apierror,
		func(name string) (api.Connection, error) {
			return juju.NewAPIFromName(name, nil)
		})
}
开发者ID:snailwalker,项目名称:juju,代码行数:9,代码来源:kill_test.go


示例3: initAPIClient

// initAPIClient initialises the API connection.
// It is the caller's responsibility to close the connection.
func (c *SSHCommon) initAPIClient() (*api.Client, error) {
	st, err := juju.NewAPIFromName(c.EnvName)
	if err != nil {
		return nil, err
	}
	c.apiClient = st.Client()
	c.apiAddr = st.Addr()
	return c.apiClient, nil
}
开发者ID:rogpeppe,项目名称:juju,代码行数:11,代码来源:ssh.go


示例4: NewAPIRoot

func (c *EnvCommandBase) NewAPIRoot() (*api.State, error) {
	// This is work in progress as we remove the EnvName from downstream code.
	// We want to be able to specify the environment in a number of ways, one of
	// which is the connection name on the client machine.
	if c.envName == "" {
		return nil, errors.Trace(ErrNoEnvironmentSpecified)
	}
	return juju.NewAPIFromName(c.envName)
}
开发者ID:Pankov404,项目名称:juju,代码行数:9,代码来源:environmentcommand.go


示例5: runKillCommand

func (s *KillSuite) runKillCommand(c *gc.C, args ...string) (*cmd.Context, error) {
	cmd := system.NewKillCommand(
		s.api,
		s.clientapi,
		s.apierror,
		func(name string) (api.Connection, error) {
			return juju.NewAPIFromName(name, nil)
		})
	return testing.RunCommand(c, cmd, args...)
}
开发者ID:snailwalker,项目名称:juju,代码行数:10,代码来源:kill_test.go


示例6: EnvClientFactory

func EnvClientFactory() (*Client, error) {
	envName := envcmd.ReadCurrentEnvironment()

	state, err := juju.NewAPIFromName(envName)
	if err != nil {
		log.Warn("Got error building API from name: %v", envName, err)
		return nil, fmt.Errorf(connectionError, envName, err)
	}

	client := state.Client()

	wrapper := &Client{}
	wrapper.client = client
	wrapper.apiState = state
	//defer apiclient.Close()
	return wrapper, err
}
开发者ID:jxaas,项目名称:jxaas,代码行数:17,代码来源:connection.go


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


示例8: openAPI

func (s *jujuNameServer) openAPI(envName string) (api.Connection, error) {
	if envName != "" {
		// Domain names are case-insensitive, but environment
		// names are not. We'll error if there are two names
		// that match case-insensitively.
		store, err := configstore.Default()
		if err != nil {
			return nil, errors.Trace(err)
		}
		envNames, err := store.List()
		if err != nil {
			return nil, errors.Trace(err)
		}
		var matches []string
		for _, storeEnvName := range envNames {
			if strings.ToLower(storeEnvName) == strings.ToLower(envName) {
				matches = append(matches, storeEnvName)
			}
		}
		if len(matches) == 0 {
			return nil, errors.NotFoundf("environment %q", envName)
		}
		if len(matches) > 1 {
			return nil, errors.Errorf(
				"%q matches multiple environments: %q",
				envName, matches,
			)
		}
		envName = matches[0]
	}

	jar, err := cookiejar.New(&cookiejar.Options{
		Filename: cookiejar.DefaultCookieFile(),
	})
	if err != nil {
		return nil, errors.Trace(err)
	}
	client := httpbakery.NewClient()
	client.Jar = jar
	client.VisitWebPage = httpbakery.OpenWebBrowser
	return juju.NewAPIFromName(envName, client)
}
开发者ID:axw,项目名称:jns,代码行数:42,代码来源:main.go


示例9: newAPIRoot

// newAPIRoot establishes a connection to the API server for
// the named system or environment.
func (ctx *apiContext) newAPIRoot(name string) (api.Connection, error) {
	if name == "" {
		return nil, errors.Trace(errNoNameSpecified)
	}
	return juju.NewAPIFromName(name, ctx.client)
}
开发者ID:snailwalker,项目名称:juju,代码行数:8,代码来源:base.go


示例10: newAPIRoot

// newAPIRoot returns a restricted API for the current system using the current
// credentials.  Only the UserManager and EnvironmentManager may be accessed
// through this API connection.
func (c *SysCommandBase) newAPIRoot() (api.Connection, error) {
	if c.systemName == "" {
		return nil, errors.Trace(ErrNoSystemSpecified)
	}
	return juju.NewAPIFromName(c.systemName)
}
开发者ID:ktsakalozos,项目名称:juju,代码行数:9,代码来源:systemcommand.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang juju.NewAPIFromStore函数代码示例发布时间:2022-05-23
下一篇:
Golang juju.NewAPIClientFromName函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap