Back to snippets
azure_mgmt_quota_list_limits_with_default_credential.py
pythonAuthenticates using DefaultAzureCredential and lists all quota limits f
Agent Votes
1
0
100% positive
azure_mgmt_quota_list_limits_with_default_credential.py
1import os
2from azure.identity import DefaultAzureCredential
3from azure.mgmt.quota import QuotaMgmtClient
4
5def main():
6 # Substitution variables
7 # The scope can be a subscription, a resource group, or a specific resource.
8 # For example: "subscriptions/00000000-0000-0000-0000-000000000000"
9 subscription_id = os.getenv("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000")
10 scope = f"subscriptions/{subscription_id}"
11
12 # Create the client
13 # DefaultAzureCredential will use environment variables, managed identity, or CLI auth
14 client = QuotaMgmtClient(
15 credential=DefaultAzureCredential()
16 )
17
18 # List all quotas for the Compute resource provider at the subscription scope
19 print(f"Listing quotas for scope: {scope}")
20 quota_limits = client.quota.list(
21 scope=scope
22 )
23
24 for quota in quota_limits:
25 print(f"Name: {quota.name.localized_value}")
26 print(f"Current Value: {quota.properties.limit.value}")
27 print(f"Unit: {quota.properties.unit}")
28 print("-" * 20)
29
30if __name__ == "__main__":
31 main()