简体   繁体   中英

Is there a way to get the maximum number of virtual machines that can be created on your Azure account using the Azure Python SDK or the API?

I am trying to make a python program that takes the current number of virtual machines from my account and the maximum number of VMs that can be created per account or per region to see how many new VMs I can create. I used ComputeManagementClient to get the current VMs, but I don't find anything in the documentation ( https://learn.microsoft.com/en-us/python/api/overview/azure/?view=azure-python ) about a way to take the limit number of VMs. Any tips or ideas?

Azure REST API:

You can use the Azure Quota REST API (Preview) to query and manage service limits (quota) for the resources programmatically. The response from the Quota - List API can be leveraged to submit quota update requests as well. Note that apart from support in REST API, quota management is available in several interfaces and languages.

Azure Python SDK:

The same is made available in the Python SDK via the UsageOperations class . The list method gets, for the specified location, the current compute resource usage information as well as the limits for compute resources under the subscription.

So you should be able to do something similar to:

for r in compute_client.usage.list(<location>):
       print(
           f"\nName: {r.name.value}\nCurrent Value: {r.current_value}\nLimit: {r.limit}")

that would yield results like:

Name: availabilitySets
Current Value: 1
Limit: 2500

Name: cores
Current Value: 20
Limit: 100

Name: virtualMachines
Current Value: 11
Limit: 25000

Name: virtualMachineScaleSets
Current Value: 0
Limit: 2500

..
..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM