Skip to content

Commit 8cec785

Browse files
committed
fix code
1 parent dcf5ef1 commit 8cec785

6 files changed

Lines changed: 163 additions & 91 deletions

File tree

src/aks-preview/azext_aks_preview/_natgateway.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ def configure_nat_gateway_profile(
9797
)
9898

9999
if outbound_ip_prefix_ids is not None:
100-
ManagedClusterNATGatewayProfileOutboundIPPrefixes = models.ManagedClusterNATGatewayProfileOutboundIPPrefixes
100+
ManagedClusterNATGatewayProfileOutboundIpPrefixes = models.ManagedClusterNATGatewayProfileOutboundIpPrefixes
101101
prefix_id_list = [x.strip() for x in outbound_ip_prefix_ids.split(',') if x.strip()]
102-
profile.outbound_ip_prefixes = ManagedClusterNATGatewayProfileOutboundIPPrefixes(
102+
profile.outbound_ip_prefixes = ManagedClusterNATGatewayProfileOutboundIpPrefixes(
103103
public_ip_prefixes=prefix_id_list
104104
)
105105

src/aks-preview/azext_aks_preview/agentpool_decorator.py

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
read_file_content,
3030
sdk_no_wait,
3131
)
32+
from azure.core import MatchConditions
3233
from knack.log import get_logger
3334
from knack.prompting import prompt_y_n
3435

@@ -59,6 +60,16 @@
5960

6061
logger = 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
6374
AgentPool = TypeVar("AgentPool")
6475
AgentPoolsOperations = 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:
@@ -1710,15 +1721,18 @@ def set_up_blue_green_upgrade_settings(self, agentpool: AgentPool) -> AgentPool:
17101721
def add_agentpool(self, agentpool: AgentPool) -> AgentPool:
17111722
"""Send request to add a new agentpool."""
17121723
self._ensure_agentpool(agentpool)
1724+
etag, match_condition = _get_etag_match_condition(
1725+
self.context.get_if_match(), self.context.get_if_none_match()
1726+
)
17131727
return sdk_no_wait(
17141728
self.context.get_no_wait(),
17151729
self.client.begin_create_or_update,
17161730
self.context.get_resource_group_name(),
17171731
self.context.get_cluster_name(),
17181732
self.context._get_nodepool_name(enable_validation=False),
17191733
agentpool,
1720-
if_match=self.context.get_if_match(),
1721-
if_none_match=self.context.get_if_none_match(),
1734+
etag=etag,
1735+
match_condition=match_condition,
17221736
headers=self.context.get_aks_custom_headers(),
17231737
)
17241738

@@ -2065,11 +2079,11 @@ def update_auto_scaler_properties_vms(self, agentpool: AgentPool) -> AgentPool:
20652079
if update_cluster_autoscaler or enable_cluster_autoscaler:
20662080
agentpool.virtual_machines_profile = self.models.VirtualMachinesProfile(
20672081
scale=self.models.ScaleProfile(
2068-
autoscale=self.models.AutoScaleProfile(
2082+
autoscale=[self.models.AutoScaleProfile(
20692083
size=vm_size,
20702084
min_count=min_count,
20712085
max_count=max_count,
2072-
)
2086+
)]
20732087
)
20742088
)
20752089

@@ -2182,15 +2196,18 @@ def update_agentpool(self, agentpool: AgentPool) -> AgentPool:
21822196
"""
21832197
self._ensure_agentpool(agentpool)
21842198

2199+
etag, match_condition = _get_etag_match_condition(
2200+
self.context.get_if_match(), self.context.get_if_none_match()
2201+
)
21852202
return sdk_no_wait(
21862203
self.context.get_no_wait(),
21872204
self.client.begin_create_or_update,
21882205
self.context.get_resource_group_name(),
21892206
self.context.get_cluster_name(),
21902207
self.context.get_nodepool_name(),
21912208
agentpool,
2192-
if_match=self.context.get_if_match(),
2193-
if_none_match=self.context.get_if_none_match(),
2209+
etag=etag,
2210+
match_condition=match_condition,
21942211
headers=self.context.get_aks_custom_headers(),
21952212
)
21962213

@@ -2205,6 +2222,9 @@ def add_agentpool(self, agentpool: AgentPool) -> AgentPool:
22052222
"""
22062223
self._ensure_agentpool(agentpool)
22072224

2225+
etag, match_condition = _get_etag_match_condition(
2226+
self.context.get_if_match(), self.context.get_if_none_match()
2227+
)
22082228
return sdk_no_wait(
22092229
self.context.get_no_wait(),
22102230
self.client.begin_create_or_update,
@@ -2213,7 +2233,7 @@ def add_agentpool(self, agentpool: AgentPool) -> AgentPool:
22132233
# validated in "init_agentpool", skip to avoid duplicate api calls
22142234
self.context._get_nodepool_name(enable_validation=False),
22152235
agentpool,
2216-
if_match=self.context.get_if_match(),
2217-
if_none_match=self.context.get_if_none_match(),
2236+
etag=etag,
2237+
match_condition=match_condition,
22182238
headers=self.context.get_aks_custom_headers(),
22192239
)

src/aks-preview/azext_aks_preview/commands.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,62 +100,62 @@ def _patch_custom_cas_in_security_profile(security_profile):
100100
def load_command_table(self, _):
101101
managed_clusters_sdk = CliCommandType(
102102
operations_tmpl="azext_aks_preview.vendored_sdks.azure_mgmt_preview_aks."
103-
"operations._managed_clusters_operations#ManagedClustersOperations.{}",
103+
"operations._operations#ManagedClustersOperations.{}",
104104
operation_group="managed_clusters",
105105
client_factory=cf_managed_clusters,
106106
)
107107

108108
agent_pools_sdk = CliCommandType(
109109
operations_tmpl="azext_aks_preview.vendored_sdks.azure_mgmt_preview_aks."
110-
"operations._agent_pools_operations#AgentPoolsOperations.{}",
110+
"operations._operations#AgentPoolsOperations.{}",
111111
client_factory=cf_managed_clusters,
112112
)
113113

114114
managed_namespaces_sdk = CliCommandType(
115115
operations_tmpl="azext_aks_preview.vendored_sdks.azure_mgmt_preview_aks."
116-
"operations._managed_namespaces_operations#ManagedNamespacesOperations.{}",
116+
"operations._operations#ManagedNamespacesOperations.{}",
117117
client_factory=cf_managed_namespaces,
118118
)
119119

120120
machines_sdk = CliCommandType(
121121
operations_tmpl="azext_aks_preview.vendored_sdks.azure_mgmt_preview_aks."
122-
"operations._machine_operations#MachinesOperations.{}",
122+
"operations._operations#MachinesOperations.{}",
123123
client_factory=cf_managed_clusters,
124124
)
125125

126126
operations_sdk = CliCommandType(
127127
operations_tmpl="azext_aks_preview.vendored_sdks.azure_mgmt_preview_aks."
128-
"operations._operationstatusresult_operations#OperationStatusResultOperations.{}",
128+
"operations._operations#OperationStatusResultOperations.{}",
129129
client_factory=cf_operations,
130130
)
131131

132132
maintenance_configuration_sdk = CliCommandType(
133133
operations_tmpl="azext_aks_preview.vendored_sdks.azure_mgmt_preview_aks."
134-
"operations._maintenance_configurations_operations#MaintenanceConfigurationsOperations.{}",
134+
"operations._operations#MaintenanceConfigurationsOperations.{}",
135135
client_factory=cf_maintenance_configurations,
136136
)
137137

138138
nodepool_snapshot_sdk = CliCommandType(
139139
operations_tmpl="azext_aks_preview.vendored_sdks.azure_mgmt_preview_aks."
140-
"operations._snapshots_operations#SnapshotsOperations.{}",
140+
"operations._operations#SnapshotsOperations.{}",
141141
client_factory=cf_nodepool_snapshots,
142142
)
143143

144144
mc_snapshot_sdk = CliCommandType(
145145
operations_tmpl="azext_aks_preview.vendored_sdks.azure_mgmt_preview_aks."
146-
"operations._managed_clusters_snapshots_operations#ManagedClusterSnapshotsOperations.{}",
146+
"operations._operations#ManagedClusterSnapshotsOperations.{}",
147147
client_factory=cf_mc_snapshots,
148148
)
149149

150150
jwt_authenticators_sdk = CliCommandType(
151151
operations_tmpl="azext_aks_preview.vendored_sdks.azure_mgmt_preview_aks."
152-
"operations._jwt_authenticators_operations#JWTAuthenticatorsOperations.{}",
152+
"operations._operations#JWTAuthenticatorsOperations.{}",
153153
client_factory=cf_jwt_authenticators,
154154
)
155155

156156
vm_skus_sdk = CliCommandType(
157157
operations_tmpl="azext_aks_preview.vendored_sdks.azure_mgmt_preview_aks."
158-
"operations._vm_skus_operations#VmSkusOperations.{}",
158+
"operations._operations#VmSkusOperations.{}",
159159
client_factory=cf_vm_skus,
160160
)
161161

src/aks-preview/azext_aks_preview/custom.py

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@
170170
send_raw_request,
171171
shell_safe_json_parse,
172172
)
173+
from azure.core import MatchConditions
173174
from azure.core.exceptions import (
174175
ResourceNotFoundError,
175176
HttpResponseError,
@@ -184,6 +185,15 @@
184185
logger = get_logger(__name__)
185186

186187

188+
def _get_etag_match_condition(if_match, if_none_match):
189+
"""Convert if_match/if_none_match to etag/match_condition for the new SDK."""
190+
if if_match is not None:
191+
return if_match, MatchConditions.IfNotModified
192+
if if_none_match is not None:
193+
return if_none_match, MatchConditions.IfMissing
194+
return None, None
195+
196+
187197
def wait_then_open(url):
188198
"""
189199
Waits for a bit then opens a URL. Useful for waiting for a proxy to come up, and then open the URL.
@@ -1463,12 +1473,15 @@ def aks_delete(cmd, client, resource_group_name, name, no_wait=False,
14631473
logger.warning(
14641474
"The '--if-none-match' option is not applicable to delete operations and will be ignored."
14651475
)
1476+
etag = if_match
1477+
match_condition = MatchConditions.IfNotModified if if_match is not None else None
14661478
return sdk_no_wait(
14671479
no_wait,
14681480
client.begin_delete,
14691481
resource_group_name,
14701482
name,
1471-
if_match=if_match,
1483+
etag=etag,
1484+
match_condition=match_condition,
14721485
ignore_pod_disruption_budget=ignore_pod_disruption_budget,
14731486
)
14741487

@@ -1509,15 +1522,24 @@ def _remove_nulls(managed_clusters):
15091522
for managed_cluster in managed_clusters:
15101523
for attr in attrs:
15111524
if getattr(managed_cluster, attr, None) is None:
1512-
delattr(managed_cluster, attr)
1525+
try:
1526+
delattr(managed_cluster, attr)
1527+
except AttributeError:
1528+
pass
15131529
if managed_cluster.agent_pool_profiles is not None:
15141530
for ap_profile in managed_cluster.agent_pool_profiles:
15151531
for attr in ap_attrs:
15161532
if getattr(ap_profile, attr, None) is None:
1517-
delattr(ap_profile, attr)
1533+
try:
1534+
delattr(ap_profile, attr)
1535+
except AttributeError:
1536+
pass
15181537
for attr in sp_attrs:
15191538
if getattr(managed_cluster.service_principal_profile, attr, None) is None:
1520-
delattr(managed_cluster.service_principal_profile, attr)
1539+
try:
1540+
delattr(managed_cluster.service_principal_profile, attr)
1541+
except AttributeError:
1542+
pass
15211543
return managed_clusters
15221544

15231545

@@ -1546,14 +1568,14 @@ def aks_get_credentials(
15461568
raise InvalidArgumentValueError("--format can only be specified when requesting clusterUser credential.")
15471569
if admin:
15481570
credentialResults = client.list_cluster_admin_credentials(
1549-
resource_group_name, name, serverType, headers=headers)
1571+
resource_group_name, name, server_fqdn=serverType, headers=headers)
15501572
else:
15511573
if user.lower() == 'clusteruser':
15521574
credentialResults = client.list_cluster_user_credentials(
1553-
resource_group_name, name, serverType, credential_format, headers=headers)
1575+
resource_group_name, name, server_fqdn=serverType, format=credential_format, headers=headers)
15541576
elif user.lower() == 'clustermonitoringuser':
15551577
credentialResults = client.list_cluster_monitoring_user_credentials(
1556-
resource_group_name, name, serverType, headers=headers)
1578+
resource_group_name, name, server_fqdn=serverType, headers=headers)
15571579
else:
15581580
raise InvalidArgumentValueError("The value of option --user is invalid.")
15591581

@@ -1769,15 +1791,16 @@ def aks_upgrade(cmd,
17691791

17701792
headers = get_aks_custom_headers(aks_custom_headers)
17711793

1794+
etag, match_condition = _get_etag_match_condition(if_match, if_none_match)
17721795
return sdk_no_wait(
17731796
no_wait,
17741797
client.begin_create_or_update,
17751798
resource_group_name,
17761799
name,
17771800
instance,
17781801
headers=headers,
1779-
if_match=if_match,
1780-
if_none_match=if_none_match)
1802+
etag=etag,
1803+
match_condition=match_condition)
17811804

17821805

17831806
def _update_upgrade_settings(cmd, instance,
@@ -2245,6 +2268,7 @@ def aks_agentpool_upgrade(cmd,
22452268
allow_appending_values_to_same_key=True,
22462269
)
22472270

2271+
etag, match_condition = _get_etag_match_condition(if_match, if_none_match)
22482272
return sdk_no_wait(
22492273
no_wait,
22502274
client.begin_create_or_update,
@@ -2253,8 +2277,8 @@ def aks_agentpool_upgrade(cmd,
22532277
nodepool_name,
22542278
instance,
22552279
headers=aks_custom_headers,
2256-
if_match=if_match,
2257-
if_none_match=if_none_match,
2280+
etag=etag,
2281+
match_condition=match_condition,
22582282
)
22592283

22602284

@@ -2481,13 +2505,16 @@ def aks_agentpool_delete(cmd, # pylint: disable=unused-argument
24812505
"use 'aks nodepool list' to get current node pool list"
24822506
)
24832507

2508+
etag = if_match
2509+
match_condition = MatchConditions.IfNotModified if if_match is not None else None
24842510
return sdk_no_wait(
24852511
no_wait,
24862512
client.begin_delete,
24872513
resource_group_name,
24882514
cluster_name,
24892515
nodepool_name,
2490-
if_match=if_match,
2516+
etag=etag,
2517+
match_condition=match_condition,
24912518
ignore_pod_disruption_budget=ignore_pod_disruption_budget,
24922519
)
24932520

src/aks-preview/azext_aks_preview/jwtauthenticator.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,10 @@ def construct_jwt_authenticator(cmd, raw_parameters):
114114

115115
# Create JWT authenticator properties from config
116116
try:
117-
properties = JWTAuthenticatorProperties.from_dict(config)
117+
if hasattr(JWTAuthenticatorProperties, 'from_dict'):
118+
properties = JWTAuthenticatorProperties.from_dict(config)
119+
else:
120+
properties = JWTAuthenticatorProperties(config)
118121
except AttributeError as e:
119122
raise InvalidArgumentValueError(
120123
f"JWT authenticator model does not support from_dict method: {str(e)}"

0 commit comments

Comments
 (0)