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?

1

There are 1 answers

0
Bhargavi Annadevara On

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

..
..