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
52 changes: 28 additions & 24 deletions cmd/microcloud/ask.go
Original file line number Diff line number Diff line change
Expand Up @@ -1042,47 +1042,51 @@ func (c *initConfig) askOVNNetwork(sh *service.Handler) error {
return nil
}

msg := fmt.Sprintf("Specify the %s gateway (CIDR) on the uplink network (empty to skip %s)", ip, ip)
msg := fmt.Sprintf("Specify the %s gateway (CIDR) on the uplink network", ip)
gateway, err := c.asker.AskString(msg, "", validator)
if err != nil {
return err
}

if gateway != "" {
if ip == "IPv4" {
rangeStart, err := c.asker.AskString(fmt.Sprintf("Specify the first %s address in the range to use on the uplink network", ip), "", validate.Required(validate.IsNetworkAddressV4))
if err != nil {
return err
}

rangeEnd, err := c.asker.AskString(fmt.Sprintf("Specify the last %s address in the range to use on the uplink network", ip), "", validate.Required(validate.IsNetworkAddressV4))
if err != nil {
return err
}
if gateway == "" {
continue
}

ipConfig[gateway] = fmt.Sprintf("%s-%s", rangeStart, rangeEnd)
} else {
ipConfig[gateway] = ""
if ip == "IPv4" {
rangeStart, err := c.asker.AskString(fmt.Sprintf("Specify the first %s address in the range to use on the uplink network", ip), "", validate.Required(validate.IsNetworkAddressV4))
if err != nil {
return err
}
}
}

if len(ipConfig) > 0 {
gateways := []string{}
for gateway := range ipConfig {
gatewayAddr, _, err := net.ParseCIDR(gateway)
rangeEnd, err := c.asker.AskString(fmt.Sprintf("Specify the last %s address in the range to use on the uplink network", ip), "", validate.Required(validate.IsNetworkAddressV4))
if err != nil {
return err
}

gateways = append(gateways, gatewayAddr.String())
ipConfig[gateway] = fmt.Sprintf("%s-%s", rangeStart, rangeEnd)
} else {
ipConfig[gateway] = ""
}
}

if len(ipConfig) == 0 {
return errors.New("Either the IPv4 or IPv6 gateway has to be set on the uplink network")
}

gatewayAddrs := strings.Join(gateways, ",")
dnsAddresses, err = c.asker.AskString("Specify the DNS addresses (comma-separated IPv4 / IPv6 addresses) for the distributed network", gatewayAddrs, validate.Optional(validate.IsListOf(validate.IsNetworkAddress)))
gateways := []string{}
for gateway := range ipConfig {
gatewayAddr, _, err := net.ParseCIDR(gateway)
if err != nil {
return err
}

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

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

Expand Down
4 changes: 4 additions & 0 deletions cmd/microcloud/preseed.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,10 @@ func (p *Preseed) validate(name string, bootstrap bool) error {

if system.UplinkInterface != "" {
uplinkCount++

if p.OVN.IPv4Gateway == "" && p.OVN.IPv6Gateway == "" && bootstrap {
return errors.New("Either the IPv4 or IPv6 gateway has to be set on the uplink network")
}
}

if system.UnderlayIP != "" {
Expand Down
16 changes: 12 additions & 4 deletions cmd/tui/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@ import (
var ContextError error = tea.ErrProgramKilled

// InvalidInputError is used to indicate false input to an asked question.
var InvalidInputError func() = func() { PrintError("Invalid input, try again") }
var InvalidInputError func(err error) = func(err error) {
errorMsg := "Invalid input, try again"

if err != nil {
PrintError(fmt.Sprintf("%s: %s", errorMsg, err.Error()))
} else {
PrintError(errorMsg)
}
}

// InputHandler handles input dialogs.
type InputHandler struct {
Expand Down Expand Up @@ -121,7 +129,7 @@ func (i *InputHandler) AskBool(question string, defaultAnswer bool) (bool, error
return false, nil
}

InvalidInputError()
InvalidInputError(nil)
}
}

Expand All @@ -145,7 +153,7 @@ func (i *InputHandler) AskString(question string, defaultAnswer string, validato
if validator != nil {
err = validator(answer)
if err != nil {
InvalidInputError()
InvalidInputError(err)
continue
}

Expand All @@ -156,6 +164,6 @@ func (i *InputHandler) AskString(question string, defaultAnswer string, validato
return answer, err
}

InvalidInputError()
InvalidInputError(nil)
}
}
4 changes: 4 additions & 0 deletions test/suites/instances.sh
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ systems:
local:
path: /dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_lxd_disk1
wipe: true
ovn:
ipv4_gateway: 10.1.123.1/24
ipv4_range: 10.1.123.100-10.1.123.254
ipv6_gateway: fd42:1:1234:1234::1/64
EOF
)"

Expand Down
Loading