forked from docker-archive/classicswarm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
123 lines (110 loc) · 2.59 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package main
import (
"fmt"
"os"
"path"
log "github.com/Sirupsen/logrus"
"github.com/codegangsta/cli"
"github.com/docker/swarm/discovery"
_ "github.com/docker/swarm/discovery/consul"
_ "github.com/docker/swarm/discovery/etcd"
_ "github.com/docker/swarm/discovery/file"
_ "github.com/docker/swarm/discovery/nodes"
"github.com/docker/swarm/discovery/token"
_ "github.com/docker/swarm/discovery/zookeeper"
)
func main() {
app := cli.NewApp()
app.Name = path.Base(os.Args[0])
app.Usage = "a Docker-native clustering system"
app.Version = "0.1.0"
app.Author = ""
app.Email = ""
app.Flags = []cli.Flag{
cli.BoolFlag{
Name: "debug",
Usage: "debug mode",
EnvVar: "DEBUG",
},
cli.StringFlag{
Name: "log-level, l",
Value: "info",
Usage: fmt.Sprintf("Log level (options: debug, info, warn, error, fatal, panic)"),
},
}
// logs
app.Before = func(c *cli.Context) error {
log.SetOutput(os.Stderr)
level, err := log.ParseLevel(c.String("log-level"))
if err != nil {
log.Fatalf(err.Error())
}
log.SetLevel(level)
// If a log level wasn't specified and we are running in debug mode,
// enforce log-level=debug.
if !c.IsSet("log-level") && !c.IsSet("l") && c.Bool("debug") {
log.SetLevel(log.DebugLevel)
}
return nil
}
app.Commands = []cli.Command{
{
Name: "create",
ShortName: "c",
Usage: "create a cluster",
Action: func(c *cli.Context) {
discovery := &token.TokenDiscoveryService{}
discovery.Initialize("", 0)
token, err := discovery.CreateCluster()
if err != nil {
log.Fatal(err)
}
fmt.Println(token)
},
},
{
Name: "list",
ShortName: "l",
Usage: "list nodes in a cluster",
Action: func(c *cli.Context) {
dflag := getDiscovery(c)
if dflag == "" {
log.Fatalf("discovery required to list a cluster. See '%s list --help'.", c.App.Name)
}
d, err := discovery.New(dflag, 0)
if err != nil {
log.Fatal(err)
}
nodes, err := d.Fetch()
if err != nil {
log.Fatal(err)
}
for _, node := range nodes {
fmt.Println(node)
}
},
},
{
Name: "manage",
ShortName: "m",
Usage: "manage a docker cluster",
Flags: []cli.Flag{
flStore,
flStrategy, flFilter,
flHosts, flHeartBeat, flOverCommit,
flTls, flTlsCaCert, flTlsCert, flTlsKey, flTlsVerify,
flEnableCors},
Action: manage,
},
{
Name: "join",
ShortName: "j",
Usage: "join a docker cluster",
Flags: []cli.Flag{flAddr, flHeartBeat},
Action: join,
},
}
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}