예제 #1
0
def _try_connect_and_fetch_basic_info(host, token):
    """Attempt to connect and call the ping endpoint and, if successful, fetch basic information."""

    # Perform the ping. This doesn't validate authentication.
    controller = VilfoClient(host=host, token=token)
    result = {"type": None, "data": {}}

    try:
        controller.ping()
    except VilfoException:
        result["type"] = RESULT_CANNOT_CONNECT
        result["data"] = CannotConnect
        return result

    # Perform a call that requires authentication.
    try:
        controller.get_board_information()
    except VilfoAuthenticationException:
        result["type"] = RESULT_INVALID_AUTH
        result["data"] = InvalidAuth
        return result

    if controller.mac:
        result["data"][CONF_ID] = controller.mac
        result["data"][CONF_MAC] = controller.mac
    else:
        result["data"][CONF_ID] = host
        result["data"][CONF_MAC] = None

    result["type"] = RESULT_SUCCESS

    return result
예제 #2
0
 def __init__(self, opp, host, access_token):
     """Initialize."""
     self._vilfo = VilfoClient(host, access_token)
     self.opp = opp
     self.host = host
     self.available = False
     self.firmware_version = None
     self.mac_address = self._vilfo.mac
     self.data = {}
     self._unavailable_logged = False