2015-06-24 19:44:31 +00:00
|
|
|
# Copyright 2015 Canonical, Ltd.
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
# License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2015-07-21 15:55:02 +00:00
|
|
|
""" Network Model
|
|
|
|
|
|
|
|
Provides network device listings and extended network information
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
2015-06-24 19:44:31 +00:00
|
|
|
import logging
|
2016-08-22 04:46:56 +00:00
|
|
|
|
2017-02-03 01:20:05 +00:00
|
|
|
from urwid import (
|
2018-06-26 03:11:42 +00:00
|
|
|
connect_signal,
|
2017-02-03 01:20:05 +00:00
|
|
|
Text,
|
|
|
|
)
|
2016-08-22 04:46:56 +00:00
|
|
|
|
2018-10-29 23:12:07 +00:00
|
|
|
from subiquitycore.models.network import (
|
|
|
|
addr_version,
|
|
|
|
NetDevAction,
|
|
|
|
)
|
2018-06-26 03:11:42 +00:00
|
|
|
from subiquitycore.ui.actionmenu import ActionMenu
|
2018-07-06 19:06:39 +00:00
|
|
|
from subiquitycore.ui.buttons import (
|
|
|
|
back_btn,
|
|
|
|
done_btn,
|
2018-07-11 03:07:08 +00:00
|
|
|
menu_btn,
|
2018-07-06 19:06:39 +00:00
|
|
|
)
|
2018-06-21 21:38:18 +00:00
|
|
|
from subiquitycore.ui.container import (
|
|
|
|
Pile,
|
|
|
|
)
|
2019-03-24 22:03:42 +00:00
|
|
|
from subiquitycore.ui.spinner import Spinner
|
2018-07-10 21:36:14 +00:00
|
|
|
from subiquitycore.ui.stretchy import StretchyOverlay
|
2018-06-26 03:11:42 +00:00
|
|
|
from subiquitycore.ui.table import ColSpec, TablePile, TableRow
|
2018-07-06 02:17:27 +00:00
|
|
|
from subiquitycore.ui.utils import (
|
|
|
|
button_pile,
|
|
|
|
Color,
|
|
|
|
make_action_menu_row,
|
2019-02-04 04:25:31 +00:00
|
|
|
screen,
|
2018-07-06 02:17:27 +00:00
|
|
|
)
|
2019-03-24 21:32:44 +00:00
|
|
|
from subiquitycore.ui.width import widget_width
|
2018-07-05 13:48:29 +00:00
|
|
|
from .network_configure_manual_interface import (
|
2018-07-06 19:06:39 +00:00
|
|
|
AddVlanStretchy,
|
2018-07-11 04:06:32 +00:00
|
|
|
BondStretchy,
|
2018-07-06 19:06:39 +00:00
|
|
|
EditNetworkStretchy,
|
|
|
|
ViewInterfaceInfo,
|
|
|
|
)
|
2018-06-27 02:20:53 +00:00
|
|
|
from .network_configure_wlan_interface import NetworkConfigureWLANStretchy
|
|
|
|
|
2016-07-26 02:21:24 +00:00
|
|
|
from subiquitycore.view import BaseView
|
2015-06-24 19:44:31 +00:00
|
|
|
|
|
|
|
|
2016-06-30 18:17:01 +00:00
|
|
|
log = logging.getLogger('subiquitycore.views.network')
|
2015-07-21 15:55:02 +00:00
|
|
|
|
|
|
|
|
2018-07-10 21:36:14 +00:00
|
|
|
def _stretchy_shower(cls, *args):
|
2019-12-19 10:19:34 +00:00
|
|
|
def impl(self, name, device):
|
|
|
|
stretchy = cls(self, device, *args)
|
2019-12-19 10:23:43 +00:00
|
|
|
stretchy.attach_context(self.controller.context.child(name))
|
2019-12-19 10:19:34 +00:00
|
|
|
self.show_stretchy_overlay(stretchy)
|
2018-07-10 21:36:14 +00:00
|
|
|
impl.opens_dialog = True
|
|
|
|
return impl
|
2016-11-07 00:35:42 +00:00
|
|
|
|
2018-05-21 21:44:02 +00:00
|
|
|
|
2016-07-26 02:21:24 +00:00
|
|
|
class NetworkView(BaseView):
|
2018-05-18 03:55:43 +00:00
|
|
|
title = _("Network connections")
|
2018-05-24 16:00:49 +00:00
|
|
|
excerpt = _("Configure at least one interface this server can use to talk "
|
|
|
|
"to other machines, and which preferably provides sufficient "
|
|
|
|
"access for updates.")
|
2018-05-18 03:55:43 +00:00
|
|
|
|
2016-10-05 02:11:32 +00:00
|
|
|
def __init__(self, model, controller):
|
2015-06-24 19:44:31 +00:00
|
|
|
self.model = model
|
2016-10-05 02:11:32 +00:00
|
|
|
self.controller = controller
|
2019-03-24 20:25:53 +00:00
|
|
|
self.dev_to_table = {}
|
2018-07-10 01:25:05 +00:00
|
|
|
self.cur_netdevs = []
|
2016-08-16 19:25:58 +00:00
|
|
|
self.error = Text("", align='center')
|
2019-03-24 20:25:53 +00:00
|
|
|
|
|
|
|
self.device_colspecs = {
|
|
|
|
0: ColSpec(rpad=1),
|
|
|
|
3: ColSpec(min_width=15),
|
|
|
|
4: ColSpec(can_shrink=True, rpad=1),
|
|
|
|
}
|
|
|
|
|
|
|
|
self.device_pile = Pile(self._build_model_inputs())
|
2018-07-11 03:07:08 +00:00
|
|
|
|
2018-07-11 09:19:03 +00:00
|
|
|
self._create_bond_btn = menu_btn(
|
|
|
|
_("Create bond"), on_press=self._create_bond)
|
2018-07-11 03:07:08 +00:00
|
|
|
bp = button_pile([self._create_bond_btn])
|
|
|
|
bp.align = 'left'
|
|
|
|
|
2019-02-04 04:25:31 +00:00
|
|
|
rows = [
|
2019-03-24 20:25:53 +00:00
|
|
|
self.device_pile,
|
2018-07-11 03:07:08 +00:00
|
|
|
bp,
|
2019-02-04 04:25:31 +00:00
|
|
|
]
|
|
|
|
|
2019-03-24 21:32:44 +00:00
|
|
|
self.buttons = button_pile([
|
|
|
|
done_btn("TBD", on_press=self.done), # See _route_watcher
|
2019-02-04 04:25:31 +00:00
|
|
|
back_btn(_("Back"), on_press=self.cancel),
|
|
|
|
])
|
2018-05-18 03:55:43 +00:00
|
|
|
self.bottom = Pile([
|
2019-03-24 21:32:44 +00:00
|
|
|
('pack', self.buttons),
|
2019-02-04 04:25:31 +00:00
|
|
|
])
|
|
|
|
|
2019-03-24 21:32:44 +00:00
|
|
|
self.controller.network_event_receiver.add_default_route_watcher(
|
|
|
|
self._route_watcher)
|
|
|
|
|
2017-09-28 20:00:35 +00:00
|
|
|
self.error_showing = False
|
2018-07-11 03:07:08 +00:00
|
|
|
|
2019-02-04 04:25:31 +00:00
|
|
|
super().__init__(screen(
|
|
|
|
rows=rows,
|
|
|
|
buttons=self.bottom,
|
|
|
|
focus_buttons=True,
|
2020-05-06 09:07:03 +00:00
|
|
|
excerpt=_(self.excerpt)))
|
2015-06-24 19:44:31 +00:00
|
|
|
|
2018-07-10 21:36:14 +00:00
|
|
|
_action_INFO = _stretchy_shower(ViewInterfaceInfo)
|
|
|
|
_action_EDIT_WLAN = _stretchy_shower(NetworkConfigureWLANStretchy)
|
|
|
|
_action_EDIT_IPV4 = _stretchy_shower(EditNetworkStretchy, 4)
|
|
|
|
_action_EDIT_IPV6 = _stretchy_shower(EditNetworkStretchy, 6)
|
2018-07-11 04:06:32 +00:00
|
|
|
_action_EDIT_BOND = _stretchy_shower(BondStretchy)
|
2018-07-10 21:36:14 +00:00
|
|
|
_action_ADD_VLAN = _stretchy_shower(AddVlanStretchy)
|
2018-06-28 09:53:45 +00:00
|
|
|
|
2020-03-19 20:07:17 +00:00
|
|
|
def _action_DELETE(self, name, device):
|
|
|
|
with self.controller.context.child(name):
|
|
|
|
touched_devs = set()
|
|
|
|
if device.type == "bond":
|
|
|
|
for name in device.config['interfaces']:
|
|
|
|
touched_devs.add(self.model.get_netdev_by_name(name))
|
|
|
|
device.config = None
|
|
|
|
self.del_link(device)
|
|
|
|
for dev in touched_devs:
|
|
|
|
self.update_link(dev)
|
|
|
|
self.controller.apply_config()
|
2018-06-28 09:53:45 +00:00
|
|
|
|
2018-06-26 03:11:42 +00:00
|
|
|
def _action(self, sender, action, device):
|
2018-07-10 00:30:01 +00:00
|
|
|
action, meth = action
|
2019-12-19 10:19:34 +00:00
|
|
|
meth("{}/{}".format(device.name, action.name), device)
|
2018-06-26 03:11:42 +00:00
|
|
|
|
2019-03-24 21:32:44 +00:00
|
|
|
def _route_watcher(self, routes):
|
|
|
|
log.debug('view route_watcher %s', routes)
|
|
|
|
if routes:
|
|
|
|
label = _("Done")
|
|
|
|
else:
|
|
|
|
label = _("Continue without network")
|
|
|
|
self.buttons.base_widget[0].set_label(label)
|
|
|
|
self.buttons.width = max(
|
|
|
|
14,
|
|
|
|
widget_width(self.buttons.base_widget[0]),
|
|
|
|
widget_width(self.buttons.base_widget[1]),
|
|
|
|
)
|
|
|
|
|
2019-03-24 22:03:42 +00:00
|
|
|
def show_apply_spinner(self):
|
2019-12-19 23:04:38 +00:00
|
|
|
s = Spinner(self.controller.app.aio_loop)
|
2019-03-24 22:03:42 +00:00
|
|
|
s.start()
|
|
|
|
c = TablePile([
|
|
|
|
TableRow([
|
|
|
|
Text(_("Applying changes")),
|
|
|
|
s,
|
|
|
|
]),
|
|
|
|
], align='center')
|
|
|
|
self.bottom.contents[0:0] = [
|
|
|
|
(c, self.bottom.options()),
|
|
|
|
(Text(""), self.bottom.options()),
|
|
|
|
]
|
|
|
|
|
|
|
|
def hide_apply_spinner(self):
|
|
|
|
if len(self.bottom.contents) > 2:
|
|
|
|
self.bottom.contents[0:2] = []
|
|
|
|
|
2019-03-24 20:25:53 +00:00
|
|
|
def _notes_for_device(self, dev):
|
2018-07-11 09:19:03 +00:00
|
|
|
notes = []
|
2019-03-24 20:25:53 +00:00
|
|
|
if dev.type == "eth" and not dev.info.is_connected:
|
|
|
|
notes.append(_("not connected"))
|
2018-10-29 23:12:07 +00:00
|
|
|
for dev2 in self.model.get_all_netdevs():
|
|
|
|
if dev2.type != "bond":
|
|
|
|
continue
|
|
|
|
if dev.name in dev2.config.get('interfaces', []):
|
2020-05-06 09:07:03 +00:00
|
|
|
notes.append(
|
|
|
|
_("enslaved to {device}").format(device=dev2.name))
|
2018-10-29 23:12:07 +00:00
|
|
|
break
|
2018-07-11 09:19:03 +00:00
|
|
|
if notes:
|
|
|
|
notes = ", ".join(notes)
|
2018-07-10 00:34:42 +00:00
|
|
|
else:
|
2018-07-11 09:19:03 +00:00
|
|
|
notes = '-'
|
2019-03-24 20:25:53 +00:00
|
|
|
return notes
|
|
|
|
|
|
|
|
def _address_rows_for_device(self, dev):
|
|
|
|
address_info = []
|
|
|
|
dhcp_addresses = dev.dhcp_addresses()
|
|
|
|
for v in 4, 6:
|
|
|
|
if dev.dhcp_enabled(v):
|
2019-10-02 18:40:58 +00:00
|
|
|
label = Text("DHCPv{v}".format(v=v))
|
2019-03-24 20:25:53 +00:00
|
|
|
addrs = dhcp_addresses.get(v)
|
|
|
|
if addrs:
|
|
|
|
address_info.extend(
|
|
|
|
[(label, Text(addr)) for addr in addrs])
|
2019-03-24 22:33:07 +00:00
|
|
|
elif dev.dhcp_state(v) == "PENDING":
|
2019-12-19 23:04:38 +00:00
|
|
|
s = Spinner(self.controller.app.aio_loop, align='left')
|
2019-03-24 22:33:07 +00:00
|
|
|
s.rate = 0.3
|
|
|
|
s.start()
|
|
|
|
address_info.append((label, s))
|
|
|
|
elif dev.dhcp_state(v) == "TIMEDOUT":
|
|
|
|
address_info.append((label, Text(_("timed out"))))
|
2019-03-25 21:18:32 +00:00
|
|
|
elif dev.dhcp_state(v) == "RECONFIGURE":
|
2019-10-02 18:45:34 +00:00
|
|
|
address_info.append((label, Text("-")))
|
2019-03-24 20:25:53 +00:00
|
|
|
else:
|
|
|
|
address_info.append((
|
|
|
|
label,
|
2020-05-06 09:07:03 +00:00
|
|
|
Text(
|
|
|
|
_("unknown state {state}".format(
|
|
|
|
state=dev.dhcp_state(v))))
|
2019-03-24 20:25:53 +00:00
|
|
|
))
|
|
|
|
else:
|
|
|
|
addrs = []
|
|
|
|
for ip in dev.config.get('addresses', []):
|
|
|
|
if addr_version(ip) == v:
|
|
|
|
addrs.append(str(ip))
|
|
|
|
if addrs:
|
|
|
|
address_info.append(
|
2020-05-08 03:40:59 +00:00
|
|
|
# Network addressing mode (static/dhcp/disabled)
|
2019-03-24 20:25:53 +00:00
|
|
|
(Text(_('static')), Text(', '.join(addrs))))
|
|
|
|
if len(address_info) == 0:
|
|
|
|
# Do not show an interface as disabled if it is part of a bond or
|
|
|
|
# has a vlan on it.
|
2019-03-25 02:06:59 +00:00
|
|
|
if not dev.is_used:
|
2019-03-24 22:30:26 +00:00
|
|
|
reason = dev.disabled_reason
|
|
|
|
if reason is None:
|
|
|
|
reason = ""
|
2020-05-08 03:40:59 +00:00
|
|
|
# Network addressing mode (static/dhcp/disabled)
|
2019-03-24 22:30:26 +00:00
|
|
|
address_info.append((Text(_("disabled")), Text(reason)))
|
2019-03-24 20:25:53 +00:00
|
|
|
rows = []
|
|
|
|
for label, value in address_info:
|
|
|
|
rows.append(TableRow([Text(""), label, (2, value)]))
|
|
|
|
return rows
|
2018-07-10 00:34:42 +00:00
|
|
|
|
2018-07-10 01:25:05 +00:00
|
|
|
def new_link(self, new_dev):
|
2019-03-25 02:06:59 +00:00
|
|
|
log.debug(
|
|
|
|
"new_link %s %s %s",
|
|
|
|
new_dev.name, new_dev.ifindex, (new_dev in self.cur_netdevs))
|
2019-03-24 20:25:53 +00:00
|
|
|
if new_dev in self.dev_to_table:
|
2018-10-29 23:12:07 +00:00
|
|
|
self.update_link(new_dev)
|
|
|
|
return
|
2018-07-10 01:25:05 +00:00
|
|
|
for i, cur_dev in enumerate(self.cur_netdevs):
|
|
|
|
if cur_dev.name > new_dev.name:
|
|
|
|
netdev_i = i
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
netdev_i = len(self.cur_netdevs)
|
2019-03-24 20:25:53 +00:00
|
|
|
w = self._device_widget(new_dev, netdev_i)
|
|
|
|
self.device_pile.contents[netdev_i+1:netdev_i+1] = [
|
|
|
|
(w, self.device_pile.options('pack'))]
|
2018-07-10 01:25:05 +00:00
|
|
|
|
|
|
|
def update_link(self, dev):
|
2019-03-25 02:06:59 +00:00
|
|
|
log.debug(
|
|
|
|
"update_link %s %s %s",
|
|
|
|
dev.name, dev.ifindex, (dev in self.cur_netdevs))
|
2019-03-25 22:32:02 +00:00
|
|
|
if dev not in self.cur_netdevs:
|
|
|
|
return
|
2019-03-24 20:25:53 +00:00
|
|
|
# Update the display of dev to represent the current state.
|
|
|
|
#
|
|
|
|
# The easiest way of doing this would be to just create a new table
|
|
|
|
# widget for the device and replace the current one with it. But that
|
|
|
|
# is jarring if the menu for the current device is open, so instead we
|
|
|
|
# overwrite the content of the first (menu) row of the old table with
|
|
|
|
# the contents of the first row of the new table, and replace all other
|
|
|
|
# rows of the old table with new content (which is OK as they cannot be
|
|
|
|
# focused).
|
|
|
|
old_table = self.dev_to_table[dev]
|
|
|
|
first_row = old_table.table_rows[0].base_widget
|
|
|
|
first_row.cells[1][1].set_text(dev.name)
|
|
|
|
first_row.cells[2][1].set_text(dev.type)
|
|
|
|
first_row.cells[3][1].set_text(self._notes_for_device(dev))
|
|
|
|
old_table.remove_rows(1, len(old_table.table_rows))
|
|
|
|
old_table.insert_rows(1, self._address_rows_for_device(dev))
|
|
|
|
|
|
|
|
def _remove_row(self, netdev_i):
|
|
|
|
# MonitoredFocusList clamps the focus position to the new
|
|
|
|
# length of the list when you remove elements but it doesn't
|
|
|
|
# check that that the element it moves the focus to is
|
|
|
|
# selectable...
|
|
|
|
new_length = len(self.device_pile.contents) - 1
|
|
|
|
refocus = self.device_pile.focus_position >= new_length
|
|
|
|
del self.device_pile.contents[netdev_i]
|
|
|
|
if refocus:
|
|
|
|
self.device_pile._select_last_selectable()
|
|
|
|
else:
|
|
|
|
while not self.device_pile.focus.selectable():
|
|
|
|
self.device_pile.focus_position += 1
|
|
|
|
self.device_pile.focus._select_first_selectable()
|
2018-07-10 01:25:05 +00:00
|
|
|
|
|
|
|
def del_link(self, dev):
|
2019-03-25 02:06:59 +00:00
|
|
|
log.debug(
|
|
|
|
"del_link %s %s %s",
|
|
|
|
dev.name, dev.ifindex, (dev in self.cur_netdevs))
|
2019-03-25 21:13:09 +00:00
|
|
|
# If a virtual device disappears while we still have config
|
|
|
|
# for it, we assume it will be back soon.
|
|
|
|
if dev.is_virtual and dev.config is not None:
|
|
|
|
return
|
2018-07-10 01:25:05 +00:00
|
|
|
if dev in self.cur_netdevs:
|
|
|
|
netdev_i = self.cur_netdevs.index(dev)
|
2019-03-24 20:25:53 +00:00
|
|
|
self._remove_row(netdev_i+1)
|
2018-07-10 01:25:05 +00:00
|
|
|
del self.cur_netdevs[netdev_i]
|
2019-03-25 02:06:59 +00:00
|
|
|
del self.dev_to_table[dev]
|
2018-07-10 21:36:14 +00:00
|
|
|
if isinstance(self._w, StretchyOverlay):
|
|
|
|
stretchy = self._w.stretchy
|
|
|
|
if getattr(stretchy, 'device', None) is dev:
|
|
|
|
self.remove_overlay()
|
2018-07-10 01:25:05 +00:00
|
|
|
|
2019-03-24 20:25:53 +00:00
|
|
|
def _device_widget(self, dev, netdev_i=None):
|
|
|
|
# Create the widget for a nic. This consists of a Pile containing a
|
|
|
|
# table, an info line and a blank line. The first row of the table is
|
|
|
|
# the one that can be focused and has a menu for manipulating the nic,
|
|
|
|
# the other rows summarize its address config.
|
|
|
|
# [ name type notes ▸ ] \
|
|
|
|
# address info | <- table
|
|
|
|
# more address info /
|
|
|
|
# mac / vendor info / model info
|
|
|
|
# <blank line>
|
2018-07-10 01:25:05 +00:00
|
|
|
if netdev_i is None:
|
|
|
|
netdev_i = len(self.cur_netdevs)
|
2019-03-24 20:25:53 +00:00
|
|
|
self.cur_netdevs[netdev_i:netdev_i] = [dev]
|
|
|
|
|
2018-07-10 01:25:05 +00:00
|
|
|
actions = []
|
|
|
|
for action in NetDevAction:
|
|
|
|
meth = getattr(self, '_action_' + action.name)
|
2018-07-10 21:36:14 +00:00
|
|
|
opens_dialog = getattr(meth, 'opens_dialog', False)
|
2018-07-10 01:25:05 +00:00
|
|
|
if dev.supports_action(action):
|
2018-07-10 21:36:14 +00:00
|
|
|
actions.append(
|
2020-05-08 03:40:59 +00:00
|
|
|
(action.str(), True, (action, meth), opens_dialog))
|
2019-03-24 20:25:53 +00:00
|
|
|
|
2018-07-10 01:25:05 +00:00
|
|
|
menu = ActionMenu(actions)
|
|
|
|
connect_signal(menu, 'action', self._action, dev)
|
2019-03-24 20:25:53 +00:00
|
|
|
|
|
|
|
trows = [make_action_menu_row([
|
2018-07-10 01:25:05 +00:00
|
|
|
Text("["),
|
2019-03-24 20:25:53 +00:00
|
|
|
Text(dev.name),
|
|
|
|
Text(dev.type),
|
|
|
|
Text(self._notes_for_device(dev), wrap='clip'),
|
2018-07-10 01:25:05 +00:00
|
|
|
menu,
|
|
|
|
Text("]"),
|
2019-03-24 20:25:53 +00:00
|
|
|
], menu)] + self._address_rows_for_device(dev)
|
|
|
|
|
|
|
|
table = TablePile(trows, colspecs=self.device_colspecs, spacing=2)
|
|
|
|
self.dev_to_table[dev] = table
|
|
|
|
table.bind(self.heading_table)
|
|
|
|
|
2018-07-10 10:58:47 +00:00
|
|
|
if dev.type == "vlan":
|
|
|
|
info = _("VLAN {id} on interface {link}").format(
|
2018-10-29 23:12:07 +00:00
|
|
|
**dev.config)
|
2018-07-11 09:19:03 +00:00
|
|
|
elif dev.type == "bond":
|
2020-05-06 09:07:03 +00:00
|
|
|
info = _("bond master for {interfaces}").format(
|
|
|
|
interfaces=', '.join(dev.config['interfaces']))
|
2018-07-10 10:58:47 +00:00
|
|
|
else:
|
2018-10-29 23:12:07 +00:00
|
|
|
info = " / ".join([
|
|
|
|
dev.info.hwaddr, dev.info.vendor, dev.info.model])
|
2019-03-24 20:25:53 +00:00
|
|
|
|
|
|
|
return Pile([
|
|
|
|
('pack', table),
|
|
|
|
('pack', Color.info_minor(Text(" " + info))),
|
|
|
|
('pack', Text("")),
|
|
|
|
])
|
2018-07-10 01:25:05 +00:00
|
|
|
|
2015-06-24 19:44:31 +00:00
|
|
|
def _build_model_inputs(self):
|
2019-03-24 20:25:53 +00:00
|
|
|
self.heading_table = TablePile([
|
|
|
|
TableRow([
|
|
|
|
Color.info_minor(Text(header)) for header in [
|
|
|
|
"", "NAME", "TYPE", "NOTES", "",
|
|
|
|
]
|
|
|
|
])
|
|
|
|
],
|
|
|
|
spacing=2, colspecs=self.device_colspecs)
|
|
|
|
rows = [self.heading_table]
|
2018-10-29 23:12:07 +00:00
|
|
|
for dev in self.model.get_all_netdevs():
|
2019-03-24 20:25:53 +00:00
|
|
|
rows.append(self._device_widget(dev))
|
2018-06-26 03:11:42 +00:00
|
|
|
return rows
|
2015-06-24 19:44:31 +00:00
|
|
|
|
2018-10-29 23:17:29 +00:00
|
|
|
def _create_bond(self, sender=None):
|
2019-12-19 10:19:34 +00:00
|
|
|
stretchy = BondStretchy(self)
|
2019-12-19 10:23:43 +00:00
|
|
|
stretchy.attach_context(self.controller.context.child("add_bond"))
|
2019-12-19 10:19:34 +00:00
|
|
|
self.show_stretchy_overlay(stretchy)
|
2018-07-11 03:07:08 +00:00
|
|
|
|
2016-11-07 21:39:54 +00:00
|
|
|
def show_network_error(self, action, info=None):
|
2017-09-28 20:00:35 +00:00
|
|
|
self.error_showing = True
|
2018-05-18 03:55:43 +00:00
|
|
|
self.bottom.contents[0:0] = [
|
|
|
|
(Color.info_error(self.error), self.bottom.options()),
|
2019-02-04 04:25:31 +00:00
|
|
|
(Text(""), self.bottom.options()),
|
2017-09-07 21:42:58 +00:00
|
|
|
]
|
2017-09-28 15:51:32 +00:00
|
|
|
if action == 'stop-networkd':
|
2018-05-20 23:52:06 +00:00
|
|
|
exc = info[0]
|
2018-05-21 21:44:02 +00:00
|
|
|
self.error.set_text(
|
|
|
|
"Stopping systemd-networkd-failed: %r" % (exc.stderr,))
|
2016-08-18 20:11:10 +00:00
|
|
|
elif action == 'apply':
|
2018-05-21 21:44:02 +00:00
|
|
|
self.error.set_text("Network configuration could not be applied; "
|
2016-08-18 20:11:10 +00:00
|
|
|
"please verify your settings.")
|
|
|
|
elif action == 'timeout':
|
2018-05-21 21:44:02 +00:00
|
|
|
self.error.set_text("Network configuration timed out; "
|
2016-08-18 20:11:10 +00:00
|
|
|
"please verify your settings.")
|
2017-09-28 15:51:32 +00:00
|
|
|
elif action == 'down':
|
|
|
|
self.error.set_text("Downing network interfaces failed.")
|
2018-06-28 09:53:45 +00:00
|
|
|
elif action == 'add-vlan':
|
|
|
|
self.error.set_text("Failed to add a VLAN tag.")
|
|
|
|
elif action == 'rm-dev':
|
|
|
|
self.error.set_text("Failed to delete a virtual interface.")
|
2016-08-18 20:11:10 +00:00
|
|
|
else:
|
2018-05-21 21:44:02 +00:00
|
|
|
self.error.set_text("An unexpected error has occurred; "
|
2016-08-18 20:11:10 +00:00
|
|
|
"please verify your settings.")
|
2016-08-16 19:25:58 +00:00
|
|
|
|
2018-10-29 23:17:29 +00:00
|
|
|
def done(self, result=None):
|
2017-09-28 20:00:35 +00:00
|
|
|
if self.error_showing:
|
2018-05-18 03:55:43 +00:00
|
|
|
self.bottom.contents[0:2] = []
|
2019-03-24 21:32:44 +00:00
|
|
|
self.controller.network_event_receiver.remove_default_route_watcher(
|
|
|
|
self._route_watcher)
|
2019-03-24 22:03:42 +00:00
|
|
|
self.controller.done()
|
2015-07-21 21:04:28 +00:00
|
|
|
|
2017-04-04 04:20:56 +00:00
|
|
|
def cancel(self, button=None):
|
2019-03-24 21:32:44 +00:00
|
|
|
self.controller.network_event_receiver.remove_default_route_watcher(
|
|
|
|
self._route_watcher)
|
2016-10-10 23:48:28 +00:00
|
|
|
self.controller.cancel()
|