def __init__(self, parent, device, ip_version): self.parent = parent self.device = device self.ip_version = ip_version self.method_form = NetworkMethodForm() self.method_form.method.caption = _( "IPv{v} Method: ").format(v=ip_version) manual_initial = {} cur_addresses = [] for addr in device.config.get('addresses', []): if addr_version(addr) == ip_version: cur_addresses.append(addr) if cur_addresses: method = 'manual' addr = ipaddress.ip_interface(cur_addresses[0]) ns = device.config.get('nameservers', {}) manual_initial = { 'subnet': str(addr.network), 'address': str(addr.ip), 'nameservers': ', '.join(ns.get('addresses', [])), 'searchdomains': ', '.join(ns.get('search', [])), } gw = device.config.get('gateway{v}'.format(v=ip_version)) if gw: manual_initial['gateway'] = str(gw) elif self.device.config.get('dhcp{v}'.format(v=ip_version)): method = 'dhcp' else: method = 'disable' self.method_form.method.value = method connect_signal( self.method_form.method.widget, 'select', self._select_method) log.debug("manual_initial %s", manual_initial) self.manual_form = NetworkConfigForm(ip_version, manual_initial) connect_signal(self.method_form, 'submit', self.done) connect_signal(self.manual_form, 'submit', self.done) connect_signal(self.method_form, 'cancel', self.cancel) connect_signal(self.manual_form, 'cancel', self.cancel) self.form_pile = Pile(self.method_form.as_rows()) self.bp = WidgetPlaceholder(self.method_form.buttons) self._select_method(None, method) widgets = [self.form_pile, Text(""), self.bp] super().__init__( "Edit {device} IPv{v} configuration".format( device=device.name, v=ip_version), widgets, 0, 0)
def _address_rows_for_device(self, dev): address_info = [] dhcp_addresses = dev.dhcp_addresses() for v in 4, 6: if dev.dhcp_enabled(v): label = Text("DHCPv{v}".format(v=v)) addrs = dhcp_addresses.get(v) if addrs: address_info.extend([(label, Text(addr)) for addr in addrs]) elif dev.dhcp_state(v) == "PENDING": s = Spinner(self.controller.app.aio_loop, align='left') s.rate = 0.3 s.start() address_info.append((label, s)) elif dev.dhcp_state(v) == "TIMEDOUT": address_info.append((label, Text(_("timed out")))) elif dev.dhcp_state(v) == "RECONFIGURE": address_info.append((label, Text("-"))) else: address_info.append((label, Text( _("unknown state {state}".format( state=dev.dhcp_state(v)))))) else: addrs = [] for ip in dev.config.get('addresses', []): if addr_version(ip) == v: addrs.append(str(ip)) if addrs: address_info.append( # Network addressing mode (static/dhcp/disabled) (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. if not dev.is_used: reason = dev.disabled_reason if reason is None: reason = "" # Network addressing mode (static/dhcp/disabled) address_info.append((Text(_("disabled")), Text(reason))) rows = [] for label, value in address_info: rows.append(TableRow([Text(""), label, (2, value)])) return rows
def _cells_for_device(self, dev): notes = [] for dev2 in self.model.get_all_netdevs(): if dev2.type != "bond": continue if dev.name in dev2.config.get('interfaces', []): notes.append(_("enslaved to {}").format(dev2.name)) break for v in 4, 6: configured_ip_addresses = [] for ip in dev.config.get('addresses', []): if addr_version(ip) == v: configured_ip_addresses.append(ip) notes.extend([ "{} (static)".format(a) for a in configured_ip_addresses ]) if dev.config.get('dhcp{v}'.format(v=v)): if v == 4: fam = AF_INET elif v == 6: fam = AF_INET6 fam_addresses = [] if dev.info is not None: for a in dev.info.addresses.values(): if a.family == fam and a.source == 'dhcp': fam_addresses.append("{} (from dhcp)".format( a.address)) if fam_addresses: notes.extend(fam_addresses) else: notes.append( _("DHCPv{v} has supplied no addresses").format(v=v)) if notes: notes = ", ".join(notes) else: notes = '-' return (dev.name, dev.type, notes)