mirror of
https://github.com/crazy-max/diun.git
synced 2026-01-03 19:45:05 +01:00
Implement Swarm provider
This commit is contained in:
@@ -1,16 +1,15 @@
|
||||
package docker
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sort"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
)
|
||||
|
||||
// Containers return containers based on filters
|
||||
func (c *Client) Containers(filterArgs filters.Args) ([]types.Container, error) {
|
||||
containers, err := c.Api.ContainerList(context.Background(), types.ContainerListOptions{
|
||||
// ContainerList returns Docker containers
|
||||
func (c *Client) ContainerList(filterArgs filters.Args) ([]types.Container, error) {
|
||||
containers, err := c.Api.ContainerList(c.ctx, types.ContainerListOptions{
|
||||
Filters: filterArgs,
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
25
pkg/docker/service.go
Normal file
25
pkg/docker/service.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package docker
|
||||
|
||||
import (
|
||||
"sort"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
"github.com/docker/docker/api/types/swarm"
|
||||
)
|
||||
|
||||
// ServiceList returns Swarm services
|
||||
func (c *Client) ServiceList(filterArgs filters.Args) ([]swarm.Service, error) {
|
||||
services, err := c.Api.ServiceList(c.ctx, types.ServiceListOptions{
|
||||
Filters: filterArgs,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sort.Slice(services, func(i, j int) bool {
|
||||
return services[i].Spec.Name < services[j].Spec.Name
|
||||
})
|
||||
|
||||
return services, nil
|
||||
}
|
||||
Reference in New Issue
Block a user