如何使用 Azure SDK 创建 Azure Spot VM

how to create a Azure Spot VM using Azure SDK

使用 Azure Net SDK,如何创建 Azure Spot VM。我做了一些研究,刚刚发现如何通过 Azure 门户或 arm 模板创建它。

您需要像往常一样创建它们,但要为虚拟机指定 eviction policy。这将是创建现货实例的方式

这是创建 Azure Spot VM 的示例代码

/// <summary>
/// Create a Spot VM
/// </summary>
/// <param name="vmSizeName">Name of the size of the VM</param>
/// <param name="spotBiddingMaximumPrice">Specifies the maximum price you are willing to pay for a Azure Spot VM/VMSS (use -1 to match on-demand pricing)</param>
/// <param name="deallocateOnEviction">If set, when the Spot VM is evicted, it will be automatically deallocated (recommended!).</param>
/// <returns>VMProperties instance</returns>
public static VMProperties CreateSpotVM(string vmSizeName, double spotBiddingMaximumPrice = -1, bool deallocateOnEviction = true)
    => new VMProperties()
    {
        Hardware = new VMHardwareProfile(vmSizeName),
        SpotVMBillingProfile = new VMBillingProfile(spotBiddingMaximumPrice),
        SpotVMEvictionPolicy = (deallocateOnEviction ? "Deallocate" : null)
    };