mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
6fcb36ff14
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
49 lines
917 B
Go
49 lines
917 B
Go
package client
|
|
|
|
import (
|
|
"context"
|
|
|
|
controlapi "github.com/moby/buildkit/api/services/control"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
type WorkerInfo struct {
|
|
ID string
|
|
Labels map[string]string
|
|
}
|
|
|
|
func (c *Client) ListWorkers(ctx context.Context, opts ...ListWorkersOption) ([]*WorkerInfo, error) {
|
|
info := &ListWorkersInfo{}
|
|
for _, o := range opts {
|
|
o(info)
|
|
}
|
|
|
|
req := &controlapi.ListWorkersRequest{Filter: info.Filter}
|
|
resp, err := c.controlClient().ListWorkers(ctx, req)
|
|
if err != nil {
|
|
return nil, errors.Wrap(err, "failed to list workers")
|
|
}
|
|
|
|
var wi []*WorkerInfo
|
|
|
|
for _, w := range resp.Record {
|
|
wi = append(wi, &WorkerInfo{
|
|
ID: w.ID,
|
|
Labels: w.Labels,
|
|
})
|
|
}
|
|
|
|
return wi, nil
|
|
}
|
|
|
|
type ListWorkersOption func(*ListWorkersInfo)
|
|
|
|
type ListWorkersInfo struct {
|
|
Filter []string
|
|
}
|
|
|
|
func WithWorkerFilter(f []string) ListWorkersOption {
|
|
return func(wi *ListWorkersInfo) {
|
|
wi.Filter = f
|
|
}
|
|
}
|