2018-04-11 09:52:13 -04:00
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/docker/docker/api/types"
|
2018-04-18 11:16:55 -04:00
|
|
|
"github.com/docker/docker/internal/test"
|
2018-04-11 09:52:13 -04:00
|
|
|
"github.com/gotestyourself/gotestyourself/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ActiveContainers returns the list of ids of the currently running containers
|
2018-04-17 04:22:04 -04:00
|
|
|
func (d *Daemon) ActiveContainers(t assert.TestingT) []string {
|
2018-04-18 11:16:55 -04:00
|
|
|
if ht, ok := t.(test.HelperT); ok {
|
|
|
|
ht.Helper()
|
|
|
|
}
|
2018-04-11 09:52:13 -04:00
|
|
|
cli := d.NewClientT(t)
|
|
|
|
defer cli.Close()
|
|
|
|
|
|
|
|
containers, err := cli.ContainerList(context.Background(), types.ContainerListOptions{})
|
|
|
|
assert.NilError(t, err)
|
|
|
|
|
|
|
|
ids := make([]string, len(containers))
|
|
|
|
for i, c := range containers {
|
|
|
|
ids[i] = c.ID
|
|
|
|
}
|
|
|
|
return ids
|
|
|
|
}
|
|
|
|
|
|
|
|
// FindContainerIP returns the ip of the specified container
|
2018-04-17 04:22:04 -04:00
|
|
|
func (d *Daemon) FindContainerIP(t assert.TestingT, id string) string {
|
2018-04-18 11:16:55 -04:00
|
|
|
if ht, ok := t.(test.HelperT); ok {
|
|
|
|
ht.Helper()
|
|
|
|
}
|
2018-04-11 09:52:13 -04:00
|
|
|
cli := d.NewClientT(t)
|
|
|
|
defer cli.Close()
|
|
|
|
|
|
|
|
i, err := cli.ContainerInspect(context.Background(), id)
|
|
|
|
assert.NilError(t, err)
|
|
|
|
return i.NetworkSettings.IPAddress
|
|
|
|
}
|