Azure cli 说未在命名空间中注册

Azure cli says not registered in namespace

我能够使用 Web 门户在 Azure 中创建 Linux 虚拟机并愉快地通过 SSH 登录,但是我已经搜索了文档并且无法 assemble 一个可以工作的 CLI 命令,因为示例:

$ azure vm quick-create -M newkey.pub -g myresgrp -Q CoreOS --name gaiusvm1 -u gaius -l westeurope -y Linux

这失败了:

error:   The subscription is not registered to use namespace 'Microsoft.Compute'. See https://aka.ms/rps-not-found for how to register subscriptions.
error:   Error information has been recorded to /Users/gaius/.azure/azure.err
error:   vm quick-create command failed

我已验证我的 CLI 使用 azure account list 看到的订阅是 Web 门户也看到的现收现付订阅。

根据我所犯错误页面上的说明:

$ azure provider register Microsoft.Compute

失败:

error:   Namespace Microsoft.Compute Registration took too long to complete
error:   Error information has been recorded to /Users/gaius/.azure/azure.err
error:   provider register command failed

CLI 与门户有何不同,我假设它们实际上会在幕后调用相同的服务,我如何在这个命名空间和任何其他命名空间中注册?

当您使用新订阅时会发生此错误。解决此问题的最简单方法是在 Azure 门户中创建一个 ARM 虚拟机,该门户将为您注册 Microsoft.Compute

如果您使用 azure provider register Microsoft.Compute 注册命名空间,您可能会收到一条错误消息,提示 "Registration took too long to complete"。这是因为注册确实需要一些时间,而 Azure CLI 的超时时间太短了。但是,别担心。最终将在几分钟内注册命名空间。并且,您可以使用以下命令检查注册状态。

azure provider show Microsoft.Compute

你会看到这样的东西。

info:    Executing command provider show
+ Getting provider information
data:    Namespace: Microsoft.Compute
data:    Registration state: Registering
....

几分钟后,当注册状态变为已注册时,您将能够使用 Azure CLI 创建 ARM 虚拟机。