Skip to content

Commit dc1a32a

Browse files
{ARO} Update aro module with features from 2025_07_25 API (#32796)
1 parent 7b69f20 commit dc1a32a

26 files changed

+3194
-387
lines changed

src/azure-cli-core/azure/cli/core/profiles/_shared.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def default_api_version(self):
218218
ResourceType.MGMT_IOTHUB: None,
219219
ResourceType.MGMT_IOTDPS: None,
220220
ResourceType.MGMT_IOTCENTRAL: None,
221-
ResourceType.MGMT_ARO: '2023-11-22',
221+
ResourceType.MGMT_ARO: None,
222222
ResourceType.MGMT_DATABOXEDGE: '2021-02-01-preview',
223223
ResourceType.MGMT_CUSTOMLOCATION: '2021-03-15-preview',
224224
ResourceType.MGMT_CONTAINERSERVICE: None,

src/azure-cli/azure/cli/command_modules/aro/__init__.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,27 @@
33
# Licensed under the MIT License. See License.txt in the project root for license information.
44
# --------------------------------------------------------------------------------------------
55

6-
from azure.cli.command_modules.aro._params import load_arguments
7-
from azure.cli.command_modules.aro.commands import load_command_table
86
from azure.cli.core import AzCommandsLoader, ModExtensionSuppress
9-
from azure.cli.core.commands import CliCommandType
10-
from azure.cli.core.profiles import ResourceType
11-
from azure.cli.command_modules.aro._client_factory import cf_aro # pylint: disable=unused-import
12-
from azure.cli.command_modules.aro._help import helps # pylint: disable=unused-import
137

8+
import azure.cli.command_modules.aro._help # pylint: disable=unused-import
149

15-
class AroCommandsLoader(AzCommandsLoader):
1610

11+
class AroCommandsLoader(AzCommandsLoader):
1712
def __init__(self, cli_ctx=None):
13+
from azure.cli.core.commands import CliCommandType
14+
from azure.cli.command_modules.aro._client_factory import cf_aro
1815
aro_custom = CliCommandType(
1916
operations_tmpl='azure.cli.command_modules.aro.custom#{}',
2017
client_factory=cf_aro)
21-
2218
suppress = ModExtensionSuppress(__name__, 'aro', '1.0.0',
2319
reason='Its functionality is included in the core az CLI.',
2420
recommend_remove=True)
2521
super().__init__(cli_ctx=cli_ctx,
2622
suppress_extension=suppress,
27-
custom_command_type=aro_custom,
28-
resource_type=ResourceType.MGMT_ARO)
23+
custom_command_type=aro_custom)
2924

3025
def load_command_table(self, args):
26+
from azure.cli.command_modules.aro.commands import load_command_table
3127
from azure.cli.core.aaz import load_aaz_command_table
3228
try:
3329
from . import aaz
@@ -43,6 +39,7 @@ def load_command_table(self, args):
4339
return self.command_table
4440

4541
def load_arguments(self, command):
42+
from azure.cli.command_modules.aro._params import load_arguments
4643
load_arguments(self, command)
4744

4845

src/azure-cli/azure/cli/command_modules/aro/_aad.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55

66
import time
77

8-
from azure.cli.command_modules.role import graph_client_factory
9-
from azure.cli.command_modules.role import GraphError
8+
from azure.cli.command_modules.role import (
9+
graph_client_factory,
10+
GraphError
11+
)
1012

1113
from knack.log import get_logger
1214

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
# --------------------------------------------------------------------------------------------
5+
6+
import argparse
7+
8+
from azure.cli.core.azclierror import CLIError
9+
10+
11+
# pylint:disable=protected-access
12+
# pylint:disable=too-few-public-methods
13+
class AROPlatformWorkloadIdentityAddAction(argparse._AppendAction):
14+
15+
def __call__(self, parser, namespace, values, option_string=None):
16+
from azure.mgmt.redhatopenshift.models import PlatformWorkloadIdentity
17+
try:
18+
if len(values) != 2:
19+
msg = f"{option_string} requires 2 values in format: `OPERATOR_NAME RESOURCE_ID`"
20+
raise argparse.ArgumentError(self, msg)
21+
22+
operator_name, resource_id = values
23+
parsed = (operator_name, PlatformWorkloadIdentity(resource_id=resource_id))
24+
25+
super().__call__(parser, namespace, parsed, option_string)
26+
27+
except ValueError as e:
28+
raise CLIError(f"usage error: {option_string} NAME ID") from e

src/azure-cli/azure/cli/command_modules/aro/_client_factory.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,7 @@
44
# --------------------------------------------------------------------------------------------
55

66

7-
from azure.cli.core.commands.client_factory import get_mgmt_service_client
8-
from azure.mgmt.redhatopenshift import AzureRedHatOpenShiftClient
9-
10-
117
def cf_aro(cli_ctx, *_):
12-
client = get_mgmt_service_client(
13-
cli_ctx, AzureRedHatOpenShiftClient)
14-
15-
return client
8+
from azure.cli.core.commands.client_factory import get_mgmt_service_client
9+
from azure.mgmt.redhatopenshift import AzureRedHatOpenShiftClient
10+
return get_mgmt_service_client(cli_ctx, AzureRedHatOpenShiftClient)

src/azure-cli/azure/cli/command_modules/aro/_dynamic_validators.py

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,27 @@
33
# Licensed under the MIT License. See License.txt in the project root for license information.
44
# --------------------------------------------------------------------------------------------
55

6-
6+
import collections
77
import ipaddress
88
import re
99
from itertools import tee
1010

11-
from azure.cli.command_modules.aro._validators import validate_vnet, validate_cidr
12-
from azure.cli.command_modules.aro._rbac import has_role_assignment_on_resource
13-
from azure.cli.command_modules.aro.aaz.latest.network.vnet.subnet import Show as subnet_show
14-
from azure.cli.command_modules.aro.aaz.latest.network.vnet import Show as vnet_show
1511
from azure.cli.core.commands.client_factory import get_mgmt_service_client
1612
from azure.cli.core.commands.validators import get_default_location_from_resource_group
1713
from azure.cli.core.profiles import ResourceType
18-
from azure.cli.core.azclierror import CLIInternalError, InvalidArgumentValueError, \
14+
from azure.cli.core.azclierror import (
15+
CLIInternalError,
16+
InvalidArgumentValueError,
1917
RequiredArgumentMissingError
20-
from azure.core.exceptions import ResourceNotFoundError, HttpResponseError
18+
)
19+
from azure.core.exceptions import HttpResponseError, ResourceNotFoundError
2120
from azure.mgmt.core.tools import is_valid_resource_id, parse_resource_id
21+
from azure.cli.command_modules.aro._validators import validate_vnet, validate_cidr
22+
from azure.cli.command_modules.aro._rbac import has_role_assignment_on_resource
23+
from azure.cli.command_modules.aro.aaz.latest.network.vnet.subnet import Show as subnet_show
24+
from azure.cli.command_modules.aro.aaz.latest.network.vnet import Show as vnet_show
25+
2226
from knack.log import get_logger
23-
import azure.cli.command_modules.aro.custom
2427

2528

2629
logger = get_logger(__name__)
@@ -289,15 +292,15 @@ def _validate_cidr_ranges(cmd, namespace):
289292
return _validate_cidr_ranges
290293

291294

292-
def dyn_validate_resource_permissions(service_principle_ids, resources):
295+
def dyn_validate_resource_permissions(service_principal_ids, resources):
293296
prog = get_progress_tracker("Validating resource permissions")
294297

295298
@prog
296299
def _validate_resource_permissions(cmd,
297300
_namespace):
298301
errors = []
299302

300-
for sp_id in service_principle_ids:
303+
for sp_id in service_principal_ids:
301304
for role in sorted(resources):
302305
for resource in resources[role]:
303306
try:
@@ -331,7 +334,8 @@ def _validate_version(cmd,
331334
if namespace.location is None:
332335
get_default_location_from_resource_group(cmd, namespace)
333336

334-
versions = azure.cli.command_modules.aro.custom.aro_get_versions(namespace.client, namespace.location)
337+
from azure.cli.command_modules.aro.custom import aro_get_versions
338+
versions = aro_get_versions(namespace.client, namespace.location)
335339

336340
found = False
337341
for version in versions:
@@ -351,15 +355,47 @@ def _validate_version(cmd,
351355

352356
def validate_cluster_create(version,
353357
resources,
354-
service_principle_ids):
358+
service_principal_ids):
355359
error_object = []
356360

357361
error_object.append(dyn_validate_vnet("vnet"))
358362
error_object.append(dyn_validate_subnet_and_route_tables("master_subnet"))
359363
error_object.append(dyn_validate_subnet_and_route_tables("worker_subnet"))
360364
error_object.append(dyn_validate_cidr_ranges())
361-
error_object.append(dyn_validate_resource_permissions(service_principle_ids, resources))
365+
error_object.append(dyn_validate_resource_permissions(service_principal_ids, resources))
362366
if version is not None:
363367
error_object.append(dyn_validate_version())
364368

365369
return error_object
370+
371+
372+
def dyn_validate_managed_identity_delete_permissions():
373+
prog = get_progress_tracker("Validating Managed Identity Delete Permissions")
374+
375+
@prog
376+
def _validate_managed_identity_delete_permissions(cmd, namespace):
377+
errors = []
378+
managed_identities = namespace.managed_identities
379+
380+
for mi in managed_identities:
381+
parts, auth_client = get_clients(mi, cmd)
382+
validation_errors = validate_resource(auth_client, "Managed Identity", parts, [
383+
"Microsoft.ManagedIdentity/userAssignedIdentities/delete"
384+
])
385+
for error in validation_errors:
386+
errors.append(f"{error[3]} over {mi}")
387+
388+
return errors
389+
390+
return _validate_managed_identity_delete_permissions
391+
392+
393+
def validate_cluster_delete(cmd, delete_identities, managed_identities):
394+
errors = []
395+
396+
if delete_identities:
397+
namespace = collections.namedtuple("Namespace", ["managed_identities"])(managed_identities)
398+
validate_managed_identity_delete = dyn_validate_managed_identity_delete_permissions()
399+
errors.extend(validate_managed_identity_delete(cmd, namespace))
400+
401+
return errors

0 commit comments

Comments
 (0)