mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
filter services by runtime; default to container
Signed-off-by: Evan Hazlett <ejhazlett@gmail.com>
This commit is contained in:
parent
e06e2ef107
commit
f71bdc67a2
4 changed files with 21 additions and 6 deletions
|
@ -45,7 +45,9 @@ func runList(dockerCli *command.DockerCli, opts listOptions) error {
|
|||
ctx := context.Background()
|
||||
client := dockerCli.Client()
|
||||
|
||||
services, err := client.ServiceList(ctx, types.ServiceListOptions{Filters: opts.filter.Value()})
|
||||
serviceFilters := opts.filter.Value()
|
||||
serviceFilters.Add("runtimes", string(swarm.RuntimeContainer))
|
||||
services, err := client.ServiceList(ctx, types.ServiceListOptions{Filters: serviceFilters})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
swarmtypes "github.com/docker/docker/api/types/swarm"
|
||||
"github.com/docker/docker/cli"
|
||||
"github.com/docker/docker/cli/command"
|
||||
"github.com/docker/docker/cli/command/formatter"
|
||||
|
@ -58,8 +59,11 @@ func runPS(dockerCli *command.DockerCli, opts psOptions) error {
|
|||
serviceIDFilter := filters.NewArgs()
|
||||
serviceNameFilter := filters.NewArgs()
|
||||
for _, service := range opts.services {
|
||||
// default to container runtime
|
||||
serviceIDFilter.Add("id", service)
|
||||
serviceIDFilter.Add("runtimes", string(swarmtypes.RuntimeContainer))
|
||||
serviceNameFilter.Add("name", service)
|
||||
serviceNameFilter.Add("runtimes", string(swarmtypes.RuntimeContainer))
|
||||
}
|
||||
serviceByIDList, err := client.ServiceList(ctx, types.ServiceListOptions{Filters: serviceIDFilter})
|
||||
if err != nil {
|
||||
|
|
|
@ -17,6 +17,12 @@ func getStackFilter(namespace string) filters.Args {
|
|||
return filter
|
||||
}
|
||||
|
||||
func getServiceFilter(namespace string) filters.Args {
|
||||
filter := getStackFilter(namespace)
|
||||
filter.Add("runtimes", string(swarm.RuntimeContainer))
|
||||
return filter
|
||||
}
|
||||
|
||||
func getStackFilterFromOpt(namespace string, opt opts.FilterOpt) filters.Args {
|
||||
filter := opt.Value()
|
||||
filter.Add("label", convert.LabelNamespace+"="+namespace)
|
||||
|
@ -36,7 +42,7 @@ func getServices(
|
|||
) ([]swarm.Service, error) {
|
||||
return apiclient.ServiceList(
|
||||
ctx,
|
||||
types.ServiceListOptions{Filters: getStackFilter(namespace)})
|
||||
types.ServiceListOptions{Filters: getServiceFilter(namespace)})
|
||||
}
|
||||
|
||||
func getStackNetworks(
|
||||
|
|
|
@ -40,18 +40,21 @@ func (c *Cluster) GetServices(options apitypes.ServiceListOptions) ([]types.Serv
|
|||
// be good to have accepted file check in the same file as
|
||||
// the filter processing (in the for loop below).
|
||||
accepted := map[string]bool{
|
||||
"name": true,
|
||||
"id": true,
|
||||
"label": true,
|
||||
"mode": true,
|
||||
"name": true,
|
||||
"id": true,
|
||||
"label": true,
|
||||
"mode": true,
|
||||
"runtimes": true,
|
||||
}
|
||||
if err := options.Filters.Validate(accepted); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
filters := &swarmapi.ListServicesRequest_Filters{
|
||||
NamePrefixes: options.Filters.Get("name"),
|
||||
IDPrefixes: options.Filters.Get("id"),
|
||||
Labels: runconfigopts.ConvertKVStringsToMap(options.Filters.Get("label")),
|
||||
Runtimes: options.Filters.Get("runtimes"),
|
||||
}
|
||||
|
||||
ctx, cancel := c.getRequestContext()
|
||||
|
|
Loading…
Reference in a new issue