99
1010from os import PathLike
1111from pathlib import Path
12- from typing import Any , Dict , Optional , Union
12+ from typing import Any , Dict , Optional , Union , IO , AnyStr
1313
1414from azure .ai .ml ._utils ._experimental import experimental
1515from azure .ai .ml .entities ._mixins import RestTranslatableMixin
@@ -70,7 +70,6 @@ def __init__( # pylint: disable=too-many-locals
7070 environment_variables : Optional [Dict [str , str ]] = None ,
7171 app_insights_enabled : Optional [bool ] = None ,
7272 allowed_instance_type : Optional [str ] = None ,
73- allowed_instance_types : Optional [str ] = None , # Handle plural form
7473 default_instance_type : Optional [str ] = None , # Handle default instance type
7574 scoring_port : Optional [int ] = None ,
7675 scoring_path : Optional [str ] = None ,
@@ -100,13 +99,7 @@ def __init__( # pylint: disable=too-many-locals
10099 self .code_configuration = code_configuration
101100 self .environment_variables = environment_variables
102101 self .app_insights_enabled = app_insights_enabled
103-
104- # Handle both singular and plural forms of allowed_instance_type
105- if allowed_instance_types and not allowed_instance_type :
106- self .allowed_instance_type = allowed_instance_types # type: ignore[assignment]
107- else :
108- self .allowed_instance_type = allowed_instance_type # type: ignore[assignment]
109-
102+ self .allowed_instance_type = allowed_instance_type
110103 self .default_instance_type = default_instance_type
111104 self .scoring_port = scoring_port
112105 self .scoring_path = scoring_path
@@ -123,8 +116,8 @@ def __init__( # pylint: disable=too-many-locals
123116 self ._original_immutable_fields = {} # type: ignore[var-annotated]
124117
125118 @property
126- def request_timeout_seconds (self ) -> Optional [int ]: # pylint: disable=docstring-missing-rtype
127- """Get request timeout in seconds (user-friendly format) ."""
119+ def request_timeout (self ) -> Optional [int ]: # pylint: disable=docstring-missing-rtype
120+ """Get request timeout in seconds."""
128121 if self .request_settings and hasattr (self .request_settings , "request_timeout_ms" ):
129122 if isinstance (self .request_settings .request_timeout_ms , str ):
130123 # This shouldn't happen with proper OnlineRequestSettings, return a default
@@ -138,100 +131,100 @@ def request_timeout_seconds(self) -> Optional[int]: # pylint: disable=docstring
138131 )
139132 return None
140133
141- @request_timeout_seconds .setter
142- def request_timeout_seconds (self , value : int ): # pylint: disable=docstring-missing-param
143- """Set request timeout in seconds (user-friendly format) ."""
134+ @request_timeout .setter
135+ def request_timeout (self , value : int ): # pylint: disable=docstring-missing-param
136+ """Set request timeout in seconds."""
144137 if not self .request_settings :
145138 self .request_settings = OnlineRequestSettings (request_timeout_ms = value * 1000 )
146139 else :
147140 self .request_settings .request_timeout_ms = value * 1000
148141
149142 @property
150- def liveness_probe_initial_delay_seconds (self ) -> Optional [int ]: # pylint: disable=docstring-missing-rtype
151- """Get liveness probe initial delay in seconds (user-friendly format) ."""
143+ def liveness_probe_initial_delay (self ) -> Optional [int ]: # pylint: disable=docstring-missing-rtype
144+ """Get liveness probe initial delay in seconds."""
152145 if self .liveness_probe and hasattr (self .liveness_probe , "initial_delay" ):
153146 return self .liveness_probe .initial_delay
154147 return None
155148
156- @liveness_probe_initial_delay_seconds .setter
157- def liveness_probe_initial_delay_seconds (self , value : int ): # pylint: disable=docstring-missing-param
158- """Set liveness probe initial delay in seconds (user-friendly format) ."""
149+ @liveness_probe_initial_delay .setter
150+ def liveness_probe_initial_delay (self , value : int ): # pylint: disable=docstring-missing-param
151+ """Set liveness probe initial delay in seconds."""
159152 if not self .liveness_probe :
160153 self .liveness_probe = ProbeSettings (initial_delay = value )
161154 else :
162155 self .liveness_probe .initial_delay = value
163156
164157 @property
165- def liveness_probe_period_seconds (self ) -> Optional [int ]:
166- """Get liveness probe period in seconds (user-friendly format) ."""
158+ def liveness_probe_period (self ) -> Optional [int ]:
159+ """Get liveness probe period in seconds."""
167160 if self .liveness_probe and hasattr (self .liveness_probe , "period" ):
168161 return self .liveness_probe .period
169162 return None
170163
171- @liveness_probe_period_seconds .setter
172- def liveness_probe_period_seconds (self , value : int ):
173- """Set liveness probe period in seconds (user-friendly format) ."""
164+ @liveness_probe_period .setter
165+ def liveness_probe_period (self , value : int ):
166+ """Set liveness probe period in seconds."""
174167 if not self .liveness_probe :
175168 self .liveness_probe = ProbeSettings (period = value )
176169 else :
177170 self .liveness_probe .period = value
178171
179172 @property
180- def liveness_probe_timeout_seconds (self ) -> Optional [int ]:
181- """Get liveness probe timeout in seconds (user-friendly format) ."""
173+ def liveness_probe_timeout (self ) -> Optional [int ]:
174+ """Get liveness probe timeout in seconds."""
182175 if self .liveness_probe and hasattr (self .liveness_probe , "timeout" ):
183176 return self .liveness_probe .timeout
184177 return None
185178
186- @liveness_probe_timeout_seconds .setter
187- def liveness_probe_timeout_seconds (self , value : int ):
188- """Set liveness probe timeout in seconds (user-friendly format) ."""
179+ @liveness_probe_timeout .setter
180+ def liveness_probe_timeout (self , value : int ):
181+ """Set liveness probe timeout in seconds."""
189182 if not self .liveness_probe :
190183 self .liveness_probe = ProbeSettings (timeout = value )
191184 else :
192185 self .liveness_probe .timeout = value
193186
194187 # Readiness probe convenience properties
195188 @property
196- def readiness_probe_initial_delay_seconds (self ) -> Optional [int ]:
197- """Get readiness probe initial delay in seconds (user-friendly format) ."""
189+ def readiness_probe_initial_delay (self ) -> Optional [int ]:
190+ """Get readiness probe initial delay in seconds."""
198191 if self .readiness_probe and hasattr (self .readiness_probe , "initial_delay" ):
199192 return self .readiness_probe .initial_delay
200193 return None
201194
202- @readiness_probe_initial_delay_seconds .setter
203- def readiness_probe_initial_delay_seconds (self , value : int ):
204- """Set readiness probe initial delay in seconds (user-friendly format) ."""
195+ @readiness_probe_initial_delay .setter
196+ def readiness_probe_initial_delay (self , value : int ):
197+ """Set readiness probe initial delay in seconds."""
205198 if not self .readiness_probe :
206199 self .readiness_probe = ProbeSettings (initial_delay = value )
207200 else :
208201 self .readiness_probe .initial_delay = value
209202
210203 @property
211- def readiness_probe_period_seconds (self ) -> Optional [int ]:
212- """Get readiness probe period in seconds (user-friendly format) ."""
204+ def readiness_probe_period (self ) -> Optional [int ]:
205+ """Get readiness probe period in seconds."""
213206 if self .readiness_probe and hasattr (self .readiness_probe , "period" ):
214207 return self .readiness_probe .period
215208 return None
216209
217- @readiness_probe_period_seconds .setter
218- def readiness_probe_period_seconds (self , value : int ):
219- """Set readiness probe period in seconds (user-friendly format) ."""
210+ @readiness_probe_period .setter
211+ def readiness_probe_period (self , value : int ):
212+ """Set readiness probe period in seconds."""
220213 if not self .readiness_probe :
221214 self .readiness_probe = ProbeSettings (period = value )
222215 else :
223216 self .readiness_probe .period = value
224217
225218 @property
226- def readiness_probe_timeout_seconds (self ) -> Optional [int ]:
227- """Get readiness probe timeout in seconds (user-friendly format) ."""
219+ def readiness_probe_timeout (self ) -> Optional [int ]:
220+ """Get readiness probe timeout in seconds."""
228221 if self .readiness_probe and hasattr (self .readiness_probe , "timeout" ):
229222 return self .readiness_probe .timeout
230223 return None
231224
232- @readiness_probe_timeout_seconds .setter
233- def readiness_probe_timeout_seconds (self , value : int ):
234- """Set readiness probe timeout in seconds (user-friendly format) ."""
225+ @readiness_probe_timeout .setter
226+ def readiness_probe_timeout (self , value : int ):
227+ """Set readiness probe timeout in seconds."""
235228 if not self .readiness_probe :
236229 self .readiness_probe = ProbeSettings (timeout = value )
237230 else :
@@ -271,12 +264,13 @@ def _load(
271264 res : DeploymentTemplate = load_from_dict (DeploymentTemplateSchema , data , context , ** kwargs )
272265 return res
273266
274- def dump (self , dest = None , ** kwargs ) -> Dict [str , Any ]:
267+ def dump (self , dest : Union [ str , PathLike , IO [ AnyStr ]] = None , ** kwargs : Any ) -> Dict [str , Any ]: # type: ignore
275268 """Dump the deployment template to a dictionary.
276269
277270 :param dest: Destination path to write the deployment template to.
271+ :type dest: Optional[Union[str, PathLike]]
278272 :return: Dictionary representation of the deployment template.
279- :rtype: dict
273+ :rtype: Dict[str, Any]
280274 """
281275 result = {
282276 "name" : self .name ,
@@ -434,7 +428,7 @@ def get_value(source, key, default=None):
434428 liveness_probe = liveness_probe_obj , # Use proper ProbeSettings object or None
435429 readiness_probe = readiness_probe_obj , # Use proper ProbeSettings object or None
436430 instance_count = instance_count ,
437- instance_type = default_instance_type , # Use default instance type
431+ default_instance_type = default_instance_type , # Use default instance type
438432 model = get_value (obj , "model" ), # May not be present in this API format
439433 code_configuration = get_value (obj , "code_configuration" ), # May not be present in this API format
440434 environment_variables = environment_variables ,
@@ -544,7 +538,9 @@ def _to_rest_object(self) -> dict:
544538 result ["readinessProbe" ] = readiness_dict # type: ignore[assignment]
545539
546540 # Add instance configuration
547- if hasattr (self , "instance_type" ) and self .instance_type :
541+ if hasattr (self , "default_instance_type" ) and self .default_instance_type :
542+ result ["defaultInstanceType" ] = self .default_instance_type
543+ elif hasattr (self , "instance_type" ) and self .instance_type :
548544 result ["defaultInstanceType" ] = self .instance_type
549545
550546 if hasattr (self , "instance_count" ) and self .instance_count is not None :
@@ -577,9 +573,6 @@ def _to_rest_object(self) -> dict:
577573 else :
578574 instance_types_array = [str (self .allowed_instance_type )]
579575 result ["allowedInstanceType" ] = instance_types_array # type: ignore[assignment]
580- elif hasattr (self , "instance_type" ) and self .instance_type :
581- # Fallback to default instance type if no allowed types specified
582- result ["allowedInstanceType" ] = [self .instance_type ] # type: ignore[assignment]
583576
584577 return result
585578
@@ -646,7 +639,9 @@ def _to_dict(self) -> Dict:
646639 # Add instance configuration
647640 if hasattr (self , "allowed_instance_type" ) and self .allowed_instance_type :
648641 result ["allowedInstanceType" ] = self .allowed_instance_type # type: ignore[assignment]
649- if self .instance_type :
642+ if self .default_instance_type :
643+ result ["defaultInstanceType" ] = self .default_instance_type
644+ elif self .instance_type :
650645 result ["defaultInstanceType" ] = self .instance_type
651646 if self .instance_count is not None :
652647 result ["instanceCount" ] = self .instance_count # type: ignore[assignment]
0 commit comments