# Path: sen/util.py
# def graceful_chain_get(d, *args, default=None):
#     t = d
#     for a in args:
#         try:
#             t = t[a]
#         except (KeyError, ValueError, TypeError, AttributeError):
#             logger.debug("can't get %r from %s", a, t)
#             return default
#     return t


from sen.util import graceful_chain_get
"""
networking in docker backend
"""


def extract_data_from_inspect(network_name, network_data):
    """
    :param network_name: str
    :param network_data: dict
    :return: dict:
        {
            "ip_address4": "12.34.56.78"
            "ip_address6": "ff:fa:..."
        }
    """
    a4 = None
    if network_name == "host":
        a4 = "127.0.0.1"
    n = {}
    a4 = graceful_chain_get(network_data, "IPAddress") or a4
    if a4:
        n["ip_address4"] = a4

# Path: sen/util.py
# def graceful_chain_get(d, *args, default=None):
#     t = d
#     for a in args:
#         try:
#             t = t[a]
#         except (KeyError, ValueError, TypeError, AttributeError):
#             logger.debug("can't get %r from %s", a, t)
#             return default
#     return t


# Path: sen/net.py
from sen.util import graceful_chain_get

"""
networking in docker backend
"""


def extract_data_from_inspect(network_name, network_data):
    """
    :param network_name: str
    :param network_data: dict
    :return: dict:
        {
            "ip_address4": "12.34.56.78"
            "ip_address6": "ff:fa:..."
        }
    """
    a4 = None
    if network_name == "host":
        a4 = "127.0.0.1"
    n = {}
    a4 = graceful_chain_get(network_data, "IPAddress") or a4
    if a4:
        n["ip_address4"] = a4

    a6 = graceful_chain_get(network_data, "GlobalIPv6Address")