你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

将 VM 与产能预留组关联

适用于:✔️ Windows 虚拟机 ✔️ Linux 虚拟机

可以将产能预留组用于新的或现有的虚拟机 (VM)。 要了解有关产能预留的详细信息,请参阅产能预留概述

关联新虚拟机

要将新虚拟机与产能预留组相关联,必须将该组显式引用为 VM 的属性。 此引用会保护组中的匹配预留,以便打算使用它的应用程序和工作负载使用它。

若要将 capacityReservationGroup 属性添加到 VM,请构造对 Microsoft.Compute 提供程序的以下 PUT 请求:

PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{VirtualMachineName}?api-version=2021-04-01

在请求正文包含 capacityReservationGroup 属性:

{ 
  "location": "eastus", 
  "properties": { 
    "hardwareProfile": { 
      "vmSize": "Standard_D2s_v3" 
    }, 
    … 
   "capacityReservation":{ 
    "capacityReservationGroup":{ 
        "id":"subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/CapacityReservationGroups/{CapacityReservationGroupName}" 
    } 
    "storageProfile": { 
    … 
    }, 
    "osProfile": { 
    … 
    }, 
    "networkProfile": { 
     …     
    } 
  } 
} 

关联现有虚拟机

初次发布产能预留时,必须将虚拟机分配给产能预留:

  1. 如有必要,请按照相关指南来创建产能预留组和产能预留。 或增加现有产能预留的数量,以提供未使用的预留容量。
  2. 解除分配虚拟机。
  3. 更新 VM 上的产能预留组属性。
  4. 重启 VM。

按照步骤将虚拟机关联到产能预留组。

  1. 解除分配虚拟机:

    PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourcegroupname}/providers/Microsoft.Compute/virtualMachines/{VirtualMachineName}/deallocate?api-version=2021-04-01
    
  2. capacityReservationGroup 属性添加到 VM。 构造对 Microsoft.Compute 提供程序的以下 PUT 请求:

    PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{VirtualMachineName}?api-version=2021-04-01
    

    在请求正文包含 capacityReservationGroup 属性:

    {
    "location": "eastus",
    "properties": {
        "capacityReservation": {
            "capacityReservationGroup": {
                "id": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/capacityReservationGroups/{capacityReservationGroupName}"
            }
        }
    }
    }
    

查看 VM 与实例视图的关联

设置 capacityReservationGroup 属性后,VM 和组之间就存在关联了。 Azure 会在组中自动查找匹配的容量预留并使用预留的槽。 产能预留组的实例视图会在 virtualMachinesAllocated 属性下反映新 VM:

GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/CapacityReservationGroups/{capacityReservationGroupName}?$expand=instanceView&api-version=2021-04-01 
{
   "name":"{CapacityReservationGroupName}",
   "id":"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/capacityReservationGroups/{CapacityReservationGroupName}",
   "type":"Microsoft.Compute/capacityReservationGroups",
   "location":"eastus",
   "properties":{
      "capacityReservations":[
         {
            "id":"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/capacityReservationGroups/ {CapacityReservationGroupName}/capacityReservations/{CapacityReservationName}"
         }
      ],
      "virtualMachinesAssociated":[
         {
            "id":"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{myVM}"
         }
      ],
      "instanceView":{
         "capacityReservations":[
            {
               "name":"{CapacityReservationName}",
               "utilizationInfo":{
                  "virtualMachinesAllocated":[
                     {
                        "id":"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{myVM}"
                     }
                  ]
               },
               "statuses":[
                  {
                     "code":"ProvisioningState/succeeded",
                     "level":"Info",
                     "displayStatus":"Provisioning succeeded",
                     "time":"2021-05-25T15:12:10.4165243+00:00"
                  }
               ]
            }
         ]
      }
   }
} 

下一步