0

I am trying to use Microsoft.Azure.Management.Compute's ComputeManagementClient to query for ResourceSKUs. But I am unable to provide the correct value for the filter parameter. Without a filter, the response is pretty large, and I want to reduce it by filtering with resourceType = virtualMachines.

More specifically this is my code:

ComputeManagementClient computeManagementClient = new ComputeManagementClient(credentials);
computeManagementClient.SubscriptionId = "**********";
string filter = "resourceType eq 'virtualMachines'";  // Doesn't work. All results are returned.
// string filter = "$filter=resourceType eq 'virtualMachines'";  // Doesn't work. All results are returned.
// string filter = "resourceType eq virtualMachines";  // Doesn't work. All results are returned.
// string filter = "resourceType eq 'Microsoft.Compute/virtualMachines'";  // Doesn't work. All results are returned.
// string filter = "resourceType = 'virtualMachines'";  // Doesn't work. All results are returned.
// string filter = "resourceType='virtualMachines'";  // Doesn't work. All results are returned.
IPage<ResourceSku> resourceSkus = await computeManagementClient.ResourceSkus.ListAsync(filter: filter);

I also tried using OData.FilterString.Generate to generate the filter string:

Expression<Func<ResourceSku, bool>> filterPredicate = x => x.ResourceType.Equals("virtualMachines", StringComparison.OrdinalIgnoreCase);
string filter = FilterString.Generate(filterPredicate);
IPage<ResourceSku> resourceSkus = await computeManagementClient.ResourceSkus.ListAsync(filter: filter);

Any idea what is the correct format?

Turbo
  • 2,179
  • 18
  • 38
  • 1
    Have you referred to https://github.com/Azure/azure-sdk-for-go/issues/6393#issuecomment-559314469 – Jim Xu Jan 09 '20 at 06:49
  • Thanks! It sounds like they only support filter by location parameter for now. – Turbo Jan 09 '20 at 06:57
  • 1
    I think so. The [Azure feedback](https://feedback.azure.com/forums/216843-virtual-machines/suggestions/37154362-impossible-to-filter-the-azure-rest-api-sku-inform) says that the api only supports filter by location – Jim Xu Jan 09 '20 at 06:59
  • Do you have any other concerns? If you have no other concerns, could you please accept the answer? It may help more people. – Jim Xu Jan 09 '20 at 07:00
  • Update: I filed this as a bug on [github](https://github.com/Azure/azure-sdk-for-net/issues/9428). It's now marked as closed mentioning this is a feature request. If you would like this supported, upvote the feature [here](https://feedback.azure.com/forums/216843-virtual-machines/suggestions/39435124-add-additional-filter-options-to-compute-resource). – Turbo Jan 15 '20 at 19:29

1 Answers1

1

According to my research, the ResourceSkus API just support filter by region. For more details, please refer to the feedback and the article

Jim Xu
  • 21,610
  • 2
  • 19
  • 39