本文整理匯總了Golang中github.com/docker/swarmkit/api.ControlClient.ListClusters方法的典型用法代碼示例。如果您正苦於以下問題:Golang ControlClient.ListClusters方法的具體用法?Golang ControlClient.ListClusters怎麽用?Golang ControlClient.ListClusters使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/docker/swarmkit/api.ControlClient
的用法示例。
在下文中一共展示了ControlClient.ListClusters方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: getCluster
func getCluster(ctx context.Context, c api.ControlClient, input string) (*api.Cluster, error) {
rg, err := c.GetCluster(ctx, &api.GetClusterRequest{ClusterID: input})
if err == nil {
return rg.Cluster, nil
}
rl, err := c.ListClusters(ctx,
&api.ListClustersRequest{
Filters: &api.ListClustersRequest_Filters{
NamePrefixes: []string{input},
},
},
)
if err != nil {
return nil, err
}
if len(rl.Clusters) == 0 {
return nil, fmt.Errorf("cluster %s not found", input)
}
if l := len(rl.Clusters); l > 1 {
return nil, fmt.Errorf("cluster %s is ambiguous (%d matches found)", input, l)
}
return rl.Clusters[0], nil
}
示例2: getSwarm
func getSwarm(ctx context.Context, c swarmapi.ControlClient) (*swarmapi.Cluster, error) {
rl, err := c.ListClusters(ctx, &swarmapi.ListClustersRequest{})
if err != nil {
return nil, err
}
if len(rl.Clusters) == 0 {
return nil, fmt.Errorf("swarm not found")
}
// TODO: assume one cluster only
return rl.Clusters[0], nil
}
示例3: getSwarm
func getSwarm(ctx context.Context, c swarmapi.ControlClient) (*swarmapi.Cluster, error) {
rl, err := c.ListClusters(ctx, &swarmapi.ListClustersRequest{})
if err != nil {
return nil, err
}
if len(rl.Clusters) == 0 {
return nil, errors.NewRequestNotFoundError(errNoSwarm)
}
// TODO: assume one cluster only
return rl.Clusters[0], nil
}