【问题标题】:Refresh IP address for Azure VM via REST API通过 REST API 刷新 Azure VM 的 IP 地址
【发布时间】:2021-06-09 17:42:36
【问题描述】:

我正在尝试使用您的 REST API 来更改我在 Azure 上的 Ubuntu 虚拟机的 IP。

在 Web 界面中,停止和启动 VM 通常会导致公共 IP 发生变化。但是,仅通过对 API 的 curl 请求停止和启动 VM 不会触发 IP 更改。

我可以使用 GET 请求请求 IP 配置的当前状态(请参阅文档 here),但我找不到任何刷新它的函数。在重新打开 VM 之前,我还尝试将 IP 设置为静态并恢复为动态,这也不起作用。

我发现了这个类似的问题here,但是当我尝试这种方法时,我收到了以下错误消息:

{  "error": {
"code": "IpConfigDeleteNotSupported",
"message": "IP Configuration ipconfig1 cannot be deleted. Deletion and renaming of primary IP Configuration is not supported",
"details": []   }

我还创建了辅助 IP 配置。第一个称为 ipconfig1,第二个我命名为“alternative”。这似乎是第二个网络接口。我已将第二个 IP 地址与第二个网络接口相关联。但我仍然遇到同样的错误。

我的最终请求如下所示:

curl -X PUT  -H "Authorization: Bearer MYTOKEN" -H "Content-Type: application/json" -d '{ "name": "NETWORKINTERFACE542", "id": "GROUP", "location": "westeurope", "properties": { "provisioningState": "Succeeded", "ipConfigurations": [ { "name": "alternative", "properties": { "privateIPAllocationMethod": "Dynamic", "subnet": { "id": "/subscriptions/xx-xx-xx-xx/resourceGroups/GROUP/providers/Microsoft.Network/virtualNetworks/GROUP-vnet/subnets/default" }, "primary": true, "privateIPAddressVersion": "IPv4" } } ], "dnsSettings": { "dnsServers": [], "appliedDnsServers": [] }, "enableAcceleratedNetworking": true, "enableIPForwarding": false }, "type": "Microsoft.Network/networkInterfaces" }' https://management.azure.com/subscriptions/xx-xx-xx-xx/resourceGroups/GROUP/providers/Microsoft.Network/networkInterfaces/NETWORKINTERFACE542?api-version=2020-07-01

(CAPS 术语是我实际变量名的替代)

我仍然收到同样的错误,即使我的请求中甚至没有引用 ipconfig1。

有没有办法实现IP重置?

【问题讨论】:

    标签: azure azure-resource-manager azure-virtual-machine azure-virtual-network azure-rest-api


    【解决方案1】:

    正如您所提到的:在 Web 界面中,停止和启动 VM 通常会导致公共 IP 发生变化。

    一般情况下,Web UI中的stop操作实际上是做deallocate操作,所以需要使用REST API Deallocate and Start来触发公网IP地址改变。

    Virtual Machines - Deallocate

    POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/deallocate?api-version=2020-12-01
    

    Virtual Machines - Start

    POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/start?api-version=2020-12-01
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-12
      • 1970-01-01
      • 1970-01-01
      • 2018-12-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多