2016-06-08 13:47:46 -04:00
|
|
|
package stack
|
|
|
|
|
|
|
|
import (
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
|
2016-09-06 14:18:12 -04:00
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
"github.com/docker/docker/api/types/filters"
|
|
|
|
"github.com/docker/docker/api/types/swarm"
|
2016-09-06 14:46:37 -04:00
|
|
|
"github.com/docker/docker/client"
|
2016-06-08 13:47:46 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
labelNamespace = "com.docker.stack.namespace"
|
|
|
|
)
|
|
|
|
|
|
|
|
func getStackLabels(namespace string, labels map[string]string) map[string]string {
|
|
|
|
if labels == nil {
|
|
|
|
labels = make(map[string]string)
|
|
|
|
}
|
|
|
|
labels[labelNamespace] = namespace
|
|
|
|
return labels
|
|
|
|
}
|
|
|
|
|
|
|
|
func getStackFilter(namespace string) filters.Args {
|
|
|
|
filter := filters.NewArgs()
|
|
|
|
filter.Add("label", labelNamespace+"="+namespace)
|
|
|
|
return filter
|
|
|
|
}
|
|
|
|
|
|
|
|
func getServices(
|
|
|
|
ctx context.Context,
|
|
|
|
apiclient client.APIClient,
|
|
|
|
namespace string,
|
|
|
|
) ([]swarm.Service, error) {
|
|
|
|
return apiclient.ServiceList(
|
|
|
|
ctx,
|
2016-11-01 10:01:16 -04:00
|
|
|
types.ServiceListOptions{Filters: getStackFilter(namespace)})
|
2016-06-08 13:47:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func getNetworks(
|
|
|
|
ctx context.Context,
|
|
|
|
apiclient client.APIClient,
|
|
|
|
namespace string,
|
|
|
|
) ([]types.NetworkResource, error) {
|
|
|
|
return apiclient.NetworkList(
|
|
|
|
ctx,
|
|
|
|
types.NetworkListOptions{Filters: getStackFilter(namespace)})
|
|
|
|
}
|
2016-11-03 19:50:03 -04:00
|
|
|
|
|
|
|
type namespace struct {
|
|
|
|
name string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n namespace) scope(name string) string {
|
|
|
|
return n.name + "_" + name
|
|
|
|
}
|