Fix network view for setting default route
- Spec calls for a list of gateway ips followed by a list of interfaces which are associated to be displayed - Use updated model.set_default_gateway() method - Add Default gateway status message to Network View - Ensure that manually assigned gateways are displayed in the set default route view by extracting the 'gateway' value from the subnets in the Networkdev object. Signed-off-by: Ryan Harper <ryan.harper@canonical.com>
This commit is contained in:
parent
5298092d15
commit
1ab56772b4
|
@ -127,7 +127,7 @@ class Networkdev():
|
||||||
[static_sn] = static_sn
|
[static_sn] = static_sn
|
||||||
ip = static_sn.get('address')
|
ip = static_sn.get('address')
|
||||||
ip_method = 'manual'
|
ip_method = 'manual'
|
||||||
ip_provider = 'local config'
|
ip_provider = static_sn.get('gateway', 'local config')
|
||||||
else:
|
else:
|
||||||
log.debug('no subnet entry')
|
log.debug('no subnet entry')
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,7 @@ class NetworkView(ViewPolicy):
|
||||||
Padding.line_break(""),
|
Padding.line_break(""),
|
||||||
Padding.center_15(self._build_buttons()),
|
Padding.center_15(self._build_buttons()),
|
||||||
]
|
]
|
||||||
|
# FIXME determine which UX widget should have focus
|
||||||
super().__init__(ListBox(self.body))
|
super().__init__(ListBox(self.body))
|
||||||
|
|
||||||
def _build_buttons(self):
|
def _build_buttons(self):
|
||||||
|
@ -122,7 +123,24 @@ class NetworkView(ViewPolicy):
|
||||||
|
|
||||||
def _build_additional_options(self):
|
def _build_additional_options(self):
|
||||||
opts = []
|
opts = []
|
||||||
|
ifaces = self.model.get_all_interface_names()
|
||||||
|
|
||||||
|
# Display default route status
|
||||||
|
if len(ifaces) > 0:
|
||||||
|
default_route = ("Default route is ")
|
||||||
|
route_source = ("whatever DHCP provides on any interface")
|
||||||
|
if self.model.default_gateway is not None:
|
||||||
|
route_source = self.model.default_gateway
|
||||||
|
default_route_w = Color.info_minor(
|
||||||
|
Text(" " + default_route + route_source))
|
||||||
|
opts.append(default_route_w)
|
||||||
|
|
||||||
for opt, sig, _ in self.model.get_menu():
|
for opt, sig, _ in self.model.get_menu():
|
||||||
|
if ':set-default-route' in sig:
|
||||||
|
if len(ifaces) < 2:
|
||||||
|
log.debug('Skipping default route menu option'
|
||||||
|
' (only one nic)')
|
||||||
|
continue
|
||||||
opts.append(
|
opts.append(
|
||||||
Color.menu_button(
|
Color.menu_button(
|
||||||
menu_btn(label=opt,
|
menu_btn(label=opt,
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
from urwid import Text, Pile, ListBox
|
from urwid import Text, Pile, ListBox
|
||||||
from subiquity.view import ViewPolicy
|
from subiquity.view import ViewPolicy
|
||||||
from subiquity.ui.buttons import cancel_btn, done_btn
|
from subiquity.ui.buttons import cancel_btn, done_btn, menu_btn
|
||||||
from subiquity.ui.utils import Color, Padding
|
from subiquity.ui.utils import Color, Padding
|
||||||
from subiquity.ui.interactive import StringEditor
|
from subiquity.ui.interactive import StringEditor
|
||||||
import logging
|
import logging
|
||||||
|
@ -38,19 +38,43 @@ class NetworkSetDefaultRouteView(ViewPolicy):
|
||||||
super().__init__(ListBox(body))
|
super().__init__(ListBox(body))
|
||||||
|
|
||||||
def _build_default_routes(self):
|
def _build_default_routes(self):
|
||||||
ifaces = self.model.get_interfaces()
|
''' iterate through interfaces collecting
|
||||||
|
any uniq provider (aka, gateway) and
|
||||||
|
associate the interface name with the gateway
|
||||||
|
|
||||||
|
then generate a line per key in the gateway
|
||||||
|
dict and display the keys.
|
||||||
|
|
||||||
|
Upon selection of the gateway entry (ip)
|
||||||
|
then we set model.set_default_gateway(ip)
|
||||||
|
|
||||||
|
if manual is selected, then we update
|
||||||
|
the second entry into a IPAddressEditor
|
||||||
|
and accept the value, submitting it to
|
||||||
|
the model.
|
||||||
|
'''
|
||||||
|
providers = {}
|
||||||
|
for iface in self.model.get_all_interfaces():
|
||||||
|
gw = iface.ip_provider
|
||||||
|
if gw in providers:
|
||||||
|
providers[gw].append(iface.ifname)
|
||||||
|
else:
|
||||||
|
providers[gw] = [iface.ifname]
|
||||||
|
|
||||||
|
log.debug('gateway providers: {}'.format(providers))
|
||||||
items = []
|
items = []
|
||||||
for iface in ifaces:
|
for (gw, ifaces) in providers.items():
|
||||||
items.append(Padding.center_50(
|
items.append(Padding.center_79(
|
||||||
Color.menu_button(done_btn(
|
Color.menu_button(menu_btn(
|
||||||
label="{ip} ({iface})".format(
|
label="{gw} ({ifaces})".format(
|
||||||
ip="FIXME: needs default gateway",
|
gw=gw,
|
||||||
iface=iface),
|
ifaces=(",".join(ifaces))),
|
||||||
on_press=self.done),
|
on_press=self.done),
|
||||||
focus_map="menu_button focus")))
|
focus_map="menu_button focus")))
|
||||||
items.append(Padding.center_50(
|
|
||||||
|
items.append(Padding.center_79(
|
||||||
Color.menu_button(
|
Color.menu_button(
|
||||||
done_btn(label="Specify the default route manually",
|
menu_btn(label="Specify the default route manually",
|
||||||
on_press=self.show_edit_default_route),
|
on_press=self.show_edit_default_route),
|
||||||
focus_map="menu_button focus")))
|
focus_map="menu_button focus")))
|
||||||
self.pile = Pile(items)
|
self.pile = Pile(items)
|
||||||
|
@ -78,9 +102,18 @@ class NetworkSetDefaultRouteView(ViewPolicy):
|
||||||
|
|
||||||
def done(self, result):
|
def done(self, result):
|
||||||
if self.default_gateway_w and self.default_gateway_w.value:
|
if self.default_gateway_w and self.default_gateway_w.value:
|
||||||
self.model.default_gateway = self.default_gateway_w.value
|
try:
|
||||||
|
self.model.set_default_gateway(self.default_gateway_w.value)
|
||||||
|
except ValueError:
|
||||||
|
# FIXME: raise UX error message
|
||||||
|
self.default_gateway_w.edit_text = ""
|
||||||
else:
|
else:
|
||||||
self.model.default_gateway = result.label
|
gw_ip_from_label = result.label.split(" ")[0]
|
||||||
|
try:
|
||||||
|
self.model.set_default_gateway(gw_ip_from_label)
|
||||||
|
except ValueError:
|
||||||
|
# FIXME: raise UX error message
|
||||||
|
pass
|
||||||
self.signal.prev_signal()
|
self.signal.prev_signal()
|
||||||
|
|
||||||
def cancel(self, button):
|
def cancel(self, button):
|
||||||
|
|
Loading…
Reference in New Issue