示例#1
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
示例#2
0
 def _address_rows(self):
     address_info = []
     for v, dhcp_status, static_config in (
         (4, self.dev_info.dhcp4, self.dev_info.static4),
         (6, self.dev_info.dhcp6, self.dev_info.static6),
     ):
         if dhcp_status.enabled:
             label = Text("DHCPv{v}".format(v=v))
             addrs = dhcp_status.addresses
             if addrs:
                 address_info.extend([(label, Text(addr))
                                      for addr in addrs])
             elif dhcp_status.state == DHCPState.PENDING:
                 s = Spinner(self.parent.controller.app.aio_loop,
                             align='left')
                 s.rate = 0.3
                 s.start()
                 address_info.append((label, s))
             elif dhcp_status.state == DHCPState.TIMED_OUT:
                 address_info.append((label, Text(_("timed out"))))
             elif dhcp_status.state == DHCPState.RECONFIGURE:
                 address_info.append((label, Text("-")))
         elif static_config.addresses:
             address_info.append((
                 Text(_('static')),
                 Text(', '.join(static_config.addresses)),
             ))
     if len(address_info) == 0 and not self.dev_info.is_used:
         reason = self.dev_info.disabled_reason
         if reason is None:
             reason = ""
         address_info.append((Text(_("disabled")), Text(reason)))
     rows = []
     for label, value in address_info:
         rows.append(TableRow([Text(""), label, (2, value)]))
     return rows