How to restrict Resources count in GET request in AzureRM

三世轮回 提交于 2019-12-11 09:24:26

问题


How to filter the resources count in GET Request in AzureRM ?

For an example in List Virtual Machines in an subscription . We get all the Vm's running in an account .

But I need to get 10 VM's alone in ascending or any sorting order . Is there any filter available like that ?


回答1:


If the sorting order does not matter for you, you can filter the resource count for the top 10 VMs in the GET request below:

I've tried the requests below and tweak resource count for filtering and they all worked as expected.

https://management.azure.com/subscriptions/{subscriptionId}/resources?$filter=resourceType eq 'Microsoft.Compute/virtualmachines'&$top=10&api-version={apiVersion}

Sample response is like below:

{
    "value": [
        {
            "id": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Compute/virtualMachines/{vm}",
            "name": "{vm}",
            "type": "Microsoft.Compute/virtualMachines",
            "location": "{location}"
        },
        {
            "id": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Compute/virtualMachines/{vm}",
            "name": "{vm}",
            "type": "Microsoft.Compute/virtualMachines",
            "location": "{location}"
        }
    ]
}

Hope this helps.




回答2:


You could use the following API.

https://management.azure.com/subscriptions/**********/providers/Microsoft.Compute/virtualmachines?api-version=2017-12-01&top=10

Using $top=10 to filter the top 10 result. See this example.



来源:https://stackoverflow.com/questions/48144625/how-to-restrict-resources-count-in-get-request-in-azurerm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!