Skip to content

Commit f26430f

Browse files
committed
Making gateway optional
1 parent 3e18586 commit f26430f

File tree

9 files changed

+22
-48
lines changed

9 files changed

+22
-48
lines changed

Godeps/Godeps.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Godeps/_workspace/src/github.com/contiv/contivmodel/app.json

-30
This file was deleted.

Godeps/_workspace/src/github.com/contiv/contivmodel/contivModel.go

-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Godeps/_workspace/src/github.com/contiv/contivmodel/network.json

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Godeps/_workspace/src/github.com/contiv/objmodel/contivModel/contivModel.go

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

netctl/commands.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ var Commands = []cli.Command{
118118
},
119119
cli.StringFlag{
120120
Name: "gateway, g",
121-
Usage: "Gateway - REQUIRED",
121+
Usage: "Gateway",
122122
},
123123
},
124124
Action: createNetwork,

netctl/netctl.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,13 @@ func createNetwork(ctx *cli.Context) {
251251
subnet := ctx.String("subnet")
252252
gateway := ctx.String("gateway")
253253

254-
if subnet == "" || gateway == "" {
255-
errExit(ctx, exitHelp, "Subnet and gateway are required", true)
254+
if subnet == "" {
255+
errExit(ctx, exitHelp, "Subnet is required", true)
256+
}
257+
if gateway != "" {
258+
if ok := net.ParseIP(gateway); ok == nil {
259+
errExit(ctx, exitHelp, "Invalid gateway - Enter in A.B.C.D format", true)
260+
}
256261
}
257262

258263
tenant := ctx.String("tenant")

netmaster/master/network.go

100644100755
+9-7
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ func CreateNetwork(network intent.ConfigNetwork, stateDriver core.StateDriver, t
103103
PktTagType: network.PktTagType,
104104
SubnetIP: subnetIP,
105105
SubnetLen: subnetLen,
106-
Gateway: network.Gateway,
107106
}
108107

109108
nwCfg.ID = networkID
@@ -126,13 +125,16 @@ func CreateNetwork(network intent.ConfigNetwork, stateDriver core.StateDriver, t
126125
nwCfg.ExtPktTag = int(extPktTag)
127126
nwCfg.PktTag = int(pktTag)
128127

129-
// Reserve gateway IP address
130-
ipAddrValue, err := netutils.GetIPNumber(nwCfg.SubnetIP, nwCfg.SubnetLen, 32, nwCfg.Gateway)
131-
if err != nil {
132-
log.Errorf("Error parsing gateway address %s. Err: %v", nwCfg.Gateway, err)
133-
return err
128+
if network.Gateway != "" {
129+
nwCfg.Gateway = network.Gateway
130+
// Reserve gateway IP address if gateway is specified
131+
ipAddrValue, err := netutils.GetIPNumber(nwCfg.SubnetIP, nwCfg.SubnetLen, 32, nwCfg.Gateway)
132+
if err != nil {
133+
log.Errorf("Error parsing gateway address %s. Err: %v", nwCfg.Gateway, err)
134+
return err
135+
}
136+
nwCfg.IPAllocMap.Set(ipAddrValue)
134137
}
135-
nwCfg.IPAllocMap.Set(ipAddrValue)
136138

137139
netutils.InitSubnetBitset(&nwCfg.IPAllocMap, nwCfg.SubnetLen)
138140
err = nwCfg.Write()

systemtests/network_test.go

100644100755
+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/Sirupsen/logrus"
77
"github.com/contiv/contivmodel/client"
88
. "gopkg.in/check.v1"
9+
"sync"
910
)
1011

1112
func (s *systemtestSuite) TestNetworkAddDeleteVXLAN(c *C) {
@@ -99,6 +100,7 @@ func (s *systemtestSuite) TestNetworkAddDeleteTenantVLAN(c *C) {
99100
}
100101

101102
func (s *systemtestSuite) testNetworkAddDeleteTenant(c *C, encap string) {
103+
mutex := sync.Mutex{}
102104
for i := 0; i < s.iterations; i++ {
103105
var (
104106
tenantNames = map[string][]string{}
@@ -141,7 +143,9 @@ func (s *systemtestSuite) testNetworkAddDeleteTenant(c *C, encap string) {
141143
for _, network := range networks {
142144
go func(network, tenant string, containers map[string][]*container) {
143145
var err error
146+
mutex.Lock()
144147
containers[network], err = s.runContainers(numContainer, false, fmt.Sprintf("%s/%s", network, tenant), nil)
148+
mutex.Unlock()
145149
endChan <- err
146150
endChan <- s.pingTest(containers[network])
147151
}(network, tenant, containers)

0 commit comments

Comments
 (0)