1515 _get_cloud_details ,
1616 _resource_to_scopes ,
1717)
18- from azure .ai .ml ._utils ._arm_id_utils import AzureResourceId , get_arm_id_object_from_id
18+ from azure .ai .ml ._utils ._arm_id_utils import (
19+ AzureResourceId ,
20+ get_arm_id_object_from_id ,
21+ )
1922from azure .ai .ml ._utils ._logger_utils import initialize_logger_info
2023from azure .ai .ml ._utils .utils import from_iso_duration_format_min_sec
21- from azure .ai .ml ._vendor .azure_resources ._resource_management_client import ResourceManagementClient
22- from azure .ai .ml ._vendor .azure_resources .models import Deployment , DeploymentProperties
24+ from azure .ai .ml ._vendor .azure_resources ._resource_management_client import (
25+ ResourceManagementClient ,
26+ )
27+ from azure .ai .ml ._vendor .azure_resources .models import (
28+ Deployment ,
29+ DeploymentProperties ,
30+ )
2331from azure .ai .ml .constants ._common import (
2432 ENDPOINT_DEPLOYMENT_START_MSG ,
2533 ArmConstants ,
2634 LROConfigurations ,
2735 OperationStatus ,
2836)
29- from azure .ai .ml .exceptions import ErrorCategory , ErrorTarget , ValidationException
37+ from azure .ai .ml .exceptions import (
38+ ErrorCategory ,
39+ ErrorTarget ,
40+ ValidationException ,
41+ )
3042from azure .core .credentials import TokenCredential
3143from azure .core .polling import LROPoller
3244
@@ -65,7 +77,9 @@ def __init__(
6577 self ._deployments_client = self ._client .deployments
6678 self ._deployment_tracking = []
6779 self ._lock = None # To allow only one deployment to print
68- self ._printed_set = set () # To prevent already printed deployment from re using the console
80+ self ._printed_set = (
81+ set ()
82+ ) # To prevent already printed deployment from re using the console
6983 self ._resources_being_deployed = {}
7084
7185 def deploy_resource (
@@ -88,14 +102,17 @@ def deploy_resource(
88102 try :
89103 poller = self ._get_poller (template = template , parameters = parameters )
90104 module_logger .info (
91- "The deployment request %s was accepted. ARM deployment URI for reference: \n " , self ._deployment_name
92- )
93- endpoint_deployment_start_message = ENDPOINT_DEPLOYMENT_START_MSG .format (
94- _get_azure_portal_id_from_metadata (),
95- self ._subscription_id ,
96- self ._resource_group_name ,
105+ "The deployment request %s was accepted. ARM deployment URI for reference: \n " ,
97106 self ._deployment_name ,
98107 )
108+ endpoint_deployment_start_message = (
109+ ENDPOINT_DEPLOYMENT_START_MSG .format (
110+ _get_azure_portal_id_from_metadata (),
111+ self ._subscription_id ,
112+ self ._resource_group_name ,
113+ self ._deployment_name ,
114+ )
115+ )
99116 module_logger .info (endpoint_deployment_start_message )
100117 if wait :
101118 try :
@@ -120,20 +137,32 @@ def deploy_resource(
120137 else :
121138 return poller
122139 except Exception as ex :
123- module_logger .debug ("Polling hit the exception: %s" , type (ex ).__name__ )
140+ module_logger .debug (
141+ "Polling hit the exception: %s" , type (ex ).__name__
142+ )
124143 raise ex
125144
126145 if error is not None :
127146 error_msg = f"Unable to create resource. \n { error } \n "
128147 module_logger .error (error_msg )
129148 raise error
130149 if len (resources_being_deployed ) > 1 and total_duration :
131- module_logger .info ("Total time : %s\n " , from_iso_duration_format_min_sec (total_duration ))
150+ module_logger .info (
151+ "Total time : %s\n " ,
152+ from_iso_duration_format_min_sec (total_duration ),
153+ )
132154 return None
133155
134- def _get_poller (self , template : str , parameters : Optional [Dict ] = None , wait : bool = True ) -> None :
156+ def _get_poller (
157+ self ,
158+ template : str ,
159+ parameters : Optional [Dict ] = None ,
160+ wait : bool = True ,
161+ ) -> None :
135162 # deploy the template
136- properties = DeploymentProperties (template = template , parameters = parameters , mode = "incremental" )
163+ properties = DeploymentProperties (
164+ template = template , parameters = parameters , mode = "incremental"
165+ )
137166 return self ._deployments_client .begin_create_or_update (
138167 resource_group_name = self ._resource_group_name ,
139168 deployment_name = self ._deployment_name ,
@@ -165,36 +194,52 @@ def _check_deployment_status(self) -> None:
165194
166195 arm_id_obj = get_arm_id_object_from_id (target_resource .id )
167196
168- resource_name = (
169- f"{ arm_id_obj .asset_name } { arm_id_obj .asset_version if hasattr (arm_id_obj ,'asset_version' ) else '' } "
170- )
197+ resource_name = f"{ arm_id_obj .asset_name } { arm_id_obj .asset_version if hasattr (arm_id_obj ,'asset_version' ) else '' } "
171198 # do swap on asset_type to avoid collision with workspaces asset_type in arm id
172199 if isinstance (arm_id_obj , AzureResourceId ):
173200 arm_id_obj .asset_type = (
174201 arm_id_obj .asset_type
175- if not arm_id_obj .provider_namespace_with_type == "OperationalInsightsworkspaces"
202+ if not arm_id_obj .provider_namespace_with_type
203+ == "OperationalInsightsworkspaces"
176204 else "LogAnalytics"
177205 )
178- deployment_message = deployment_message_mapping [arm_id_obj .asset_type ].format (f"{ resource_name } " )
179- if target_resource .resource_name not in self ._resources_being_deployed :
180- self ._resources_being_deployed [target_resource .resource_name ] = (
206+ deployment_message = deployment_message_mapping [
207+ arm_id_obj .asset_type
208+ ].format (f"{ resource_name } " )
209+ if (
210+ target_resource .resource_name
211+ not in self ._resources_being_deployed
212+ ):
213+ self ._resources_being_deployed [
214+ target_resource .resource_name
215+ ] = (
181216 deployment_message ,
182217 None ,
183218 )
184219
185220 if (
186221 properties .provisioning_state
187- and (not self ._lock or self ._lock == target_resource .resource_name )
222+ and (
223+ not self ._lock
224+ or self ._lock == target_resource .resource_name
225+ )
188226 and target_resource .resource_name not in self ._printed_set
189227 ):
190- status_in_resource_dict = self ._resources_being_deployed [target_resource .resource_name ][1 ]
228+ status_in_resource_dict = self ._resources_being_deployed [
229+ target_resource .resource_name
230+ ][1 ]
191231 module_logger .debug (
192- ("\n LOCK STATUS : %s, Status in the resources dict : %s , Already in printed set: %s\n " ),
232+ (
233+ "\n LOCK STATUS : %s, Status in the resources dict : %s , Already in printed set: %s\n "
234+ ),
193235 self ._lock ,
194236 status_in_resource_dict ,
195237 self ._printed_set ,
196238 )
197- module_logger .debug ("Locking with the deployment : %s\n \n " , target_resource .resource_name )
239+ module_logger .debug (
240+ "Locking with the deployment : %s\n \n " ,
241+ target_resource .resource_name ,
242+ )
198243 self ._lock = target_resource .resource_name
199244 provisioning_state = properties .provisioning_state
200245 request_id = properties .service_request_id
@@ -206,12 +251,16 @@ def _check_deployment_status(self) -> None:
206251 if resource_name not in self ._resources_being_deployed :
207252 resource_type , previous_state = resource_name , None
208253 else :
209- resource_type , previous_state = self ._resources_being_deployed [resource_name ]
254+ resource_type , previous_state = (
255+ self ._resources_being_deployed [resource_name ]
256+ )
210257
211258 duration = properties .duration
212259 # duration comes in format: "PT1M56.3454108S"
213260 try :
214- duration_in_min_sec = from_iso_duration_format_min_sec (duration )
261+ duration_in_min_sec = from_iso_duration_format_min_sec (
262+ duration
263+ )
215264 except Exception : # pylint: disable=W0718
216265 duration_in_min_sec = ""
217266
@@ -220,7 +269,10 @@ def _check_deployment_status(self) -> None:
220269 provisioning_state ,
221270 )
222271
223- if provisioning_state == OperationStatus .FAILED and previous_state != OperationStatus .FAILED :
272+ if (
273+ provisioning_state == OperationStatus .FAILED
274+ and previous_state != OperationStatus .FAILED
275+ ):
224276 status_code = properties .status_code
225277 status_message = properties .status_message
226278 module_logger .debug (
@@ -237,11 +289,18 @@ def _check_deployment_status(self) -> None:
237289 )
238290 module_logger .debug (
239291 "More details: %s\n " ,
240- status_message .error .details [0 ].message if status_message .error .details else None ,
292+ (
293+ status_message .error .details [0 ].message
294+ if status_message .error .details
295+ else None
296+ ),
241297 )
242298 # self._lock = None
243299 # First time we're seeing this so let the user know it's being deployed
244- elif properties .provisioning_state == OperationStatus .RUNNING and previous_state is None :
300+ elif (
301+ properties .provisioning_state == OperationStatus .RUNNING
302+ and previous_state is None
303+ ):
245304 module_logger .info ("%s " , resource_type )
246305 elif (
247306 properties .provisioning_state == OperationStatus .RUNNING
@@ -251,11 +310,19 @@ def _check_deployment_status(self) -> None:
251310 # If the provisioning has already succeeded but we hadn't seen it Running before
252311 # (really quick deployment - so probably never happening) let user know resource
253312 # is being deployed and then let user know it has been deployed
254- elif properties .provisioning_state == OperationStatus .SUCCEEDED and previous_state is None :
255- module_logger .info ("%s Done (%s)\n " , resource_type , duration_in_min_sec )
313+ elif (
314+ properties .provisioning_state == OperationStatus .SUCCEEDED
315+ and previous_state is None
316+ ):
317+ module_logger .info (
318+ "%s Done (%s)\n " , resource_type , duration_in_min_sec
319+ )
256320 self ._lock = None
257321 self ._printed_set .add (resource_name )
258- module_logger .debug ("Releasing lock for deployment: %s\n \n " , target_resource .resource_name )
322+ module_logger .debug (
323+ "Releasing lock for deployment: %s\n \n " ,
324+ target_resource .resource_name ,
325+ )
259326 # Finally, deployment has succeeded and was previously running, so mark it as finished
260327 elif (
261328 properties .provisioning_state == OperationStatus .SUCCEEDED
@@ -264,4 +331,7 @@ def _check_deployment_status(self) -> None:
264331 module_logger .info (" Done (%s)\n " , duration_in_min_sec )
265332 self ._lock = None
266333 self ._printed_set .add (resource_name )
267- module_logger .debug ("Releasing lock for deployment: %s\n \n " , target_resource .resource_name )
334+ module_logger .debug (
335+ "Releasing lock for deployment: %s\n \n " ,
336+ target_resource .resource_name ,
337+ )
0 commit comments