Docker-DCO-1.1-Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com> (github: unclejack)
| ... | ... |
@@ -3,6 +3,7 @@ package main |
| 3 | 3 |
import ( |
| 4 | 4 |
"fmt" |
| 5 | 5 |
"os/exec" |
| 6 |
+ "strconv" |
|
| 6 | 7 |
"strings" |
| 7 | 8 |
"testing" |
| 8 | 9 |
) |
| ... | ... |
@@ -71,3 +72,28 @@ func findContainerIp(t *testing.T, id string) string {
|
| 71 | 71 |
|
| 72 | 72 |
return strings.Trim(out, " \r\n'") |
| 73 | 73 |
} |
| 74 |
+ |
|
| 75 |
+func getContainerCount() (int, error) {
|
|
| 76 |
+ const containers = "Containers:" |
|
| 77 |
+ |
|
| 78 |
+ cmd := exec.Command(dockerBinary, "info") |
|
| 79 |
+ out, _, err := runCommandWithOutput(cmd) |
|
| 80 |
+ if err != nil {
|
|
| 81 |
+ return 0, err |
|
| 82 |
+ } |
|
| 83 |
+ |
|
| 84 |
+ lines := strings.Split(out, "\n") |
|
| 85 |
+ for _, line := range lines {
|
|
| 86 |
+ if strings.Contains(line, containers) {
|
|
| 87 |
+ output := stripTrailingCharacters(line) |
|
| 88 |
+ output = strings.TrimLeft(output, containers) |
|
| 89 |
+ output = strings.Trim(output, " ") |
|
| 90 |
+ containerCount, err := strconv.Atoi(output) |
|
| 91 |
+ if err != nil {
|
|
| 92 |
+ return 0, err |
|
| 93 |
+ } |
|
| 94 |
+ return containerCount, nil |
|
| 95 |
+ } |
|
| 96 |
+ } |
|
| 97 |
+ return 0, fmt.Errorf("couldn't find the Container count in the output")
|
|
| 98 |
+} |