Skip to content

Commit e015162

Browse files
committed
Fix style issues and datetime deprecation warning in safeguards
1 parent 67c2470 commit e015162

File tree

1 file changed

+15
-13
lines changed
  • src/azure-cli/azure/cli/command_modules/acs

1 file changed

+15
-13
lines changed

src/azure-cli/azure/cli/command_modules/acs/custom.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import yaml
4545
from azure.cli.command_modules.acs._client_factory import (
4646
cf_agent_pools,
47-
get_container_service_client,
4847
)
4948
from azure.cli.command_modules.acs._consts import (
5049
ADDONS,
@@ -197,35 +196,38 @@ def _build_arguments_schema(cls, *args, **kwargs):
197196
class AKSSafeguardsCreateCustom(Create):
198197

199198
def pre_operations(self):
200-
from azure.cli.core.azclierror import ClientRequestError
201199
from azure.cli.core.util import send_raw_request
202-
200+
203201
# Validate and set managed cluster argument first
204202
_validate_and_set_managed_cluster_argument(self.ctx)
205-
203+
206204
# Check if Deployment Safeguards already exists
207205
resource_group_name = self.ctx.args.resource_group
208206
cluster_name = self.ctx.args.cluster_name
209207
subscription_id = self.ctx.subscription_id
210-
208+
211209
# 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+
214216
# Check if resource already exists
215217
resource_exists = False
216218
try:
217219
response = send_raw_request(self.ctx.cli_ctx, "GET", safeguards_url)
218220
if response.status_code == 200:
219221
resource_exists = True
220-
except Exception:
222+
except Exception: # pylint: disable=broad-exception-caught
221223
# 404 or any error means resource doesn't exist
222224
pass
223-
225+
224226
if resource_exists:
225227
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."
229231
)
230232

231233
@classmethod
@@ -1384,7 +1386,7 @@ def _update_upgrade_settings(cmd, instance,
13841386
f"{upgrade_override_until} is not a valid datatime format."
13851387
)
13861388
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)
13881390
if existing_until is None or existing_until.timestamp() < default_extended_until.timestamp():
13891391
instance.upgrade_settings.override_settings.until = default_extended_until
13901392
return instance

0 commit comments

Comments
 (0)