|
44 | 44 | import yaml |
45 | 45 | from azure.cli.command_modules.acs._client_factory import ( |
46 | 46 | cf_agent_pools, |
47 | | - get_container_service_client, |
48 | 47 | ) |
49 | 48 | from azure.cli.command_modules.acs._consts import ( |
50 | 49 | ADDONS, |
@@ -197,35 +196,38 @@ def _build_arguments_schema(cls, *args, **kwargs): |
197 | 196 | class AKSSafeguardsCreateCustom(Create): |
198 | 197 |
|
199 | 198 | def pre_operations(self): |
200 | | - from azure.cli.core.azclierror import ClientRequestError |
201 | 199 | from azure.cli.core.util import send_raw_request |
202 | | - |
| 200 | + |
203 | 201 | # Validate and set managed cluster argument first |
204 | 202 | _validate_and_set_managed_cluster_argument(self.ctx) |
205 | | - |
| 203 | + |
206 | 204 | # Check if Deployment Safeguards already exists |
207 | 205 | resource_group_name = self.ctx.args.resource_group |
208 | 206 | cluster_name = self.ctx.args.cluster_name |
209 | 207 | subscription_id = self.ctx.subscription_id |
210 | | - |
| 208 | + |
211 | 209 | # Construct the URL to check if safeguards already exists |
212 | | - safeguards_url = f"https://management.azure.com/subscriptions/{subscription_id}/resourceGroups/{resource_group_name}/providers/Microsoft.ContainerService/managedClusters/{cluster_name}/providers/Microsoft.ContainerService/deploymentSafeguards/default?api-version=2025-05-02-preview" |
213 | | - |
| 210 | + safeguards_url = ( |
| 211 | + "https://management.azure.com/subscriptions/{}/resourceGroups/{}/providers/" |
| 212 | + "Microsoft.ContainerService/managedClusters/{}/providers/Microsoft.ContainerService/" |
| 213 | + "deploymentSafeguards/default?api-version=2025-05-02-preview" |
| 214 | + ).format(subscription_id, resource_group_name, cluster_name) |
| 215 | + |
214 | 216 | # Check if resource already exists |
215 | 217 | resource_exists = False |
216 | 218 | try: |
217 | 219 | response = send_raw_request(self.ctx.cli_ctx, "GET", safeguards_url) |
218 | 220 | if response.status_code == 200: |
219 | 221 | resource_exists = True |
220 | | - except Exception: |
| 222 | + except Exception: # pylint: disable=broad-exception-caught |
221 | 223 | # 404 or any error means resource doesn't exist |
222 | 224 | pass |
223 | | - |
| 225 | + |
224 | 226 | if resource_exists: |
225 | 227 | raise ClientRequestError( |
226 | | - f"Deployment Safeguards instance already exists for this cluster. " |
227 | | - f"Please use 'az aks safeguards update' to modify the configuration, " |
228 | | - f"or 'az aks safeguards delete' to remove it before creating a new one." |
| 228 | + "Deployment Safeguards instance already exists for this cluster. " |
| 229 | + "Please use 'az aks safeguards update' to modify the configuration, " |
| 230 | + "or 'az aks safeguards delete' to remove it before creating a new one." |
229 | 231 | ) |
230 | 232 |
|
231 | 233 | @classmethod |
@@ -1384,7 +1386,7 @@ def _update_upgrade_settings(cmd, instance, |
1384 | 1386 | f"{upgrade_override_until} is not a valid datatime format." |
1385 | 1387 | ) |
1386 | 1388 | elif force_upgrade: |
1387 | | - default_extended_until = datetime.datetime.utcnow() + datetime.timedelta(days=3) |
| 1389 | + default_extended_until = datetime.datetime.now(datetime.UTC) + datetime.timedelta(days=3) |
1388 | 1390 | if existing_until is None or existing_until.timestamp() < default_extended_until.timestamp(): |
1389 | 1391 | instance.upgrade_settings.override_settings.until = default_extended_until |
1390 | 1392 | return instance |
|
0 commit comments