本文整理汇总了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())
}
}