Пример #1
0
// GetContainer retrieves the container tracked by the given client with the
// given stitchID.
func GetContainer(c client.Client, stitchID int) (db.Container, error) {
	containers, err := c.QueryContainers()
	if err != nil {
		return db.Container{}, err
	}

	for _, c := range containers {
		if c.StitchID == stitchID {
			return c, nil
		}
	}

	return db.Container{}, fmt.Errorf("no container with stitchID %d", stitchID)
}
Пример #2
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)
}
Пример #3
0
func getCurrentDeployment(c client.Client) (string, error) {
	clusters, err := c.QueryClusters()
	if err != nil {
		return "", err
	}
	switch len(clusters) {
	case 0:
		return emptyDeployment, nil
	case 1:
		return clusters[0].Spec, nil
	default:
		panic("unreached")
	}
}
Пример #4
0
func newNetworkTester(clnt client.Client) (networkTester, error) {
	labels, err := clnt.QueryLabels()
	if err != nil {
		return networkTester{}, err
	}

	allIPsSet := make(map[string]struct{})
	labelMap := make(map[string]db.Label)
	for _, label := range labels {
		labelMap[label.Label] = label
		for _, ip := range append(label.ContainerIPs, label.IP) {
			allIPsSet[ip] = struct{}{}
		}
	}

	var allIPs []string
	for ip := range allIPsSet {
		allIPs = append(allIPs, ip)
	}

	connections, err := clnt.QueryConnections()
	if err != nil {
		return networkTester{}, err
	}

	connectionMap := make(map[string][]string)
	for _, conn := range connections {
		connectionMap[conn.From] = append(connectionMap[conn.From], conn.To)
		// Connections are bi-directional.
		connectionMap[conn.To] = append(connectionMap[conn.To], conn.From)
	}

	return networkTester{
		labelMap:      labelMap,
		connectionMap: connectionMap,
		allIPs:        allIPs,
	}, nil
}
Пример #5
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")
}