1212from azure .core .exceptions import HttpResponseError
1313from azure .common import AzureHttpError
1414from azure .cli .core .profiles import ResourceType , get_sdk
15- from ._azure_utils import get_blob_info
1615from ._constants import ACR_RUN_DEFAULT_TIMEOUT_IN_SEC
1716
1817logger = get_logger (__name__ )
@@ -50,20 +49,14 @@ def stream_logs(cmd, client,
5049 raise CLIError (error_msg )
5150
5251 if not artifact :
53- account_name , endpoint_suffix , container_name , blob_name , sas_token = get_blob_info (
54- log_file_sas )
55- AppendBlobService = get_sdk (cmd .cli_ctx , ResourceType .DATA_STORAGE , 'blob#AppendBlobService' )
52+ BlobClient = get_sdk (cmd .cli_ctx , ResourceType .DATA_STORAGE_BLOB , '_blob_client#BlobClient' )
53+ blob_client = BlobClient .from_blob_url (log_file_sas )
5654 if not timeout :
5755 timeout = ACR_RUN_DEFAULT_TIMEOUT_IN_SEC
5856 _stream_logs (no_format ,
5957 DEFAULT_CHUNK_SIZE ,
6058 timeout ,
61- AppendBlobService (
62- account_name = account_name ,
63- sas_token = sas_token ,
64- endpoint_suffix = endpoint_suffix ),
65- container_name ,
66- blob_name ,
59+ blob_client ,
6760 raise_error_on_failure )
6861 else :
6962 _stream_artifact_logs (log_file_sas ,
@@ -74,8 +67,6 @@ def _stream_logs(no_format, # pylint: disable=too-many-locals, too-many-stateme
7467 byte_size ,
7568 timeout_in_seconds ,
7669 blob_service ,
77- container_name ,
78- blob_name ,
7970 raise_error_on_failure ):
8071
8172 if not no_format :
@@ -85,7 +76,6 @@ def _stream_logs(no_format, # pylint: disable=too-many-locals, too-many-stateme
8576 stream = BytesIO ()
8677 metadata = {}
8778 start = 0
88- end = byte_size - 1
8979 available = 0
9080 sleep_time = 1
9181 max_sleep_time = 15
@@ -97,14 +87,12 @@ def _stream_logs(no_format, # pylint: disable=too-many-locals, too-many-stateme
9787 # If the storage call fails, we'll just sleep and try again after.
9888 try :
9989 # Need to call "exists" API to prevent storage SDK logging BlobNotFound error
100- log_exist = blob_service .exists (
101- container_name = container_name , blob_name = blob_name )
90+ log_exist = blob_service .exists ()
10291
10392 if log_exist :
104- props = blob_service .get_blob_properties (
105- container_name = container_name , blob_name = blob_name )
93+ props = blob_service .get_blob_properties ()
10694 metadata = props .metadata
107- available = props .properties . content_length
95+ available = props .size
10896 else :
10997 # Wait a little bit before checking the existence again
11098 time .sleep (1 )
@@ -120,18 +108,13 @@ def _stream_logs(no_format, # pylint: disable=too-many-locals, too-many-stateme
120108
121109 try :
122110 old_byte_size = len (stream .getvalue ())
123- blob_service .get_blob_to_stream (
124- container_name = container_name ,
125- blob_name = blob_name ,
126- start_range = start ,
127- end_range = end ,
128- stream = stream )
111+ downloader = blob_service .download_blob (offset = start , length = byte_size , max_concurrency = 1 )
112+ downloader .readinto (stream )
129113
130114 curr_bytes = stream .getvalue ()
131115 new_byte_size = len (curr_bytes )
132116 amount_read = new_byte_size - old_byte_size
133117 start += amount_read
134- end = start + byte_size - 1
135118
136119 # Only scan what's newly read. If nothing is read, default to 0.
137120 min_scan_range = max (new_byte_size - amount_read - 1 , 0 )
@@ -153,13 +136,11 @@ def _stream_logs(no_format, # pylint: disable=too-many-locals, too-many-stateme
153136
154137 try :
155138 if log_exist :
156- props = blob_service .get_blob_properties (
157- container_name = container_name , blob_name = blob_name )
139+ props = blob_service .get_blob_properties ()
158140 metadata = props .metadata
159- available = props .properties . content_length
141+ available = props .size
160142 else :
161- log_exist = blob_service .exists (
162- container_name = container_name , blob_name = blob_name )
143+ log_exist = blob_service .exists ()
163144 except AzureHttpError as ae :
164145 if ae .status_code != 404 :
165146 raise CLIError (ae )
0 commit comments