1- # ---------------------------------------------------------
1+ # ---------------------------------------------------------
22# Copyright (c) Microsoft Corporation. All rights reserved.
33# ---------------------------------------------------------
44
1010except ImportError :
1111 load_deployment_template = None
1212
13- from azure .ai .ml .exceptions import ErrorCategory , ErrorTarget , UserErrorException , ValidationException
14-
1513from .raise_error import log_and_raise_error
1614from .utils import (
17- _dump_entity_with_warnings ,
1815 get_ml_client ,
1916 is_not_found_error ,
2017 wrap_lro ,
@@ -30,7 +27,7 @@ def ml_deployment_template_list(cmd, registry_name=None):
3027 ml_client , debug = get_ml_client (
3128 cli_ctx = cmd .cli_ctx , registry_name = registry_name
3229 )
33-
30+
3431 try :
3532 deployment_templates = ml_client .deployment_templates .list ()
3633 # Handle DeploymentTemplate serialization - try as_dict() first, then _to_dict()
@@ -57,16 +54,15 @@ def ml_deployment_template_get(cmd, name, version=None, registry_name=None):
5754 ml_client , debug = get_ml_client (
5855 cli_ctx = cmd .cli_ctx , registry_name = registry_name
5956 )
60-
57+
6158 try :
6259 deployment_template = ml_client .deployment_templates .get (name = name , version = version )
6360 # Handle DeploymentTemplate serialization
6461 if hasattr (deployment_template , 'as_dict' ):
6562 return deployment_template .as_dict ()
66- elif hasattr (deployment_template , '_to_dict' ):
63+ if hasattr (deployment_template , '_to_dict' ):
6764 return deployment_template ._to_dict () # pylint: disable=protected-access
68- else :
69- return dict (deployment_template )
65+ return dict (deployment_template )
7066 except Exception as err : # pylint: disable=broad-except
7167 if is_not_found_error (err ):
7268 raise ValueError (f"Deployment template '{ name } ' with version '{ version } ' does not exist." ) from err
@@ -87,35 +83,35 @@ def ml_deployment_template_create(
8783 ml_client , debug = get_ml_client (
8884 cli_ctx = cmd .cli_ctx , registry_name = registry_name
8985 )
90-
86+
9187 params_override = params_override or []
92-
88+
9389 try :
9490 if name :
9591 params_override .append ({"name" : name })
9692 if version :
9793 params_override .append ({"version" : version })
98-
94+
9995 if load_deployment_template :
10096 deployment_template = load_deployment_template (source = file , params_override = params_override )
10197 else :
10298 # Fallback: load YAML manually if load_deployment_template is not available
10399 import yaml
104100 if not file :
105101 raise ValueError ("A YAML file must be provided for deployment template creation." )
106-
102+
107103 with open (file , 'r' , encoding = 'utf-8' ) as f :
108104 yaml_content = yaml .safe_load (f )
109-
105+
110106 # Apply parameter overrides
111107 for override in params_override :
112108 if isinstance (override , dict ):
113109 yaml_content .update (override )
114-
110+
115111 deployment_template = yaml_content
116-
112+
117113 deployment_template_result = ml_client .deployment_templates .create_or_update (deployment_template )
118-
114+
119115 if no_wait :
120116 module_logger .warning (
121117 "Deployment template create/update request initiated. "
@@ -124,16 +120,14 @@ def ml_deployment_template_create(
124120 deployment_template .version if hasattr (deployment_template , 'version' ) else version or "unknown"
125121 )
126122 return None
127- else :
128- deployment_template_result = wrap_lro (cmd .cli_ctx , deployment_template_result )
129-
123+ deployment_template_result = wrap_lro (cmd .cli_ctx , deployment_template_result )
124+
130125 # Handle serialization
131126 if hasattr (deployment_template_result , 'as_dict' ):
132127 return deployment_template_result .as_dict ()
133- elif hasattr (deployment_template_result , '_to_dict' ):
128+ if hasattr (deployment_template_result , '_to_dict' ):
134129 return deployment_template_result ._to_dict () # pylint: disable=protected-access
135- else :
136- return dict (deployment_template_result )
130+ return dict (deployment_template_result )
137131 except Exception as err : # pylint: disable=broad-except
138132 yaml_operation = bool (file )
139133 log_and_raise_error (err , debug , yaml_operation = yaml_operation )
@@ -158,10 +152,9 @@ def _ml_deployment_template_update(
158152 # Handle serialization
159153 if hasattr (deployment_template_result , 'as_dict' ):
160154 return deployment_template_result .as_dict ()
161- elif hasattr (deployment_template_result , '_to_dict' ):
155+ if hasattr (deployment_template_result , '_to_dict' ):
162156 return deployment_template_result ._to_dict () # pylint: disable=protected-access
163- else :
164- return dict (deployment_template_result )
157+ return dict (deployment_template_result )
165158 except Exception as err : # pylint: disable=broad-except
166159 log_and_raise_error (err , debug )
167160
@@ -171,19 +164,18 @@ def _ml_deployment_template_show(cmd, name, version=None, registry_name=None):
171164 ml_client , debug = get_ml_client (
172165 cli_ctx = cmd .cli_ctx , registry_name = registry_name
173166 )
174-
167+
175168 try :
176169 deployment_template = ml_client .deployment_templates .get (name = name , version = version )
177-
170+
178171 # Use to_rest_object to get proper field naming (snake_case instead of camelCase)
179172 if hasattr (deployment_template , 'to_rest_object' ):
180173 return deployment_template .to_rest_object ()
181- elif hasattr (deployment_template , 'as_dict' ):
174+ if hasattr (deployment_template , 'as_dict' ):
182175 return deployment_template .as_dict ()
183- elif hasattr (deployment_template , '_to_dict' ):
176+ if hasattr (deployment_template , '_to_dict' ):
184177 return deployment_template ._to_dict () # pylint: disable=protected-access
185- else :
186- return dict (deployment_template )
178+ return dict (deployment_template )
187179 except Exception as err : # pylint: disable=broad-except
188180 if is_not_found_error (err ):
189181 raise ValueError (f"Deployment template '{ name } ' with version '{ version } ' does not exist." ) from err
@@ -202,7 +194,7 @@ def ml_deployment_template_archive(
202194 ml_client , debug = get_ml_client (
203195 cli_ctx = cmd .cli_ctx , registry_name = registry_name
204196 )
205-
197+
206198 try :
207199 ml_client .deployment_templates .archive (name = name , version = version )
208200 except Exception as err : # pylint: disable=broad-except
@@ -221,11 +213,8 @@ def ml_deployment_template_restore(
221213 ml_client , debug = get_ml_client (
222214 cli_ctx = cmd .cli_ctx , registry_name = registry_name
223215 )
224-
216+
225217 try :
226218 ml_client .deployment_templates .restore (name = name , version = version )
227219 except Exception as err : # pylint: disable=broad-except
228220 log_and_raise_error (err , debug )
229-
230-
231-
0 commit comments