コード例 #1
0
ファイル: util.go プロジェクト: NetSys/quilt
// 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
ファイル: getter.go プロジェクト: NetSys/quilt
// 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
ファイル: run.go プロジェクト: NetSys/quilt
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
ファイル: check_network.go プロジェクト: NetSys/quilt
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
ファイル: getter.go プロジェクト: NetSys/quilt
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")
}