Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Network defaults #164

Merged
merged 5 commits into from
Nov 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions clab/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ var srlTypes = map[string]string{
// it is provided via docker network object
type mgmtNet struct {
Network string `yaml:"network,omitempty"` // docker network name
Ipv4Subnet string `yaml:"ipv4_subnet,omitempty"`
Ipv6Subnet string `yaml:"ipv6_subnet,omitempty"`
IPv4Subnet string `yaml:"ipv4_subnet,omitempty"`
IPv6Subnet string `yaml:"ipv6_subnet,omitempty"`
}

// NodeConfig represents a configuration a given node can have in the lab definition file
Expand All @@ -52,8 +52,8 @@ type NodeConfig struct {
License string `yaml:"license,omitempty"`
Position string `yaml:"position,omitempty"`
Cmd string `yaml:"cmd,omitempty"`
Binds []string `yaml:"binds,omitempty" json:"binds,omitempty"` // list of bind mount compatible strings
Ports []string `yaml:"ports,omitempty"` // list of port bindings
Binds []string `yaml:"binds,omitempty"` // list of bind mount compatible strings
Ports []string `yaml:"ports,omitempty"` // list of port bindings
}

// Topology represents a lab topology
Expand Down Expand Up @@ -121,15 +121,16 @@ type Endpoint struct {

// ParseIPInfo parses IP information
func (c *cLab) parseIPInfo() error {
// DockerInfo = t.DockerInfo
if c.Config.Mgmt.Network == "" {
c.Config.Mgmt.Network = dockerNetName
}
if c.Config.Mgmt.Ipv4Subnet == "" {
c.Config.Mgmt.Ipv4Subnet = dockerNetIPv4Addr
}
if c.Config.Mgmt.Ipv6Subnet == "" {
c.Config.Mgmt.Ipv6Subnet = dockerNetIPv6Addr
if c.Config.Mgmt.IPv4Subnet == "" && c.Config.Mgmt.IPv6Subnet == "" {
if c.Config.Mgmt.IPv4Subnet == "" {
c.Config.Mgmt.IPv4Subnet = dockerNetIPv4Addr
}
if c.Config.Mgmt.IPv6Subnet == "" {
c.Config.Mgmt.IPv6Subnet = dockerNetIPv6Addr
}
}
return nil
}
Expand Down
21 changes: 13 additions & 8 deletions clab/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,21 @@ const sysctlBase = "/proc/sys"
// CreateBridge creates a docker bridge
func (c *cLab) CreateBridge(ctx context.Context) (err error) {
log.Info("Creating docker bridge")
log.Debugf("Creating docker bridge: Name: %s, IPv4Subnet: '%s', IPv6Subnet: '%s", c.Config.Mgmt.Network, c.Config.Mgmt.IPv4Subnet, c.Config.Mgmt.IPv6Subnet)

ipamIPv4Config := network.IPAMConfig{
Subnet: c.Config.Mgmt.Ipv4Subnet,
enableIPv6 := false
var ipamConfig []network.IPAMConfig
if c.Config.Mgmt.IPv4Subnet != "" {
ipamConfig = append(ipamConfig, network.IPAMConfig{
Subnet: c.Config.Mgmt.IPv4Subnet,
})
}
ipamIPv6Config := network.IPAMConfig{
Subnet: c.Config.Mgmt.Ipv6Subnet,
if c.Config.Mgmt.IPv6Subnet != "" {
ipamConfig = append(ipamConfig, network.IPAMConfig{
Subnet: c.Config.Mgmt.IPv6Subnet,
})
enableIPv6 = true
}
var ipamConfig []network.IPAMConfig
ipamConfig = append(ipamConfig, ipamIPv4Config)
ipamConfig = append(ipamConfig, ipamIPv6Config)

ipam := &network.IPAM{
Driver: "default",
Expand All @@ -44,7 +49,7 @@ func (c *cLab) CreateBridge(ctx context.Context) (err error) {
CheckDuplicate: true,
Driver: "bridge",
//Scope: "local",
EnableIPv6: true,
EnableIPv6: enableIPv6,
IPAM: ipam,
Internal: false,
Attachable: false,
Expand Down
4 changes: 2 additions & 2 deletions cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,10 @@ func setFlags(conf *clab.Config) {
conf.Mgmt.Network = mgmtNetName
}
if mgmtIPv4Subnet.String() != "<nil>" {
conf.Mgmt.Ipv4Subnet = mgmtIPv4Subnet.String()
conf.Mgmt.IPv4Subnet = mgmtIPv4Subnet.String()
}
if mgmtIPv6Subnet.String() != "<nil>" {
conf.Mgmt.Ipv6Subnet = mgmtIPv6Subnet.String()
conf.Mgmt.IPv6Subnet = mgmtIPv6Subnet.String()
}
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@ func generateTopologyConfig(name, network, ipv4range, ipv6range string, images m
}
config.Mgmt.Network = network
if ipv4range != "<nil>" {
config.Mgmt.Ipv4Subnet = ipv4range
config.Mgmt.IPv4Subnet = ipv4range
}
if ipv6range != "<nil>" {
config.Mgmt.Ipv6Subnet = ipv6range
config.Mgmt.IPv6Subnet = ipv6range
}
for k, img := range images {
config.Topology.Kinds[k] = clab.NodeConfig{Image: img}
Expand Down
6 changes: 6 additions & 0 deletions cmd/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,16 @@ func getContainerIPv6(container types.Container, bridgeName string) string {
}
if bridgeName != "" {
if br, ok := container.NetworkSettings.Networks[bridgeName]; ok {
if br.GlobalIPv6Address == "" {
return "NA"
}
return fmt.Sprintf("%s/%d", br.GlobalIPv6Address, br.GlobalIPv6PrefixLen)
}
}
for _, br := range container.NetworkSettings.Networks {
if br.GlobalIPv6Address == "" {
return "NA"
}
return fmt.Sprintf("%s/%d", br.GlobalIPv6Address, br.GlobalIPv6PrefixLen)
}
return ""
Expand Down