MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / get_by_method

Function get_by_method

pager_lib/getmac/getmac.py:1626–1689  ·  view source on GitHub ↗

Query for a MAC using a specific method. Args: method_type: the type of lookup being performed. Allowed values are: ``ip4``, ``ip6``, ``iface``, ``default_iface`` arg: Argument to pass to the method, e.g. an interface name or IP address network_request:

(method_type, arg="", network_request=True)

Source from the content-addressed store, hash-verified

1624
1625
1626def get_by_method(method_type, arg="", network_request=True):
1627 # type: (str, str, bool) -> Optional[str]
1628 """
1629 Query for a MAC using a specific method.
1630
1631 Args:
1632 method_type: the type of lookup being performed.
1633 Allowed values are: ``ip4``, ``ip6``, ``iface``, ``default_iface``
1634 arg: Argument to pass to the method, e.g. an interface name or IP address
1635 network_request: if methods that make network requests should be included
1636 (those methods that have the attribute ``network_request`` set to ``True``)
1637 """
1638 if not arg and method_type != "default_iface":
1639 log.error("Empty arg for method '%s' (raw value: %s)", method_type, repr(arg))
1640 return None
1641
1642 if FORCE_METHOD:
1643 log.warning(
1644 "Forcing method '%s' to be used for '%s' lookup (arg: '%s')",
1645 FORCE_METHOD,
1646 method_type,
1647 arg,
1648 )
1649
1650 forced_method = get_method_by_name(FORCE_METHOD)
1651
1652 if not forced_method:
1653 log.error("Invalid FORCE_METHOD method name '%s'", FORCE_METHOD)
1654 return None
1655
1656 return forced_method().get(arg)
1657
1658 method = METHOD_CACHE.get(method_type) # type: Optional[Method]
1659
1660 if not method:
1661 # Initialize the cache if it hasn't been already
1662 if not initialize_method_cache(method_type, network_request):
1663 log.error(
1664 "Failed to initialize method cache for method '%s' (arg: '%s')",
1665 method_type,
1666 arg,
1667 )
1668 return None
1669
1670 method = METHOD_CACHE[method_type]
1671
1672 if not method:
1673 log.error(
1674 "Initialization failed for method '%s'. It may not be supported "
1675 "on this platform or another issue occurred.",
1676 method_type,
1677 )
1678 return None
1679
1680 # TODO: add a "net_ok" argument, check network_request attribute
1681 # on method in CACHE, if not then keep checking for method in
1682 # FALLBACK_CACHE that has network_request.
1683 result = _attempt_method_get(method, method_type, arg)

Callers 1

get_mac_addressFunction · 0.85

Calls 7

get_method_by_nameFunction · 0.85
initialize_method_cacheFunction · 0.85
_attempt_method_getFunction · 0.85
errorMethod · 0.80
warningMethod · 0.80
debugMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected