Repository: libcloud Updated Branches: refs/heads/trunk 4a7424367 -> 232f9491f
Revert exception message change, rename "response" variable to "result" and add additional clarification to the docstring. Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/232f9491 Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/232f9491 Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/232f9491 Branch: refs/heads/trunk Commit: 232f9491f6ad62f8c6db8239f1291575c60b0f81 Parents: 4a74243 Author: Tomaz Muraus <[email protected]> Authored: Fri Nov 13 00:30:17 2015 +0100 Committer: Tomaz Muraus <[email protected]> Committed: Fri Nov 13 00:34:39 2015 +0100 ---------------------------------------------------------------------- libcloud/common/dimensiondata.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/232f9491/libcloud/common/dimensiondata.py ---------------------------------------------------------------------- diff --git a/libcloud/common/dimensiondata.py b/libcloud/common/dimensiondata.py index 90e6690..8c4c8af 100644 --- a/libcloud/common/dimensiondata.py +++ b/libcloud/common/dimensiondata.py @@ -221,15 +221,17 @@ class DimensionDataConnection(ConnectionUserAndKey): def wait_for_state(self, state, func, poll_interval=2, timeout=60, *args, **kwargs): """ - Wait for the function which returns a instance - with field status to match + Wait for the function which returns a instance with field status 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 + :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 @@ -243,17 +245,19 @@ class DimensionDataConnection(ConnectionUserAndKey): :param kwargs: The arguments for func :type kwargs: Keyword arguments + + :return: Result from the calling function. """ cnt = 0 while cnt < timeout / poll_interval: - response = func(*args, **kwargs) - if response.status is state or response.status in state: - return response + result = func(*args, **kwargs) + if result.status is state or result.status in state: + return result sleep(poll_interval) cnt += 1 - msg = 'Status check timed out: %s' % (response.body) - raise DimensionDataAPIException(code=response.status, + msg = 'Status check for object %s timed out' % (result) + raise DimensionDataAPIException(code=result.status, msg=msg, driver=self.connection.driver)
