Merge pull request #2927 from dgageot/extra_ls_info

Add RESPONSE time to available columns in ls
This commit is contained in:
David Gageot 2016-01-26 12:22:53 +01:00
commit 8f3d952242
3 changed files with 32 additions and 40 deletions

View File

@ -33,16 +33,23 @@ const (
var ( var (
stateTimeoutDuration = lsDefaultTimeout * time.Second stateTimeoutDuration = lsDefaultTimeout * time.Second
)
// FilterOptions - headers = map[string]string{
type FilterOptions struct { "Name": "NAME",
SwarmName []string "Active": "ACTIVE",
DriverName []string "ActiveHost": "DRIVER",
State []string "ActiveSwarm": "STATE",
Name []string "DriverName": "URL",
Labels []string "State": "STATE",
"URL": "URL",
"SwarmOptions": "SWARM_OPTIONS",
"Swarm": "SWARM",
"EngineOptions": "ENGINE_OPTIONS",
"Error": "ERRORS",
"DockerVersion": "DOCKER",
"ResponseTime": "RESPONSE",
} }
)
type HostListItem struct { type HostListItem struct {
Name string Name string
@ -57,21 +64,16 @@ type HostListItem struct {
EngineOptions *engine.Options EngineOptions *engine.Options
Error string Error string
DockerVersion string DockerVersion string
ResponseTime time.Duration
} }
type Headers struct { // FilterOptions -
Name string type FilterOptions struct {
Active string SwarmName []string
ActiveHost string DriverName []string
ActiveSwarm string State []string
DriverName string Name []string
State string Labels []string
URL string
SwarmOptions string
Swarm string
EngineOptions string
Error string
DockerVersion string
} }
func cmdLs(c CommandLine, api libmachine.API) error { func cmdLs(c CommandLine, api libmachine.API) error {
@ -110,21 +112,6 @@ func cmdLs(c CommandLine, api libmachine.API) error {
w = tabWriter w = tabWriter
headers := &Headers{
Name: "NAME",
Active: "ACTIVE",
ActiveHost: "DRIVER",
ActiveSwarm: "STATE",
DriverName: "URL",
State: "STATE",
URL: "URL",
SwarmOptions: "SWARM_OPTIONS",
Swarm: "SWARM",
EngineOptions: "ENGINE_OPTIONS",
Error: "ERRORS",
DockerVersion: "DOCKER",
}
if err := template.Execute(w, headers); err != nil { if err := template.Execute(w, headers); err != nil {
return err return err
} }
@ -349,6 +336,7 @@ func matchesLabel(host *host.Host, labels []string) bool {
// to call the underlying drivers as less as possible to get the information // to call the underlying drivers as less as possible to get the information
// we need. // we need.
func attemptGetHostState(h *host.Host, stateQueryChan chan<- HostListItem) { func attemptGetHostState(h *host.Host, stateQueryChan chan<- HostListItem) {
requestBeginning := time.Now()
url := "" url := ""
currentState := state.None currentState := state.None
dockerVersion := "Unknown" dockerVersion := "Unknown"
@ -427,6 +415,7 @@ func attemptGetHostState(h *host.Host, stateQueryChan chan<- HostListItem) {
EngineOptions: engineOptions, EngineOptions: engineOptions,
DockerVersion: dockerVersion, DockerVersion: dockerVersion,
Error: hostError, Error: hostError,
ResponseTime: time.Now().Round(time.Millisecond).Sub(requestBeginning.Round(time.Millisecond)),
} }
} }
@ -449,6 +438,7 @@ func getHostState(h *host.Host, hostListItemsChan chan<- HostListItem) {
Name: h.Name, Name: h.Name,
DriverName: h.Driver.DriverName(), DriverName: h.Driver.DriverName(),
State: state.Timeout, State: state.Timeout,
ResponseTime: stateTimeoutDuration,
} }
} }
} }

View File

@ -475,6 +475,7 @@ func TestGetHostStateTimeout(t *testing.T) {
assert.Equal(t, "foo", hostItem.Name) assert.Equal(t, "foo", hostItem.Name)
assert.Equal(t, state.Timeout, hostItem.State) assert.Equal(t, state.Timeout, hostItem.State)
assert.Equal(t, "Driver", hostItem.DriverName) assert.Equal(t, "Driver", hostItem.DriverName)
assert.Equal(t, stateTimeoutDuration, hostItem.ResponseTime)
} }
func TestGetHostStateError(t *testing.T) { func TestGetHostStateError(t *testing.T) {

View File

@ -88,6 +88,7 @@ Valid placeholders for the Go template are listed below:
| .Swarm | Machine swarm name | | .Swarm | Machine swarm name |
| .Error | Machine errors | | .Error | Machine errors |
| .DockerVersion | Docker Daemon version | | .DockerVersion | Docker Daemon version |
| .ResponseTime | Time taken by the host to respond |
When using the `--format` option, the `ls` command will either output the data exactly as the template declares or, When using the `--format` option, the `ls` command will either output the data exactly as the template declares or,
when using the table directive, will include column headers as well. when using the table directive, will include column headers as well.