# Path: lava_dispatcher/action.py
# class InfrastructureError(LAVAError):
#     """
#     Exceptions based on an error raised by a component of the
#     test which is neither the LAVA dispatcher code nor the
#     code being executed on the device under test. This includes
#     errors arising from the device (like the arndale SD controller
#     issue) and errors arising from the hardware to which the device
#     is connected (serial console connection, ethernet switches or
#     internet connection beyond the control of the device under test).
# 
#     Use LAVABug for errors arising from bugs in LAVA code.
#     """
#     error_help = "InfrastructureError: The Infrastructure is not working " \
#                  "correctly. Please report this error to LAVA admins."
#     error_type = "Infrastructure"
# 
# Path: lava_dispatcher/utils/constants.py
# XNBD_PORT_RANGE_MIN = 55000
# 
# Path: lava_dispatcher/utils/constants.py
# XNBD_PORT_RANGE_MAX = 56000


import os
import netifaces
import random
import socket
import subprocess
from lava_dispatcher.action import InfrastructureError
from lava_dispatcher.utils.constants import XNBD_PORT_RANGE_MIN
from lava_dispatcher.utils.constants import XNBD_PORT_RANGE_MAX
# with this program; if not, see <http://www.gnu.org/licenses>.

# List just the subclasses supported for this base strategy
# imported by the parser to populate the list of subclasses.


# pylint: disable=no-member


def dispatcher_gateway():
    """
    Retrieves the IP address of the current default gateway.
    """
    gateways = netifaces.gateways()
    if 'default' not in gateways:
        raise InfrastructureError("Unable to find default gateway")
    return gateways['default'][netifaces.AF_INET][0]


def dispatcher_ip(dispatcher_config):
    """
    Retrieves the IP address of the interface associated
    with the current default gateway.
    """
    try:
        return dispatcher_config["dispatcher_ip"]
    except (KeyError, TypeError):
        pass
    gateways = netifaces.gateways()
    if 'default' not in gateways:

# Path: lava_dispatcher/action.py
# class InfrastructureError(LAVAError):
#     """
#     Exceptions based on an error raised by a component of the
#     test which is neither the LAVA dispatcher code nor the
#     code being executed on the device under test. This includes
#     errors arising from the device (like the arndale SD controller
#     issue) and errors arising from the hardware to which the device
#     is connected (serial console connection, ethernet switches or
#     internet connection beyond the control of the device under test).
# 
#     Use LAVABug for errors arising from bugs in LAVA code.
#     """
#     error_help = "InfrastructureError: The Infrastructure is not working " \
#                  "correctly. Please report this error to LAVA admins."
#     error_type = "Infrastructure"
# 
# Path: lava_dispatcher/utils/constants.py
# XNBD_PORT_RANGE_MIN = 55000
# 
# Path: lava_dispatcher/utils/constants.py
# XNBD_PORT_RANGE_MAX = 56000


# Path: lava_dispatcher/utils/network.py
import os
import netifaces
import random
import socket
import subprocess
from lava_dispatcher.action import InfrastructureError
from lava_dispatcher.utils.constants import XNBD_PORT_RANGE_MIN
from lava_dispatcher.utils.constants import XNBD_PORT_RANGE_MAX

# with this program; if not, see <http://www.gnu.org/licenses>.

# List just the subclasses supported for this base strategy
# imported by the parser to populate the list of subclasses.


# pylint: disable=no-member


def dispatcher_gateway():
    """
    Retrieves the IP address of the current default gateway.
    """
    gateways = netifaces.gateways()
    if 'default' not in gateways:
        raise InfrastructureError("Unable to find default gateway")
    return gateways['default'][netifaces.AF_INET][0]


def dispatcher_ip(dispatcher_config):
    """
    Retrieves the IP address of the interface associated
    with the current default gateway.
    """
    try:
        return dispatcher_config["dispatcher_ip"]
    except (KeyError, TypeError):
        pass
    gateways = netifaces.gateways()
    if 'default' not in gateways:

        raise InfrastructureError("Unable to find dispatcher 'default' gateway")