2017-11-20 09:30:52 -05:00
|
|
|
package swarm
|
2016-09-08 13:11:39 -04:00
|
|
|
|
|
|
|
import (
|
2018-05-03 21:02:44 -04:00
|
|
|
"context"
|
|
|
|
|
2017-04-17 18:07:56 -04:00
|
|
|
"github.com/docker/cli/cli/compose/convert"
|
2017-05-15 08:45:19 -04:00
|
|
|
"github.com/docker/cli/opts"
|
2016-09-08 13:11:39 -04:00
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
"github.com/docker/docker/api/types/filters"
|
2024-06-04 03:17:20 -04:00
|
|
|
"github.com/docker/docker/api/types/network"
|
2016-09-08 13:11:39 -04:00
|
|
|
"github.com/docker/docker/api/types/swarm"
|
2017-05-08 13:51:30 -04:00
|
|
|
"github.com/docker/docker/client"
|
2016-09-08 13:11:39 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func getStackFilter(namespace string) filters.Args {
|
|
|
|
filter := filters.NewArgs()
|
2016-12-05 16:14:08 -05:00
|
|
|
filter.Add("label", convert.LabelNamespace+"="+namespace)
|
2016-09-08 13:11:39 -04:00
|
|
|
return filter
|
|
|
|
}
|
|
|
|
|
2016-11-30 17:38:40 -05:00
|
|
|
func getStackFilterFromOpt(namespace string, opt opts.FilterOpt) filters.Args {
|
|
|
|
filter := opt.Value()
|
2016-12-05 16:14:08 -05:00
|
|
|
filter.Add("label", convert.LabelNamespace+"="+namespace)
|
2016-11-30 17:38:40 -05:00
|
|
|
return filter
|
|
|
|
}
|
|
|
|
|
|
|
|
func getAllStacksFilter() filters.Args {
|
|
|
|
filter := filters.NewArgs()
|
2016-12-05 16:14:08 -05:00
|
|
|
filter.Add("label", convert.LabelNamespace)
|
2016-11-30 17:38:40 -05:00
|
|
|
return filter
|
|
|
|
}
|
|
|
|
|
2018-05-28 06:26:14 -04:00
|
|
|
func getStackServices(ctx context.Context, apiclient client.APIClient, namespace string) ([]swarm.Service, error) {
|
2022-02-23 12:02:15 -05:00
|
|
|
return apiclient.ServiceList(ctx, types.ServiceListOptions{Filters: getStackFilter(namespace)})
|
2016-09-08 13:11:39 -04:00
|
|
|
}
|
|
|
|
|
2024-06-05 10:28:24 -04:00
|
|
|
func getStackNetworks(ctx context.Context, apiclient client.APIClient, namespace string) ([]network.Summary, error) {
|
2024-06-04 03:17:20 -04:00
|
|
|
return apiclient.NetworkList(ctx, network.ListOptions{Filters: getStackFilter(namespace)})
|
2016-09-08 13:11:39 -04:00
|
|
|
}
|
2017-01-18 14:40:29 -05:00
|
|
|
|
2018-05-28 06:26:14 -04:00
|
|
|
func getStackSecrets(ctx context.Context, apiclient client.APIClient, namespace string) ([]swarm.Secret, error) {
|
|
|
|
return apiclient.SecretList(ctx, types.SecretListOptions{Filters: getStackFilter(namespace)})
|
2017-01-18 14:40:29 -05:00
|
|
|
}
|
2017-05-26 20:30:33 -04:00
|
|
|
|
2018-05-28 06:26:14 -04:00
|
|
|
func getStackConfigs(ctx context.Context, apiclient client.APIClient, namespace string) ([]swarm.Config, error) {
|
|
|
|
return apiclient.ConfigList(ctx, types.ConfigListOptions{Filters: getStackFilter(namespace)})
|
2017-05-26 20:30:33 -04:00
|
|
|
}
|
2023-05-05 08:36:36 -04:00
|
|
|
|
|
|
|
func getStackTasks(ctx context.Context, apiclient client.APIClient, namespace string) ([]swarm.Task, error) {
|
|
|
|
return apiclient.TaskList(ctx, types.TaskListOptions{Filters: getStackFilter(namespace)})
|
|
|
|
}
|