def _build_model_inputs(self): netdevs = self.model.get_all_netdevs() ifname_width = 8 # default padding if netdevs: ifname_width += max(map(lambda dev: len(dev.name), netdevs)) if ifname_width > 20: ifname_width = 20 iface_menus = [] # Display each interface -- name in first column, then configured IPs # in the second. log.debug('interfaces: {}'.format(netdevs)) for dev in netdevs: col_1 = [] col_2 = [] col_1.append( menu_btn(label=dev.name, on_press=self.on_net_dev_press)) if dev.type == 'wlan': col_2.extend(_build_wifi_info(dev)) if len(dev.actual_ip_addresses) == 0 and (dev.type == 'eth' and not dev.is_connected): col_2.append(Color.info_primary(Text(_("Not connected")))) col_2.extend(_build_gateway_ip_info_for_version(dev, 4)) col_2.extend(_build_gateway_ip_info_for_version(dev, 6)) # Other device info (MAC, vendor/model, speed) template = '' if dev.hwaddr: template += '{} '.format(dev.hwaddr) # TODO is this to translate? if dev.is_bond_slave: template += '(Bonded) ' # TODO to check if this is affected by translations if not dev.vendor.lower().startswith('unknown'): vendor = textwrap.wrap(dev.vendor, 15)[0] template += '{} '.format(vendor) if not dev.model.lower().startswith('unknown'): model = textwrap.wrap(dev.model, 20)[0] template += '{} '.format(model) if dev.speed: template += '({})'.format(dev.speed) col_2.append(Color.info_minor(Text(template))) iface_menus.append( Columns([(ifname_width, Pile(col_1)), Pile(col_2)], 2)) return iface_menus
def _build_model_inputs(self): ifaces = self.model.get_all_interface_names() ifname_width = 8 # default padding if ifaces: ifname_width += len(max(ifaces, key=len)) if ifname_width > 20: ifname_width = 20 iface_menus = [] # Display each interface -- name in first column, then configured IPs # in the second. log.debug('interfaces: {}'.format(ifaces)) for iface in ifaces: col_1 = [] col_2 = [] col_1.append( Color.info_major( menu_btn(label=iface, on_press=self.on_net_dev_press), focus_map='button focus')) interface = self.model.get_interface(iface) ip_status = { 'ipv4_addresses': interface.ipv4_addresses, 'ipv6_addresses': interface.ipv6_addresses, 'dhcp4_addresses': interface.dhcp4_addresses, 'dhcp6_addresses': interface.dhcp6_addresses, 'dhcp4': interface.dhcp4, 'dhcp6': interface.dhcp6, } for addr in ip_status['dhcp4_addresses']: template = '{} (dhcp)'.format(addr[0]) col_1.append(Text("")) col_2.append(Color.info_primary(Text(template))) for addr in ip_status['ipv4_addresses']: template = '{} (manual)'.format(addr) col_1.append(Text("")) col_2.append(Color.info_primary(Text(template))) for addr in ip_status['dhcp6_addresses']: template = '{} (dhcp)'.format(addr[0]) col_1.append(Text("")) col_2.append(Color.info_primary(Text(template))) for addr in ip_status['ipv6_addresses']: template = '{} (manual)'.format(addr) col_1.append(Text("")) col_2.append(Color.info_primary(Text(template))) template = None if ( not ip_status['dhcp4'] and not ip_status['dhcp6'] ) \ and len(ip_status['ipv4_addresses']) == 0 and \ len(ip_status['ipv6_addresses']) == 0: if interface.type == 'eth': if interface.is_connected(): template = "Not configured" else: template = "Not connected" else: template = "Not configured" if ip_status['dhcp4'] and ip_status['dhcp6'] and \ len(ip_status['ipv4_addresses']) == 0 and \ len(ip_status['dhcp4_addresses']) == 0 and \ len(ip_status['ipv6_addresses']) == 0 and \ len(ip_status['dhcp6_addresses']) == 0: template = "DHCP is enabled" elif ip_status['dhcp4'] and \ len(ip_status['ipv4_addresses']) == 0 and \ len(ip_status['dhcp4_addresses']) == 0: template = "DHCPv4 is enabled" elif ip_status['dhcp6'] and \ len(ip_status['ipv6_addresses']) == 0 and \ len(ip_status['dhcp6_addresses']) == 0: template = "DHCPv6 is enabled" if template is not None: col_1.append(Text("")) col_2.append(Color.info_primary(Text(template))) if interface.iftype == 'wlan': if interface.essid is not None: col_2.append(Text("Associated to '" + interface.essid + "'")) else: col_2.append(Text("Not associated.")) # Other device info (MAC, vendor/model, speed) info = self.model.get_iface_info(iface) hwaddr = self.model.get_hw_addr(iface) log.debug('iface info:{}'.format(info)) template = '' if hwaddr: template += '{} '.format(hwaddr) if info['bond_slave']: template += '(Bonded) ' if not info['vendor'].lower().startswith('unknown'): vendor = textwrap.wrap(info['vendor'], 15)[0] template += '{} '.format(vendor) if not info['model'].lower().startswith('unknown'): model = textwrap.wrap(info['model'], 20)[0] template += '{} '.format(model) if info['speed']: template += '({speed})'.format(**info) #log.debug('template: {}', template) log.debug('hwaddr:{}, {}'.format(hwaddr, template)) col_2.append(Color.info_minor(Text(template))) iface_menus.append(Columns([(ifname_width, Pile(col_1)), Pile(col_2)], 2)) return Pile(iface_menus)