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


Golang network.SelectInternalHostPort函数代码示例

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


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

示例1: ToolsURL

func (t *toolsURLGetter) ToolsURL(v version.Binary) (string, error) {
	apiHostPorts, err := t.apiHostPortsGetter.APIHostPorts()
	if err != nil {
		return "", err
	}
	if len(apiHostPorts) == 0 {
		return "", errors.New("no API host ports")
	}
	// TODO(axw) return all known URLs, so clients can try each one.
	//
	// The clients currently accept a single URL; we should change
	// the clients to disregard the URL, and have them download
	// straight from the API server.
	//
	// For now we choose a API server at random, and then select its
	// cloud-local address. The only user that will care about the URL
	// is the upgrader, and that is cloud-local.
	hostPorts := apiHostPorts[rand.Int()%len(apiHostPorts)]
	apiAddress := network.SelectInternalHostPort(hostPorts, false)
	if apiAddress == "" {
		return "", errors.Errorf("no suitable API server address to pick from %v", hostPorts)
	}
	serverRoot := fmt.Sprintf("https://%s/model/%s", apiAddress, t.modelUUID)
	return ToolsURL(serverRoot, v), nil
}
开发者ID:pmatulis,项目名称:juju,代码行数:25,代码来源:tools.go

示例2: TestSelectInternalMachineHostPort

func (*HostPortSuite) TestSelectInternalMachineHostPort(c *gc.C) {
	for i, t0 := range selectInternalMachineTests {
		t := t0.hostPortTest()
		c.Logf("test %d: %s", i, t.about)
		c.Check(network.SelectInternalHostPort(t.hostPorts, true), gc.DeepEquals, t.expected())
	}
}
开发者ID:kat-co,项目名称:juju,代码行数:7,代码来源:hostport_test.go

示例3: TestSelectInternalHostPort

func (s *PortSuite) TestSelectInternalHostPort(c *gc.C) {
	for i, t0 := range selectInternalTests {
		t := t0.hostPortTest()
		c.Logf("test %d: %s", i, t.about)
		c.Assert(network.SelectInternalHostPort(t.hostPorts, false), jc.DeepEquals, t.expected())
	}
}
开发者ID:rogpeppe,项目名称:juju,代码行数:7,代码来源:port_test.go

示例4: TestSelectInternalMachineHostPort

func (s *PortSuite) TestSelectInternalMachineHostPort(c *gc.C) {
	oldValue := network.GetPreferIPv6()
	defer func() {
		network.SetPreferIPv6(oldValue)
	}()
	for i, t0 := range selectInternalMachineTests {
		t := t0.hostPortTest()
		c.Logf("test %d: %s", i, t.about)
		network.SetPreferIPv6(t.preferIPv6)
		c.Check(network.SelectInternalHostPort(t.hostPorts, true), gc.DeepEquals, t.expected())
	}
}
开发者ID:kapilt,项目名称:juju,代码行数:12,代码来源:port_test.go

示例5: SetAPIHostPorts

func (c *configInternal) SetAPIHostPorts(servers [][]network.HostPort) {
	if c.apiDetails == nil {
		return
	}
	var addrs []string
	for _, serverHostPorts := range servers {
		addr := network.SelectInternalHostPort(serverHostPorts, false)
		if addr != "" {
			addrs = append(addrs, addr)
		}
	}
	c.apiDetails.addresses = addrs
}
开发者ID:klyachin,项目名称:juju,代码行数:13,代码来源:agent.go

示例6: APIAddresses

// APIAddresses returns the list of addresses used to connect to the API.
func (api *APIAddresser) APIAddresses() (params.StringsResult, error) {
	apiHostPorts, err := api.getter.APIHostPorts()
	if err != nil {
		return params.StringsResult{}, err
	}
	var addrs = make([]string, 0, len(apiHostPorts))
	for _, hostPorts := range apiHostPorts {
		addr := network.SelectInternalHostPort(hostPorts, false)
		if addr != "" {
			addrs = append(addrs, addr)
		}
	}
	return params.StringsResult{
		Result: addrs,
	}, nil
}
开发者ID:imoapps,项目名称:juju,代码行数:17,代码来源:addresses.go

示例7: CharmArchiveURLs

// CharmArchiveURLs returns the URLS for the charm archive
// (bundle) data for each charm url in the given parameters.
func (u *UniterAPIV3) CharmArchiveURLs(args params.CharmURLs) (params.StringsResults, error) {
	apiHostPorts, err := u.st.APIHostPorts()
	if err != nil {
		return params.StringsResults{}, err
	}
	modelUUID := u.st.ModelUUID()
	result := params.StringsResults{
		Results: make([]params.StringsResult, len(args.URLs)),
	}
	for i, curl := range args.URLs {
		if _, err := charm.ParseURL(curl.URL); err != nil {
			result.Results[i].Error = common.ServerError(common.ErrPerm)
			continue
		}
		urlPath := "/"
		if modelUUID != "" {
			urlPath = path.Join(urlPath, "model", modelUUID)
		}
		urlPath = path.Join(urlPath, "charms")
		archiveURLs := make([]string, len(apiHostPorts))
		for j, server := range apiHostPorts {
			archiveURL := &url.URL{
				Scheme: "https",
				Host:   network.SelectInternalHostPort(server, false),
				Path:   urlPath,
			}
			q := archiveURL.Query()
			q.Set("url", curl.URL)
			q.Set("file", "*")
			archiveURL.RawQuery = q.Encode()
			archiveURLs[j] = archiveURL.String()
		}
		result.Results[i].Result = archiveURLs
	}
	return result, nil
}
开发者ID:pmatulis,项目名称:juju,代码行数:38,代码来源:uniter.go

示例8: SelectPeerHostPort

// SelectPeerHostPort returns the HostPort to use as the
// mongo replica set peer by selecting it from the given hostPorts.
func SelectPeerHostPort(hostPorts []network.HostPort) string {
	return network.SelectInternalHostPort(hostPorts, false)
}
开发者ID:klyachin,项目名称:juju,代码行数:5,代码来源:mongo.go


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