|
|
@ -215,43 +215,52 @@ func parseStorageEndPoints(eps []string, defaultPort int) (endpoints []storageEn |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// getListenIPs - gets all the ips to listen on.
|
|
|
|
// getListenIPs - gets all the ips to listen on.
|
|
|
|
func getListenIPs(httpServerConf *http.Server) (hosts []string, port string) { |
|
|
|
func getListenIPs(httpServerConf *http.Server) (hosts []string, port string, err error) { |
|
|
|
host, port, err := net.SplitHostPort(httpServerConf.Addr) |
|
|
|
var host string |
|
|
|
fatalIf(err, "Unable to parse host address.", httpServerConf.Addr) |
|
|
|
host, port, err = net.SplitHostPort(httpServerConf.Addr) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if host != "" { |
|
|
|
return nil, port, fmt.Errorf("Unable to parse host address %s", err) |
|
|
|
hosts = append(hosts, host) |
|
|
|
|
|
|
|
return hosts, port |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
addrs, err := net.InterfaceAddrs() |
|
|
|
if host == "" { |
|
|
|
fatalIf(err, "Unable to determine network interface address.") |
|
|
|
var addrs []net.Addr |
|
|
|
for _, addr := range addrs { |
|
|
|
addrs, err = net.InterfaceAddrs() |
|
|
|
if addr.Network() == "ip+net" { |
|
|
|
if err != nil { |
|
|
|
host := strings.Split(addr.String(), "/")[0] |
|
|
|
return nil, port, fmt.Errorf("Unable to determine network interface address. %s", err) |
|
|
|
if ip := net.ParseIP(host); ip.To4() != nil { |
|
|
|
} |
|
|
|
hosts = append(hosts, host) |
|
|
|
for _, addr := range addrs { |
|
|
|
|
|
|
|
if addr.Network() == "ip+net" { |
|
|
|
|
|
|
|
hostname := strings.Split(addr.String(), "/")[0] |
|
|
|
|
|
|
|
if ip := net.ParseIP(hostname); ip.To4() != nil { |
|
|
|
|
|
|
|
hosts = append(hosts, hostname) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
err = sortIPsByOctet(hosts) |
|
|
|
return hosts, port |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return nil, port, fmt.Errorf("Unable reverse sorted ips from hosts %s", err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return hosts, port, nil |
|
|
|
|
|
|
|
} // if host != "" {
|
|
|
|
|
|
|
|
// Proceed to append itself, since user requested a specific endpoint.
|
|
|
|
|
|
|
|
hosts = append(hosts, host) |
|
|
|
|
|
|
|
return hosts, port, nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Finalizes the endpoints based on the host list and port.
|
|
|
|
// Finalizes the endpoints based on the host list and port.
|
|
|
|
func finalizeEndpoints(tls bool, apiServer *http.Server) (endPoints []string) { |
|
|
|
func finalizeEndpoints(tls bool, apiServer *http.Server) (endPoints []string) { |
|
|
|
// Get list of listen ips and port.
|
|
|
|
|
|
|
|
hosts, port := getListenIPs(apiServer) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Verify current scheme.
|
|
|
|
// Verify current scheme.
|
|
|
|
scheme := "http" |
|
|
|
scheme := "http" |
|
|
|
if tls { |
|
|
|
if tls { |
|
|
|
scheme = "https" |
|
|
|
scheme = "https" |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ips := getIPsFromHosts(hosts) |
|
|
|
// Get list of listen ips and port.
|
|
|
|
|
|
|
|
hosts, port, err := getListenIPs(apiServer) |
|
|
|
|
|
|
|
fatalIf(err, "Unable to get list of ips to listen on") |
|
|
|
|
|
|
|
|
|
|
|
// Construct proper endpoints.
|
|
|
|
// Construct proper endpoints.
|
|
|
|
for _, ip := range ips { |
|
|
|
for _, host := range hosts { |
|
|
|
endPoints = append(endPoints, fmt.Sprintf("%s://%s:%s", scheme, ip.String(), port)) |
|
|
|
endPoints = append(endPoints, fmt.Sprintf("%s://%s:%s", scheme, host, port)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Success.
|
|
|
|
// Success.
|
|
|
|