1212from knack .util import CLIError
1313from knack .log import get_logger
1414from azure .core .exceptions import HttpResponseError
15- from azure .multiapi . storage . v2018_11_09 . blob import AppendBlobService
15+ from azure .cli . core . profiles import ResourceType , get_sdk
1616from azure .common import AzureHttpError
17- from ._utils import get_blob_info
1817
1918logger = get_logger (__name__ )
2019
2120DEFAULT_CHUNK_SIZE = 1024 * 4
2221DEFAULT_LOG_TIMEOUT_IN_SEC = 60 * 30 # 30 minutes
2322
2423
25- def stream_logs (client ,
24+ def stream_logs (cmd ,
25+ client ,
2626 resource_group ,
2727 service ,
2828 app ,
@@ -47,18 +47,13 @@ def stream_logs(client,
4747 logger .warning ("%s Empty SAS URL." , error_msg )
4848 raise CLIError (error_msg )
4949
50- account_name , endpoint_suffix , container_name , blob_name , sas_token = get_blob_info (
51- log_file_sas )
50+ BlobClient = get_sdk ( cmd . cli_ctx , ResourceType . DATA_STORAGE_BLOB , '_blob_client#BlobClient' )
51+ blob_client = BlobClient . from_blob_url ( log_file_sas )
5252
5353 _stream_logs (no_format ,
5454 DEFAULT_CHUNK_SIZE ,
5555 DEFAULT_LOG_TIMEOUT_IN_SEC ,
56- AppendBlobService (
57- account_name = account_name ,
58- sas_token = sas_token ,
59- endpoint_suffix = endpoint_suffix ),
60- container_name ,
61- blob_name ,
56+ blob_client ,
6257 raise_error_on_failure ,
6358 logger_level_func )
6459
@@ -67,8 +62,6 @@ def _stream_logs(no_format, # pylint: disable=too-many-locals, too-many-stateme
6762 byte_size ,
6863 timeout_in_seconds ,
6964 blob_service ,
70- container_name ,
71- blob_name ,
7265 raise_error_on_failure ,
7366 logger_level_func ):
7467
@@ -78,7 +71,6 @@ def _stream_logs(no_format, # pylint: disable=too-many-locals, too-many-stateme
7871 stream = BytesIO ()
7972 metadata = {}
8073 start = 0
81- end = byte_size - 1
8274 available = 0
8375 sleep_time = 1
8476 max_sleep_time = 15
@@ -97,11 +89,9 @@ def safe_get_blob_properties():
9789 '''
9890 nonlocal blob_exists
9991 if not blob_exists :
100- blob_exists = blob_service .exists (
101- container_name = container_name , blob_name = blob_name )
92+ blob_exists = blob_service .exists ()
10293 if blob_exists :
103- return blob_service .get_blob_properties (
104- container_name = container_name , blob_name = blob_name )
94+ return blob_service .get_blob_properties ()
10595 return None
10696
10797 # Try to get the initial properties so there's no waiting.
@@ -110,7 +100,7 @@ def safe_get_blob_properties():
110100 props = safe_get_blob_properties ()
111101 if props :
112102 metadata = props .metadata
113- available = props .properties . content_length
103+ available = props .size
114104 except (AttributeError , AzureHttpError ):
115105 pass
116106
@@ -123,18 +113,13 @@ def safe_get_blob_properties():
123113
124114 try :
125115 old_byte_size = len (stream .getvalue ())
126- blob_service .get_blob_to_stream (
127- container_name = container_name ,
128- blob_name = blob_name ,
129- start_range = start ,
130- end_range = end ,
131- stream = stream )
116+ downloader = blob_service .download_blob (offset = start , length = byte_size , max_concurrency = 1 )
117+ downloader .readinto (stream )
132118
133119 curr_bytes = stream .getvalue ()
134120 new_byte_size = len (curr_bytes )
135121 amount_read = new_byte_size - old_byte_size
136122 start += amount_read
137- end = start + byte_size - 1
138123
139124 # Only scan what's newly read. If nothing is read, default to 0.
140125 min_scan_range = max (new_byte_size - amount_read - 1 , 0 )
@@ -165,7 +150,7 @@ def safe_get_blob_properties():
165150 props = safe_get_blob_properties ()
166151 if props :
167152 metadata = props .metadata
168- available = props .properties . content_length
153+ available = props .size
169154 except AzureHttpError as ae :
170155 if ae .status_code != 404 :
171156 raise CLIError (ae )
0 commit comments