首页 > 解决方案 > 使用 azure cli 启动解除分配的 VM (3-6) 大约需要半小时

问题描述

我编写了一个 shell 脚本,其中包含一个 azure cli 命令,并希望启动由其标记标识的已释放 VM。机器在很短的时间(大约 1-2 分钟)后启动,但命令继续运行并在大约半小时后完成。

该命令如下所示:

az vm start \
  --ids $(az resource list \
  --tag "environment=$env" \
  --query "[?type=='Microsoft.Compute/virtualMachines'].id" \
  -o tsv)

在调试模式下,我看到它重复了这个块:

00:00:27.352  DEBUG: urllib3.connectionpool : https://management.azure.com:443 "GET /subscriptions/****/providers/Microsoft.Compute/locations/westeurope/operations/hduske73-sg43-156df-afg4-4jefasfgs?api-version=2019-03-01 HTTP/1.1" 200 None
00:00:27.352  DEBUG: msrest.http_logger : Response status: 200
00:00:27.352  DEBUG: msrest.http_logger : Response headers:
00:00:27.352  DEBUG: msrest.http_logger :     'Cache-Control': 'no-cache'
00:00:27.352  DEBUG: msrest.http_logger :     'Pragma': 'no-cache'
00:00:27.352  DEBUG: msrest.http_logger :     'Transfer-Encoding': 'chunked'
00:00:27.352  DEBUG: msrest.http_logger :     'Content-Type': 'application/json; charset=utf-8'
00:00:27.352  DEBUG: msrest.http_logger :     'Content-Encoding': 'gzip'
00:00:27.352  DEBUG: msrest.http_logger :     'Expires': '-1'
00:00:27.352  DEBUG: msrest.http_logger :     'Retry-After': '9'
00:00:27.352  DEBUG: msrest.http_logger :     'Vary': 'Accept-Encoding'
00:00:27.352  DEBUG: msrest.http_logger :     'x-ms-ratelimit-remaining-resource': 'Microsoft.Compute/GetOperation3Min;14997,Microsoft.Compute/GetOperation30Min;29997'
00:00:27.352  DEBUG: msrest.http_logger :     'Strict-Transport-Security': 'max-age=31536000; includeSubDomains'
00:00:27.352  DEBUG: msrest.http_logger :     'x-ms-request-id': '3876g8d-h383-d8eh-h482-dhu372dfg'
00:00:27.352  DEBUG: msrest.http_logger :     'Server': 'Microsoft-HTTPAPI/2.0, Microsoft-HTTPAPI/2.0'
00:00:27.352  DEBUG: msrest.http_logger :     'x-ms-ratelimit-remaining-subscription-reads': '11938'
00:00:27.352  DEBUG: msrest.http_logger :     'x-ms-correlation-request-id': 'dh3819874-4fb4i3-1435-5215-behxb3819'
00:00:27.352  DEBUG: msrest.http_logger :     'x-ms-routing-request-id': 'GERMANYNORTH:20191031T091214Z:dh3819874-4fb4i3-1435-5215-behxb3819'
00:00:27.352  DEBUG: msrest.http_logger :     'X-Content-Type-Options': 'nosniff'
00:00:27.352  DEBUG: msrest.http_logger :     'Date': 'Thu, 31 Oct 2019 09:12:13 GMT'
00:00:27.352  DEBUG: msrest.http_logger : Response content:
00:00:27.352  DEBUG: msrest.http_logger : {
00:00:27.352    "startTime": "2019-10-31T09:12:02.7728761+00:00",
00:00:27.352    "status": "InProgress",
00:00:27.352    "name": "efu2728392-38f9-2a24-24d2-c214152g1245"
00:00:27.352  }

谁能帮我找到问题?

标签: azureazure-cli

解决方案


我也面临着虚拟机在短时间内启动但命令使用 azure-cli 长时间运行的问题2.0.75。似乎该命令旨在仅围绕 ID 数组循环而不是并行。

MSFT在这里对此进行了澄清。

它现在是设计使然,因为核心层只是围绕 id 数组循环并一个接一个地调用相同的命令。同意我们应该通过并行来改进它。REST 调用是 io-bound 的,因此并行处理会更快地获取命令。


推荐阅读