forked from seatgeek/nomad-helper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
99 lines (87 loc) · 1.99 KB
/
main.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
package main
import (
"os"
"sort"
"fmt"
log "github.com/Sirupsen/logrus"
cli "gopkg.in/urfave/cli.v1"
)
// JobState ...
type JobState map[string]int
// NomadState ...
type NomadState struct {
Info map[string]string
Jobs map[string]TaskGroupState
}
// TaskGroupState ...
type TaskGroupState map[string]int
func main() {
app := cli.NewApp()
app.Name = "nomad-scale-helper"
app.Usage = "easily restore / snapshot your nomad job scale config"
app.Version = "0.1"
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "log-level",
Value: "info",
Usage: "Debug level (debug, info, warn/warning, error, fatal, panic)",
EnvVar: "LOG_LEVEL",
},
}
app.Commands = []cli.Command{
{
Name: "scale-export",
Usage: "Export nomad job scale config to a local file",
Action: func(c *cli.Context) error {
configFile := c.Args().Get(0)
if configFile == "" {
return fmt.Errorf("Missing file name")
}
return exportCommand(configFile)
},
},
{
Name: "scale-import",
Usage: "Import nomad job scale config from a local file to Nomad cluster",
Action: func(c *cli.Context) error {
configFile := c.Args().Get(0)
if configFile == "" {
return fmt.Errorf("Missing file name")
}
return importCommand(configFile)
},
},
{
Name: "drain",
Usage: "Drain node and wait for all allocations to stop",
Action: func(c *cli.Context) error {
return drainCommand()
},
},
{
Name: "reevaluate-all",
Usage: "Force re-evaluate all jobs",
Action: func(c *cli.Context) error {
return reevaluateCommand()
},
},
{
Name: "gc",
Usage: "Force a cluster GC",
Action: func(c *cli.Context) error {
return gcCommand()
},
},
}
app.Before = func(c *cli.Context) error {
// convert the human passed log level into logrus levels
level, err := log.ParseLevel(c.String("log-level"))
if err != nil {
log.Fatal(err)
}
log.SetLevel(level)
return nil
}
sort.Sort(cli.FlagsByName(app.Flags))
app.Run(os.Args)
}