2016-06-08 17:47:46 +00:00
|
|
|
package stack
|
|
|
|
|
|
|
|
import (
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
|
2016-09-06 18:18:12 +00:00
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
"github.com/docker/docker/api/types/filters"
|
|
|
|
"github.com/docker/docker/api/types/swarm"
|
2016-12-05 21:14:08 +00:00
|
|
|
"github.com/docker/docker/cli/compose/convert"
|
2016-09-06 18:46:37 +00:00
|
|
|
"github.com/docker/docker/client"
|
2016-11-30 22:38:40 +00:00
|
|
|
"github.com/docker/docker/opts"
|
2016-06-08 17:47:46 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func getStackFilter(namespace string) filters.Args {
|
|
|
|
filter := filters.NewArgs()
|
2016-12-05 21:14:08 +00:00
|
|
|
filter.Add("label", convert.LabelNamespace+"="+namespace)
|
2016-06-08 17:47:46 +00:00
|
|
|
return filter
|
|
|
|
}
|
|
|
|
|
2016-11-30 22:38:40 +00:00
|
|
|
func getStackFilterFromOpt(namespace string, opt opts.FilterOpt) filters.Args {
|
|
|
|
filter := opt.Value()
|
2016-12-05 21:14:08 +00:00
|
|
|
filter.Add("label", convert.LabelNamespace+"="+namespace)
|
2016-11-30 22:38:40 +00:00
|
|
|
return filter
|
|
|
|
}
|
|
|
|
|
|
|
|
func getAllStacksFilter() filters.Args {
|
|
|
|
filter := filters.NewArgs()
|
2016-12-05 21:14:08 +00:00
|
|
|
filter.Add("label", convert.LabelNamespace)
|
2016-11-30 22:38:40 +00:00
|
|
|
return filter
|
|
|
|
}
|
|
|
|
|
2016-06-08 17:47:46 +00:00
|
|
|
func getServices(
|
|
|
|
ctx context.Context,
|
|
|
|
apiclient client.APIClient,
|
|
|
|
namespace string,
|
|
|
|
) ([]swarm.Service, error) {
|
|
|
|
return apiclient.ServiceList(
|
|
|
|
ctx,
|
2016-11-01 14:01:16 +00:00
|
|
|
types.ServiceListOptions{Filters: getStackFilter(namespace)})
|
2016-06-08 17:47:46 +00:00
|
|
|
}
|
|
|
|
|
2016-11-28 16:38:41 +00:00
|
|
|
func getStackNetworks(
|
2016-06-08 17:47:46 +00:00
|
|
|
ctx context.Context,
|
|
|
|
apiclient client.APIClient,
|
|
|
|
namespace string,
|
|
|
|
) ([]types.NetworkResource, error) {
|
|
|
|
return apiclient.NetworkList(
|
|
|
|
ctx,
|
|
|
|
types.NetworkListOptions{Filters: getStackFilter(namespace)})
|
|
|
|
}
|
2017-01-18 19:40:29 +00:00
|
|
|
|
|
|
|
func getStackSecrets(
|
|
|
|
ctx context.Context,
|
|
|
|
apiclient client.APIClient,
|
|
|
|
namespace string,
|
|
|
|
) ([]swarm.Secret, error) {
|
|
|
|
return apiclient.SecretList(
|
|
|
|
ctx,
|
|
|
|
types.SecretListOptions{Filters: getStackFilter(namespace)})
|
|
|
|
}
|