Add control for removing stopped docker containers.

This commit is contained in:
Tom Wilkie
2016-04-13 12:27:17 +01:00
committed by Tom Wilkie
parent 7e9edb03a7
commit 65dbca997c
5 changed files with 21 additions and 1 deletions

View File

@@ -388,7 +388,7 @@ func (c *container) GetNode(hostID string, localAddrs []net.IP) report.Node {
RestartContainer, StopContainer, PauseContainer, AttachContainer, ExecContainer,
)
} else {
result = result.WithControls(StartContainer)
result = result.WithControls(StartContainer, RemoveContainer)
}
result = result.AddTable(LabelPrefix, c.container.Config.Labels)

View File

@@ -17,6 +17,7 @@ const (
RestartContainer = "docker_restart_container"
PauseContainer = "docker_pause_container"
UnpauseContainer = "docker_unpause_container"
RemoveContainer = "docker_remove_container"
AttachContainer = "docker_attach_container"
ExecContainer = "docker_exec_container"
@@ -48,6 +49,13 @@ func (r *registry) unpauseContainer(containerID string, _ xfer.Request) xfer.Res
return xfer.ResponseError(r.client.UnpauseContainer(containerID))
}
func (r *registry) removeContainer(containerID string, _ xfer.Request) xfer.Response {
log.Infof("Removing container %s", containerID)
return xfer.ResponseError(r.client.RemoveContainer(docker_client.RemoveContainerOptions{
ID: containerID,
}))
}
func (r *registry) attachContainer(containerID string, req xfer.Request) xfer.Response {
c, ok := r.GetContainer(containerID)
if !ok {
@@ -156,6 +164,7 @@ func (r *registry) registerControls() {
controls.Register(RestartContainer, captureContainerID(r.restartContainer))
controls.Register(PauseContainer, captureContainerID(r.pauseContainer))
controls.Register(UnpauseContainer, captureContainerID(r.unpauseContainer))
controls.Register(RemoveContainer, captureContainerID(r.removeContainer))
controls.Register(AttachContainer, captureContainerID(r.attachContainer))
controls.Register(ExecContainer, captureContainerID(r.execContainer))
}
@@ -166,6 +175,7 @@ func (r *registry) deregisterControls() {
controls.Rm(RestartContainer)
controls.Rm(PauseContainer)
controls.Rm(UnpauseContainer)
controls.Rm(RemoveContainer)
controls.Rm(AttachContainer)
controls.Rm(ExecContainer)
}

View File

@@ -68,6 +68,7 @@ type Client interface {
RestartContainer(string, uint) error
PauseContainer(string) error
UnpauseContainer(string) error
RemoveContainer(docker_client.RemoveContainerOptions) error
AttachToContainerNonBlocking(docker_client.AttachToContainerOptions) (docker_client.CloseWaiter, error)
CreateExec(docker_client.CreateExecOptions) (*docker_client.Exec, error)
StartExecNonBlocking(string, docker_client.StartExecOptions) (docker_client.CloseWaiter, error)

View File

@@ -136,6 +136,10 @@ func (m *mockDockerClient) UnpauseContainer(_ string) error {
return fmt.Errorf("unpaused")
}
func (m *mockDockerClient) RemoveContainer(_ client.RemoveContainerOptions) error {
return fmt.Errorf("remove")
}
type mockCloseWaiter struct{}
func (mockCloseWaiter) Close() error { return nil }

View File

@@ -132,6 +132,11 @@ func (r *Reporter) containerTopology(localAddrs []net.IP) report.Topology {
Human: "Unpause",
Icon: "fa-play",
})
result.Controls.AddControl(report.Control{
ID: RemoveContainer,
Human: "Remove",
Icon: "fa-trash-o",
})
result.Controls.AddControl(report.Control{
ID: AttachContainer,
Human: "Attach",