當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Machine.Addresses方法代碼示例

本文整理匯總了Golang中launchpad/net/juju-core/state.Machine.Addresses方法的典型用法代碼示例。如果您正苦於以下問題:Golang Machine.Addresses方法的具體用法?Golang Machine.Addresses怎麽用?Golang Machine.Addresses使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在launchpad/net/juju-core/state.Machine的用法示例。


在下文中一共展示了Machine.Addresses方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: ExecSsh

func (c *NatCommand) ExecSsh(m *state.Machine, script string) error {
	host := instance.SelectPublicAddress(m.Addresses())
	if host == "" {
		return fmt.Errorf("could not resolve machine's public address")
	}
	log.Println("Configuring NAT routing on machine ", m.Id())
	var options ssh.Options
	cmd := ssh.Command("[email protected]"+host, []string{"sh -c 'NATCMD=$(mktemp); cat >${NATCMD}; sudo sh -x ${NATCMD}'"}, &options)
	cmd.Stdin = strings.NewReader(script)
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr
	return cmd.Run()
}
開發者ID:tasdomas,項目名稱:juju-nat,代碼行數:13,代碼來源:common.go

示例2: MatchNetworks

func MatchNetworks(host, gateway *state.Machine) (string, string, error) {
	var bestPrefix, bestHost, bestGw string
	for _, hostAddr := range host.Addresses() {
		if hostAddr.Type != instance.Ipv4Address || isLoopback(hostAddr.Value) {
			continue
		}
		for _, gwAddr := range gateway.Addresses() {
			if gwAddr.Type != instance.Ipv4Address || isLoopback(hostAddr.Value) {
				continue
			}
			prefix := greatestCommonPrefix(hostAddr.Value, gwAddr.Value)
			if len(prefix) > len(bestPrefix) {
				bestPrefix = prefix
				bestHost = hostAddr.Value
				bestGw = gwAddr.Value
			}
		}
	}
	if bestHost != "" && bestGw != "" {
		return bestHost, bestGw, nil
	} else {
		return "", "", fmt.Errorf("failed to find common network for %s and %s", host.Id(), gateway.Id())
	}
}
開發者ID:tasdomas,項目名稱:juju-nat,代碼行數:24,代碼來源:common.go


注:本文中的launchpad/net/juju-core/state.Machine.Addresses方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。