2017-07-15 19:03:17 -04:00
|
|
|
package system
|
|
|
|
|
|
|
|
import (
|
2018-05-03 21:02:44 -04:00
|
|
|
"context"
|
|
|
|
|
2017-12-05 09:41:03 -05:00
|
|
|
"github.com/docker/docker/api/types"
|
2024-06-09 07:54:37 -04:00
|
|
|
"github.com/docker/docker/api/types/container"
|
cli/command/system: fix "docker events" not supporting --format=json
Before this patch:
docker events --format=json
json
json
json
^C
With this patch:
docker events --format=json
{"status":"create","id":"4ac3bba8abd68961e627540fed81ad16d55b88e45629d7cdb792126d09b6488d","from":"hello-world","Type":"container","Action":"create","Actor":{"ID":"4ac3bba8abd68961e627540fed81ad16d55b88e45629d7cdb792126d09b6488d","Attributes":{"image":"hello-world","name":"dreamy_goldstine"}},"scope":"local","time":1693168508,"timeNano":1693168508190136885}
{"status":"attach","id":"4ac3bba8abd68961e627540fed81ad16d55b88e45629d7cdb792126d09b6488d","from":"hello-world","Type":"container","Action":"attach","Actor":{"ID":"4ac3bba8abd68961e627540fed81ad16d55b88e45629d7cdb792126d09b6488d","Attributes":{"image":"hello-world","name":"dreamy_goldstine"}},"scope":"local","time":1693168508,"timeNano":1693168508192851593}
{"Type":"network","Action":"connect","Actor":{"ID":"c54920dd5074a73e28bea62007e0334d81cc040a90372be311cf16806403d350","Attributes":{"container":"4ac3bba8abd68961e627540fed81ad16d55b88e45629d7cdb792126d09b6488d","name":"bridge","type":"bridge"}},"scope":"local","time":1693168508,"timeNano":1693168508212398802}
{"status":"start","id":"4ac3bba8abd68961e627540fed81ad16d55b88e45629d7cdb792126d09b6488d","from":"hello-world","Type":"container","Action":"start","Actor":{"ID":"4ac3bba8abd68961e627540fed81ad16d55b88e45629d7cdb792126d09b6488d","Attributes":{"image":"hello-world","name":"dreamy_goldstine"}},"scope":"local","time":1693168508,"timeNano":1693168508312969843}
^C
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-08-27 19:28:11 -04:00
|
|
|
"github.com/docker/docker/api/types/events"
|
2024-02-21 10:36:17 -05:00
|
|
|
"github.com/docker/docker/api/types/filters"
|
2024-10-19 12:00:41 -04:00
|
|
|
"github.com/docker/docker/api/types/image"
|
2024-06-06 20:31:09 -04:00
|
|
|
"github.com/docker/docker/api/types/network"
|
2024-10-19 12:00:41 -04:00
|
|
|
"github.com/docker/docker/api/types/swarm"
|
|
|
|
"github.com/docker/docker/api/types/system"
|
|
|
|
"github.com/docker/docker/api/types/volume"
|
2017-07-15 19:03:17 -04:00
|
|
|
"github.com/docker/docker/client"
|
|
|
|
)
|
|
|
|
|
|
|
|
type fakeClient struct {
|
|
|
|
client.Client
|
|
|
|
|
2024-02-21 10:36:17 -05:00
|
|
|
version string
|
2024-10-19 12:00:41 -04:00
|
|
|
containerListFunc func(context.Context, container.ListOptions) ([]container.Summary, error)
|
2024-06-09 07:54:37 -04:00
|
|
|
containerPruneFunc func(ctx context.Context, pruneFilters filters.Args) (container.PruneReport, error)
|
2024-10-19 12:00:41 -04:00
|
|
|
eventsFn func(context.Context, events.ListOptions) (<-chan events.Message, <-chan error)
|
|
|
|
imageListFunc func(ctx context.Context, options image.ListOptions) ([]image.Summary, error)
|
|
|
|
infoFunc func(ctx context.Context) (system.Info, error)
|
|
|
|
networkListFunc func(ctx context.Context, options network.ListOptions) ([]network.Summary, error)
|
2024-06-06 20:31:09 -04:00
|
|
|
networkPruneFunc func(ctx context.Context, pruneFilter filters.Args) (network.PruneReport, error)
|
2024-10-19 12:00:41 -04:00
|
|
|
nodeListFunc func(ctx context.Context, options types.NodeListOptions) ([]swarm.Node, error)
|
|
|
|
serverVersion func(ctx context.Context) (types.Version, error)
|
|
|
|
volumeListFunc func(ctx context.Context, options volume.ListOptions) (volume.ListResponse, error)
|
2017-07-15 19:03:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (cli *fakeClient) ClientVersion() string {
|
|
|
|
return cli.version
|
|
|
|
}
|
cli/command/system: fix "docker events" not supporting --format=json
Before this patch:
docker events --format=json
json
json
json
^C
With this patch:
docker events --format=json
{"status":"create","id":"4ac3bba8abd68961e627540fed81ad16d55b88e45629d7cdb792126d09b6488d","from":"hello-world","Type":"container","Action":"create","Actor":{"ID":"4ac3bba8abd68961e627540fed81ad16d55b88e45629d7cdb792126d09b6488d","Attributes":{"image":"hello-world","name":"dreamy_goldstine"}},"scope":"local","time":1693168508,"timeNano":1693168508190136885}
{"status":"attach","id":"4ac3bba8abd68961e627540fed81ad16d55b88e45629d7cdb792126d09b6488d","from":"hello-world","Type":"container","Action":"attach","Actor":{"ID":"4ac3bba8abd68961e627540fed81ad16d55b88e45629d7cdb792126d09b6488d","Attributes":{"image":"hello-world","name":"dreamy_goldstine"}},"scope":"local","time":1693168508,"timeNano":1693168508192851593}
{"Type":"network","Action":"connect","Actor":{"ID":"c54920dd5074a73e28bea62007e0334d81cc040a90372be311cf16806403d350","Attributes":{"container":"4ac3bba8abd68961e627540fed81ad16d55b88e45629d7cdb792126d09b6488d","name":"bridge","type":"bridge"}},"scope":"local","time":1693168508,"timeNano":1693168508212398802}
{"status":"start","id":"4ac3bba8abd68961e627540fed81ad16d55b88e45629d7cdb792126d09b6488d","from":"hello-world","Type":"container","Action":"start","Actor":{"ID":"4ac3bba8abd68961e627540fed81ad16d55b88e45629d7cdb792126d09b6488d","Attributes":{"image":"hello-world","name":"dreamy_goldstine"}},"scope":"local","time":1693168508,"timeNano":1693168508312969843}
^C
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-08-27 19:28:11 -04:00
|
|
|
|
2024-10-19 12:00:41 -04:00
|
|
|
func (cli *fakeClient) ContainerList(ctx context.Context, options container.ListOptions) ([]container.Summary, error) {
|
|
|
|
if cli.containerListFunc != nil {
|
|
|
|
return cli.containerListFunc(ctx, options)
|
|
|
|
}
|
|
|
|
return []container.Summary{}, nil
|
cli/command/system: fix "docker events" not supporting --format=json
Before this patch:
docker events --format=json
json
json
json
^C
With this patch:
docker events --format=json
{"status":"create","id":"4ac3bba8abd68961e627540fed81ad16d55b88e45629d7cdb792126d09b6488d","from":"hello-world","Type":"container","Action":"create","Actor":{"ID":"4ac3bba8abd68961e627540fed81ad16d55b88e45629d7cdb792126d09b6488d","Attributes":{"image":"hello-world","name":"dreamy_goldstine"}},"scope":"local","time":1693168508,"timeNano":1693168508190136885}
{"status":"attach","id":"4ac3bba8abd68961e627540fed81ad16d55b88e45629d7cdb792126d09b6488d","from":"hello-world","Type":"container","Action":"attach","Actor":{"ID":"4ac3bba8abd68961e627540fed81ad16d55b88e45629d7cdb792126d09b6488d","Attributes":{"image":"hello-world","name":"dreamy_goldstine"}},"scope":"local","time":1693168508,"timeNano":1693168508192851593}
{"Type":"network","Action":"connect","Actor":{"ID":"c54920dd5074a73e28bea62007e0334d81cc040a90372be311cf16806403d350","Attributes":{"container":"4ac3bba8abd68961e627540fed81ad16d55b88e45629d7cdb792126d09b6488d","name":"bridge","type":"bridge"}},"scope":"local","time":1693168508,"timeNano":1693168508212398802}
{"status":"start","id":"4ac3bba8abd68961e627540fed81ad16d55b88e45629d7cdb792126d09b6488d","from":"hello-world","Type":"container","Action":"start","Actor":{"ID":"4ac3bba8abd68961e627540fed81ad16d55b88e45629d7cdb792126d09b6488d","Attributes":{"image":"hello-world","name":"dreamy_goldstine"}},"scope":"local","time":1693168508,"timeNano":1693168508312969843}
^C
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-08-27 19:28:11 -04:00
|
|
|
}
|
2024-02-21 10:36:17 -05:00
|
|
|
|
2024-06-09 07:54:37 -04:00
|
|
|
func (cli *fakeClient) ContainersPrune(ctx context.Context, pruneFilters filters.Args) (container.PruneReport, error) {
|
2024-02-21 10:36:17 -05:00
|
|
|
if cli.containerPruneFunc != nil {
|
|
|
|
return cli.containerPruneFunc(ctx, pruneFilters)
|
|
|
|
}
|
2024-06-09 07:54:37 -04:00
|
|
|
return container.PruneReport{}, nil
|
2024-02-21 10:36:17 -05:00
|
|
|
}
|
|
|
|
|
2024-10-19 12:00:41 -04:00
|
|
|
func (cli *fakeClient) Events(ctx context.Context, opts events.ListOptions) (<-chan events.Message, <-chan error) {
|
|
|
|
return cli.eventsFn(ctx, opts)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cli *fakeClient) ImageList(ctx context.Context, options image.ListOptions) ([]image.Summary, error) {
|
|
|
|
if cli.imageListFunc != nil {
|
|
|
|
return cli.imageListFunc(ctx, options)
|
|
|
|
}
|
|
|
|
return []image.Summary{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cli *fakeClient) Info(ctx context.Context) (system.Info, error) {
|
|
|
|
if cli.infoFunc != nil {
|
|
|
|
return cli.infoFunc(ctx)
|
|
|
|
}
|
|
|
|
return system.Info{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cli *fakeClient) NetworkList(ctx context.Context, options network.ListOptions) ([]network.Summary, error) {
|
|
|
|
if cli.networkListFunc != nil {
|
|
|
|
return cli.networkListFunc(ctx, options)
|
|
|
|
}
|
|
|
|
return []network.Summary{}, nil
|
|
|
|
}
|
|
|
|
|
2024-06-06 20:31:09 -04:00
|
|
|
func (cli *fakeClient) NetworksPrune(ctx context.Context, pruneFilter filters.Args) (network.PruneReport, error) {
|
2024-02-21 10:36:17 -05:00
|
|
|
if cli.networkPruneFunc != nil {
|
|
|
|
return cli.networkPruneFunc(ctx, pruneFilter)
|
|
|
|
}
|
2024-06-06 20:31:09 -04:00
|
|
|
return network.PruneReport{}, nil
|
2024-02-21 10:36:17 -05:00
|
|
|
}
|
2024-10-19 12:00:41 -04:00
|
|
|
|
|
|
|
func (cli *fakeClient) NodeList(ctx context.Context, options types.NodeListOptions) ([]swarm.Node, error) {
|
|
|
|
if cli.nodeListFunc != nil {
|
|
|
|
return cli.nodeListFunc(ctx, options)
|
|
|
|
}
|
|
|
|
return []swarm.Node{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cli *fakeClient) ServerVersion(ctx context.Context) (types.Version, error) {
|
|
|
|
return cli.serverVersion(ctx)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cli *fakeClient) VolumeList(ctx context.Context, options volume.ListOptions) (volume.ListResponse, error) {
|
|
|
|
if cli.volumeListFunc != nil {
|
|
|
|
return cli.volumeListFunc(ctx, options)
|
|
|
|
}
|
|
|
|
return volume.ListResponse{}, nil
|
|
|
|
}
|