azure-sdk-for-python icon indicating copy to clipboard operation
azure-sdk-for-python copied to clipboard

Subscriptions class does not return associated tags

Open tanjoht opened this issue 3 years ago • 10 comments

  • Package Name: azure-mgmt-resource
  • Package Version: 22.0.0
  • Operating System: mac
  • Python Version: 3.10

Describe the bug The subscriptions class in the azure-mgmt-resource module does not return the tags

To Reproduce Steps to reproduce the behavior: from azure.mgmt.resource.subscriptions import SubscriptionClient from azure.identity import DefaultAzureCredential

subscriptionClient = SubscriptionClient(loginCredentials) subscriptionObjectList = subscriptionClient.subscriptions.list()

for subscriptionObject in subscriptionObjectList: print(subscriptionObject)

{'additional_properties': {}, 'id': '/subscriptions/f5f8d7b7-8edf-xx', 'subscription_id': 'f5f8d7b7-8edf-4fd0-xx', 'display_name': 'Visual Studio Professional Subscription', 'tenant_id': '5d3e2773-e07f-xx', 'state': 'Enabled', 'subscription_policies': <azure.mgmt.resource.subscriptions.v2021_01_01.models.models_py3.SubscriptionPolicies object at 0x106f89c60>, 'authorization_source': 'RoleBased', 'managed_by_tenants': [], **'tags': None_**}

Expected behavior the tags property should list the tags associated with the subscription

Screenshots If applicable, add screenshots to help explain your problem.

Additional context Add any other context about the problem here.

tanjoht avatar Mar 23 '23 18:03 tanjoht

Hi @tanjoht, thank you for opening an issue! I'll tag some folks who should be able to help and we'll get back to you as soon as possible.

laiapat avatar Mar 23 '23 19:03 laiapat

Thank you for your feedback. This has been routed to the support team for assistance.

ghost avatar Mar 23 '23 19:03 ghost

hi @msyyc any ideas?

It looks like the equivalent REST API is working (although it shows all tags to all resources under the subscription instead of just the subscription itself):

https://learn.microsoft.com/en-us/rest/api/resources/tags/list

tanjoht avatar Mar 24 '23 13:03 tanjoht

hi @changlong-liu saw your post on https://github.com/Azure/azure-sdk-for-python/issues/10240#issuecomment-625681666

I tried to retrieve the subscription tags using the azure-mgmt-resource and was unable to - the tags always showed "None" even though i could see the tags on azure portal. Any ideas whether there is a bug in the response or if I'm making the call incorrectly?

tanjoht avatar Mar 24 '23 20:03 tanjoht

Hi @tanjoht If you just want to retrieve subscription tags, please try the following code:

from azure.mgmt.resource import ResourceManagementClient
resource_client = ResourceManagementClient(credentials, subscription)
resource_client.tags.list()

The SDK release is sometime behind the rest api release, the tags feature has not been added into current azure-mgmt-resource SDK.

Wzb123456789 avatar Mar 27 '23 06:03 Wzb123456789

hi @Wzb123456789. it looks like that API call is similar to the rest API call. It lists all the tags for all resources under that subscription.

Is it possible to list only the tags for the "subscription resource" and not tags for other resources? (ie: AKS cluster tags).

ie: only the tags for: https://portal.azure.com/#@MFC.onmicrosoft.com/resource/subscriptions/SUBSCRIPTION-ID/tags

tanjoht avatar Mar 27 '23 14:03 tanjoht

The SDK API does not have this function yet, you can find a way to get the tags you want from all the tags.

Wzb123456789 avatar Mar 28 '23 05:03 Wzb123456789

Hi @tanjoht. Thank you for opening this issue and giving us the opportunity to assist. We believe that this has been addressed. If you feel that further discussion is needed, please add a comment with the text “/unresolve” to remove the “issue-addressed” label and continue the conversation.

ghost avatar Mar 28 '23 05:03 ghost

Hi @tanjoht, since you haven’t asked that we “/unresolve” the issue, we’ll close this out. If you believe further discussion is needed, please add a comment “/unresolve” to reopen the issue.

ghost avatar Apr 04 '23 10:04 ghost

# NOTE the SubscriptionClient in azure.mgmt.subscription won't work!
from azure.mgmt.resource import SubscriptionClient

related issue https://github.com/Azure/azure-sdk-for-python/issues/22180

kentnsw avatar Jun 16 '23 14:06 kentnsw