Skip to content
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
39 changes: 18 additions & 21 deletions microcloud/cmd/microcloud/ask.go
Original file line number Diff line number Diff line change
Expand Up @@ -696,8 +696,8 @@ func (c *CmdControl) askNetwork(sh *service.Handler, systems map[string]InitSyst
fmt.Println("")

// Prepare the configuration.
var dnsAddresses string
ipConfig := map[string]string{}
dnsConfig := map[string]string{}
if bootstrap {
for _, ip := range []string{"IPv4", "IPv6"} {
validator := func(s string) error {
Expand Down Expand Up @@ -740,25 +740,27 @@ func (c *CmdControl) askNetwork(sh *service.Handler, systems map[string]InitSyst
}

ipConfig[gateway] = fmt.Sprintf("%s-%s", rangeStart, rangeEnd)

gatewayAddr, _, err := net.ParseCIDR(gateway)
if err != nil {
return err
}

dnsAddresses, err := c.asker.AskString(fmt.Sprintf("Specify the DNS addresses (comma-separated IPv4 / IPv6 addresses) for the distributed network (default: %s): ", gatewayAddr.String()), gatewayAddr.String(), validate.Optional(validate.IsListOf(validate.IsNetworkAddress)))
if err != nil {
return err
}

if dnsAddresses != "" {
dnsConfig[gateway] = dnsAddresses
}
} else {
ipConfig[gateway] = ""
}
}
}

gateways := []string{}
for gateway := range ipConfig {
gatewayAddr, _, err := net.ParseCIDR(gateway)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you run net.ParseCIDR here? Is it for the purpose of validating that the gateway is valid? I think the validation is already done in the step before when invoking AskString.

Below you again get the string from the net.IP and append it to the list of gateways. So could you just take the gateway from the map and append it to the list?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, you want to extract the IP only without the subnetmask.

if err != nil {
return err
}

gateways = append(gateways, gatewayAddr.String())
}

gatewayAddrs := strings.Join(gateways, ",")
dnsAddresses, err = c.asker.AskString(fmt.Sprintf("Specify the DNS addresses (comma-separated IPv4 / IPv6 addresses) for the distributed network (default: %s): ", gatewayAddrs), gatewayAddrs, validate.Optional(validate.IsListOf(validate.IsNetworkAddress)))
if err != nil {
return err
}
}

// If interfaces were selected for OVN, remove the FAN config.
Expand Down Expand Up @@ -807,12 +809,7 @@ func (c *CmdControl) askNetwork(sh *service.Handler, systems map[string]InitSyst
}
}

var allDNSServers string
for _, dnsAddr := range dnsConfig {
allDNSServers = dnsAddr
}

uplink, ovn := lxd.DefaultOVNNetwork(ipv4Gateway, ipv4Ranges, ipv6Gateway, allDNSServers)
uplink, ovn := lxd.DefaultOVNNetwork(ipv4Gateway, ipv4Ranges, ipv6Gateway, dnsAddresses)
bootstrapSystem.Networks = []api.NetworksPost{uplink, ovn}
systems[sh.Name] = bootstrapSystem
}
Expand Down
2 changes: 1 addition & 1 deletion microcloud/test/includes/microcloud.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ $([ "${SETUP_OVN}" = "yes" ] && printf -- "---")
${IPV4_SUBNET} # setup ipv4/ipv6 gateways and ranges
${IPV4_START}
${IPV4_END}
${CUSTOM_DNS_ADDRESSES}
${IPV6_SUBNET}
${CUSTOM_DNS_ADDRESSES}
EOF
)
fi
Expand Down