'Wait for the function which returns a instance with field status/state
to match.
Keep polling func until one of the desired states is matched
:param state: Either the desired state (`str`) or a `list` of states
:type  state: ``str`` or ``list``
:param  func: The function to call, e.g. ex_get_vlan. Note: This
function needs to return an object which has ``status``
attribute.
:type   func: ``function``
:param  poll_interval: The number of seconds to wait between checks
:type   poll_interval: `int`
:param  timeout: The total number of seconds to wait to reach a state
:type   timeout: `int`
:param  args: The arguments for func
:type   args: Positional arguments
:param  kwargs: The arguments for func
:type   kwargs: Keyword arguments
:return: Result from the calling function.'

def wait_for_state(self, state, func, poll_interval=2, timeout=60, *args, **kwargs):

    cnt = 0
    result = None
    object_state = None
    while (cnt < (timeout / poll_interval)):
        result = func(*args, **kwargs)
        if isinstance(result, Node):
            object_state = result.state
        else:
            object_state = result.status
        if ((object_state is state) or (object_state in state)):
            return result
        sleep(poll_interval)
        cnt += 1
    msg = ('Status    check    for    object    %s    timed    out' % result)
    raise DimensionDataAPIException(code=object_state, msg=msg, driver=self.driver)
