|
14 | 14 | from knack.prompting import NoTTYException, prompt_y_n
|
15 | 15 | from knack.util import CLIError
|
16 | 16 | from azure.cli.command_modules.acs._roleassignments import add_role_assignment
|
17 |
| -from azure.mgmt.core.tools import is_valid_resource_id, parse_resource_id |
| 17 | +from azure.mgmt.core.tools import parse_resource_id |
18 | 18 |
|
19 | 19 |
|
20 | 20 | from azext_fleet._client_factory import get_provider_client
|
@@ -156,32 +156,24 @@ def _load_kubernetes_configuration(filename):
|
156 | 156 | raise CLIError(f'Error parsing {filename} ({str(ex)})') from ex
|
157 | 157 |
|
158 | 158 |
|
159 |
| -def assign_network_contributor_role_to_subnet(cmd, objectId, subnet_id): |
160 |
| - resource_client = get_provider_client(cmd.cli_ctx) |
161 |
| - provider = resource_client.providers.get("Microsoft.ContainerService") |
162 |
| - |
163 |
| - # provider registration state being is checked to ensure that the Fleet service principal is available |
164 |
| - # to create the role assignment on the subnet |
165 |
| - if provider.registration_state != 'Registered': |
166 |
| - raise CLIError("The Microsoft.ContainerService resource provider is not registered." |
167 |
| - "Run `az provider register -n Microsoft.ContainerService --wait`.") |
168 |
| - |
169 |
| - if not add_role_assignment(cmd, 'Network Contributor', objectId, scope=subnet_id): |
| 159 | +def assign_network_contributor_role_to_subnet(cmd, object_id, subnet_id): |
| 160 | + if not add_role_assignment(cmd, 'Network Contributor', object_id, scope=subnet_id): |
170 | 161 | logger.warning("Failed to create Network Contributor role assignment on the subnet.\n"
|
171 | 162 | "Please ensure you have sufficient permissions to assign roles on subnet %s.", subnet_id)
|
172 | 163 |
|
173 | 164 |
|
174 | 165 | def get_msi_object_id(cmd, msi_resource_id):
|
175 |
| - try: |
176 |
| - if not is_valid_resource_id(msi_resource_id): |
177 |
| - raise CLIError(f"The provided managed identity resource ID '{msi_resource_id}' is not valid.") |
178 |
| - parsed = parse_resource_id(msi_resource_id) |
179 |
| - subscription_id = parsed['subscription'] |
180 |
| - resource_group_name = parsed['resource_group'] |
181 |
| - msi_name = parsed['resource_name'] |
182 |
| - msi_client = get_msi_client(cmd.cli_ctx, subscription_id=subscription_id) |
183 |
| - msi = msi_client.user_assigned_identities.get(resource_name=msi_name, |
184 |
| - resource_group_name=resource_group_name) |
185 |
| - return msi.principal_id |
186 |
| - except Exception as ex: |
187 |
| - raise CLIError(f"Failed to get object ID for managed identity {msi_resource_id}: {str(ex)}") from ex |
| 166 | + parsed = parse_resource_id(msi_resource_id) |
| 167 | + subscription_id = parsed['subscription'] |
| 168 | + resource_group_name = parsed['resource_group'] |
| 169 | + msi_name = parsed['resource_name'] |
| 170 | + msi_client = get_msi_client(cmd.cli_ctx, subscription_id=subscription_id) |
| 171 | + msi = msi_client.user_assigned_identities.get(resource_name=msi_name, |
| 172 | + resource_group_name=resource_group_name) |
| 173 | + return msi.principal_id |
| 174 | + |
| 175 | + |
| 176 | +def is_rp_registered(cmd): |
| 177 | + resource_client = get_provider_client(cmd.cli_ctx) |
| 178 | + provider = resource_client.providers.get("Microsoft.ContainerService") |
| 179 | + return provider.registration_state == 'Registered' |
0 commit comments