~ubuntu-branches/ubuntu/saucy/juju-core/saucy-updates

« back to all changes in this revision

Viewing changes to src/launchpad.net/juju-core/instance/address.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-09-03 14:22:22 UTC
  • mfrom: (1.1.7)
  • Revision ID: package-import@ubuntu.com-20130903142222-9mes2r8wqr0bs7lp
Tags: 1.13.3-0ubuntu1
New upstream point release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
59
59
        return Address{value, addresstype, "", NetworkUnknown}
60
60
}
61
61
 
 
62
// HostAddresses looks up the IP addresses of the specified
 
63
// host, and translates them into instance.Address values.
 
64
func HostAddresses(host string) ([]Address, error) {
 
65
        ipaddrs, err := net.LookupIP(host)
 
66
        if err != nil {
 
67
                return nil, err
 
68
        }
 
69
        addrs := make([]Address, len(ipaddrs))
 
70
        for i, ipaddr := range ipaddrs {
 
71
                switch len(ipaddr) {
 
72
                case 4:
 
73
                        addrs[i].Type = Ipv4Address
 
74
                        addrs[i].Value = ipaddr.String()
 
75
                case 16:
 
76
                        addrs[i].Type = Ipv6Address
 
77
                        addrs[i].Value = ipaddr.String()
 
78
                }
 
79
        }
 
80
        return addrs, err
 
81
}
 
82
 
62
83
// SelectPublicAddress picks one address from a slice that would
63
84
// be appropriate to display as a publicly accessible endpoint.
64
85
// If there are no suitable addresses, the empty string is returned.