0

对于下面的 JSON,我正在尝试获取特定资源类型的位置列表。

这个命令:

az provider list --query "[?namespace=='Microsoft.Compute']" 

最后给了我示例输出(太多了,无法包括所有)。然后如何查询特定的资源类型?我尝试了以下方法,但它不起作用:

az provider list --query "[?contains(namespace, 'Microsoft.Compute')] | [?contains(resourceType, 'virtualMachines']"

第一个命令的示例输出:

[
  {
    "id": "/subscriptions/fed7f475-6055-4e3c-8529-c1345df70589/providers/Microsoft.Compute",
    "namespace": "Microsoft.Compute",
    "registrationState": "Registered",
    "resourceTypes": [
      {
        "aliases": null,
        "apiVersions": [
          "2017-03-30",
          "2016-08-30",
          "2016-04-30-preview",
          "2016-03-30",
          "2015-06-15",
          "2015-05-01-preview"
        ],
        "locations": [
          "East US",
          "East US 2",
          "West US",
          "Central US",
          "North Central US",
          "South Central US",
          "North Europe",
          "West Europe",
          "East Asia",
          "Southeast Asia",
          "Japan East",
          "Japan West",
          "Australia East",
          "Australia Southeast",
          "Brazil South",
          "South India",
          "Central India",
          "West India",
          "Canada Central",
          "Canada East",
          "West US 2",
          "West Central US",
          "UK South",
          "UK West",
          "Korea Central",
          "Korea South"
        ],
        "properties": null,
        "resourceType": "availabilitySets"
      },
  }
]
4

1 回答 1

2

这应该有效:

az provider list --query "[?namespace=='Microsoft.Compute'].resourceTypes[].{resourceType:resourceType, locations:locations} | [?resourceType=='virtualMachines'] | [0].locations"

我没有声称这是最简单的方法 - 我自己还在学习 jmespath :)

于 2017-09-27T02:12:49.713 回答