-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
154 lines (143 loc) · 3.49 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package main
import (
"os"
// "fmt"
"path"
"text/template"
"github.com/codegangsta/cli"
)
type ospfconfig struct {
Password string
Interface string
RouterId string
HomeNet string
// PortalNet string
ContainerNet string
}
type zebraconfig struct {
Password string
PortalNet string
PortalGw string
}
const zebraTemplate = `password {{.Password}}
log stdout
ip route {{.PortalNet}} {{.PortalGw}}
`
const ospfdTemplate = `
password {{.Password}}
enable password {{.Password}}
log stdout
interface {{.Interface}}
ip ospf authentication-key {{.Password}}
router ospf
ospf router-id {{.RouterId}}
log-adjacency-changes detail
default-information originate
redistribute static
network {{.HomeNet}} area 0.0.0.0
network {{.ContainerNet}} area 0.0.0.0
`
func check(e error) {
if e != nil {
panic(e)
}
}
func main() {
app := cli.NewApp()
app.Version = "0.0.4"
app.Flags = []cli.Flag {
cli.StringFlag{
Name: "output",
Value: "/etc/quagga",
Usage: "Directory to output config to",
EnvVar: "K8S_QUAGGA_OUTPUT",
},
cli.StringFlag{
Name: "password",
Value: "changeme",
Usage: "Password for authorization",
EnvVar: "K8S_QUAGGA_PASSWORD",
},
}
app.Commands = []cli.Command{
{
Name: "ospfd",
Usage: "output ospfd config",
Flags: []cli.Flag {
cli.StringFlag{
Name: "Interface",
Value: "eth0",
Usage: "The interface to announce on",
},
cli.StringFlag{
Name: "RouterId",
Value: "10.0.0.1",
Usage: "Router ID to announce",
},
cli.StringFlag{
Name: "ContainerNet",
Value: "10.2.0.0/24",
Usage: "Container Network CIDR",
},
// cli.StringFlag{
// Name: "PortalNet",
// Value: "10.2.0.0/24",
// Usage: "Portal Network CIDR",
// },
cli.StringFlag{
Name: "HomeNet",
Value: "10.0.1.0/24",
Usage: "Home Network CIDR",
},
},
Action: func(c *cli.Context) {
config := ospfconfig{
Password: c.GlobalString("password"),
Interface: c.String("Interface"),
RouterId: c.String("RouterId"),
HomeNet: c.String("HomeNet"),
// PortalNet: c.String("PortalNet"),
ContainerNet: c.String("ContainerNet"),
}
f, err := os.Create(path.Join(c.GlobalString("output"), "ospfd.conf"))
check(err)
defer f.Close()
t, err := template.New("config").Parse(ospfdTemplate)
check(err)
err = t.Execute(f, config)
check(err)
},
},
{
Name: "zebra",
Usage: "output zebra config",
Flags: []cli.Flag {
cli.StringFlag{
Name: "PortalNet",
Value: "10.2.0.0/24",
Usage: "Portal Network CIDR",
},
cli.StringFlag{
Name: "PortalGw",
Value: "10.0.1.4",
Usage: "Portal Network Gateway",
},
},
Action: func(c *cli.Context) {
config := zebraconfig{
Password: c.GlobalString("password"),
PortalNet: c.String("PortalNet"),
PortalGw: c.String("PortalGw"),
}
f, err := os.Create(path.Join(c.GlobalString("output"), "zebra.conf"))
check(err)
defer f.Close()
t, err := template.New("config").Parse(zebraTemplate)
check(err)
err = t.Execute(f, config)
check(err)
},
},
}
app.Run(os.Args)
}