當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。