parameters: (which_iface: NETWORK_IFACES)
return_statement: return info
docstring: Get the basic network configuration of an interface.
  
      Returns a dict containing the info:
      {
        'ipAddress': 'xx.xx.xx.xx/yy' (ip4 addr with subnet as CIDR) or None
        'macAddress': 'aa:bb:cc:dd:ee:ff' or None
        'gatewayAddress: 'zz.zz.zz.zz' or None
      }
  
      which_iface should be a string in IFACE_NAMES.
docstring_summary: Get the basic network configuration of an interface.
docstring_tokens: Get the basic network configuration of an interface .
function: async def iface_info(which_iface: NETWORK_IFACES) -> Dict[str, Optional[str]]:
      """Get the basic network configuration of an interface.
  
      Returns a dict containing the info:
      {
        'ipAddress': 'xx.xx.xx.xx/yy' (ip4 addr with subnet as CIDR) or None
        'macAddress': 'aa:bb:cc:dd:ee:ff' or None
        'gatewayAddress: 'zz.zz.zz.zz' or None
      }
  
      which_iface should be a string in IFACE_NAMES.
      """
      # example device info lines
      #  GENERAL.HWADDR:B8:27:EB:24:D1:D0
      #  IP4.ADDRESS[1]:10.10.2.221/22
      # capture the field name (without the number in brackets) and the value
      # using regex instead of split because there may be ":" in the value
      _DEV_INFO_LINE_RE = re.compile(r"([\w.]+)(?:\[\d+])?:(.*)")
      # example device info: 30 (disconnected)
      # capture the string without the number
      _IFACE_STATE_RE = re.compile(r"\d+ \((.+)\)")
  
      info: Dict[str, Optional[str]] = {
          "ipAddress": None,
          "macAddress": None,
          "gatewayAddress": None,
          "state": None,
          "type": None,
      }
      fields = [
          "GENERAL.HWADDR",
          "IP4.ADDRESS",
          "IP4.GATEWAY",
          "GENERAL.TYPE",
          "GENERAL.STATE",
      ]
      # Note on this specific command: Most nmcli commands default to a tabular
      # output mode, where if there are multiple things to pull a couple specific
      # fields from it you’ll get a table where rows are, say, connections, and
      # columns are field name. However, specifically ‘con show <con-name>‘ and
      # ‘dev show <dev-name>’ default to a multiline representation, and even if
      # explicitly ask for it to be tabular, it’s not quite the same as the other
      # commands. So we have to special-case the parsing.
      res, err = await _call(
          [
              "--mode",
              "multiline",
              "--escape",
              "no",
              "--terse",
              "--fields",
              ",".join(fields),
              "dev",
              "show",
              which_iface.value,
          ]
      )
  
      field_map = {}
      for line in res.split("\n"):
          # pull the key (without brackets) and the value out of the line
          match = _DEV_INFO_LINE_RE.fullmatch(line)
          if match is None:
              raise ValueError("Bad nmcli result; out: {}; err: {}".format(res, err))
          key, val = match.groups()
          # nmcli can put "--" instead of "" for None
          field_map[key] = None if val == "--" else val
  
      info["macAddress"] = field_map.get("GENERAL.HWADDR")
      info["ipAddress"] = field_map.get("IP4.ADDRESS")
      info["gatewayAddress"] = field_map.get("IP4.GATEWAY")
      info["type"] = field_map.get("GENERAL.TYPE")
      state_val = field_map.get("GENERAL.STATE")
  
      if state_val:
          state_match = _IFACE_STATE_RE.fullmatch(state_val)
          if state_match:
              info["state"] = state_match.group(1)
  
      return info
function_tokens: async def iface_info ( which_iface : NETWORK_IFACES ) -> Dict [ str , Optional [ str ] ] : # example device info lines #  GENERAL.HWADDR:B8:27:EB:24:D1:D0 #  IP4.ADDRESS[1]:10.10.2.221/22 # capture the field name (without the number in brackets) and the value # using regex instead of split because there may be ":" in the value _DEV_INFO_LINE_RE = re . compile ( r"([\w.]+)(?:\[\d+])?:(.*)" ) # example device info: 30 (disconnected) # capture the string without the number _IFACE_STATE_RE = re . compile ( r"\d+ \((.+)\)" ) info : Dict [ str , Optional [ str ] ] = { "ipAddress" : None , "macAddress" : None , "gatewayAddress" : None , "state" : None , "type" : None , } fields = [ "GENERAL.HWADDR" , "IP4.ADDRESS" , "IP4.GATEWAY" , "GENERAL.TYPE" , "GENERAL.STATE" , ] # Note on this specific command: Most nmcli commands default to a tabular # output mode, where if there are multiple things to pull a couple specific # fields from it you’ll get a table where rows are, say, connections, and # columns are field name. However, specifically ‘con show <con-name>‘ and # ‘dev show <dev-name>’ default to a multiline representation, and even if # explicitly ask for it to be tabular, it’s not quite the same as the other # commands. So we have to special-case the parsing. res , err = await _call ( [ "--mode" , "multiline" , "--escape" , "no" , "--terse" , "--fields" , "," . join ( fields ) , "dev" , "show" , which_iface . value , ] ) field_map = { } for line in res . split ( "\n" ) : # pull the key (without brackets) and the value out of the line match = _DEV_INFO_LINE_RE . fullmatch ( line ) if match is None : raise ValueError ( "Bad nmcli result; out: {}; err: {}" . format ( res , err ) ) key , val = match . groups ( ) # nmcli can put "--" instead of "" for None field_map [ key ] = None if val == "--" else val info [ "macAddress" ] = field_map . get ( "GENERAL.HWADDR" ) info [ "ipAddress" ] = field_map . get ( "IP4.ADDRESS" ) info [ "gatewayAddress" ] = field_map . get ( "IP4.GATEWAY" ) info [ "type" ] = field_map . get ( "GENERAL.TYPE" ) state_val = field_map . get ( "GENERAL.STATE" ) if state_val : state_match = _IFACE_STATE_RE . fullmatch ( state_val ) if state_match : info [ "state" ] = state_match . group ( 1 ) return info