88
99from typing import Any , Dict , Iterable , Optional , cast
1010
11- from azure .ai .ml ._scope_dependent_operations import OperationScope , OperationConfig , _ScopeDependentOperations
11+ from azure .ai .ml ._scope_dependent_operations import OperationConfig , OperationScope , _ScopeDependentOperations
1212from azure .ai .ml ._telemetry import ActivityType , monitor_with_telemetry_mixin
1313from azure .ai .ml ._utils ._experimental import experimental
1414from azure .ai .ml ._utils ._logger_utils import OpsLogger
1515from azure .ai .ml .entities import DeploymentTemplate
16- from azure .core .tracing .decorator import distributed_trace
1716from azure .core .exceptions import ResourceNotFoundError
17+ from azure .core .tracing .decorator import distributed_trace
1818
1919ops_logger = OpsLogger (__name__ )
2020module_logger = ops_logger .module_logger
@@ -51,10 +51,10 @@ def _get_registry_endpoint(self) -> str:
5151 """
5252 try :
5353 # Import here to avoid circular dependencies
54- from azure .ai .ml .operations import RegistryOperations
5554 from azure .ai .ml ._restclient .v2022_10_01_preview import (
5655 AzureMachineLearningWorkspaces as ServiceClient102022 ,
5756 )
57+ from azure .ai .ml .operations import RegistryOperations
5858
5959 # Try to get credential from service client or operation config
6060 credential = None
@@ -91,7 +91,7 @@ def _get_registry_endpoint(self) -> str:
9191 return f"https://{ region } .api.azureml.ms"
9292
9393 except Exception as e :
94- module_logger .warning ("Could not determine registry region dynamically: %s. Using default." , e )
94+ module_logger .debug ("Could not determine registry region dynamically: %s. Using default." , e )
9595
9696 # Fallback to default region if unable to determine dynamically
9797 return f"https://int.experiments.azureml-test.net"
@@ -337,7 +337,7 @@ def get(self, name: str, version: Optional[str] = None, **kwargs: Any) -> Deploy
337337 )
338338 return DeploymentTemplate ._from_rest_object (result )
339339 except Exception as e :
340- module_logger .warning ("DeploymentTemplate get operation failed: %s" , e )
340+ module_logger .debug ("DeploymentTemplate get operation failed: %s" , e )
341341 raise ResourceNotFoundError (f"DeploymentTemplate { name } :{ version } not found" ) from e
342342
343343 @distributed_trace
@@ -351,31 +351,27 @@ def create_or_update(self, deployment_template: DeploymentTemplate, **kwargs: An
351351 :return: DeploymentTemplate object representing the created or updated resource.
352352 :rtype: ~azure.ai.ml.entities.DeploymentTemplate
353353 """
354- try :
355- # Ensure we have a DeploymentTemplate object
356- if not isinstance (deployment_template , DeploymentTemplate ):
357- raise ValueError ("deployment_template must be a DeploymentTemplate object" )
354+ # Ensure we have a DeploymentTemplate object
355+ if not isinstance (deployment_template , DeploymentTemplate ):
356+ raise ValueError ("deployment_template must be a DeploymentTemplate object" )
358357
359- if hasattr (self ._service_client , "deployment_templates" ):
360- endpoint = self ._get_registry_endpoint ()
358+ if hasattr (self ._service_client , "deployment_templates" ):
359+ endpoint = self ._get_registry_endpoint ()
361360
362- rest_object = deployment_template ._to_rest_object ()
363- self ._service_client .deployment_templates .begin_create (
364- endpoint = endpoint ,
365- subscription_id = self ._operation_scope .subscription_id ,
366- resource_group_name = self ._operation_scope .resource_group_name ,
367- registry_name = self ._operation_scope .registry_name ,
368- name = deployment_template .name ,
369- version = deployment_template .version ,
370- body = rest_object ,
371- ** kwargs ,
372- )
373- return deployment_template
374- else :
375- raise RuntimeError ("DeploymentTemplate service not available" )
376- except Exception as e :
377- module_logger .error ("DeploymentTemplate create_or_update operation failed: %s" , e )
378- raise
361+ rest_object = deployment_template ._to_rest_object ()
362+ self ._service_client .deployment_templates .begin_create (
363+ endpoint = endpoint ,
364+ subscription_id = self ._operation_scope .subscription_id ,
365+ resource_group_name = self ._operation_scope .resource_group_name ,
366+ registry_name = self ._operation_scope .registry_name ,
367+ name = deployment_template .name ,
368+ version = deployment_template .version ,
369+ body = rest_object ,
370+ ** kwargs ,
371+ )
372+ return deployment_template
373+ else :
374+ raise RuntimeError ("DeploymentTemplate service not available" )
379375
380376 @distributed_trace
381377 @monitor_with_telemetry_mixin (ops_logger , "DeploymentTemplate.Delete" , ActivityType .PUBLICAPI )
@@ -407,7 +403,7 @@ def delete(self, name: str, version: Optional[str] = None, **kwargs: Any) -> Non
407403 except ResourceNotFoundError :
408404 raise
409405 except Exception as e :
410- module_logger .error ("DeploymentTemplate delete operation failed: %s" , e )
406+ module_logger .debug ("DeploymentTemplate delete operation failed: %s" , e )
411407 raise
412408
413409 @distributed_trace
@@ -423,18 +419,14 @@ def archive(self, name: str, version: Optional[str] = None, **kwargs: Any) -> De
423419 :rtype: ~azure.ai.ml.entities.DeploymentTemplate
424420 :raises: ~azure.core.exceptions.ResourceNotFoundError if deployment template not found.
425421 """
426- try :
427- # Get the existing template
428- template = self .get (name = name , version = version , ** kwargs )
422+ # Get the existing template
423+ template = self .get (name = name , version = version , ** kwargs )
429424
430- # Set stage to Archived
431- template .stage = "Archived"
425+ # Set stage to Archived
426+ template .stage = "Archived"
432427
433- # Update the template using create_or_update
434- return self .create_or_update (template , ** kwargs )
435- except Exception as e :
436- module_logger .error ("DeploymentTemplate archive operation failed: %s" , e )
437- raise
428+ # Update the template using create_or_update
429+ return self .create_or_update (template , ** kwargs )
438430
439431 @distributed_trace
440432 @monitor_with_telemetry_mixin (ops_logger , "DeploymentTemplate.Restore" , ActivityType .PUBLICAPI )
@@ -449,15 +441,11 @@ def restore(self, name: str, version: Optional[str] = None, **kwargs: Any) -> De
449441 :rtype: ~azure.ai.ml.entities.DeploymentTemplate
450442 :raises: ~azure.core.exceptions.ResourceNotFoundError if deployment template not found.
451443 """
452- try :
453- # Get the existing template
454- template = self .get (name = name , version = version , ** kwargs )
444+ # Get the existing template
445+ template = self .get (name = name , version = version , ** kwargs )
455446
456- # Set stage to Development
457- template .stage = "Development"
447+ # Set stage to Development
448+ template .stage = "Development"
458449
459- # Update the template using create_or_update
460- return self .create_or_update (template , ** kwargs )
461- except Exception as e :
462- module_logger .error ("DeploymentTemplate restore operation failed: %s" , e )
463- raise
450+ # Update the template using create_or_update
451+ return self .create_or_update (template , ** kwargs )
0 commit comments