Пример #1
0
func getChain(address string) ([]string, error) {
	repClient, err := replicaClient.NewReplicaClient(address)
	if err != nil {
		return nil, err
	}

	r, err := repClient.GetReplica()
	if err != nil {
		return nil, err
	}

	return r.Chain, err
}
Пример #2
0
func (c *Controller) clientsAndSnapshot(name string) (map[string]*client.ReplicaClient, string, error) {
	clients := map[string]*client.ReplicaClient{}

	for _, replica := range c.replicas {
		if !strings.HasPrefix(replica.Address, "tcp://") {
			return nil, "", fmt.Errorf("Backend %s does not support revert", replica.Address)
		}

		repClient, err := client.NewReplicaClient(replica.Address)
		if err != nil {
			return nil, "", err
		}

		_, err = repClient.GetReplica()
		if err != nil {
			return nil, "", err
		}

		/*
			found := ""
			for _, snapshot := range rep.Chain {
				if snapshot == name {
					found = name
					break
				}
				fullName := "volume-snap-" + name + ".img"
				if snapshot == fullName {
					found = fullName
					break
				}
			}

			if found == "" {
				return nil, "", fmt.Errorf("Failed to find snapshot %s on %s", name, replica)
			}

			name = found
		*/
		clients[replica.Address] = repClient
	}
	name = "volume-snap-" + name + ".img"

	return clients, name, nil
}
Пример #3
0
func NewReplicaStatus() (*ReplicaStatus, error) {
	metadata, err := md.NewClientAndWait(controller.MetadataURL)
	if err != nil {
		return nil, err
	}
	self, err := metadata.GetSelfContainer()
	if err != nil {
		return nil, err
	}
	addr := controller.ReplicaAddress(self.PrimaryIp, 9502)

	controllerClient := client.NewControllerClient("http://controller:9501/v1")
	replicaClient, err := replicaClient.NewReplicaClient("http://localhost:9502/v1")
	if err != nil {
		return nil, err
	}

	return &ReplicaStatus{
		controller: controllerClient,
		replica:    replicaClient,
		address:    addr,
	}, nil
}