Exemple #1
0
// getPublicIP returns the public IP associated with the machine with the
// given private IP.
func getPublicIP(c client.Client, privateIP string) (string, error) {
	machines, err := c.QueryMachines()
	if err != nil {
		return "", err
	}

	for _, m := range machines {
		if m.PrivateIP == privateIP {
			return m.PublicIP, nil
		}
	}

	return "", fmt.Errorf("no machine with private IP %s", privateIP)
}
Exemple #2
0
func (getter clientGetterImpl) LeaderClient(localClient client.Client) (
	client.Client, error) {

	machines, err := localClient.QueryMachines()
	if err != nil {
		return nil, fmt.Errorf("unable to query machines: %s", err.Error())
	}

	// Try to figure out the lead minion's IP by asking each of the machines
	// tracked by the local daemon.
	for _, m := range machines {
		if m.PublicIP == "" {
			continue
		}

		ip, err := getter.getLeaderIP(localClient, m.PublicIP)
		if err == nil {
			return getter.Client(api.RemoteAddress(ip))
		}
		log.WithError(err).Debug("Unable to get leader IP")
	}

	return nil, errors.New("no leader found")
}