From 02c235b8b91e093fc185713e965fd17d7c462873 Mon Sep 17 00:00:00 2001 From: Jean-Laurent de Morlhon Date: Thu, 10 Dec 2015 12:14:05 +0100 Subject: [PATCH] Fix #2534 and #1696 Signed-off-by: Jean-Laurent de Morlhon --- commands/commands.go | 7 +++++++ commands/ls.go | 7 ++++++- docs/reference/ls.md | 15 ++++++++++++++- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/commands/commands.go b/commands/commands.go index 51d8852de9..21cea662bf 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -37,6 +37,8 @@ type CommandLine interface { Bool(name string) bool + Int(name string) int + String(name string) string StringSlice(name string) []string @@ -216,6 +218,11 @@ var Commands = []cli.Command{ Usage: "Filter output based on conditions provided", Value: &cli.StringSlice{}, }, + cli.IntFlag{ + Name: "timeout, t", + Usage: fmt.Sprintf("Timeout in seconds, default to %ds", DefaultTimeoutDuration), + Value: DefaultTimeoutDuration, + }, }, Name: "ls", Usage: "List machines", diff --git a/commands/ls.go b/commands/ls.go index 9a67b94d34..0030fcc7dc 100644 --- a/commands/ls.go +++ b/commands/ls.go @@ -21,8 +21,10 @@ import ( "github.com/skarademir/naturalsort" ) +const DefaultTimeoutDuration = 10 + var ( - stateTimeoutDuration = 10 * time.Second + stateTimeoutDuration = DefaultTimeoutDuration * time.Second ) // FilterOptions - @@ -47,6 +49,9 @@ type HostListItem struct { } func cmdLs(c CommandLine, api libmachine.API) error { + stateTimeoutDuration = time.Duration(c.Int("timeout")) * time.Second + log.Debugf("ls timeout set to %d seconds", stateTimeoutDuration/time.Second) + quiet := c.Bool("quiet") filters, err := parseFilters(c.StringSlice("filter")) if err != nil { diff --git a/docs/reference/ls.md b/docs/reference/ls.md index 113e4427c1..e8cf87dfdf 100644 --- a/docs/reference/ls.md +++ b/docs/reference/ls.md @@ -16,8 +16,21 @@ parent="smn_machine_subcmds" Options: - --quiet, -q Enable quiet mode + --quiet, -q Enable quiet mode --filter [--filter option --filter option] Filter output based on conditions provided + --timeout, -t Timeout in seconds, default to 10s + +## Timeout + +The `ls` command tries to reach each host in parallel. If a given host does not answer in less than 10 seconds, the `ls` command +will state that this host is in `timeout`. In some circumstances (poor connection, high load or while troubleshooting) you may want to +increase or decrease this value. You can use the `-t` flag for this purpose with a numerical value in seconds. + +### Example + + $ docker-machine ls -t 12 + NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS + default - virtualbox Running tcp://192.168.99.100:2376 v1.9.0 ## Filtering