func (e *TeardownExecutor) Execute(t *Task) error { if e.arg.ContainerIDs == nil && e.arg.All == false { return errors.New("Please specify container ids or all.") } var containerIDs []string if e.arg.All { t.Log("All requested.") conts, _ := containers.List() containerIDs = make([]string, len(conts)) i := 0 for id, _ := range conts { t.Log("-> found container %s", id) containerIDs[i] = id i++ } } else { containerIDs = e.arg.ContainerIDs } e.reply.ContainerIDs = []string{} for _, containerID := range containerIDs { if !containers.Teardown(containerID) { t.Log("-> no such container: %s", containerID) e.reply.Status += "no such container: " + containerID + "\n" } else { e.reply.ContainerIDs = append(e.reply.ContainerIDs, containerID) } } if e.reply.Status == "" { e.reply.Status = StatusOk } return nil }
func (e *ListExecutor) Execute(t *Task) error { e.reply.Containers, e.reply.UnusedPorts = containers.List() return nil }