2016-09-08 13:11:39 -04:00
|
|
|
package stack
|
|
|
|
|
|
|
|
import (
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
|
2017-04-17 18:07:56 -04:00
|
|
|
"github.com/docker/cli/cli/compose/convert"
|
2016-09-08 13:11:39 -04:00
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
"github.com/docker/docker/api/types/filters"
|
|
|
|
"github.com/docker/docker/api/types/swarm"
|
2017-05-08 13:51:30 -04:00
|
|
|
"github.com/docker/docker/client"
|
2016-11-30 17:38:40 -05:00
|
|
|
"github.com/docker/docker/opts"
|
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
|
|
|
|
}
|
|
|
|
|
2017-03-24 12:26:15 -04:00
|
|
|
func getServiceFilter(namespace string) filters.Args {
|
2017-04-26 09:09:54 -04:00
|
|
|
return getStackFilter(namespace)
|
2017-03-24 12:26:15 -04:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2016-09-08 13:11:39 -04:00
|
|
|
func getServices(
|
|
|
|
ctx context.Context,
|
|
|
|
apiclient client.APIClient,
|
|
|
|
namespace string,
|
|
|
|
) ([]swarm.Service, error) {
|
|
|
|
return apiclient.ServiceList(
|
|
|
|
ctx,
|
2017-03-24 12:26:15 -04:00
|
|
|
types.ServiceListOptions{Filters: getServiceFilter(namespace)})
|
2016-09-08 13:11:39 -04:00
|
|
|
}
|
|
|
|
|
2016-11-28 11:38:41 -05:00
|
|
|
func getStackNetworks(
|
2016-09-08 13:11:39 -04:00
|
|
|
ctx context.Context,
|
|
|
|
apiclient client.APIClient,
|
|
|
|
namespace string,
|
|
|
|
) ([]types.NetworkResource, error) {
|
|
|
|
return apiclient.NetworkList(
|
|
|
|
ctx,
|
|
|
|
types.NetworkListOptions{Filters: getStackFilter(namespace)})
|
|
|
|
}
|
2017-01-18 14:40:29 -05:00
|
|
|
|
|
|
|
func getStackSecrets(
|
|
|
|
ctx context.Context,
|
|
|
|
apiclient client.APIClient,
|
|
|
|
namespace string,
|
|
|
|
) ([]swarm.Secret, error) {
|
|
|
|
return apiclient.SecretList(
|
|
|
|
ctx,
|
|
|
|
types.SecretListOptions{Filters: getStackFilter(namespace)})
|
|
|
|
}
|