func getRemoteFreePort(host string) string {
	if host == "localhost" || host == "127.0.0.1" || host == "0.0.0.0" {
		return getLocalFreePort()
	}
	url := getFQDN("http://"+host, "7777")
	response, errGet := http.Get(url)
	if errGet != nil {
		port := strconv.Itoa(rand.Intn(64510) + 1024)
		log.Errorf("Can not pick a free port on %v, using %v instead. Reason: %v", url, port, errGet)
		return port
	}
	defer response.Body.Close()
	body, _ := ioutil.ReadAll(response.Body)
	return string(body)
}
finds single free port on the given host, using find_open_port.py service
package main
import (
	"fmt"
	"io"
	"io/ioutil"
	"math/rand"
	"net"
	"net/http"
	"os"
	"path"
	"path/filepath"
	"strconv"
	"github.com/bitly/go-simplejson"
)
const (
	sparkPorts              = 6
	zeppelinConfDir         = "ZEPPELIN_CONF_DIR"
	sparkPublicDNS          = "SPARK_PUBLIC_DNS"
	sparkLocalHostname      = "SPARK_LOCAL_HOSTNAME"
	zeppelinIntpJavaOpts    = "ZEPPELIN_INTP_JAVA_OPTS"
	volumeZeppelinConfig    = "VOLUME_ZEPPELIN_CONFIG"
	volumeZeppelinNotebooks = "VOLUME_ZEPPELIN_NOTEBOOKS"
)
var DefaultUsersFolder = os.Getenv("USERS_FOLDER_PATH")
var DefaultUser = os.Getenv("DEFAULT_USER_FOLDER_NAME")
func getFreePorts(num int) []string {
	ports := make([]string, num)
	for i := 0; i < num; i++ {
		ports[i] = getLocalFreePort()
	}
	return ports
}
func getLocalFreePort() string {
	ln, err := net.Listen("tcp", ":0")
	if err != nil {
		log.Debugf("Couldn't allocate free port")
	}
	port := ln.Addr().String()[5:]
	ln.Close()
	return port
}
func getRemoteFreePorts(N int, host string) []string {
	ports := make([]string, N)
	for i := 0; i < N; i++ {
		ports[i] = getRemoteFreePort(host)
	}
	return ports
}