Update manual network config ux to use network model objects

- Use get_interface method to obtain and Networkdev object
and interact with this.  Validates {add,remove}_subnet methods
on Networkdev objects.
- Add method in model for setting and validating gateway values

Signed-off-by: Ryan Harper <ryan.harper@canonical.com>
This commit is contained in:
Ryan Harper 2015-11-06 09:52:05 -06:00
parent e83981c063
commit 1788d89557
2 changed files with 21 additions and 9 deletions

View File

@ -46,9 +46,9 @@ class Networkdev():
log.debug('Info: {}'.format(probe_info))
self.action = action
self.probe_info = probe_info
self._configure_from_info()
self.configure_from_info()
def _configure_from_info(self):
def configure_from_info(self):
log.debug('configuring netdev from info source')
ip_info = self.probe_info.ip
@ -170,7 +170,7 @@ class Networkdev():
if ipaddr is False:
raise ValueError(('Invalid IP address ') + address)
ipnet = self.valid_ipv4_network(network)
ipnet = valid_ipv4_network(network)
if ipnet is False:
raise ValueError(('Invalid IP network ') + network)
@ -478,3 +478,10 @@ class NetworkModel(ModelPolicy):
self.configured_interfaces.update({ifname: BondAction(**action)})
log.debug("add_bond: {} as BondAction({})".format(
ifname, action))
def set_default_gateway(self, gateway_input):
addr = valid_ipv4_address(gateway_input)
if addr is False:
raise ValueError(('Invalid gateway IP ') + gateway_input)
self.default_gateway = addr.compressed

View File

@ -27,7 +27,8 @@ class NetworkConfigureIPv4InterfaceView(ViewPolicy):
def __init__(self, model, signal, iface):
self.model = model
self.signal = signal
self.iface = iface
self.ifname = iface
self.iface = self.model.get_interface(self.ifname)
self.gateway_input = StringEditor(caption="") # FIXME: ipaddr_editor
self.address_input = StringEditor(caption="") # FIXME: ipaddr_editor
self.subnet_input = StringEditor(caption="") # FIXME: ipaddr_editor
@ -76,7 +77,7 @@ class NetworkConfigureIPv4InterfaceView(ViewPolicy):
return Pile(col1)
def _build_set_as_default_gw_button(self):
ifaces = self.model.get_interfaces()
ifaces = self.model.get_all_interface_names()
if len(ifaces) > 1:
btn = menu_btn(label="Set this as default gateway",
on_press=self.set_default_gateway)
@ -86,7 +87,11 @@ class NetworkConfigureIPv4InterfaceView(ViewPolicy):
def set_default_gateway(self, button):
if self.gateway_input.value:
self.model.default_gateway = self.gateway_input.value
try:
self.model.set_default_gateway(self.gateway_input.value)
except ValueError:
# FIXME: set error message UX ala identity
pass
def _build_buttons(self):
cancel = cancel_btn(on_press=self.cancel)
@ -108,11 +113,11 @@ class NetworkConfigureIPv4InterfaceView(ViewPolicy):
'searchpath': self.searchpath_input.value,
}
try:
self.model.remove_subnets(self.iface)
self.model.add_subnet(self.iface, **result)
self.iface.remove_subnets()
self.iface.add_subnet(**result)
except ValueError:
log.exception('Failed to manually configure interface')
self.model.configure_iface_from_info(self.iface)
self.iface.configure_from_info()
# FIXME: set error message in UX ala identity
return