-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move RunCommandLocationPolling class to separate file
- Loading branch information
1 parent
67b9c42
commit 7bbfe83
Showing
2 changed files
with
36 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from typing import Optional | ||
|
||
from azure.core.polling.base_polling import LocationPolling, _is_empty, BadResponse, _as_json | ||
|
||
|
||
class RunCommandLocationPolling(LocationPolling): | ||
"""Extends LocationPolling but uses the body content instead of the status code for the status""" | ||
|
||
@staticmethod | ||
def _get_provisioning_state(response: Optional[str]): | ||
"""Attempt to get provisioning state from resource. | ||
:param azure.core.pipeline.transport.HttpResponse response: latest REST call response. | ||
:returns: Status if found, else 'None'. | ||
""" | ||
if _is_empty(response): | ||
return None | ||
body = _as_json(response) | ||
return body.get("properties", {}).get("provisioningState") | ||
|
||
def get_status(self, pipeline_response): | ||
"""Process the latest status update retrieved from the same URL as | ||
the previous request. | ||
:param azure.core.pipeline.PipelineResponse response: latest REST call response. | ||
:raises: BadResponse if status not 200 or 204. | ||
""" | ||
response = pipeline_response.http_response | ||
if _is_empty(response): | ||
raise BadResponse( | ||
"The response from long running operation does not contain a body." | ||
) | ||
|
||
status = self._get_provisioning_state(response) | ||
return status or "Succeeded" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters