66from typing import Dict , Tuple , TypeVar , Union
77
88from azure .cli .command_modules .acs ._client_factory import cf_agent_pools
9- from azure .cli .command_modules .acs ._consts import DecoratorMode
9+ from azure .cli .command_modules .acs ._consts import DecoratorMode , AgentPoolDecoratorMode
1010from azure .cli .command_modules .acs ._validators import extract_comma_separated_string
1111from azure .cli .command_modules .acs .base_decorator import BaseAKSContext , BaseAKSModels , BaseAKSParamDict
12+ from azure .cli .core import AzCommandsLoader
1213from azure .cli .core .azclierror import CLIInternalError , InvalidArgumentValueError , RequiredArgumentMissingError
1314from azure .cli .core .commands import AzCliCommand
1415from azure .cli .core .profiles import ResourceType
@@ -29,6 +30,23 @@ class AKSAgentPoolModels(BaseAKSModels):
2930 The api version of the class corresponding to a model is determined by resource_type.
3031 """
3132
33+ def __init__ (
34+ self ,
35+ cmd : AzCommandsLoader ,
36+ resource_type : ResourceType ,
37+ agentpool_decorator_mode : AgentPoolDecoratorMode ,
38+ ):
39+ super ().__init__ (cmd , resource_type )
40+ self .agentpool_decorator_mode = agentpool_decorator_mode
41+ self .UnifiedAgentPoolModel = self .__choose_agentpool_model_by_agentpool_decorator_mode ()
42+
43+ def __choose_agentpool_model_by_agentpool_decorator_mode (self ):
44+ """Choose the model reference for agentpool based on agentpool_decorator_mode.
45+ """
46+ if self .agentpool_decorator_mode == AgentPoolDecoratorMode .MANAGED_CLUSTER :
47+ return self .ManagedClusterAgentPoolProfile
48+ return self .AgentPool
49+
3250
3351# pylint: disable=too-few-public-methods
3452class AKSAgentPoolParamDict (BaseAKSParamDict ):
@@ -48,8 +66,10 @@ def __init__(
4866 raw_parameters : AKSAgentPoolParamDict ,
4967 models : AKSAgentPoolModels ,
5068 decorator_mode : DecoratorMode ,
69+ agentpool_decorator_mode : AgentPoolDecoratorMode ,
5170 ):
5271 super ().__init__ (cmd , raw_parameters , models , decorator_mode )
72+ self .agentpool_decorator_mode = agentpool_decorator_mode
5373 self .agentpool = None
5474
5575 # pylint: disable=no-self-use
@@ -350,6 +370,7 @@ def __init__(
350370 client : AgentPoolsOperations ,
351371 raw_parameters : Dict ,
352372 resource_type : ResourceType ,
373+ agentpool_decorator_mode : AgentPoolDecoratorMode ,
353374 ):
354375 """Internal controller of aks_agentpool_add.
355376
@@ -361,10 +382,11 @@ def __init__(
361382 """
362383 self .cmd = cmd
363384 self .client = client
364- self .models = AKSAgentPoolModels (cmd , resource_type )
385+ self .agentpool_decorator_mode = agentpool_decorator_mode
386+ self .models = AKSAgentPoolModels (cmd , resource_type , agentpool_decorator_mode )
365387 # store the context in the process of assemble the AgentPool object
366388 self .context = AKSAgentPoolContext (
367- cmd , AKSAgentPoolParamDict (raw_parameters ), self .models , decorator_mode = DecoratorMode .CREATE
389+ cmd , AKSAgentPoolParamDict (raw_parameters ), self .models , DecoratorMode .CREATE , agentpool_decorator_mode
368390 )
369391
370392 def _ensure_agentpool (self , agentpool : AgentPool ) -> None :
@@ -376,7 +398,7 @@ def _ensure_agentpool(self, agentpool: AgentPool) -> None:
376398
377399 :return: None
378400 """
379- if not isinstance (agentpool , self .models .AgentPool ):
401+ if not isinstance (agentpool , self .models .UnifiedAgentPoolModel ):
380402 raise CLIInternalError (
381403 "Unexpected agentpool object with type '{}'." .format (type (agentpool ))
382404 )
@@ -390,17 +412,18 @@ def _ensure_agentpool(self, agentpool: AgentPool) -> None:
390412 def init_agentpool (self ) -> AgentPool :
391413 """Initialize an AgentPool object with name and attach it to internal context.
392414
393- Note: As a read only property, name would be ignored when serialized.
394-
395415 :return: the AgentPool object
396416 """
397- # Initialize a AgentPool object with name.
398- agentpool = self .models .AgentPool ()
399- # Note: As a read only property, name would be ignored when serialized.
400- # Set the name property by explicit assignment, otherwise it will be ignored by initialization.
401- agentpool .name = self .context .get_nodepool_name ()
417+ if self .agentpool_decorator_mode == AgentPoolDecoratorMode .MANAGED_CLUSTER :
418+ # Note: As a required property, name must be provided during initialization.
419+ agentpool = self .models .UnifiedAgentPoolModel (name = self .context .get_nodepool_name ())
420+ else :
421+ # Note: As a read only property, name would be ignored when serialized.
422+ # Set the name property by explicit assignment, otherwise it will be ignored by initialization.
423+ agentpool = self .models .UnifiedAgentPoolModel ()
424+ agentpool .name = self .context .get_nodepool_name ()
402425
403- # attach mc to AKSContext
426+ # attach agentpool to AKSAgentPoolContext
404427 self .context .attach_agentpool (agentpool )
405428 return agentpool
406429
0 commit comments