-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmarathon-cli.go
129 lines (122 loc) · 2.58 KB
/
marathon-cli.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package main
import (
log "github.com/Sirupsen/logrus"
"github.com/codegangsta/cli"
"os"
)
const (
VERSION = "0.1.0"
AUTHOR = "Steven Borrelli"
EMAIL = "[email protected]"
)
func run_cli() {
app := cli.NewApp()
app.Name = "marathon-cli"
app.Usage = "Mange marathon apps and groups"
app.Version = VERSION
app.Author = AUTHOR
app.Email = EMAIL
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "host",
Value: "localhost:8080",
Usage: "Marathon host (default localhost:8080)",
EnvVar: "MARATHON_HOST",
},
cli.StringFlag{
Name: "format",
Value: "json",
Usage: "Output format (json)",
},
}
app.Commands = []cli.Command{
{
Name: "ping",
Usage: "Test Marathon connection",
Action: func(c *cli.Context) {
_, _ = Ping(c.GlobalString("host"))
},
}, {
Name: "info",
Usage: "Gets information about the Marathon cluster",
Action: func(c *cli.Context) {
r, _ := Info(c.GlobalString("host"))
Output(c.GlobalString("format"), r)
},
},
{
Name: "leader",
Usage: "Gets the current leader",
Action: func(c *cli.Context) {
r, _ := Leader(c.GlobalString("host"))
Output(c.GlobalString("format"), r)
},
},
{
Name: "rmleader",
Usage: "Forces current leader to abdicate",
Action: func(c *cli.Context) {
r, _ := DeleteLeader(c.GlobalString("host"))
Output(c.GlobalString("format"), r)
},
},
{
Name: "app",
Usage: "Launches a new app",
Flags: []cli.Flag{
cli.StringFlag{
Name: "file, f",
Usage: "json App config file",
},
},
Action: func(c *cli.Context) {
if c.String("file") == "" {
log.Fatal("Please provide a --file")
}
r, err := MkApp(c)
if err == nil {
Output(c.GlobalString("format"), r)
}
},
},
{
Name: "lsapp",
Usage: "List all apps, or list a single <appId> ",
Action: func(c *cli.Context) {
r, _ := LsApps(c)
Output(c.GlobalString("format"), r)
},
},
{
Name: "rmapp",
Usage: "Deletes app <appId>",
Action: func(c *cli.Context) {
_, _ = RmApp(c)
},
},
{
Name: "lstask",
Usage: "List all running tasks in the cluster",
Action: func(c *cli.Context) {
r, err := LsTask(c)
if err == nil {
Output(c.GlobalString("format"), r)
}
},
},
{
Name: "killAppTasks",
Usage: "Kill all the tasks for app <app Id>.\nTo kill <appID> tasks on one host use, --onhost <hostname>.",
Action: func(c *cli.Context) {
r, err := KillAppTasks(c)
if err == nil {
Output(c.GlobalString("format"), r)
}
},
},
}
app.Run(os.Args)
}
func main() {
run_cli()
}