-
Notifications
You must be signed in to change notification settings - Fork 1
/
stop.go
52 lines (41 loc) · 1.12 KB
/
stop.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package commands
import (
"context"
"fmt"
"path"
cli "github.com/urfave/cli"
"github.com/ipsn/go-ipfs/gxlibs/github.com/ipfs/iptb/testbed"
"github.com/ipsn/go-ipfs/gxlibs/github.com/ipfs/iptb/testbed/interfaces"
)
var StopCmd = cli.Command{
Category: "CORE",
Name: "stop",
Usage: "stop specified nodes (or all)",
ArgsUsage: "[nodes]",
Action: func(c *cli.Context) error {
flagRoot := c.GlobalString("IPTB_ROOT")
flagTestbed := c.GlobalString("testbed")
flagQuiet := c.GlobalBool("quiet")
tb := testbed.NewTestbed(path.Join(flagRoot, "testbeds", flagTestbed))
nodes, err := tb.Nodes()
if err != nil {
return err
}
nodeRange := c.Args().First()
if nodeRange == "" {
nodeRange = fmt.Sprintf("[0-%d]", len(nodes)-1)
}
list, err := parseRange(nodeRange)
if err != nil {
return fmt.Errorf("could not parse node range %s", nodeRange)
}
runCmd := func(node testbedi.Core) (testbedi.Output, error) {
return nil, node.Stop(context.Background())
}
results, err := mapWithOutput(list, nodes, runCmd)
if err != nil {
return err
}
return buildReport(results, flagQuiet)
},
}