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)) log.debug('Info: {}'.format(probe_info))
self.action = action self.action = action
self.probe_info = probe_info 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') log.debug('configuring netdev from info source')
ip_info = self.probe_info.ip ip_info = self.probe_info.ip
@ -170,7 +170,7 @@ class Networkdev():
if ipaddr is False: if ipaddr is False:
raise ValueError(('Invalid IP address ') + address) raise ValueError(('Invalid IP address ') + address)
ipnet = self.valid_ipv4_network(network) ipnet = valid_ipv4_network(network)
if ipnet is False: if ipnet is False:
raise ValueError(('Invalid IP network ') + network) raise ValueError(('Invalid IP network ') + network)
@ -478,3 +478,10 @@ class NetworkModel(ModelPolicy):
self.configured_interfaces.update({ifname: BondAction(**action)}) self.configured_interfaces.update({ifname: BondAction(**action)})
log.debug("add_bond: {} as BondAction({})".format( log.debug("add_bond: {} as BondAction({})".format(
ifname, action)) 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): def __init__(self, model, signal, iface):
self.model = model self.model = model
self.signal = signal 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.gateway_input = StringEditor(caption="") # FIXME: ipaddr_editor
self.address_input = StringEditor(caption="") # FIXME: ipaddr_editor self.address_input = StringEditor(caption="") # FIXME: ipaddr_editor
self.subnet_input = StringEditor(caption="") # FIXME: ipaddr_editor self.subnet_input = StringEditor(caption="") # FIXME: ipaddr_editor
@ -76,7 +77,7 @@ class NetworkConfigureIPv4InterfaceView(ViewPolicy):
return Pile(col1) return Pile(col1)
def _build_set_as_default_gw_button(self): def _build_set_as_default_gw_button(self):
ifaces = self.model.get_interfaces() ifaces = self.model.get_all_interface_names()
if len(ifaces) > 1: if len(ifaces) > 1:
btn = menu_btn(label="Set this as default gateway", btn = menu_btn(label="Set this as default gateway",
on_press=self.set_default_gateway) on_press=self.set_default_gateway)
@ -86,7 +87,11 @@ class NetworkConfigureIPv4InterfaceView(ViewPolicy):
def set_default_gateway(self, button): def set_default_gateway(self, button):
if self.gateway_input.value: 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): def _build_buttons(self):
cancel = cancel_btn(on_press=self.cancel) cancel = cancel_btn(on_press=self.cancel)
@ -108,11 +113,11 @@ class NetworkConfigureIPv4InterfaceView(ViewPolicy):
'searchpath': self.searchpath_input.value, 'searchpath': self.searchpath_input.value,
} }
try: try:
self.model.remove_subnets(self.iface) self.iface.remove_subnets()
self.model.add_subnet(self.iface, **result) self.iface.add_subnet(**result)
except ValueError: except ValueError:
log.exception('Failed to manually configure interface') 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 # FIXME: set error message in UX ala identity
return return