2015-12-17 16:07:04 -08:00
|
|
|
package supervisor
|
2015-12-01 10:55:13 -08:00
|
|
|
|
2016-02-17 10:55:54 -08:00
|
|
|
import "github.com/docker/containerd/runtime"
|
|
|
|
|
2016-06-03 15:00:49 -07:00
|
|
|
// GetContainersTask holds needed parameters to retrieve a list of
|
|
|
|
// containers
|
2016-02-11 17:26:24 -08:00
|
|
|
type GetContainersTask struct {
|
2016-02-17 10:55:54 -08:00
|
|
|
baseTask
|
2016-07-13 11:01:07 -07:00
|
|
|
ID string
|
|
|
|
GetState func(c runtime.Container) (interface{}, error)
|
|
|
|
|
2016-02-17 10:55:54 -08:00
|
|
|
Containers []runtime.Container
|
2016-07-13 11:01:07 -07:00
|
|
|
States []interface{}
|
2015-12-01 10:55:13 -08:00
|
|
|
}
|
|
|
|
|
2016-02-17 10:55:54 -08:00
|
|
|
func (s *Supervisor) getContainers(t *GetContainersTask) error {
|
2016-04-22 17:29:30 -04:00
|
|
|
|
2016-02-17 10:55:54 -08:00
|
|
|
if t.ID != "" {
|
2016-04-22 17:29:30 -04:00
|
|
|
ci, ok := s.containers[t.ID]
|
|
|
|
if !ok {
|
2016-02-11 12:20:29 -08:00
|
|
|
return ErrContainerNotFound
|
|
|
|
}
|
2016-02-17 10:55:54 -08:00
|
|
|
t.Containers = append(t.Containers, ci.container)
|
2016-07-13 11:01:07 -07:00
|
|
|
if t.GetState != nil {
|
|
|
|
st, err := t.GetState(ci.container)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
t.States = append(t.States, st)
|
|
|
|
}
|
2016-04-22 17:29:30 -04:00
|
|
|
|
2016-02-11 12:20:29 -08:00
|
|
|
return nil
|
|
|
|
}
|
2016-04-22 17:29:30 -04:00
|
|
|
|
|
|
|
for _, ci := range s.containers {
|
|
|
|
t.Containers = append(t.Containers, ci.container)
|
2016-07-13 11:01:07 -07:00
|
|
|
if t.GetState != nil {
|
|
|
|
st, err := t.GetState(ci.container)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
t.States = append(t.States, st)
|
|
|
|
}
|
2015-12-01 10:55:13 -08:00
|
|
|
}
|
2016-04-22 17:29:30 -04:00
|
|
|
|
2015-12-01 10:55:13 -08:00
|
|
|
return nil
|
|
|
|
}
|