本文整理匯總了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()
}
示例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())
}
}