2929 read_file_content ,
3030 sdk_no_wait ,
3131)
32+ from azure .core import MatchConditions
3233from knack .log import get_logger
3334from knack .prompting import prompt_y_n
3435
5960
6061logger = get_logger (__name__ )
6162
63+
64+ def _get_etag_match_condition (if_match , if_none_match ):
65+ """Convert if_match/if_none_match to etag/match_condition for the new SDK."""
66+ if if_match is not None :
67+ return if_match , MatchConditions .IfNotModified
68+ if if_none_match is not None :
69+ return if_none_match , MatchConditions .IfMissing
70+ return None , None
71+
72+
6273# type variables
6374AgentPool = TypeVar ("AgentPool" )
6475AgentPoolsOperations = TypeVar ("AgentPoolsOperations" )
@@ -1184,7 +1195,7 @@ def get_update_enable_disable_cluster_autoscaler_and_min_max_count_vmsize_vms(
11841195 # if vm_size is not specified, use the size from the existing agentpool profile
11851196 if vm_size is None :
11861197 if autoscale_profile :
1187- vm_size = autoscale_profile .size
1198+ vm_size = autoscale_profile [ 0 ] .size
11881199
11891200 if manual_scale_profile :
11901201 vm_size = manual_scale_profile [0 ].size
@@ -1481,11 +1492,11 @@ def set_up_virtual_machines_profile(self, agentpool: AgentPool) -> AgentPool:
14811492 if enable_auto_scaling :
14821493 agentpool .virtual_machines_profile = self .models .VirtualMachinesProfile (
14831494 scale = self .models .ScaleProfile (
1484- autoscale = self .models .AutoScaleProfile (
1495+ autoscale = [ self .models .AutoScaleProfile (
14851496 size = sizes [0 ],
14861497 min_count = min_count ,
14871498 max_count = max_count ,
1488- )
1499+ )]
14891500 )
14901501 )
14911502 else :
@@ -1549,10 +1560,26 @@ def set_up_machines_mode(self, agentpool: AgentPool) -> AgentPool:
15491560 if mode == CONST_NODEPOOL_MODE_MACHINES :
15501561 agentpool .mode = CONST_NODEPOOL_MODE_MACHINES
15511562 # Make sure all other attributes are None
1552- for attr in vars (agentpool ):
1553- if attr != 'name' and attr != 'mode' and not attr .startswith ('_' ):
1554- if hasattr (agentpool , attr ):
1563+ # Check properties sub-model first (AgentPool), then flat fields (ManagedClusterAgentPoolProfile)
1564+ props = getattr (agentpool , 'properties' , None )
1565+ rest_fields = getattr (props , '_attr_to_rest_field' , None ) if props is not None else None
1566+ if rest_fields is not None :
1567+ target , fields = props , rest_fields
1568+ else :
1569+ rest_fields = getattr (agentpool , '_attr_to_rest_field' , None )
1570+ if rest_fields is not None and 'mode' in rest_fields :
1571+ target , fields = agentpool , rest_fields
1572+ else :
1573+ target , fields = None , None
1574+ if target is not None :
1575+ for attr in list (fields .keys ()):
1576+ if attr not in ('name' , 'mode' ):
15551577 setattr (agentpool , attr , None )
1578+ else :
1579+ for attr in vars (agentpool ):
1580+ if attr != 'name' and attr != 'mode' and not attr .startswith ('_' ):
1581+ if hasattr (agentpool , attr ):
1582+ setattr (agentpool , attr , None )
15561583
15571584 return agentpool
15581585
@@ -1710,15 +1737,18 @@ def set_up_blue_green_upgrade_settings(self, agentpool: AgentPool) -> AgentPool:
17101737 def add_agentpool (self , agentpool : AgentPool ) -> AgentPool :
17111738 """Send request to add a new agentpool."""
17121739 self ._ensure_agentpool (agentpool )
1740+ etag , match_condition = _get_etag_match_condition (
1741+ self .context .get_if_match (), self .context .get_if_none_match ()
1742+ )
17131743 return sdk_no_wait (
17141744 self .context .get_no_wait (),
17151745 self .client .begin_create_or_update ,
17161746 self .context .get_resource_group_name (),
17171747 self .context .get_cluster_name (),
17181748 self .context ._get_nodepool_name (enable_validation = False ),
17191749 agentpool ,
1720- if_match = self . context . get_if_match () ,
1721- if_none_match = self . context . get_if_none_match () ,
1750+ etag = etag ,
1751+ match_condition = match_condition ,
17221752 headers = self .context .get_aks_custom_headers (),
17231753 )
17241754
@@ -2065,11 +2095,11 @@ def update_auto_scaler_properties_vms(self, agentpool: AgentPool) -> AgentPool:
20652095 if update_cluster_autoscaler or enable_cluster_autoscaler :
20662096 agentpool .virtual_machines_profile = self .models .VirtualMachinesProfile (
20672097 scale = self .models .ScaleProfile (
2068- autoscale = self .models .AutoScaleProfile (
2098+ autoscale = [ self .models .AutoScaleProfile (
20692099 size = vm_size ,
20702100 min_count = min_count ,
20712101 max_count = max_count ,
2072- )
2102+ )]
20732103 )
20742104 )
20752105
@@ -2182,15 +2212,18 @@ def update_agentpool(self, agentpool: AgentPool) -> AgentPool:
21822212 """
21832213 self ._ensure_agentpool (agentpool )
21842214
2215+ etag , match_condition = _get_etag_match_condition (
2216+ self .context .get_if_match (), self .context .get_if_none_match ()
2217+ )
21852218 return sdk_no_wait (
21862219 self .context .get_no_wait (),
21872220 self .client .begin_create_or_update ,
21882221 self .context .get_resource_group_name (),
21892222 self .context .get_cluster_name (),
21902223 self .context .get_nodepool_name (),
21912224 agentpool ,
2192- if_match = self . context . get_if_match () ,
2193- if_none_match = self . context . get_if_none_match () ,
2225+ etag = etag ,
2226+ match_condition = match_condition ,
21942227 headers = self .context .get_aks_custom_headers (),
21952228 )
21962229
@@ -2205,6 +2238,9 @@ def add_agentpool(self, agentpool: AgentPool) -> AgentPool:
22052238 """
22062239 self ._ensure_agentpool (agentpool )
22072240
2241+ etag , match_condition = _get_etag_match_condition (
2242+ self .context .get_if_match (), self .context .get_if_none_match ()
2243+ )
22082244 return sdk_no_wait (
22092245 self .context .get_no_wait (),
22102246 self .client .begin_create_or_update ,
@@ -2213,7 +2249,7 @@ def add_agentpool(self, agentpool: AgentPool) -> AgentPool:
22132249 # validated in "init_agentpool", skip to avoid duplicate api calls
22142250 self .context ._get_nodepool_name (enable_validation = False ),
22152251 agentpool ,
2216- if_match = self . context . get_if_match () ,
2217- if_none_match = self . context . get_if_none_match () ,
2252+ etag = etag ,
2253+ match_condition = match_condition ,
22182254 headers = self .context .get_aks_custom_headers (),
22192255 )
0 commit comments