Skip to content

Commit

Permalink
Show input panels based on VIP method
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Sim <[email protected]>
  • Loading branch information
ihcsim authored and bk201 committed Dec 23, 2024
1 parent 8ef99dd commit 3e5a113
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
3 changes: 2 additions & 1 deletion pkg/console/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const (
askVipMethodPanel = "askVipMethodPanel"
vipPanel = "vipPanel"
vipHwAddrPanel = "vipHwAddrPanel"
vipHwAddrNotePanel = "vipHwAddrNotePanel"
vipTextPanel = "vipTextPanel"
ntpServersPanel = "ntpServersPanel"
askRolePanel = "askRolePanel"
Expand All @@ -70,7 +71,7 @@ const (

vipTitle = "Configure VIP"
vipLabel = "VIP"
vipHwAddrLabel = "Hardware Address"
vipHwAddrLabel = "MAC Address"
askVipMethodLabel = "VIP Mode"

clusterNetworkTitle = "Configure cluster network"
Expand Down
30 changes: 21 additions & 9 deletions pkg/console/install_panels.go
Original file line number Diff line number Diff line change
Expand Up @@ -1175,7 +1175,7 @@ func addTokenPanel(c *Console) error {
closeThisPage()
if c.config.Install.Mode == config.ModeCreate {
g.Cursor = false
return showNext(c, vipTextPanel, vipHwAddrPanel, vipPanel, askVipMethodPanel)
return showNext(c, vipTextPanel, askVipMethodPanel)
}
return showNext(c, serverURLPanel)
},
Expand Down Expand Up @@ -2492,12 +2492,14 @@ func addVIPPanel(c *Console) error {
if err != nil {
return err
}
hwAddrNoteV := widgets.NewPanel(c.Gui, vipHwAddrNotePanel)
vipTextV := widgets.NewPanel(c.Gui, vipTextPanel)

closeThisPage := func() {
c.CloseElements(
askVipMethodPanel,
vipHwAddrPanel,
vipHwAddrNotePanel,
vipPanel,
vipTextPanel)
}
Expand Down Expand Up @@ -2584,31 +2586,36 @@ func addVIPPanel(c *Console) error {
gotoAskVipMethodPanel := func(_ *gocui.Gui, _ *gocui.View) error {
return showNext(c, askVipMethodPanel)
}
gotoNextPanel := func(_ *gocui.Gui, _ *gocui.View) error {
confirmAskVipMethod := func(_ *gocui.Gui, _ *gocui.View) error {
method, err := askVipMethodV.GetData()
if err != nil {
return err
}
if method == config.NetworkMethodDHCP {
return showNext(c, vipHwAddrPanel)
hwAddrNoteV.SetContent("Note: If DHCP MAC/IP address binding is configured on the DHCP server, enter the MAC address to fetch the static VIP. Otherwise, leave it blank.")
return showNext(c, vipPanel, vipHwAddrNotePanel, vipHwAddrPanel)
}

hwAddrV.Close()
hwAddrNoteV.Close()
return showNext(c, vipPanel)
}
gotoPrevPanel := func(_ *gocui.Gui, _ *gocui.View) error {
gotoVipParentPanel := func(_ *gocui.Gui, _ *gocui.View) error {
method, err := askVipMethodV.GetData()
if err != nil {
return err
}
if method == config.NetworkMethodDHCP {
return showNext(c, vipHwAddrPanel)
if err := showNext(c, vipHwAddrPanel); err != nil {
return err
}
return hwAddrV.SetData(c.config.VipHwAddr)
}
return showNext(c, askVipMethodPanel)
}
askVipMethodV.KeyBindings = map[gocui.Key]func(*gocui.Gui, *gocui.View) error{
gocui.KeyArrowDown: gotoNextPanel,
gocui.KeyEnter: gotoNextPanel,
gocui.KeyArrowDown: confirmAskVipMethod,
gocui.KeyEnter: confirmAskVipMethod,
gocui.KeyEsc: gotoPrevPage,
}
hwAddrV.KeyBindings = map[gocui.Key]func(*gocui.Gui, *gocui.View) error{
Expand All @@ -2618,7 +2625,7 @@ func addVIPPanel(c *Console) error {
gocui.KeyEsc: gotoPrevPage,
}
vipV.KeyBindings = map[gocui.Key]func(*gocui.Gui, *gocui.View) error{
gocui.KeyArrowUp: gotoPrevPanel,
gocui.KeyArrowUp: gotoVipParentPanel,
gocui.KeyArrowDown: gotoVerifyIP,
gocui.KeyEnter: gotoVerifyIP,
gocui.KeyEsc: gotoPrevPage,
Expand All @@ -2639,6 +2646,11 @@ func addVIPPanel(c *Console) error {
setLocation(vipV, 3)
c.AddElement(vipPanel, vipV)

hwAddrNoteV.Focus = false
hwAddrNoteV.Wrap = true
setLocation(hwAddrNoteV, 3)
c.AddElement(vipHwAddrNotePanel, hwAddrNoteV)

vipTextV.FgColor = gocui.ColorRed
vipTextV.Focus = false
vipTextV.Wrap = true
Expand Down Expand Up @@ -2789,7 +2801,7 @@ func addDNSServersPanel(c *Console) error {
gotoNextPage := func() error {
closeThisPage()
if c.config.Install.Mode == config.ModeCreate {
return showNext(c, vipTextPanel, vipHwAddrPanel, vipPanel, askVipMethodPanel)
return showNext(c, vipTextPanel, askVipMethodPanel)
}
return showNext(c, serverURLPanel)
}
Expand Down

0 comments on commit 3e5a113

Please sign in to comment.