建立或更新 VM 擴展集。
PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachineScaleSets/{vmScaleSetName}?api-version=2022-11-01
展開資料表
名稱
位於
必要
類型
Description
resourceGroupName
path
True
string
資源群組的名稱。
subscriptionId
path
True
string
可唯一識別 Microsoft Azure 訂用帳戶的訂用帳戶認證。 訂用帳戶識別碼會構成每個服務呼叫 URI 的一部分。
vmScaleSetName
path
True
string
要建立或更新的 VM 擴展集名稱。
api-version
query
True
string
用戶端 API 版本。
展開資料表
名稱
必要
類型
Description
location
True
string
資源位置
extendedLocation
ExtendedLocation
虛擬機擴展集的擴充位置。
identity
VirtualMachineScaleSetIdentity
如果已設定,則為虛擬機擴展集的身分識別。
plan
Plan
指定用來建立虛擬機之 Marketplace 映像的相關信息。 此元素僅用於市集映像。 您必須先啟用映像以供程序設計使用,才能從 API 使用市集映射。 在 Azure 入口網站 中,尋找您想要使用的市集映射,然後按兩下 [以程序設計方式部署] [開始使用] -> 。 輸入任何必要資訊,然後按兩下 [ 儲存 ]。
properties.additionalCapabilities
AdditionalCapabilities
指定虛擬機擴展集中 虛擬機器 上啟用或停用的其他功能。 例如:虛擬機器 是否能夠支援使用UltraSSD_LRS記憶體帳戶類型鏈接受控數據磁碟。
properties.automaticRepairsPolicy
AutomaticRepairsPolicy
自動修復的原則。
properties.constrainedMaximumCapacity
boolean
必須設定為 True 或省略的選擇性屬性。
properties.doNotRunExtensionsOnOverprovisionedVMs
boolean
啟用 Overprovision 時,擴充功能只會在最後保留的要求 VM 數目上啟動。 因此,此屬性可確保擴充功能不會在額外的過度布建 VM 上執行。
properties.hostGroup
SubResource
指定虛擬機擴展集所在專用主機群組的相關信息。 API 版本下限:2020-06-01。
properties.orchestrationMode
OrchestrationMode
指定虛擬機擴展集的協調流程模式。
properties.overprovision
boolean
指定是否應過度布建虛擬機擴展集。
properties.platformFaultDomainCount
integer
每個放置群組的容錯網域計數。
properties.priorityMixPolicy
PriorityMixPolicy
指定在相同 VMSS Flex 實例內混合現成和一般優先順序 VM 所需的目標。
properties.proximityPlacementGroup
SubResource
指定虛擬機擴展集應指派給之鄰近放置群組的相關信息。 API 版本下限:2018-04-01。
properties.scaleInPolicy
ScaleInPolicy
指定在虛擬機擴展集中調整 虛擬機器 時套用的原則。
properties.singlePlacementGroup
boolean
若為 true,則會將擴展集限制為單一放置群組,大小上限為 100 部虛擬機。 注意:如果 singlePlacementGroup 為 true,可能會將其修改為 false。 不過,如果 singlePlacementGroup 為 false,則無法修改成 true。
properties.spotRestorePolicy
SpotRestorePolicy
指定虛擬機擴展集的現成還原屬性。
properties.upgradePolicy
UpgradePolicy
升級原則。
properties.virtualMachineProfile
VirtualMachineScaleSetVMProfile
虛擬機器配置檔。
properties.zoneBalance
boolean
如果發生區域中斷,是否強制嚴格地跨 x 區域散發虛擬機。 只有在擴展集的區域屬性包含多個區域時,才能設定 zoneBalance 屬性。 如果沒有指定區域或只指定一個區域,不應設定 zoneBalance 屬性。
sku
Sku
虛擬機擴展集 SKU。
tags
object
資源標籤
zones
string[]
虛擬機擴展集區域。 注意:只有在建立擴展集時,才能設定可用性區域
展開資料表
Azure Active Directory OAuth2 Flow
類型:
oauth2
Flow:
implicit
授權 URL:
https://login.microsoftonline.com/common/oauth2/authorize
展開資料表
名稱
Description
user_impersonation
模擬您的用戶帳戶
展開資料表
Create a custom-image scale set from an unmanaged generalized os image.
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}?api-version=2022-11-01
{
"sku" : {
"tier" : "Standard",
"capacity" : 3,
"name" : "Standard_D1_v2"
},
"location" : "westus",
"properties" : {
"overprovision" : true,
"virtualMachineProfile" : {
"storageProfile" : {
"osDisk" : {
"caching" : "ReadWrite",
"image" : {
"uri" : "http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/{existing-generalized-os-image-blob-name}.vhd"
},
"createOption" : "FromImage",
"name" : "osDisk"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}",
"adminUsername" : "{your-username}",
"adminPassword" : "{your-password}"
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"primary" : true,
"enableIPForwarding" : true,
"ipConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
}
}
]
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineScaleSetInner;
import com.azure.resourcemanager.compute.models.ApiEntityReference;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.Sku;
import com.azure.resourcemanager.compute.models.UpgradeMode;
import com.azure.resourcemanager.compute.models.UpgradePolicy;
import com.azure.resourcemanager.compute.models.VirtualHardDisk;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetIpConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSDisk;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetStorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetVMProfile;
import java.util.Arrays;
public final class Main {
public static void createACustomImageScaleSetFromAnUnmanagedGeneralizedOsImage (
com.azure.resourcemanager.AzureResourceManager azure) {
azure
.virtualMachines()
.manager()
.serviceClient()
.getVirtualMachineScaleSets()
.createOrUpdate(
"myResourceGroup" ,
"{vmss-name}" ,
new VirtualMachineScaleSetInner()
.withLocation("westus" )
.withSku(new Sku().withName("Standard_D1_v2" ).withTier("Standard" ).withCapacity(3L ))
.withUpgradePolicy(new UpgradePolicy().withMode(UpgradeMode.MANUAL))
.withVirtualMachineProfile(
new VirtualMachineScaleSetVMProfile()
.withOsProfile(
new VirtualMachineScaleSetOSProfile()
.withComputerNamePrefix("{vmss-name}" )
.withAdminUsername("{your-username}" )
.withAdminPassword("fakeTokenPlaceholder" ))
.withStorageProfile(
new VirtualMachineScaleSetStorageProfile()
.withOsDisk(
new VirtualMachineScaleSetOSDisk()
.withName("osDisk" )
.withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)
.withImage(
new VirtualHardDisk()
.withUri(
"http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/{existing-generalized-os-image-blob-name}.vhd" ))))
.withNetworkProfile(
new VirtualMachineScaleSetNetworkProfile()
.withNetworkInterfaceConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetNetworkConfiguration()
.withName("{vmss-name}" )
.withPrimary(true )
.withIpConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetIpConfiguration()
.withName("{vmss-name}" )
.withSubnet(
new ApiEntityReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ))))
.withEnableIpForwarding(true )))))
.withOverprovision(true ),
com.azure.core.util.Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_scale_set_create_custom_image_from_an_unmanaged_generalized_os_image.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main () :
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="{subscription-id}" ,
)
response = client.virtual_machine_scale_sets.begin_create_or_update(
resource_group_name="myResourceGroup" ,
vm_scale_set_name="{vmss-name}" ,
parameters={
"location" : "westus" ,
"properties" : {
"overprovision" : True ,
"upgradePolicy" : {"mode" : "Manual" },
"virtualMachineProfile" : {
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"enableIPForwarding" : True ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
},
}
],
"primary" : True ,
},
}
]
},
"osProfile" : {
"adminPassword" : "{your-password}" ,
"adminUsername" : "{your-username}" ,
"computerNamePrefix" : "{vmss-name}" ,
},
"storageProfile" : {
"osDisk" : {
"caching" : "ReadWrite" ,
"createOption" : "FromImage" ,
"image" : {
"uri" : "http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/{existing-generalized-os-image-blob-name}.vhd"
},
"name" : "osDisk" ,
}
},
},
},
"sku" : {"capacity" : 3 , "name" : "Standard_D1_v2" , "tier" : "Standard" },
},
).result()
print(response)
if __name__ == "__main__" :
main()
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4"
)
func ExampleVirtualMachineScaleSetsClient_BeginCreateOrUpdate_createACustomImageScaleSetFromAnUnmanagedGeneralizedOsImage () {
cred, err := azidentity.NewDefaultAzureCredential(nil )
if err != nil {
log.Fatalf("failed to obtain a credential: %v" , err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("<subscription-id>" , cred, nil )
if err != nil {
log.Fatalf("failed to create client: %v" , err)
}
poller, err := clientFactory.NewVirtualMachineScaleSetsClient().BeginCreateOrUpdate(ctx, "myResourceGroup" , "{vmss-name}" , armcompute.VirtualMachineScaleSet{
Location: to.Ptr("westus" ),
Properties: &armcompute.VirtualMachineScaleSetProperties{
Overprovision: to.Ptr(true ),
UpgradePolicy: &armcompute.UpgradePolicy{
Mode: to.Ptr(armcompute.UpgradeModeManual),
},
VirtualMachineProfile: &armcompute.VirtualMachineScaleSetVMProfile{
NetworkProfile: &armcompute.VirtualMachineScaleSetNetworkProfile{
NetworkInterfaceConfigurations: []*armcompute.VirtualMachineScaleSetNetworkConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetNetworkConfigurationProperties{
EnableIPForwarding: to.Ptr(true ),
IPConfigurations: []*armcompute.VirtualMachineScaleSetIPConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetIPConfigurationProperties{
Subnet: &armcompute.APIEntityReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
},
},
}},
Primary: to.Ptr(true ),
},
}},
},
OSProfile: &armcompute.VirtualMachineScaleSetOSProfile{
AdminPassword: to.Ptr("{your-password}" ),
AdminUsername: to.Ptr("{your-username}" ),
ComputerNamePrefix: to.Ptr("{vmss-name}" ),
},
StorageProfile: &armcompute.VirtualMachineScaleSetStorageProfile{
OSDisk: &armcompute.VirtualMachineScaleSetOSDisk{
Name: to.Ptr("osDisk" ),
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
Image: &armcompute.VirtualHardDisk{
URI: to.Ptr("http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/{existing-generalized-os-image-blob-name}.vhd" ),
},
},
},
},
},
SKU: &armcompute.SKU{
Name: to.Ptr("Standard_D1_v2" ),
Capacity: to.Ptr[int64 ](3 ),
Tier: to.Ptr("Standard" ),
},
}, nil )
if err != nil {
log.Fatalf("failed to finish the request: %v" , err)
}
res, err := poller.PollUntilDone(ctx, nil )
if err != nil {
log.Fatalf("failed to pull the result: %v" , err)
}
_ = res
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require ("@azure/arm-compute" );
const { DefaultAzureCredential } = require ("@azure/identity" );
async function createACustomImageScaleSetFromAnUnmanagedGeneralizedOSImage ( ) {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID" ] || "{subscription-id}" ;
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP" ] || "myResourceGroup" ;
const vmScaleSetName = "{vmss-name}" ;
const parameters = {
location : "westus" ,
overprovision : true ,
sku : { name : "Standard_D1_v2" , capacity : 3 , tier : "Standard" },
upgradePolicy : { mode : "Manual" },
virtualMachineProfile : {
networkProfile : {
networkInterfaceConfigurations : [
{
name : "{vmss-name}" ,
enableIPForwarding : true ,
ipConfigurations : [
{
name : "{vmss-name}" ,
subnet : {
id : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ,
},
},
],
primary : true ,
},
],
},
osProfile : {
adminPassword : "{your-password}" ,
adminUsername : "{your-username}" ,
computerNamePrefix : "{vmss-name}" ,
},
storageProfile : {
osDisk : {
name : "osDisk" ,
caching : "ReadWrite" ,
createOption : "FromImage" ,
image : {
uri : "http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/{existing-generalized-os-image-blob-name}.vhd" ,
},
},
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachineScaleSets.beginCreateOrUpdateAndWait(
resourceGroupName,
vmScaleSetName,
parameters
);
console .log(result);
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Compute;
using Azure.ResourceManager.Compute.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Resources.Models;
TokenCredential cred = new DefaultAzureCredential();
ArmClient client = new ArmClient(cred);
string subscriptionId = "{subscription-id}" ;
string resourceGroupName = "myResourceGroup" ;
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
VirtualMachineScaleSetCollection collection = resourceGroupResource.GetVirtualMachineScaleSets();
string virtualMachineScaleSetName = "{vmss-name}" ;
VirtualMachineScaleSetData data = new VirtualMachineScaleSetData(new AzureLocation("westus" ))
{
Sku = new ComputeSku()
{
Name = "Standard_D1_v2" ,
Tier = "Standard" ,
Capacity = 3 ,
},
UpgradePolicy = new VirtualMachineScaleSetUpgradePolicy()
{
Mode = VirtualMachineScaleSetUpgradeMode.Manual,
},
VirtualMachineProfile = new VirtualMachineScaleSetVmProfile()
{
OSProfile = new VirtualMachineScaleSetOSProfile()
{
ComputerNamePrefix = "{vmss-name}" ,
AdminUsername = "{your-username}" ,
AdminPassword = "{your-password}" ,
},
StorageProfile = new VirtualMachineScaleSetStorageProfile()
{
OSDisk = new VirtualMachineScaleSetOSDisk(DiskCreateOptionType.FromImage)
{
Name = "osDisk" ,
Caching = CachingType.ReadWrite,
ImageUri = new Uri("http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/{existing-generalized-os-image-blob-name}.vhd" ),
},
},
NetworkProfile = new VirtualMachineScaleSetNetworkProfile()
{
NetworkInterfaceConfigurations =
{
new VirtualMachineScaleSetNetworkConfiguration("{vmss-name}" )
{
Primary = true ,
IPConfigurations =
{
new VirtualMachineScaleSetIPConfiguration("{vmss-name}" )
{
SubnetId = new ResourceIdentifier("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
}
},
EnableIPForwarding = true ,
}
},
},
},
Overprovision = true ,
};
ArmOperation<VirtualMachineScaleSetResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, virtualMachineScaleSetName, data);
VirtualMachineScaleSetResource result = lro.Value;
VirtualMachineScaleSetData resourceData = result.Data;
Console.WriteLine($"Succeeded on id: {resourceData.Id} " );
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
範例回覆
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_D1_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "d6e9ab29-f8c9-4792-978c-ae2c07b98f17" ,
"virtualMachineProfile" : {
"storageProfile" : {
"osDisk" : {
"osType" : "Windows" ,
"caching" : "ReadWrite" ,
"image" : {
"uri" : "https://{existing-storage-account-name}.blob.core.windows.net/system/Microsoft.Compute/Images/vhds/{existing-generalized-os-image-blob-name}.vhd"
},
"createOption" : "FromImage" ,
"name" : "osDisk"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_D1_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "d6e9ab29-f8c9-4792-978c-ae2c07b98f17" ,
"virtualMachineProfile" : {
"storageProfile" : {
"osDisk" : {
"osType" : "Windows" ,
"caching" : "ReadWrite" ,
"image" : {
"uri" : "https://{existing-storage-account-name}.blob.core.windows.net/system/Microsoft.Compute/Images/vhds/{existing-generalized-os-image-blob-name}.vhd"
},
"createOption" : "FromImage" ,
"name" : "osDisk"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}?api-version=2022-11-01
{
"sku" : {
"tier" : "Standard",
"capacity" : 3,
"name" : "Standard_D1_v2"
},
"location" : "westus",
"properties" : {
"overprovision" : true,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter",
"publisher" : "MicrosoftWindowsServer",
"version" : "latest",
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite",
"createOption" : "FromImage",
"name" : "osDisk",
"vhdContainers" : [
"http://{existing-storage-account-name-0}.blob.core.windows.net/vhdContainer",
"http://{existing-storage-account-name-1}.blob.core.windows.net/vhdContainer",
"http://{existing-storage-account-name-2}.blob.core.windows.net/vhdContainer",
"http://{existing-storage-account-name-3}.blob.core.windows.net/vhdContainer",
"http://{existing-storage-account-name-4}.blob.core.windows.net/vhdContainer"
]
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}",
"adminUsername" : "{your-username}",
"adminPassword" : "{your-password}"
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"primary" : true,
"enableIPForwarding" : true,
"ipConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
}
}
]
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineScaleSetInner;
import com.azure.resourcemanager.compute.models.ApiEntityReference;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.Sku;
import com.azure.resourcemanager.compute.models.UpgradeMode;
import com.azure.resourcemanager.compute.models.UpgradePolicy;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetIpConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSDisk;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetStorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetVMProfile;
import java.util.Arrays;
public final class Main {
public static void createAPlatformImageScaleSetWithUnmanagedOsDisks (
com.azure.resourcemanager.AzureResourceManager azure) {
azure
.virtualMachines()
.manager()
.serviceClient()
.getVirtualMachineScaleSets()
.createOrUpdate(
"myResourceGroup" ,
"{vmss-name}" ,
new VirtualMachineScaleSetInner()
.withLocation("westus" )
.withSku(new Sku().withName("Standard_D1_v2" ).withTier("Standard" ).withCapacity(3L ))
.withUpgradePolicy(new UpgradePolicy().withMode(UpgradeMode.MANUAL))
.withVirtualMachineProfile(
new VirtualMachineScaleSetVMProfile()
.withOsProfile(
new VirtualMachineScaleSetOSProfile()
.withComputerNamePrefix("{vmss-name}" )
.withAdminUsername("{your-username}" )
.withAdminPassword("fakeTokenPlaceholder" ))
.withStorageProfile(
new VirtualMachineScaleSetStorageProfile()
.withImageReference(
new ImageReference()
.withPublisher("MicrosoftWindowsServer" )
.withOffer("WindowsServer" )
.withSku("2016-Datacenter" )
.withVersion("latest" ))
.withOsDisk(
new VirtualMachineScaleSetOSDisk()
.withName("osDisk" )
.withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)
.withVhdContainers(
Arrays
.asList(
"http://{existing-storage-account-name-0}.blob.core.windows.net/vhdContainer" ,
"http://{existing-storage-account-name-1}.blob.core.windows.net/vhdContainer" ,
"http://{existing-storage-account-name-2}.blob.core.windows.net/vhdContainer" ,
"http://{existing-storage-account-name-3}.blob.core.windows.net/vhdContainer" ,
"http://{existing-storage-account-name-4}.blob.core.windows.net/vhdContainer" ))))
.withNetworkProfile(
new VirtualMachineScaleSetNetworkProfile()
.withNetworkInterfaceConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetNetworkConfiguration()
.withName("{vmss-name}" )
.withPrimary(true )
.withIpConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetIpConfiguration()
.withName("{vmss-name}" )
.withSubnet(
new ApiEntityReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ))))
.withEnableIpForwarding(true )))))
.withOverprovision(true ),
com.azure.core.util.Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_scale_set_create_platform_image_with_unmanaged_os_disks.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main () :
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="{subscription-id}" ,
)
response = client.virtual_machine_scale_sets.begin_create_or_update(
resource_group_name="myResourceGroup" ,
vm_scale_set_name="{vmss-name}" ,
parameters={
"location" : "westus" ,
"properties" : {
"overprovision" : True ,
"upgradePolicy" : {"mode" : "Manual" },
"virtualMachineProfile" : {
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"enableIPForwarding" : True ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
},
}
],
"primary" : True ,
},
}
]
},
"osProfile" : {
"adminPassword" : "{your-password}" ,
"adminUsername" : "{your-username}" ,
"computerNamePrefix" : "{vmss-name}" ,
},
"storageProfile" : {
"imageReference" : {
"offer" : "WindowsServer" ,
"publisher" : "MicrosoftWindowsServer" ,
"sku" : "2016-Datacenter" ,
"version" : "latest" ,
},
"osDisk" : {
"caching" : "ReadWrite" ,
"createOption" : "FromImage" ,
"name" : "osDisk" ,
"vhdContainers" : [
"http://{existing-storage-account-name-0}.blob.core.windows.net/vhdContainer" ,
"http://{existing-storage-account-name-1}.blob.core.windows.net/vhdContainer" ,
"http://{existing-storage-account-name-2}.blob.core.windows.net/vhdContainer" ,
"http://{existing-storage-account-name-3}.blob.core.windows.net/vhdContainer" ,
"http://{existing-storage-account-name-4}.blob.core.windows.net/vhdContainer" ,
],
},
},
},
},
"sku" : {"capacity" : 3 , "name" : "Standard_D1_v2" , "tier" : "Standard" },
},
).result()
print(response)
if __name__ == "__main__" :
main()
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4"
)
func ExampleVirtualMachineScaleSetsClient_BeginCreateOrUpdate_createAPlatformImageScaleSetWithUnmanagedOsDisks () {
cred, err := azidentity.NewDefaultAzureCredential(nil )
if err != nil {
log.Fatalf("failed to obtain a credential: %v" , err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("<subscription-id>" , cred, nil )
if err != nil {
log.Fatalf("failed to create client: %v" , err)
}
poller, err := clientFactory.NewVirtualMachineScaleSetsClient().BeginCreateOrUpdate(ctx, "myResourceGroup" , "{vmss-name}" , armcompute.VirtualMachineScaleSet{
Location: to.Ptr("westus" ),
Properties: &armcompute.VirtualMachineScaleSetProperties{
Overprovision: to.Ptr(true ),
UpgradePolicy: &armcompute.UpgradePolicy{
Mode: to.Ptr(armcompute.UpgradeModeManual),
},
VirtualMachineProfile: &armcompute.VirtualMachineScaleSetVMProfile{
NetworkProfile: &armcompute.VirtualMachineScaleSetNetworkProfile{
NetworkInterfaceConfigurations: []*armcompute.VirtualMachineScaleSetNetworkConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetNetworkConfigurationProperties{
EnableIPForwarding: to.Ptr(true ),
IPConfigurations: []*armcompute.VirtualMachineScaleSetIPConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetIPConfigurationProperties{
Subnet: &armcompute.APIEntityReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
},
},
}},
Primary: to.Ptr(true ),
},
}},
},
OSProfile: &armcompute.VirtualMachineScaleSetOSProfile{
AdminPassword: to.Ptr("{your-password}" ),
AdminUsername: to.Ptr("{your-username}" ),
ComputerNamePrefix: to.Ptr("{vmss-name}" ),
},
StorageProfile: &armcompute.VirtualMachineScaleSetStorageProfile{
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("WindowsServer" ),
Publisher: to.Ptr("MicrosoftWindowsServer" ),
SKU: to.Ptr("2016-Datacenter" ),
Version: to.Ptr("latest" ),
},
OSDisk: &armcompute.VirtualMachineScaleSetOSDisk{
Name: to.Ptr("osDisk" ),
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
VhdContainers: []*string {
to.Ptr("http://{existing-storage-account-name-0}.blob.core.windows.net/vhdContainer" ),
to.Ptr("http://{existing-storage-account-name-1}.blob.core.windows.net/vhdContainer" ),
to.Ptr("http://{existing-storage-account-name-2}.blob.core.windows.net/vhdContainer" ),
to.Ptr("http://{existing-storage-account-name-3}.blob.core.windows.net/vhdContainer" ),
to.Ptr("http://{existing-storage-account-name-4}.blob.core.windows.net/vhdContainer" )},
},
},
},
},
SKU: &armcompute.SKU{
Name: to.Ptr("Standard_D1_v2" ),
Capacity: to.Ptr[int64 ](3 ),
Tier: to.Ptr("Standard" ),
},
}, nil )
if err != nil {
log.Fatalf("failed to finish the request: %v" , err)
}
res, err := poller.PollUntilDone(ctx, nil )
if err != nil {
log.Fatalf("failed to pull the result: %v" , err)
}
_ = res
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require ("@azure/arm-compute" );
const { DefaultAzureCredential } = require ("@azure/identity" );
async function createAPlatformImageScaleSetWithUnmanagedOSDisks ( ) {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID" ] || "{subscription-id}" ;
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP" ] || "myResourceGroup" ;
const vmScaleSetName = "{vmss-name}" ;
const parameters = {
location : "westus" ,
overprovision : true ,
sku : { name : "Standard_D1_v2" , capacity : 3 , tier : "Standard" },
upgradePolicy : { mode : "Manual" },
virtualMachineProfile : {
networkProfile : {
networkInterfaceConfigurations : [
{
name : "{vmss-name}" ,
enableIPForwarding : true ,
ipConfigurations : [
{
name : "{vmss-name}" ,
subnet : {
id : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ,
},
},
],
primary : true ,
},
],
},
osProfile : {
adminPassword : "{your-password}" ,
adminUsername : "{your-username}" ,
computerNamePrefix : "{vmss-name}" ,
},
storageProfile : {
imageReference : {
offer : "WindowsServer" ,
publisher : "MicrosoftWindowsServer" ,
sku : "2016-Datacenter" ,
version : "latest" ,
},
osDisk : {
name : "osDisk" ,
caching : "ReadWrite" ,
createOption : "FromImage" ,
vhdContainers : [
"http://{existing-storage-account-name-0}.blob.core.windows.net/vhdContainer" ,
"http://{existing-storage-account-name-1}.blob.core.windows.net/vhdContainer" ,
"http://{existing-storage-account-name-2}.blob.core.windows.net/vhdContainer" ,
"http://{existing-storage-account-name-3}.blob.core.windows.net/vhdContainer" ,
"http://{existing-storage-account-name-4}.blob.core.windows.net/vhdContainer" ,
],
},
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachineScaleSets.beginCreateOrUpdateAndWait(
resourceGroupName,
vmScaleSetName,
parameters
);
console .log(result);
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Compute;
using Azure.ResourceManager.Compute.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Resources.Models;
TokenCredential cred = new DefaultAzureCredential();
ArmClient client = new ArmClient(cred);
string subscriptionId = "{subscription-id}" ;
string resourceGroupName = "myResourceGroup" ;
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
VirtualMachineScaleSetCollection collection = resourceGroupResource.GetVirtualMachineScaleSets();
string virtualMachineScaleSetName = "{vmss-name}" ;
VirtualMachineScaleSetData data = new VirtualMachineScaleSetData(new AzureLocation("westus" ))
{
Sku = new ComputeSku()
{
Name = "Standard_D1_v2" ,
Tier = "Standard" ,
Capacity = 3 ,
},
UpgradePolicy = new VirtualMachineScaleSetUpgradePolicy()
{
Mode = VirtualMachineScaleSetUpgradeMode.Manual,
},
VirtualMachineProfile = new VirtualMachineScaleSetVmProfile()
{
OSProfile = new VirtualMachineScaleSetOSProfile()
{
ComputerNamePrefix = "{vmss-name}" ,
AdminUsername = "{your-username}" ,
AdminPassword = "{your-password}" ,
},
StorageProfile = new VirtualMachineScaleSetStorageProfile()
{
ImageReference = new ImageReference()
{
Publisher = "MicrosoftWindowsServer" ,
Offer = "WindowsServer" ,
Sku = "2016-Datacenter" ,
Version = "latest" ,
},
OSDisk = new VirtualMachineScaleSetOSDisk(DiskCreateOptionType.FromImage)
{
Name = "osDisk" ,
Caching = CachingType.ReadWrite,
VhdContainers =
{
"http://{existing-storage-account-name-0}.blob.core.windows.net/vhdContainer" ,"http://{existing-storage-account-name-1}.blob.core.windows.net/vhdContainer" ,"http://{existing-storage-account-name-2}.blob.core.windows.net/vhdContainer" ,"http://{existing-storage-account-name-3}.blob.core.windows.net/vhdContainer" ,"http://{existing-storage-account-name-4}.blob.core.windows.net/vhdContainer"
},
},
},
NetworkProfile = new VirtualMachineScaleSetNetworkProfile()
{
NetworkInterfaceConfigurations =
{
new VirtualMachineScaleSetNetworkConfiguration("{vmss-name}" )
{
Primary = true ,
IPConfigurations =
{
new VirtualMachineScaleSetIPConfiguration("{vmss-name}" )
{
SubnetId = new ResourceIdentifier("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
}
},
EnableIPForwarding = true ,
}
},
},
},
Overprovision = true ,
};
ArmOperation<VirtualMachineScaleSetResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, virtualMachineScaleSetName, data);
VirtualMachineScaleSetResource result = lro.Value;
VirtualMachineScaleSetData resourceData = result.Data;
Console.WriteLine($"Succeeded on id: {resourceData.Id} " );
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
範例回覆
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_D1_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "77b7df9a-32fe-45e3-8911-60ac9c9b9c64" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter" ,
"publisher" : "MicrosoftWindowsServer" ,
"version" : "latest" ,
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"vhdContainers" : [
"http://{existing-storage-account-name}.blob.core.windows.net/vhds"
],
"name" : "osDisk" ,
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_D1_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "77b7df9a-32fe-45e3-8911-60ac9c9b9c64" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter" ,
"publisher" : "MicrosoftWindowsServer" ,
"version" : "latest" ,
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"vhdContainers" : [
"http://{existing-storage-account-name}.blob.core.windows.net/vhds"
],
"name" : "osDisk" ,
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
Create a scale set from a custom image.
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}?api-version=2022-11-01
{
"sku" : {
"tier" : "Standard",
"capacity" : 3,
"name" : "Standard_D1_v2"
},
"location" : "westus",
"properties" : {
"overprovision" : true,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/{existing-custom-image-name}"
},
"osDisk" : {
"caching" : "ReadWrite",
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}",
"adminUsername" : "{your-username}",
"adminPassword" : "{your-password}"
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"primary" : true,
"enableIPForwarding" : true,
"ipConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
}
}
]
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineScaleSetInner;
import com.azure.resourcemanager.compute.models.ApiEntityReference;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.Sku;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.UpgradeMode;
import com.azure.resourcemanager.compute.models.UpgradePolicy;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetIpConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetManagedDiskParameters;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSDisk;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetStorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetVMProfile;
import java.util.Arrays;
public final class Main {
public static void createAScaleSetFromACustomImage (com.azure.resourcemanager.AzureResourceManager azure) {
azure
.virtualMachines()
.manager()
.serviceClient()
.getVirtualMachineScaleSets()
.createOrUpdate(
"myResourceGroup" ,
"{vmss-name}" ,
new VirtualMachineScaleSetInner()
.withLocation("westus" )
.withSku(new Sku().withName("Standard_D1_v2" ).withTier("Standard" ).withCapacity(3L ))
.withUpgradePolicy(new UpgradePolicy().withMode(UpgradeMode.MANUAL))
.withVirtualMachineProfile(
new VirtualMachineScaleSetVMProfile()
.withOsProfile(
new VirtualMachineScaleSetOSProfile()
.withComputerNamePrefix("{vmss-name}" )
.withAdminUsername("{your-username}" )
.withAdminPassword("fakeTokenPlaceholder" ))
.withStorageProfile(
new VirtualMachineScaleSetStorageProfile()
.withImageReference(
new ImageReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/{existing-custom-image-name}" ))
.withOsDisk(
new VirtualMachineScaleSetOSDisk()
.withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)
.withManagedDisk(
new VirtualMachineScaleSetManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withNetworkProfile(
new VirtualMachineScaleSetNetworkProfile()
.withNetworkInterfaceConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetNetworkConfiguration()
.withName("{vmss-name}" )
.withPrimary(true )
.withIpConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetIpConfiguration()
.withName("{vmss-name}" )
.withSubnet(
new ApiEntityReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ))))
.withEnableIpForwarding(true )))))
.withOverprovision(true ),
com.azure.core.util.Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_scale_set_create_from_acustom_image.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main () :
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="{subscription-id}" ,
)
response = client.virtual_machine_scale_sets.begin_create_or_update(
resource_group_name="myResourceGroup" ,
vm_scale_set_name="{vmss-name}" ,
parameters={
"location" : "westus" ,
"properties" : {
"overprovision" : True ,
"upgradePolicy" : {"mode" : "Manual" },
"virtualMachineProfile" : {
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"enableIPForwarding" : True ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
},
}
],
"primary" : True ,
},
}
]
},
"osProfile" : {
"adminPassword" : "{your-password}" ,
"adminUsername" : "{your-username}" ,
"computerNamePrefix" : "{vmss-name}" ,
},
"storageProfile" : {
"imageReference" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/{existing-custom-image-name}"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"createOption" : "FromImage" ,
"managedDisk" : {"storageAccountType" : "Standard_LRS" },
},
},
},
},
"sku" : {"capacity" : 3 , "name" : "Standard_D1_v2" , "tier" : "Standard" },
},
).result()
print(response)
if __name__ == "__main__" :
main()
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4"
)
func ExampleVirtualMachineScaleSetsClient_BeginCreateOrUpdate_createAScaleSetFromACustomImage () {
cred, err := azidentity.NewDefaultAzureCredential(nil )
if err != nil {
log.Fatalf("failed to obtain a credential: %v" , err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("<subscription-id>" , cred, nil )
if err != nil {
log.Fatalf("failed to create client: %v" , err)
}
poller, err := clientFactory.NewVirtualMachineScaleSetsClient().BeginCreateOrUpdate(ctx, "myResourceGroup" , "{vmss-name}" , armcompute.VirtualMachineScaleSet{
Location: to.Ptr("westus" ),
Properties: &armcompute.VirtualMachineScaleSetProperties{
Overprovision: to.Ptr(true ),
UpgradePolicy: &armcompute.UpgradePolicy{
Mode: to.Ptr(armcompute.UpgradeModeManual),
},
VirtualMachineProfile: &armcompute.VirtualMachineScaleSetVMProfile{
NetworkProfile: &armcompute.VirtualMachineScaleSetNetworkProfile{
NetworkInterfaceConfigurations: []*armcompute.VirtualMachineScaleSetNetworkConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetNetworkConfigurationProperties{
EnableIPForwarding: to.Ptr(true ),
IPConfigurations: []*armcompute.VirtualMachineScaleSetIPConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetIPConfigurationProperties{
Subnet: &armcompute.APIEntityReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
},
},
}},
Primary: to.Ptr(true ),
},
}},
},
OSProfile: &armcompute.VirtualMachineScaleSetOSProfile{
AdminPassword: to.Ptr("{your-password}" ),
AdminUsername: to.Ptr("{your-username}" ),
ComputerNamePrefix: to.Ptr("{vmss-name}" ),
},
StorageProfile: &armcompute.VirtualMachineScaleSetStorageProfile{
ImageReference: &armcompute.ImageReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/{existing-custom-image-name}" ),
},
OSDisk: &armcompute.VirtualMachineScaleSetOSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.VirtualMachineScaleSetManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
},
},
SKU: &armcompute.SKU{
Name: to.Ptr("Standard_D1_v2" ),
Capacity: to.Ptr[int64 ](3 ),
Tier: to.Ptr("Standard" ),
},
}, nil )
if err != nil {
log.Fatalf("failed to finish the request: %v" , err)
}
res, err := poller.PollUntilDone(ctx, nil )
if err != nil {
log.Fatalf("failed to pull the result: %v" , err)
}
_ = res
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require ("@azure/arm-compute" );
const { DefaultAzureCredential } = require ("@azure/identity" );
async function createAScaleSetFromACustomImage ( ) {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID" ] || "{subscription-id}" ;
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP" ] || "myResourceGroup" ;
const vmScaleSetName = "{vmss-name}" ;
const parameters = {
location : "westus" ,
overprovision : true ,
sku : { name : "Standard_D1_v2" , capacity : 3 , tier : "Standard" },
upgradePolicy : { mode : "Manual" },
virtualMachineProfile : {
networkProfile : {
networkInterfaceConfigurations : [
{
name : "{vmss-name}" ,
enableIPForwarding : true ,
ipConfigurations : [
{
name : "{vmss-name}" ,
subnet : {
id : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ,
},
},
],
primary : true ,
},
],
},
osProfile : {
adminPassword : "{your-password}" ,
adminUsername : "{your-username}" ,
computerNamePrefix : "{vmss-name}" ,
},
storageProfile : {
imageReference : {
id : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/{existing-custom-image-name}" ,
},
osDisk : {
caching : "ReadWrite" ,
createOption : "FromImage" ,
managedDisk : { storageAccountType : "Standard_LRS" },
},
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachineScaleSets.beginCreateOrUpdateAndWait(
resourceGroupName,
vmScaleSetName,
parameters
);
console .log(result);
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Compute;
using Azure.ResourceManager.Compute.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Resources.Models;
TokenCredential cred = new DefaultAzureCredential();
ArmClient client = new ArmClient(cred);
string subscriptionId = "{subscription-id}" ;
string resourceGroupName = "myResourceGroup" ;
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
VirtualMachineScaleSetCollection collection = resourceGroupResource.GetVirtualMachineScaleSets();
string virtualMachineScaleSetName = "{vmss-name}" ;
VirtualMachineScaleSetData data = new VirtualMachineScaleSetData(new AzureLocation("westus" ))
{
Sku = new ComputeSku()
{
Name = "Standard_D1_v2" ,
Tier = "Standard" ,
Capacity = 3 ,
},
UpgradePolicy = new VirtualMachineScaleSetUpgradePolicy()
{
Mode = VirtualMachineScaleSetUpgradeMode.Manual,
},
VirtualMachineProfile = new VirtualMachineScaleSetVmProfile()
{
OSProfile = new VirtualMachineScaleSetOSProfile()
{
ComputerNamePrefix = "{vmss-name}" ,
AdminUsername = "{your-username}" ,
AdminPassword = "{your-password}" ,
},
StorageProfile = new VirtualMachineScaleSetStorageProfile()
{
ImageReference = new ImageReference()
{
Id = new ResourceIdentifier("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/{existing-custom-image-name}" ),
},
OSDisk = new VirtualMachineScaleSetOSDisk(DiskCreateOptionType.FromImage)
{
Caching = CachingType.ReadWrite,
ManagedDisk = new VirtualMachineScaleSetManagedDisk()
{
StorageAccountType = StorageAccountType.StandardLrs,
},
},
},
NetworkProfile = new VirtualMachineScaleSetNetworkProfile()
{
NetworkInterfaceConfigurations =
{
new VirtualMachineScaleSetNetworkConfiguration("{vmss-name}" )
{
Primary = true ,
IPConfigurations =
{
new VirtualMachineScaleSetIPConfiguration("{vmss-name}" )
{
SubnetId = new ResourceIdentifier("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
}
},
EnableIPForwarding = true ,
}
},
},
},
Overprovision = true ,
};
ArmOperation<VirtualMachineScaleSetResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, virtualMachineScaleSetName, data);
VirtualMachineScaleSetResource result = lro.Value;
VirtualMachineScaleSetData resourceData = result.Data;
Console.WriteLine($"Succeeded on id: {resourceData.Id} " );
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
範例回覆
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_D1_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "afa2afa8-9e49-48fb-9d18-c86323b5d064" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/nsgcustom"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"linuxConfiguration" : {
"disablePasswordAuthentication" : false
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_D1_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "afa2afa8-9e49-48fb-9d18-c86323b5d064" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/nsgcustom"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"linuxConfiguration" : {
"disablePasswordAuthentication" : false
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
Create a scale set from a generalized shared image.
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}?api-version=2022-11-01
{
"sku" : {
"tier" : "Standard",
"capacity" : 3,
"name" : "Standard_D1_v2"
},
"location" : "westus",
"properties" : {
"overprovision" : true,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/mySharedGallery/images/mySharedImage"
},
"osDisk" : {
"caching" : "ReadWrite",
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}",
"adminUsername" : "{your-username}",
"adminPassword" : "{your-password}"
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"primary" : true,
"enableIPForwarding" : true,
"ipConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
}
}
]
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineScaleSetInner;
import com.azure.resourcemanager.compute.models.ApiEntityReference;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.Sku;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.UpgradeMode;
import com.azure.resourcemanager.compute.models.UpgradePolicy;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetIpConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetManagedDiskParameters;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSDisk;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetStorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetVMProfile;
import java.util.Arrays;
public final class Main {
public static void createAScaleSetFromAGeneralizedSharedImage (
com.azure.resourcemanager.AzureResourceManager azure) {
azure
.virtualMachines()
.manager()
.serviceClient()
.getVirtualMachineScaleSets()
.createOrUpdate(
"myResourceGroup" ,
"{vmss-name}" ,
new VirtualMachineScaleSetInner()
.withLocation("westus" )
.withSku(new Sku().withName("Standard_D1_v2" ).withTier("Standard" ).withCapacity(3L ))
.withUpgradePolicy(new UpgradePolicy().withMode(UpgradeMode.MANUAL))
.withVirtualMachineProfile(
new VirtualMachineScaleSetVMProfile()
.withOsProfile(
new VirtualMachineScaleSetOSProfile()
.withComputerNamePrefix("{vmss-name}" )
.withAdminUsername("{your-username}" )
.withAdminPassword("fakeTokenPlaceholder" ))
.withStorageProfile(
new VirtualMachineScaleSetStorageProfile()
.withImageReference(
new ImageReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/mySharedGallery/images/mySharedImage" ))
.withOsDisk(
new VirtualMachineScaleSetOSDisk()
.withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)
.withManagedDisk(
new VirtualMachineScaleSetManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withNetworkProfile(
new VirtualMachineScaleSetNetworkProfile()
.withNetworkInterfaceConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetNetworkConfiguration()
.withName("{vmss-name}" )
.withPrimary(true )
.withIpConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetIpConfiguration()
.withName("{vmss-name}" )
.withSubnet(
new ApiEntityReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ))))
.withEnableIpForwarding(true )))))
.withOverprovision(true ),
com.azure.core.util.Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_scale_set_create_from_ageneralized_shared_image.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main () :
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="{subscription-id}" ,
)
response = client.virtual_machine_scale_sets.begin_create_or_update(
resource_group_name="myResourceGroup" ,
vm_scale_set_name="{vmss-name}" ,
parameters={
"location" : "westus" ,
"properties" : {
"overprovision" : True ,
"upgradePolicy" : {"mode" : "Manual" },
"virtualMachineProfile" : {
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"enableIPForwarding" : True ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
},
}
],
"primary" : True ,
},
}
]
},
"osProfile" : {
"adminPassword" : "{your-password}" ,
"adminUsername" : "{your-username}" ,
"computerNamePrefix" : "{vmss-name}" ,
},
"storageProfile" : {
"imageReference" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/mySharedGallery/images/mySharedImage"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"createOption" : "FromImage" ,
"managedDisk" : {"storageAccountType" : "Standard_LRS" },
},
},
},
},
"sku" : {"capacity" : 3 , "name" : "Standard_D1_v2" , "tier" : "Standard" },
},
).result()
print(response)
if __name__ == "__main__" :
main()
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4"
)
func ExampleVirtualMachineScaleSetsClient_BeginCreateOrUpdate_createAScaleSetFromAGeneralizedSharedImage () {
cred, err := azidentity.NewDefaultAzureCredential(nil )
if err != nil {
log.Fatalf("failed to obtain a credential: %v" , err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("<subscription-id>" , cred, nil )
if err != nil {
log.Fatalf("failed to create client: %v" , err)
}
poller, err := clientFactory.NewVirtualMachineScaleSetsClient().BeginCreateOrUpdate(ctx, "myResourceGroup" , "{vmss-name}" , armcompute.VirtualMachineScaleSet{
Location: to.Ptr("westus" ),
Properties: &armcompute.VirtualMachineScaleSetProperties{
Overprovision: to.Ptr(true ),
UpgradePolicy: &armcompute.UpgradePolicy{
Mode: to.Ptr(armcompute.UpgradeModeManual),
},
VirtualMachineProfile: &armcompute.VirtualMachineScaleSetVMProfile{
NetworkProfile: &armcompute.VirtualMachineScaleSetNetworkProfile{
NetworkInterfaceConfigurations: []*armcompute.VirtualMachineScaleSetNetworkConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetNetworkConfigurationProperties{
EnableIPForwarding: to.Ptr(true ),
IPConfigurations: []*armcompute.VirtualMachineScaleSetIPConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetIPConfigurationProperties{
Subnet: &armcompute.APIEntityReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
},
},
}},
Primary: to.Ptr(true ),
},
}},
},
OSProfile: &armcompute.VirtualMachineScaleSetOSProfile{
AdminPassword: to.Ptr("{your-password}" ),
AdminUsername: to.Ptr("{your-username}" ),
ComputerNamePrefix: to.Ptr("{vmss-name}" ),
},
StorageProfile: &armcompute.VirtualMachineScaleSetStorageProfile{
ImageReference: &armcompute.ImageReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/mySharedGallery/images/mySharedImage" ),
},
OSDisk: &armcompute.VirtualMachineScaleSetOSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.VirtualMachineScaleSetManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
},
},
SKU: &armcompute.SKU{
Name: to.Ptr("Standard_D1_v2" ),
Capacity: to.Ptr[int64 ](3 ),
Tier: to.Ptr("Standard" ),
},
}, nil )
if err != nil {
log.Fatalf("failed to finish the request: %v" , err)
}
res, err := poller.PollUntilDone(ctx, nil )
if err != nil {
log.Fatalf("failed to pull the result: %v" , err)
}
_ = res
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require ("@azure/arm-compute" );
const { DefaultAzureCredential } = require ("@azure/identity" );
async function createAScaleSetFromAGeneralizedSharedImage ( ) {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID" ] || "{subscription-id}" ;
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP" ] || "myResourceGroup" ;
const vmScaleSetName = "{vmss-name}" ;
const parameters = {
location : "westus" ,
overprovision : true ,
sku : { name : "Standard_D1_v2" , capacity : 3 , tier : "Standard" },
upgradePolicy : { mode : "Manual" },
virtualMachineProfile : {
networkProfile : {
networkInterfaceConfigurations : [
{
name : "{vmss-name}" ,
enableIPForwarding : true ,
ipConfigurations : [
{
name : "{vmss-name}" ,
subnet : {
id : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ,
},
},
],
primary : true ,
},
],
},
osProfile : {
adminPassword : "{your-password}" ,
adminUsername : "{your-username}" ,
computerNamePrefix : "{vmss-name}" ,
},
storageProfile : {
imageReference : {
id : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/mySharedGallery/images/mySharedImage" ,
},
osDisk : {
caching : "ReadWrite" ,
createOption : "FromImage" ,
managedDisk : { storageAccountType : "Standard_LRS" },
},
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachineScaleSets.beginCreateOrUpdateAndWait(
resourceGroupName,
vmScaleSetName,
parameters
);
console .log(result);
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Compute;
using Azure.ResourceManager.Compute.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Resources.Models;
TokenCredential cred = new DefaultAzureCredential();
ArmClient client = new ArmClient(cred);
string subscriptionId = "{subscription-id}" ;
string resourceGroupName = "myResourceGroup" ;
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
VirtualMachineScaleSetCollection collection = resourceGroupResource.GetVirtualMachineScaleSets();
string virtualMachineScaleSetName = "{vmss-name}" ;
VirtualMachineScaleSetData data = new VirtualMachineScaleSetData(new AzureLocation("westus" ))
{
Sku = new ComputeSku()
{
Name = "Standard_D1_v2" ,
Tier = "Standard" ,
Capacity = 3 ,
},
UpgradePolicy = new VirtualMachineScaleSetUpgradePolicy()
{
Mode = VirtualMachineScaleSetUpgradeMode.Manual,
},
VirtualMachineProfile = new VirtualMachineScaleSetVmProfile()
{
OSProfile = new VirtualMachineScaleSetOSProfile()
{
ComputerNamePrefix = "{vmss-name}" ,
AdminUsername = "{your-username}" ,
AdminPassword = "{your-password}" ,
},
StorageProfile = new VirtualMachineScaleSetStorageProfile()
{
ImageReference = new ImageReference()
{
Id = new ResourceIdentifier("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/mySharedGallery/images/mySharedImage" ),
},
OSDisk = new VirtualMachineScaleSetOSDisk(DiskCreateOptionType.FromImage)
{
Caching = CachingType.ReadWrite,
ManagedDisk = new VirtualMachineScaleSetManagedDisk()
{
StorageAccountType = StorageAccountType.StandardLrs,
},
},
},
NetworkProfile = new VirtualMachineScaleSetNetworkProfile()
{
NetworkInterfaceConfigurations =
{
new VirtualMachineScaleSetNetworkConfiguration("{vmss-name}" )
{
Primary = true ,
IPConfigurations =
{
new VirtualMachineScaleSetIPConfiguration("{vmss-name}" )
{
SubnetId = new ResourceIdentifier("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
}
},
EnableIPForwarding = true ,
}
},
},
},
Overprovision = true ,
};
ArmOperation<VirtualMachineScaleSetResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, virtualMachineScaleSetName, data);
VirtualMachineScaleSetResource result = lro.Value;
VirtualMachineScaleSetData resourceData = result.Data;
Console.WriteLine($"Succeeded on id: {resourceData.Id} " );
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
範例回覆
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_D1_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "afa2afa8-9e49-48fb-9d18-c86323b5d064" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/mySharedGallery/images/mySharedImage"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"linuxConfiguration" : {
"disablePasswordAuthentication" : false
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_D1_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "afa2afa8-9e49-48fb-9d18-c86323b5d064" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/mySharedGallery/images/mySharedImage"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"linuxConfiguration" : {
"disablePasswordAuthentication" : false
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
Create a scale set from a specialized shared image.
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}?api-version=2022-11-01
{
"sku" : {
"tier" : "Standard",
"capacity" : 3,
"name" : "Standard_D1_v2"
},
"location" : "westus",
"properties" : {
"overprovision" : true,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/mySharedGallery/images/mySharedImage"
},
"osDisk" : {
"caching" : "ReadWrite",
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"primary" : true,
"enableIPForwarding" : true,
"ipConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
}
}
]
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineScaleSetInner;
import com.azure.resourcemanager.compute.models.ApiEntityReference;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.Sku;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.UpgradeMode;
import com.azure.resourcemanager.compute.models.UpgradePolicy;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetIpConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetManagedDiskParameters;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSDisk;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetStorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetVMProfile;
import java.util.Arrays;
public final class Main {
public static void createAScaleSetFromASpecializedSharedImage (
com.azure.resourcemanager.AzureResourceManager azure) {
azure
.virtualMachines()
.manager()
.serviceClient()
.getVirtualMachineScaleSets()
.createOrUpdate(
"myResourceGroup" ,
"{vmss-name}" ,
new VirtualMachineScaleSetInner()
.withLocation("westus" )
.withSku(new Sku().withName("Standard_D1_v2" ).withTier("Standard" ).withCapacity(3L ))
.withUpgradePolicy(new UpgradePolicy().withMode(UpgradeMode.MANUAL))
.withVirtualMachineProfile(
new VirtualMachineScaleSetVMProfile()
.withStorageProfile(
new VirtualMachineScaleSetStorageProfile()
.withImageReference(
new ImageReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/mySharedGallery/images/mySharedImage" ))
.withOsDisk(
new VirtualMachineScaleSetOSDisk()
.withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)
.withManagedDisk(
new VirtualMachineScaleSetManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withNetworkProfile(
new VirtualMachineScaleSetNetworkProfile()
.withNetworkInterfaceConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetNetworkConfiguration()
.withName("{vmss-name}" )
.withPrimary(true )
.withIpConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetIpConfiguration()
.withName("{vmss-name}" )
.withSubnet(
new ApiEntityReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ))))
.withEnableIpForwarding(true )))))
.withOverprovision(true ),
com.azure.core.util.Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_scale_set_create_from_aspecialized_shared_image.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main () :
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="{subscription-id}" ,
)
response = client.virtual_machine_scale_sets.begin_create_or_update(
resource_group_name="myResourceGroup" ,
vm_scale_set_name="{vmss-name}" ,
parameters={
"location" : "westus" ,
"properties" : {
"overprovision" : True ,
"upgradePolicy" : {"mode" : "Manual" },
"virtualMachineProfile" : {
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"enableIPForwarding" : True ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
},
}
],
"primary" : True ,
},
}
]
},
"storageProfile" : {
"imageReference" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/mySharedGallery/images/mySharedImage"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"createOption" : "FromImage" ,
"managedDisk" : {"storageAccountType" : "Standard_LRS" },
},
},
},
},
"sku" : {"capacity" : 3 , "name" : "Standard_D1_v2" , "tier" : "Standard" },
},
).result()
print(response)
if __name__ == "__main__" :
main()
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4"
)
func ExampleVirtualMachineScaleSetsClient_BeginCreateOrUpdate_createAScaleSetFromASpecializedSharedImage () {
cred, err := azidentity.NewDefaultAzureCredential(nil )
if err != nil {
log.Fatalf("failed to obtain a credential: %v" , err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("<subscription-id>" , cred, nil )
if err != nil {
log.Fatalf("failed to create client: %v" , err)
}
poller, err := clientFactory.NewVirtualMachineScaleSetsClient().BeginCreateOrUpdate(ctx, "myResourceGroup" , "{vmss-name}" , armcompute.VirtualMachineScaleSet{
Location: to.Ptr("westus" ),
Properties: &armcompute.VirtualMachineScaleSetProperties{
Overprovision: to.Ptr(true ),
UpgradePolicy: &armcompute.UpgradePolicy{
Mode: to.Ptr(armcompute.UpgradeModeManual),
},
VirtualMachineProfile: &armcompute.VirtualMachineScaleSetVMProfile{
NetworkProfile: &armcompute.VirtualMachineScaleSetNetworkProfile{
NetworkInterfaceConfigurations: []*armcompute.VirtualMachineScaleSetNetworkConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetNetworkConfigurationProperties{
EnableIPForwarding: to.Ptr(true ),
IPConfigurations: []*armcompute.VirtualMachineScaleSetIPConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetIPConfigurationProperties{
Subnet: &armcompute.APIEntityReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
},
},
}},
Primary: to.Ptr(true ),
},
}},
},
StorageProfile: &armcompute.VirtualMachineScaleSetStorageProfile{
ImageReference: &armcompute.ImageReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/mySharedGallery/images/mySharedImage" ),
},
OSDisk: &armcompute.VirtualMachineScaleSetOSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.VirtualMachineScaleSetManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
},
},
SKU: &armcompute.SKU{
Name: to.Ptr("Standard_D1_v2" ),
Capacity: to.Ptr[int64 ](3 ),
Tier: to.Ptr("Standard" ),
},
}, nil )
if err != nil {
log.Fatalf("failed to finish the request: %v" , err)
}
res, err := poller.PollUntilDone(ctx, nil )
if err != nil {
log.Fatalf("failed to pull the result: %v" , err)
}
_ = res
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require ("@azure/arm-compute" );
const { DefaultAzureCredential } = require ("@azure/identity" );
async function createAScaleSetFromASpecializedSharedImage ( ) {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID" ] || "{subscription-id}" ;
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP" ] || "myResourceGroup" ;
const vmScaleSetName = "{vmss-name}" ;
const parameters = {
location : "westus" ,
overprovision : true ,
sku : { name : "Standard_D1_v2" , capacity : 3 , tier : "Standard" },
upgradePolicy : { mode : "Manual" },
virtualMachineProfile : {
networkProfile : {
networkInterfaceConfigurations : [
{
name : "{vmss-name}" ,
enableIPForwarding : true ,
ipConfigurations : [
{
name : "{vmss-name}" ,
subnet : {
id : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ,
},
},
],
primary : true ,
},
],
},
storageProfile : {
imageReference : {
id : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/mySharedGallery/images/mySharedImage" ,
},
osDisk : {
caching : "ReadWrite" ,
createOption : "FromImage" ,
managedDisk : { storageAccountType : "Standard_LRS" },
},
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachineScaleSets.beginCreateOrUpdateAndWait(
resourceGroupName,
vmScaleSetName,
parameters
);
console .log(result);
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Compute;
using Azure.ResourceManager.Compute.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Resources.Models;
TokenCredential cred = new DefaultAzureCredential();
ArmClient client = new ArmClient(cred);
string subscriptionId = "{subscription-id}" ;
string resourceGroupName = "myResourceGroup" ;
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
VirtualMachineScaleSetCollection collection = resourceGroupResource.GetVirtualMachineScaleSets();
string virtualMachineScaleSetName = "{vmss-name}" ;
VirtualMachineScaleSetData data = new VirtualMachineScaleSetData(new AzureLocation("westus" ))
{
Sku = new ComputeSku()
{
Name = "Standard_D1_v2" ,
Tier = "Standard" ,
Capacity = 3 ,
},
UpgradePolicy = new VirtualMachineScaleSetUpgradePolicy()
{
Mode = VirtualMachineScaleSetUpgradeMode.Manual,
},
VirtualMachineProfile = new VirtualMachineScaleSetVmProfile()
{
StorageProfile = new VirtualMachineScaleSetStorageProfile()
{
ImageReference = new ImageReference()
{
Id = new ResourceIdentifier("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/mySharedGallery/images/mySharedImage" ),
},
OSDisk = new VirtualMachineScaleSetOSDisk(DiskCreateOptionType.FromImage)
{
Caching = CachingType.ReadWrite,
ManagedDisk = new VirtualMachineScaleSetManagedDisk()
{
StorageAccountType = StorageAccountType.StandardLrs,
},
},
},
NetworkProfile = new VirtualMachineScaleSetNetworkProfile()
{
NetworkInterfaceConfigurations =
{
new VirtualMachineScaleSetNetworkConfiguration("{vmss-name}" )
{
Primary = true ,
IPConfigurations =
{
new VirtualMachineScaleSetIPConfiguration("{vmss-name}" )
{
SubnetId = new ResourceIdentifier("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
}
},
EnableIPForwarding = true ,
}
},
},
},
Overprovision = true ,
};
ArmOperation<VirtualMachineScaleSetResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, virtualMachineScaleSetName, data);
VirtualMachineScaleSetResource result = lro.Value;
VirtualMachineScaleSetData resourceData = result.Data;
Console.WriteLine($"Succeeded on id: {resourceData.Id} " );
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
範例回覆
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_D1_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "afa2afa8-9e49-48fb-9d18-c86323b5d064" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/mySharedGallery/images/mySharedImage"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_D1_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "afa2afa8-9e49-48fb-9d18-c86323b5d064" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/mySharedGallery/images/mySharedImage"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
Create a scale set where nic config has DisableTcpStateTracking property
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}?api-version=2022-11-01
{
"sku" : {
"tier" : "Standard",
"capacity" : 3,
"name" : "Standard_D1_v2"
},
"location" : "westus",
"properties" : {
"overprovision" : true,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/{existing-custom-image-name}"
},
"osDisk" : {
"caching" : "ReadWrite",
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}",
"adminUsername" : "{your-username}",
"adminPassword" : "{your-password}"
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{nicConfig1-name}",
"properties" : {
"primary" : true,
"enableIPForwarding" : true,
"disableTcpStateTracking" : true,
"enableAcceleratedNetworking" : true,
"ipConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
}
}
]
}
},
{
"name" : "{nicConfig2-name}",
"properties" : {
"primary" : false,
"enableAcceleratedNetworking" : false,
"enableIPForwarding" : false,
"disableTcpStateTracking" : false,
"ipConfigurations" : [
{
"name" : "{nicConfig2-name}",
"properties" : {
"primary" : true,
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-fpga-subnet-name2}"
},
"privateIPAddressVersion" : "IPv4"
}
}
]
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineScaleSetInner;
import com.azure.resourcemanager.compute.models.ApiEntityReference;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.IpVersion;
import com.azure.resourcemanager.compute.models.Sku;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.UpgradeMode;
import com.azure.resourcemanager.compute.models.UpgradePolicy;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetIpConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetManagedDiskParameters;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSDisk;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetStorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetVMProfile;
import java.util.Arrays;
public final class Main {
public static void createAScaleSetWhereNicConfigHasDisableTcpStateTrackingProperty (
com.azure.resourcemanager.AzureResourceManager azure) {
azure
.virtualMachines()
.manager()
.serviceClient()
.getVirtualMachineScaleSets()
.createOrUpdate(
"myResourceGroup" ,
"{vmss-name}" ,
new VirtualMachineScaleSetInner()
.withLocation("westus" )
.withSku(new Sku().withName("Standard_D1_v2" ).withTier("Standard" ).withCapacity(3L ))
.withUpgradePolicy(new UpgradePolicy().withMode(UpgradeMode.MANUAL))
.withVirtualMachineProfile(
new VirtualMachineScaleSetVMProfile()
.withOsProfile(
new VirtualMachineScaleSetOSProfile()
.withComputerNamePrefix("{vmss-name}" )
.withAdminUsername("{your-username}" )
.withAdminPassword("fakeTokenPlaceholder" ))
.withStorageProfile(
new VirtualMachineScaleSetStorageProfile()
.withImageReference(
new ImageReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/{existing-custom-image-name}" ))
.withOsDisk(
new VirtualMachineScaleSetOSDisk()
.withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)
.withManagedDisk(
new VirtualMachineScaleSetManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withNetworkProfile(
new VirtualMachineScaleSetNetworkProfile()
.withNetworkInterfaceConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetNetworkConfiguration()
.withName("{nicConfig1-name}" )
.withPrimary(true )
.withEnableAcceleratedNetworking(true )
.withDisableTcpStateTracking(true )
.withIpConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetIpConfiguration()
.withName("{vmss-name}" )
.withSubnet(
new ApiEntityReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ))))
.withEnableIpForwarding(true ),
new VirtualMachineScaleSetNetworkConfiguration()
.withName("{nicConfig2-name}" )
.withPrimary(false )
.withEnableAcceleratedNetworking(false )
.withDisableTcpStateTracking(false )
.withIpConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetIpConfiguration()
.withName("{nicConfig2-name}" )
.withSubnet(
new ApiEntityReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-fpga-subnet-name2}" ))
.withPrimary(true )
.withPrivateIpAddressVersion(IpVersion.IPV4)))
.withEnableIpForwarding(false )))))
.withOverprovision(true ),
com.azure.core.util.Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_scale_set_create_from_with_disable_tcp_state_tracking_network_interface.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main () :
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="{subscription-id}" ,
)
response = client.virtual_machine_scale_sets.begin_create_or_update(
resource_group_name="myResourceGroup" ,
vm_scale_set_name="{vmss-name}" ,
parameters={
"location" : "westus" ,
"properties" : {
"overprovision" : True ,
"upgradePolicy" : {"mode" : "Manual" },
"virtualMachineProfile" : {
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{nicConfig1-name}" ,
"properties" : {
"disableTcpStateTracking" : True ,
"enableAcceleratedNetworking" : True ,
"enableIPForwarding" : True ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
},
}
],
"primary" : True ,
},
},
{
"name" : "{nicConfig2-name}" ,
"properties" : {
"disableTcpStateTracking" : False ,
"enableAcceleratedNetworking" : False ,
"enableIPForwarding" : False ,
"ipConfigurations" : [
{
"name" : "{nicConfig2-name}" ,
"properties" : {
"primary" : True ,
"privateIPAddressVersion" : "IPv4" ,
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-fpga-subnet-name2}"
},
},
}
],
"primary" : False ,
},
},
]
},
"osProfile" : {
"adminPassword" : "{your-password}" ,
"adminUsername" : "{your-username}" ,
"computerNamePrefix" : "{vmss-name}" ,
},
"storageProfile" : {
"imageReference" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/{existing-custom-image-name}"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"createOption" : "FromImage" ,
"managedDisk" : {"storageAccountType" : "Standard_LRS" },
},
},
},
},
"sku" : {"capacity" : 3 , "name" : "Standard_D1_v2" , "tier" : "Standard" },
},
).result()
print(response)
if __name__ == "__main__" :
main()
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4"
)
func ExampleVirtualMachineScaleSetsClient_BeginCreateOrUpdate_createAScaleSetWhereNicConfigHasDisableTcpStateTrackingProperty () {
cred, err := azidentity.NewDefaultAzureCredential(nil )
if err != nil {
log.Fatalf("failed to obtain a credential: %v" , err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("<subscription-id>" , cred, nil )
if err != nil {
log.Fatalf("failed to create client: %v" , err)
}
poller, err := clientFactory.NewVirtualMachineScaleSetsClient().BeginCreateOrUpdate(ctx, "myResourceGroup" , "{vmss-name}" , armcompute.VirtualMachineScaleSet{
Location: to.Ptr("westus" ),
Properties: &armcompute.VirtualMachineScaleSetProperties{
Overprovision: to.Ptr(true ),
UpgradePolicy: &armcompute.UpgradePolicy{
Mode: to.Ptr(armcompute.UpgradeModeManual),
},
VirtualMachineProfile: &armcompute.VirtualMachineScaleSetVMProfile{
NetworkProfile: &armcompute.VirtualMachineScaleSetNetworkProfile{
NetworkInterfaceConfigurations: []*armcompute.VirtualMachineScaleSetNetworkConfiguration{
{
Name: to.Ptr("{nicConfig1-name}" ),
Properties: &armcompute.VirtualMachineScaleSetNetworkConfigurationProperties{
DisableTCPStateTracking: to.Ptr(true ),
EnableAcceleratedNetworking: to.Ptr(true ),
EnableIPForwarding: to.Ptr(true ),
IPConfigurations: []*armcompute.VirtualMachineScaleSetIPConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetIPConfigurationProperties{
Subnet: &armcompute.APIEntityReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
},
},
}},
Primary: to.Ptr(true ),
},
},
{
Name: to.Ptr("{nicConfig2-name}" ),
Properties: &armcompute.VirtualMachineScaleSetNetworkConfigurationProperties{
DisableTCPStateTracking: to.Ptr(false ),
EnableAcceleratedNetworking: to.Ptr(false ),
EnableIPForwarding: to.Ptr(false ),
IPConfigurations: []*armcompute.VirtualMachineScaleSetIPConfiguration{
{
Name: to.Ptr("{nicConfig2-name}" ),
Properties: &armcompute.VirtualMachineScaleSetIPConfigurationProperties{
Primary: to.Ptr(true ),
PrivateIPAddressVersion: to.Ptr(armcompute.IPVersionIPv4),
Subnet: &armcompute.APIEntityReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-fpga-subnet-name2}" ),
},
},
}},
Primary: to.Ptr(false ),
},
}},
},
OSProfile: &armcompute.VirtualMachineScaleSetOSProfile{
AdminPassword: to.Ptr("{your-password}" ),
AdminUsername: to.Ptr("{your-username}" ),
ComputerNamePrefix: to.Ptr("{vmss-name}" ),
},
StorageProfile: &armcompute.VirtualMachineScaleSetStorageProfile{
ImageReference: &armcompute.ImageReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/{existing-custom-image-name}" ),
},
OSDisk: &armcompute.VirtualMachineScaleSetOSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.VirtualMachineScaleSetManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
},
},
SKU: &armcompute.SKU{
Name: to.Ptr("Standard_D1_v2" ),
Capacity: to.Ptr[int64 ](3 ),
Tier: to.Ptr("Standard" ),
},
}, nil )
if err != nil {
log.Fatalf("failed to finish the request: %v" , err)
}
res, err := poller.PollUntilDone(ctx, nil )
if err != nil {
log.Fatalf("failed to pull the result: %v" , err)
}
_ = res
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require ("@azure/arm-compute" );
const { DefaultAzureCredential } = require ("@azure/identity" );
async function createAScaleSetWhereNicConfigHasDisableTcpStateTrackingProperty ( ) {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID" ] || "{subscription-id}" ;
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP" ] || "myResourceGroup" ;
const vmScaleSetName = "{vmss-name}" ;
const parameters = {
location : "westus" ,
overprovision : true ,
sku : { name : "Standard_D1_v2" , capacity : 3 , tier : "Standard" },
upgradePolicy : { mode : "Manual" },
virtualMachineProfile : {
networkProfile : {
networkInterfaceConfigurations : [
{
name : "{nicConfig1-name}" ,
disableTcpStateTracking : true ,
enableAcceleratedNetworking : true ,
enableIPForwarding : true ,
ipConfigurations : [
{
name : "{vmss-name}" ,
subnet : {
id : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ,
},
},
],
primary : true ,
},
{
name : "{nicConfig2-name}" ,
disableTcpStateTracking : false ,
enableAcceleratedNetworking : false ,
enableIPForwarding : false ,
ipConfigurations : [
{
name : "{nicConfig2-name}" ,
primary : true ,
privateIPAddressVersion : "IPv4" ,
subnet : {
id : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-fpga-subnet-name2}" ,
},
},
],
primary : false ,
},
],
},
osProfile : {
adminPassword : "{your-password}" ,
adminUsername : "{your-username}" ,
computerNamePrefix : "{vmss-name}" ,
},
storageProfile : {
imageReference : {
id : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/{existing-custom-image-name}" ,
},
osDisk : {
caching : "ReadWrite" ,
createOption : "FromImage" ,
managedDisk : { storageAccountType : "Standard_LRS" },
},
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachineScaleSets.beginCreateOrUpdateAndWait(
resourceGroupName,
vmScaleSetName,
parameters
);
console .log(result);
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Compute;
using Azure.ResourceManager.Compute.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Resources.Models;
TokenCredential cred = new DefaultAzureCredential();
ArmClient client = new ArmClient(cred);
string subscriptionId = "{subscription-id}" ;
string resourceGroupName = "myResourceGroup" ;
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
VirtualMachineScaleSetCollection collection = resourceGroupResource.GetVirtualMachineScaleSets();
string virtualMachineScaleSetName = "{vmss-name}" ;
VirtualMachineScaleSetData data = new VirtualMachineScaleSetData(new AzureLocation("westus" ))
{
Sku = new ComputeSku()
{
Name = "Standard_D1_v2" ,
Tier = "Standard" ,
Capacity = 3 ,
},
UpgradePolicy = new VirtualMachineScaleSetUpgradePolicy()
{
Mode = VirtualMachineScaleSetUpgradeMode.Manual,
},
VirtualMachineProfile = new VirtualMachineScaleSetVmProfile()
{
OSProfile = new VirtualMachineScaleSetOSProfile()
{
ComputerNamePrefix = "{vmss-name}" ,
AdminUsername = "{your-username}" ,
AdminPassword = "{your-password}" ,
},
StorageProfile = new VirtualMachineScaleSetStorageProfile()
{
ImageReference = new ImageReference()
{
Id = new ResourceIdentifier("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/{existing-custom-image-name}" ),
},
OSDisk = new VirtualMachineScaleSetOSDisk(DiskCreateOptionType.FromImage)
{
Caching = CachingType.ReadWrite,
ManagedDisk = new VirtualMachineScaleSetManagedDisk()
{
StorageAccountType = StorageAccountType.StandardLrs,
},
},
},
NetworkProfile = new VirtualMachineScaleSetNetworkProfile()
{
NetworkInterfaceConfigurations =
{
new VirtualMachineScaleSetNetworkConfiguration("{nicConfig1-name}" )
{
Primary = true ,
EnableAcceleratedNetworking = true ,
IsTcpStateTrackingDisabled = true ,
IPConfigurations =
{
new VirtualMachineScaleSetIPConfiguration("{vmss-name}" )
{
SubnetId = new ResourceIdentifier("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
}
},
EnableIPForwarding = true ,
},new VirtualMachineScaleSetNetworkConfiguration("{nicConfig2-name}" )
{
Primary = false ,
EnableAcceleratedNetworking = false ,
IsTcpStateTrackingDisabled = false ,
IPConfigurations =
{
new VirtualMachineScaleSetIPConfiguration("{nicConfig2-name}" )
{
SubnetId = new ResourceIdentifier("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-fpga-subnet-name2}" ),
Primary = true ,
PrivateIPAddressVersion = IPVersion.IPv4,
}
},
EnableIPForwarding = false ,
}
},
},
},
Overprovision = true ,
};
ArmOperation<VirtualMachineScaleSetResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, virtualMachineScaleSetName, data);
VirtualMachineScaleSetResource result = lro.Value;
VirtualMachineScaleSetData resourceData = result.Data;
Console.WriteLine($"Succeeded on id: {resourceData.Id} " );
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
範例回覆
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_D1_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "afa2afa8-9e49-48fb-9d18-c86323b5d064" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/nsgcustom"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"linuxConfiguration" : {
"disablePasswordAuthentication" : false
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{nicConfig1-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"disableTcpStateTracking" : true ,
"ipConfigurations" : [
{
"name" : "{nicConfig1-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : true
}
},
{
"name" : "{nicConfig2-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : false ,
"enableFpga" : false ,
"disableTcpStateTracking" : false ,
"ipConfigurations" : [
{
"name" : "{nicConfig2-name}" ,
"properties" : {
"primary" : true ,
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-fpga-subnet-name2}"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_D1_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "afa2afa8-9e49-48fb-9d18-c86323b5d064" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/nsgcustom"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"linuxConfiguration" : {
"disablePasswordAuthentication" : false
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{nicConfig1-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"disableTcpStateTracking" : true ,
"ipConfigurations" : [
{
"name" : "{nicConfig1-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : true
}
},
{
"name" : "{nicConfig2-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : false ,
"enableFpga" : false ,
"disableTcpStateTracking" : false ,
"ipConfigurations" : [
{
"name" : "{nicConfig2-name}" ,
"properties" : {
"primary" : true ,
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-fpga-subnet-name2}"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
Create a scale set with a marketplace image plan.
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}?api-version=2022-11-01
{
"sku" : {
"tier" : "Standard",
"capacity" : 3,
"name" : "Standard_D1_v2"
},
"properties" : {
"overprovision" : true,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "windows2016",
"publisher" : "microsoft-ads",
"version" : "latest",
"offer" : "windows-data-science-vm"
},
"osDisk" : {
"caching" : "ReadWrite",
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}",
"adminUsername" : "{your-username}",
"adminPassword" : "{your-password}"
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"primary" : true,
"enableIPForwarding" : true,
"ipConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
}
}
]
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
}
},
"plan" : {
"publisher" : "microsoft-ads",
"product" : "windows-data-science-vm",
"name" : "windows2016"
},
"location" : "westus"
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineScaleSetInner;
import com.azure.resourcemanager.compute.models.ApiEntityReference;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.Plan;
import com.azure.resourcemanager.compute.models.Sku;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.UpgradeMode;
import com.azure.resourcemanager.compute.models.UpgradePolicy;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetIpConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetManagedDiskParameters;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSDisk;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetStorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetVMProfile;
import java.util.Arrays;
public final class Main {
public static void createAScaleSetWithAMarketplaceImagePlan (com.azure.resourcemanager.AzureResourceManager azure) {
azure
.virtualMachines()
.manager()
.serviceClient()
.getVirtualMachineScaleSets()
.createOrUpdate(
"myResourceGroup" ,
"{vmss-name}" ,
new VirtualMachineScaleSetInner()
.withLocation("westus" )
.withSku(new Sku().withName("Standard_D1_v2" ).withTier("Standard" ).withCapacity(3L ))
.withPlan(
new Plan()
.withName("windows2016" )
.withPublisher("microsoft-ads" )
.withProduct("windows-data-science-vm" ))
.withUpgradePolicy(new UpgradePolicy().withMode(UpgradeMode.MANUAL))
.withVirtualMachineProfile(
new VirtualMachineScaleSetVMProfile()
.withOsProfile(
new VirtualMachineScaleSetOSProfile()
.withComputerNamePrefix("{vmss-name}" )
.withAdminUsername("{your-username}" )
.withAdminPassword("fakeTokenPlaceholder" ))
.withStorageProfile(
new VirtualMachineScaleSetStorageProfile()
.withImageReference(
new ImageReference()
.withPublisher("microsoft-ads" )
.withOffer("windows-data-science-vm" )
.withSku("windows2016" )
.withVersion("latest" ))
.withOsDisk(
new VirtualMachineScaleSetOSDisk()
.withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)
.withManagedDisk(
new VirtualMachineScaleSetManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withNetworkProfile(
new VirtualMachineScaleSetNetworkProfile()
.withNetworkInterfaceConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetNetworkConfiguration()
.withName("{vmss-name}" )
.withPrimary(true )
.withIpConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetIpConfiguration()
.withName("{vmss-name}" )
.withSubnet(
new ApiEntityReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ))))
.withEnableIpForwarding(true )))))
.withOverprovision(true ),
com.azure.core.util.Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_scale_set_create_with_amarketplace_image_plan.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main () :
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="{subscription-id}" ,
)
response = client.virtual_machine_scale_sets.begin_create_or_update(
resource_group_name="myResourceGroup" ,
vm_scale_set_name="{vmss-name}" ,
parameters={
"location" : "westus" ,
"plan" : {"name" : "windows2016" , "product" : "windows-data-science-vm" , "publisher" : "microsoft-ads" },
"properties" : {
"overprovision" : True ,
"upgradePolicy" : {"mode" : "Manual" },
"virtualMachineProfile" : {
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"enableIPForwarding" : True ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
},
}
],
"primary" : True ,
},
}
]
},
"osProfile" : {
"adminPassword" : "{your-password}" ,
"adminUsername" : "{your-username}" ,
"computerNamePrefix" : "{vmss-name}" ,
},
"storageProfile" : {
"imageReference" : {
"offer" : "windows-data-science-vm" ,
"publisher" : "microsoft-ads" ,
"sku" : "windows2016" ,
"version" : "latest" ,
},
"osDisk" : {
"caching" : "ReadWrite" ,
"createOption" : "FromImage" ,
"managedDisk" : {"storageAccountType" : "Standard_LRS" },
},
},
},
},
"sku" : {"capacity" : 3 , "name" : "Standard_D1_v2" , "tier" : "Standard" },
},
).result()
print(response)
if __name__ == "__main__" :
main()
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4"
)
func ExampleVirtualMachineScaleSetsClient_BeginCreateOrUpdate_createAScaleSetWithAMarketplaceImagePlan () {
cred, err := azidentity.NewDefaultAzureCredential(nil )
if err != nil {
log.Fatalf("failed to obtain a credential: %v" , err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("<subscription-id>" , cred, nil )
if err != nil {
log.Fatalf("failed to create client: %v" , err)
}
poller, err := clientFactory.NewVirtualMachineScaleSetsClient().BeginCreateOrUpdate(ctx, "myResourceGroup" , "{vmss-name}" , armcompute.VirtualMachineScaleSet{
Location: to.Ptr("westus" ),
Plan: &armcompute.Plan{
Name: to.Ptr("windows2016" ),
Product: to.Ptr("windows-data-science-vm" ),
Publisher: to.Ptr("microsoft-ads" ),
},
Properties: &armcompute.VirtualMachineScaleSetProperties{
Overprovision: to.Ptr(true ),
UpgradePolicy: &armcompute.UpgradePolicy{
Mode: to.Ptr(armcompute.UpgradeModeManual),
},
VirtualMachineProfile: &armcompute.VirtualMachineScaleSetVMProfile{
NetworkProfile: &armcompute.VirtualMachineScaleSetNetworkProfile{
NetworkInterfaceConfigurations: []*armcompute.VirtualMachineScaleSetNetworkConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetNetworkConfigurationProperties{
EnableIPForwarding: to.Ptr(true ),
IPConfigurations: []*armcompute.VirtualMachineScaleSetIPConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetIPConfigurationProperties{
Subnet: &armcompute.APIEntityReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
},
},
}},
Primary: to.Ptr(true ),
},
}},
},
OSProfile: &armcompute.VirtualMachineScaleSetOSProfile{
AdminPassword: to.Ptr("{your-password}" ),
AdminUsername: to.Ptr("{your-username}" ),
ComputerNamePrefix: to.Ptr("{vmss-name}" ),
},
StorageProfile: &armcompute.VirtualMachineScaleSetStorageProfile{
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("windows-data-science-vm" ),
Publisher: to.Ptr("microsoft-ads" ),
SKU: to.Ptr("windows2016" ),
Version: to.Ptr("latest" ),
},
OSDisk: &armcompute.VirtualMachineScaleSetOSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.VirtualMachineScaleSetManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
},
},
SKU: &armcompute.SKU{
Name: to.Ptr("Standard_D1_v2" ),
Capacity: to.Ptr[int64 ](3 ),
Tier: to.Ptr("Standard" ),
},
}, nil )
if err != nil {
log.Fatalf("failed to finish the request: %v" , err)
}
res, err := poller.PollUntilDone(ctx, nil )
if err != nil {
log.Fatalf("failed to pull the result: %v" , err)
}
_ = res
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require ("@azure/arm-compute" );
const { DefaultAzureCredential } = require ("@azure/identity" );
async function createAScaleSetWithAMarketplaceImagePlan ( ) {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID" ] || "{subscription-id}" ;
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP" ] || "myResourceGroup" ;
const vmScaleSetName = "{vmss-name}" ;
const parameters = {
location : "westus" ,
overprovision : true ,
plan : {
name : "windows2016" ,
product : "windows-data-science-vm" ,
publisher : "microsoft-ads" ,
},
sku : { name : "Standard_D1_v2" , capacity : 3 , tier : "Standard" },
upgradePolicy : { mode : "Manual" },
virtualMachineProfile : {
networkProfile : {
networkInterfaceConfigurations : [
{
name : "{vmss-name}" ,
enableIPForwarding : true ,
ipConfigurations : [
{
name : "{vmss-name}" ,
subnet : {
id : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ,
},
},
],
primary : true ,
},
],
},
osProfile : {
adminPassword : "{your-password}" ,
adminUsername : "{your-username}" ,
computerNamePrefix : "{vmss-name}" ,
},
storageProfile : {
imageReference : {
offer : "windows-data-science-vm" ,
publisher : "microsoft-ads" ,
sku : "windows2016" ,
version : "latest" ,
},
osDisk : {
caching : "ReadWrite" ,
createOption : "FromImage" ,
managedDisk : { storageAccountType : "Standard_LRS" },
},
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachineScaleSets.beginCreateOrUpdateAndWait(
resourceGroupName,
vmScaleSetName,
parameters
);
console .log(result);
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Compute;
using Azure.ResourceManager.Compute.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Resources.Models;
TokenCredential cred = new DefaultAzureCredential();
ArmClient client = new ArmClient(cred);
string subscriptionId = "{subscription-id}" ;
string resourceGroupName = "myResourceGroup" ;
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
VirtualMachineScaleSetCollection collection = resourceGroupResource.GetVirtualMachineScaleSets();
string virtualMachineScaleSetName = "{vmss-name}" ;
VirtualMachineScaleSetData data = new VirtualMachineScaleSetData(new AzureLocation("westus" ))
{
Sku = new ComputeSku()
{
Name = "Standard_D1_v2" ,
Tier = "Standard" ,
Capacity = 3 ,
},
Plan = new ComputePlan()
{
Name = "windows2016" ,
Publisher = "microsoft-ads" ,
Product = "windows-data-science-vm" ,
},
UpgradePolicy = new VirtualMachineScaleSetUpgradePolicy()
{
Mode = VirtualMachineScaleSetUpgradeMode.Manual,
},
VirtualMachineProfile = new VirtualMachineScaleSetVmProfile()
{
OSProfile = new VirtualMachineScaleSetOSProfile()
{
ComputerNamePrefix = "{vmss-name}" ,
AdminUsername = "{your-username}" ,
AdminPassword = "{your-password}" ,
},
StorageProfile = new VirtualMachineScaleSetStorageProfile()
{
ImageReference = new ImageReference()
{
Publisher = "microsoft-ads" ,
Offer = "windows-data-science-vm" ,
Sku = "windows2016" ,
Version = "latest" ,
},
OSDisk = new VirtualMachineScaleSetOSDisk(DiskCreateOptionType.FromImage)
{
Caching = CachingType.ReadWrite,
ManagedDisk = new VirtualMachineScaleSetManagedDisk()
{
StorageAccountType = StorageAccountType.StandardLrs,
},
},
},
NetworkProfile = new VirtualMachineScaleSetNetworkProfile()
{
NetworkInterfaceConfigurations =
{
new VirtualMachineScaleSetNetworkConfiguration("{vmss-name}" )
{
Primary = true ,
IPConfigurations =
{
new VirtualMachineScaleSetIPConfiguration("{vmss-name}" )
{
SubnetId = new ResourceIdentifier("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
}
},
EnableIPForwarding = true ,
}
},
},
},
Overprovision = true ,
};
ArmOperation<VirtualMachineScaleSetResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, virtualMachineScaleSetName, data);
VirtualMachineScaleSetResource result = lro.Value;
VirtualMachineScaleSetData resourceData = result.Data;
Console.WriteLine($"Succeeded on id: {resourceData.Id} " );
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
範例回覆
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_D1_v2"
},
"name" : "{vmss-name}" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}" ,
"plan" : {
"publisher" : "microsoft-ads" ,
"product" : "standard-data-science-vm" ,
"name" : "standard-data-science-vm"
},
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "b9e23088-6ffc-46e0-9e02-b0a6eeef47db" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "standard-data-science-vm" ,
"publisher" : "microsoft-ads" ,
"version" : "latest" ,
"offer" : "standard-data-science-vm"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus"
}
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_D1_v2"
},
"name" : "{vmss-name}" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}" ,
"plan" : {
"publisher" : "microsoft-ads" ,
"product" : "standard-data-science-vm" ,
"name" : "standard-data-science-vm"
},
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "b9e23088-6ffc-46e0-9e02-b0a6eeef47db" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "standard-data-science-vm" ,
"publisher" : "microsoft-ads" ,
"version" : "latest" ,
"offer" : "standard-data-science-vm"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus"
}
Create a scale set with an azure application gateway.
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}?api-version=2022-11-01
{
"sku" : {
"tier" : "Standard",
"capacity" : 3,
"name" : "Standard_D1_v2"
},
"location" : "westus",
"properties" : {
"overprovision" : true,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter",
"publisher" : "MicrosoftWindowsServer",
"version" : "latest",
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite",
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}",
"adminUsername" : "{your-username}",
"adminPassword" : "{your-password}"
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"primary" : true,
"enableIPForwarding" : true,
"ipConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"applicationGatewayBackendAddressPools" : [
{
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/applicationGateways/{existing-application-gateway-name}/backendAddressPools/{existing-backend-address-pool-name}"
}
],
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
}
}
]
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
}
}
}
import com.azure.core.management.SubResource;
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineScaleSetInner;
import com.azure.resourcemanager.compute.models.ApiEntityReference;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.Sku;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.UpgradeMode;
import com.azure.resourcemanager.compute.models.UpgradePolicy;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetIpConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetManagedDiskParameters;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSDisk;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetStorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetVMProfile;
import java.util.Arrays;
public final class Main {
public static void createAScaleSetWithAnAzureApplicationGateway (
com.azure.resourcemanager.AzureResourceManager azure) {
azure
.virtualMachines()
.manager()
.serviceClient()
.getVirtualMachineScaleSets()
.createOrUpdate(
"myResourceGroup" ,
"{vmss-name}" ,
new VirtualMachineScaleSetInner()
.withLocation("westus" )
.withSku(new Sku().withName("Standard_D1_v2" ).withTier("Standard" ).withCapacity(3L ))
.withUpgradePolicy(new UpgradePolicy().withMode(UpgradeMode.MANUAL))
.withVirtualMachineProfile(
new VirtualMachineScaleSetVMProfile()
.withOsProfile(
new VirtualMachineScaleSetOSProfile()
.withComputerNamePrefix("{vmss-name}" )
.withAdminUsername("{your-username}" )
.withAdminPassword("fakeTokenPlaceholder" ))
.withStorageProfile(
new VirtualMachineScaleSetStorageProfile()
.withImageReference(
new ImageReference()
.withPublisher("MicrosoftWindowsServer" )
.withOffer("WindowsServer" )
.withSku("2016-Datacenter" )
.withVersion("latest" ))
.withOsDisk(
new VirtualMachineScaleSetOSDisk()
.withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)
.withManagedDisk(
new VirtualMachineScaleSetManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withNetworkProfile(
new VirtualMachineScaleSetNetworkProfile()
.withNetworkInterfaceConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetNetworkConfiguration()
.withName("{vmss-name}" )
.withPrimary(true )
.withIpConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetIpConfiguration()
.withName("{vmss-name}" )
.withSubnet(
new ApiEntityReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ))
.withApplicationGatewayBackendAddressPools(
Arrays
.asList(
new SubResource()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/applicationGateways/{existing-application-gateway-name}/backendAddressPools/{existing-backend-address-pool-name}" )))))
.withEnableIpForwarding(true )))))
.withOverprovision(true ),
com.azure.core.util.Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_scale_set_create_with_azure_application_gateway.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main () :
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="{subscription-id}" ,
)
response = client.virtual_machine_scale_sets.begin_create_or_update(
resource_group_name="myResourceGroup" ,
vm_scale_set_name="{vmss-name}" ,
parameters={
"location" : "westus" ,
"properties" : {
"overprovision" : True ,
"upgradePolicy" : {"mode" : "Manual" },
"virtualMachineProfile" : {
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"enableIPForwarding" : True ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"applicationGatewayBackendAddressPools" : [
{
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/applicationGateways/{existing-application-gateway-name}/backendAddressPools/{existing-backend-address-pool-name}"
}
],
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
},
},
}
],
"primary" : True ,
},
}
]
},
"osProfile" : {
"adminPassword" : "{your-password}" ,
"adminUsername" : "{your-username}" ,
"computerNamePrefix" : "{vmss-name}" ,
},
"storageProfile" : {
"imageReference" : {
"offer" : "WindowsServer" ,
"publisher" : "MicrosoftWindowsServer" ,
"sku" : "2016-Datacenter" ,
"version" : "latest" ,
},
"osDisk" : {
"caching" : "ReadWrite" ,
"createOption" : "FromImage" ,
"managedDisk" : {"storageAccountType" : "Standard_LRS" },
},
},
},
},
"sku" : {"capacity" : 3 , "name" : "Standard_D1_v2" , "tier" : "Standard" },
},
).result()
print(response)
if __name__ == "__main__" :
main()
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4"
)
func ExampleVirtualMachineScaleSetsClient_BeginCreateOrUpdate_createAScaleSetWithAnAzureApplicationGateway () {
cred, err := azidentity.NewDefaultAzureCredential(nil )
if err != nil {
log.Fatalf("failed to obtain a credential: %v" , err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("<subscription-id>" , cred, nil )
if err != nil {
log.Fatalf("failed to create client: %v" , err)
}
poller, err := clientFactory.NewVirtualMachineScaleSetsClient().BeginCreateOrUpdate(ctx, "myResourceGroup" , "{vmss-name}" , armcompute.VirtualMachineScaleSet{
Location: to.Ptr("westus" ),
Properties: &armcompute.VirtualMachineScaleSetProperties{
Overprovision: to.Ptr(true ),
UpgradePolicy: &armcompute.UpgradePolicy{
Mode: to.Ptr(armcompute.UpgradeModeManual),
},
VirtualMachineProfile: &armcompute.VirtualMachineScaleSetVMProfile{
NetworkProfile: &armcompute.VirtualMachineScaleSetNetworkProfile{
NetworkInterfaceConfigurations: []*armcompute.VirtualMachineScaleSetNetworkConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetNetworkConfigurationProperties{
EnableIPForwarding: to.Ptr(true ),
IPConfigurations: []*armcompute.VirtualMachineScaleSetIPConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetIPConfigurationProperties{
ApplicationGatewayBackendAddressPools: []*armcompute.SubResource{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/applicationGateways/{existing-application-gateway-name}/backendAddressPools/{existing-backend-address-pool-name}" ),
}},
Subnet: &armcompute.APIEntityReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
},
},
}},
Primary: to.Ptr(true ),
},
}},
},
OSProfile: &armcompute.VirtualMachineScaleSetOSProfile{
AdminPassword: to.Ptr("{your-password}" ),
AdminUsername: to.Ptr("{your-username}" ),
ComputerNamePrefix: to.Ptr("{vmss-name}" ),
},
StorageProfile: &armcompute.VirtualMachineScaleSetStorageProfile{
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("WindowsServer" ),
Publisher: to.Ptr("MicrosoftWindowsServer" ),
SKU: to.Ptr("2016-Datacenter" ),
Version: to.Ptr("latest" ),
},
OSDisk: &armcompute.VirtualMachineScaleSetOSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.VirtualMachineScaleSetManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
},
},
SKU: &armcompute.SKU{
Name: to.Ptr("Standard_D1_v2" ),
Capacity: to.Ptr[int64 ](3 ),
Tier: to.Ptr("Standard" ),
},
}, nil )
if err != nil {
log.Fatalf("failed to finish the request: %v" , err)
}
res, err := poller.PollUntilDone(ctx, nil )
if err != nil {
log.Fatalf("failed to pull the result: %v" , err)
}
_ = res
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require ("@azure/arm-compute" );
const { DefaultAzureCredential } = require ("@azure/identity" );
async function createAScaleSetWithAnAzureApplicationGateway ( ) {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID" ] || "{subscription-id}" ;
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP" ] || "myResourceGroup" ;
const vmScaleSetName = "{vmss-name}" ;
const parameters = {
location : "westus" ,
overprovision : true ,
sku : { name : "Standard_D1_v2" , capacity : 3 , tier : "Standard" },
upgradePolicy : { mode : "Manual" },
virtualMachineProfile : {
networkProfile : {
networkInterfaceConfigurations : [
{
name : "{vmss-name}" ,
enableIPForwarding : true ,
ipConfigurations : [
{
name : "{vmss-name}" ,
applicationGatewayBackendAddressPools : [
{
id : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/applicationGateways/{existing-application-gateway-name}/backendAddressPools/{existing-backend-address-pool-name}" ,
},
],
subnet : {
id : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ,
},
},
],
primary : true ,
},
],
},
osProfile : {
adminPassword : "{your-password}" ,
adminUsername : "{your-username}" ,
computerNamePrefix : "{vmss-name}" ,
},
storageProfile : {
imageReference : {
offer : "WindowsServer" ,
publisher : "MicrosoftWindowsServer" ,
sku : "2016-Datacenter" ,
version : "latest" ,
},
osDisk : {
caching : "ReadWrite" ,
createOption : "FromImage" ,
managedDisk : { storageAccountType : "Standard_LRS" },
},
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachineScaleSets.beginCreateOrUpdateAndWait(
resourceGroupName,
vmScaleSetName,
parameters
);
console .log(result);
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Compute;
using Azure.ResourceManager.Compute.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Resources.Models;
TokenCredential cred = new DefaultAzureCredential();
ArmClient client = new ArmClient(cred);
string subscriptionId = "{subscription-id}" ;
string resourceGroupName = "myResourceGroup" ;
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
VirtualMachineScaleSetCollection collection = resourceGroupResource.GetVirtualMachineScaleSets();
string virtualMachineScaleSetName = "{vmss-name}" ;
VirtualMachineScaleSetData data = new VirtualMachineScaleSetData(new AzureLocation("westus" ))
{
Sku = new ComputeSku()
{
Name = "Standard_D1_v2" ,
Tier = "Standard" ,
Capacity = 3 ,
},
UpgradePolicy = new VirtualMachineScaleSetUpgradePolicy()
{
Mode = VirtualMachineScaleSetUpgradeMode.Manual,
},
VirtualMachineProfile = new VirtualMachineScaleSetVmProfile()
{
OSProfile = new VirtualMachineScaleSetOSProfile()
{
ComputerNamePrefix = "{vmss-name}" ,
AdminUsername = "{your-username}" ,
AdminPassword = "{your-password}" ,
},
StorageProfile = new VirtualMachineScaleSetStorageProfile()
{
ImageReference = new ImageReference()
{
Publisher = "MicrosoftWindowsServer" ,
Offer = "WindowsServer" ,
Sku = "2016-Datacenter" ,
Version = "latest" ,
},
OSDisk = new VirtualMachineScaleSetOSDisk(DiskCreateOptionType.FromImage)
{
Caching = CachingType.ReadWrite,
ManagedDisk = new VirtualMachineScaleSetManagedDisk()
{
StorageAccountType = StorageAccountType.StandardLrs,
},
},
},
NetworkProfile = new VirtualMachineScaleSetNetworkProfile()
{
NetworkInterfaceConfigurations =
{
new VirtualMachineScaleSetNetworkConfiguration("{vmss-name}" )
{
Primary = true ,
IPConfigurations =
{
new VirtualMachineScaleSetIPConfiguration("{vmss-name}" )
{
SubnetId = new ResourceIdentifier("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
ApplicationGatewayBackendAddressPools =
{
new WritableSubResource()
{
Id = new ResourceIdentifier("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/applicationGateways/{existing-application-gateway-name}/backendAddressPools/{existing-backend-address-pool-name}" ),
}
},
}
},
EnableIPForwarding = true ,
}
},
},
},
Overprovision = true ,
};
ArmOperation<VirtualMachineScaleSetResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, virtualMachineScaleSetName, data);
VirtualMachineScaleSetResource result = lro.Value;
VirtualMachineScaleSetData resourceData = result.Data;
Console.WriteLine($"Succeeded on id: {resourceData.Id} " );
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
範例回覆
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_D1_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "a0134477-b9d9-484b-b0e3-205c1c089ffa" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter" ,
"publisher" : "MicrosoftWindowsServer" ,
"version" : "latest" ,
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"applicationGatewayBackendAddressPools" : [
{
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/applicationGateways/nsgExistingAppGw/backendAddressPools/appGatewayBackendPool"
}
],
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_D1_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "a0134477-b9d9-484b-b0e3-205c1c089ffa" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter" ,
"publisher" : "MicrosoftWindowsServer" ,
"version" : "latest" ,
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"applicationGatewayBackendAddressPools" : [
{
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/applicationGateways/nsgExistingAppGw/backendAddressPools/appGatewayBackendPool"
}
],
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
Create a scale set with an azure load balancer.
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}?api-version=2022-11-01
{
"sku" : {
"tier" : "Standard",
"capacity" : 3,
"name" : "Standard_D1_v2"
},
"location" : "westus",
"properties" : {
"overprovision" : true,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter",
"publisher" : "MicrosoftWindowsServer",
"version" : "latest",
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite",
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}",
"adminUsername" : "{your-username}",
"adminPassword" : "{your-password}"
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"primary" : true,
"enableIPForwarding" : true,
"ipConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
},
"publicIPAddressConfiguration" : {
"name" : "{vmss-name}",
"properties" : {
"publicIPAddressVersion" : "IPv4"
}
},
"loadBalancerInboundNatPools" : [
{
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/loadBalancers/{existing-load-balancer-name}/inboundNatPools/{existing-nat-pool-name}"
}
],
"loadBalancerBackendAddressPools" : [
{
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/loadBalancers/{existing-load-balancer-name}/backendAddressPools/{existing-backend-address-pool-name}"
}
]
}
}
]
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
}
}
}
import com.azure.core.management.SubResource;
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineScaleSetInner;
import com.azure.resourcemanager.compute.models.ApiEntityReference;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.IpVersion;
import com.azure.resourcemanager.compute.models.Sku;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.UpgradeMode;
import com.azure.resourcemanager.compute.models.UpgradePolicy;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetIpConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetManagedDiskParameters;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSDisk;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetPublicIpAddressConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetStorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetVMProfile;
import java.util.Arrays;
public final class Main {
public static void createAScaleSetWithAnAzureLoadBalancer (com.azure.resourcemanager.AzureResourceManager azure) {
azure
.virtualMachines()
.manager()
.serviceClient()
.getVirtualMachineScaleSets()
.createOrUpdate(
"myResourceGroup" ,
"{vmss-name}" ,
new VirtualMachineScaleSetInner()
.withLocation("westus" )
.withSku(new Sku().withName("Standard_D1_v2" ).withTier("Standard" ).withCapacity(3L ))
.withUpgradePolicy(new UpgradePolicy().withMode(UpgradeMode.MANUAL))
.withVirtualMachineProfile(
new VirtualMachineScaleSetVMProfile()
.withOsProfile(
new VirtualMachineScaleSetOSProfile()
.withComputerNamePrefix("{vmss-name}" )
.withAdminUsername("{your-username}" )
.withAdminPassword("fakeTokenPlaceholder" ))
.withStorageProfile(
new VirtualMachineScaleSetStorageProfile()
.withImageReference(
new ImageReference()
.withPublisher("MicrosoftWindowsServer" )
.withOffer("WindowsServer" )
.withSku("2016-Datacenter" )
.withVersion("latest" ))
.withOsDisk(
new VirtualMachineScaleSetOSDisk()
.withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)
.withManagedDisk(
new VirtualMachineScaleSetManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withNetworkProfile(
new VirtualMachineScaleSetNetworkProfile()
.withNetworkInterfaceConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetNetworkConfiguration()
.withName("{vmss-name}" )
.withPrimary(true )
.withIpConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetIpConfiguration()
.withName("{vmss-name}" )
.withSubnet(
new ApiEntityReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ))
.withPublicIpAddressConfiguration(
new VirtualMachineScaleSetPublicIpAddressConfiguration()
.withName("{vmss-name}" )
.withPublicIpAddressVersion(IpVersion.IPV4))
.withLoadBalancerBackendAddressPools(
Arrays
.asList(
new SubResource()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/loadBalancers/{existing-load-balancer-name}/backendAddressPools/{existing-backend-address-pool-name}" )))
.withLoadBalancerInboundNatPools(
Arrays
.asList(
new SubResource()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/loadBalancers/{existing-load-balancer-name}/inboundNatPools/{existing-nat-pool-name}" )))))
.withEnableIpForwarding(true )))))
.withOverprovision(true ),
com.azure.core.util.Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_scale_set_create_with_azure_load_balancer.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main () :
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="{subscription-id}" ,
)
response = client.virtual_machine_scale_sets.begin_create_or_update(
resource_group_name="myResourceGroup" ,
vm_scale_set_name="{vmss-name}" ,
parameters={
"location" : "westus" ,
"properties" : {
"overprovision" : True ,
"upgradePolicy" : {"mode" : "Manual" },
"virtualMachineProfile" : {
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"enableIPForwarding" : True ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"loadBalancerBackendAddressPools" : [
{
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/loadBalancers/{existing-load-balancer-name}/backendAddressPools/{existing-backend-address-pool-name}"
}
],
"loadBalancerInboundNatPools" : [
{
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/loadBalancers/{existing-load-balancer-name}/inboundNatPools/{existing-nat-pool-name}"
}
],
"publicIPAddressConfiguration" : {
"name" : "{vmss-name}" ,
"properties" : {"publicIPAddressVersion" : "IPv4" },
},
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
},
},
}
],
"primary" : True ,
},
}
]
},
"osProfile" : {
"adminPassword" : "{your-password}" ,
"adminUsername" : "{your-username}" ,
"computerNamePrefix" : "{vmss-name}" ,
},
"storageProfile" : {
"imageReference" : {
"offer" : "WindowsServer" ,
"publisher" : "MicrosoftWindowsServer" ,
"sku" : "2016-Datacenter" ,
"version" : "latest" ,
},
"osDisk" : {
"caching" : "ReadWrite" ,
"createOption" : "FromImage" ,
"managedDisk" : {"storageAccountType" : "Standard_LRS" },
},
},
},
},
"sku" : {"capacity" : 3 , "name" : "Standard_D1_v2" , "tier" : "Standard" },
},
).result()
print(response)
if __name__ == "__main__" :
main()
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4"
)
func ExampleVirtualMachineScaleSetsClient_BeginCreateOrUpdate_createAScaleSetWithAnAzureLoadBalancer () {
cred, err := azidentity.NewDefaultAzureCredential(nil )
if err != nil {
log.Fatalf("failed to obtain a credential: %v" , err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("<subscription-id>" , cred, nil )
if err != nil {
log.Fatalf("failed to create client: %v" , err)
}
poller, err := clientFactory.NewVirtualMachineScaleSetsClient().BeginCreateOrUpdate(ctx, "myResourceGroup" , "{vmss-name}" , armcompute.VirtualMachineScaleSet{
Location: to.Ptr("westus" ),
Properties: &armcompute.VirtualMachineScaleSetProperties{
Overprovision: to.Ptr(true ),
UpgradePolicy: &armcompute.UpgradePolicy{
Mode: to.Ptr(armcompute.UpgradeModeManual),
},
VirtualMachineProfile: &armcompute.VirtualMachineScaleSetVMProfile{
NetworkProfile: &armcompute.VirtualMachineScaleSetNetworkProfile{
NetworkInterfaceConfigurations: []*armcompute.VirtualMachineScaleSetNetworkConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetNetworkConfigurationProperties{
EnableIPForwarding: to.Ptr(true ),
IPConfigurations: []*armcompute.VirtualMachineScaleSetIPConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetIPConfigurationProperties{
LoadBalancerBackendAddressPools: []*armcompute.SubResource{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/loadBalancers/{existing-load-balancer-name}/backendAddressPools/{existing-backend-address-pool-name}" ),
}},
LoadBalancerInboundNatPools: []*armcompute.SubResource{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/loadBalancers/{existing-load-balancer-name}/inboundNatPools/{existing-nat-pool-name}" ),
}},
PublicIPAddressConfiguration: &armcompute.VirtualMachineScaleSetPublicIPAddressConfiguration{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetPublicIPAddressConfigurationProperties{
PublicIPAddressVersion: to.Ptr(armcompute.IPVersionIPv4),
},
},
Subnet: &armcompute.APIEntityReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
},
},
}},
Primary: to.Ptr(true ),
},
}},
},
OSProfile: &armcompute.VirtualMachineScaleSetOSProfile{
AdminPassword: to.Ptr("{your-password}" ),
AdminUsername: to.Ptr("{your-username}" ),
ComputerNamePrefix: to.Ptr("{vmss-name}" ),
},
StorageProfile: &armcompute.VirtualMachineScaleSetStorageProfile{
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("WindowsServer" ),
Publisher: to.Ptr("MicrosoftWindowsServer" ),
SKU: to.Ptr("2016-Datacenter" ),
Version: to.Ptr("latest" ),
},
OSDisk: &armcompute.VirtualMachineScaleSetOSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.VirtualMachineScaleSetManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
},
},
SKU: &armcompute.SKU{
Name: to.Ptr("Standard_D1_v2" ),
Capacity: to.Ptr[int64 ](3 ),
Tier: to.Ptr("Standard" ),
},
}, nil )
if err != nil {
log.Fatalf("failed to finish the request: %v" , err)
}
res, err := poller.PollUntilDone(ctx, nil )
if err != nil {
log.Fatalf("failed to pull the result: %v" , err)
}
_ = res
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require ("@azure/arm-compute" );
const { DefaultAzureCredential } = require ("@azure/identity" );
async function createAScaleSetWithAnAzureLoadBalancer ( ) {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID" ] || "{subscription-id}" ;
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP" ] || "myResourceGroup" ;
const vmScaleSetName = "{vmss-name}" ;
const parameters = {
location : "westus" ,
overprovision : true ,
sku : { name : "Standard_D1_v2" , capacity : 3 , tier : "Standard" },
upgradePolicy : { mode : "Manual" },
virtualMachineProfile : {
networkProfile : {
networkInterfaceConfigurations : [
{
name : "{vmss-name}" ,
enableIPForwarding : true ,
ipConfigurations : [
{
name : "{vmss-name}" ,
loadBalancerBackendAddressPools : [
{
id : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/loadBalancers/{existing-load-balancer-name}/backendAddressPools/{existing-backend-address-pool-name}" ,
},
],
loadBalancerInboundNatPools : [
{
id : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/loadBalancers/{existing-load-balancer-name}/inboundNatPools/{existing-nat-pool-name}" ,
},
],
publicIPAddressConfiguration : {
name : "{vmss-name}" ,
publicIPAddressVersion : "IPv4" ,
},
subnet : {
id : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ,
},
},
],
primary : true ,
},
],
},
osProfile : {
adminPassword : "{your-password}" ,
adminUsername : "{your-username}" ,
computerNamePrefix : "{vmss-name}" ,
},
storageProfile : {
imageReference : {
offer : "WindowsServer" ,
publisher : "MicrosoftWindowsServer" ,
sku : "2016-Datacenter" ,
version : "latest" ,
},
osDisk : {
caching : "ReadWrite" ,
createOption : "FromImage" ,
managedDisk : { storageAccountType : "Standard_LRS" },
},
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachineScaleSets.beginCreateOrUpdateAndWait(
resourceGroupName,
vmScaleSetName,
parameters
);
console .log(result);
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Compute;
using Azure.ResourceManager.Compute.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Resources.Models;
TokenCredential cred = new DefaultAzureCredential();
ArmClient client = new ArmClient(cred);
string subscriptionId = "{subscription-id}" ;
string resourceGroupName = "myResourceGroup" ;
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
VirtualMachineScaleSetCollection collection = resourceGroupResource.GetVirtualMachineScaleSets();
string virtualMachineScaleSetName = "{vmss-name}" ;
VirtualMachineScaleSetData data = new VirtualMachineScaleSetData(new AzureLocation("westus" ))
{
Sku = new ComputeSku()
{
Name = "Standard_D1_v2" ,
Tier = "Standard" ,
Capacity = 3 ,
},
UpgradePolicy = new VirtualMachineScaleSetUpgradePolicy()
{
Mode = VirtualMachineScaleSetUpgradeMode.Manual,
},
VirtualMachineProfile = new VirtualMachineScaleSetVmProfile()
{
OSProfile = new VirtualMachineScaleSetOSProfile()
{
ComputerNamePrefix = "{vmss-name}" ,
AdminUsername = "{your-username}" ,
AdminPassword = "{your-password}" ,
},
StorageProfile = new VirtualMachineScaleSetStorageProfile()
{
ImageReference = new ImageReference()
{
Publisher = "MicrosoftWindowsServer" ,
Offer = "WindowsServer" ,
Sku = "2016-Datacenter" ,
Version = "latest" ,
},
OSDisk = new VirtualMachineScaleSetOSDisk(DiskCreateOptionType.FromImage)
{
Caching = CachingType.ReadWrite,
ManagedDisk = new VirtualMachineScaleSetManagedDisk()
{
StorageAccountType = StorageAccountType.StandardLrs,
},
},
},
NetworkProfile = new VirtualMachineScaleSetNetworkProfile()
{
NetworkInterfaceConfigurations =
{
new VirtualMachineScaleSetNetworkConfiguration("{vmss-name}" )
{
Primary = true ,
IPConfigurations =
{
new VirtualMachineScaleSetIPConfiguration("{vmss-name}" )
{
SubnetId = new ResourceIdentifier("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
PublicIPAddressConfiguration = new VirtualMachineScaleSetPublicIPAddressConfiguration("{vmss-name}" )
{
PublicIPAddressVersion = IPVersion.IPv4,
},
LoadBalancerBackendAddressPools =
{
new WritableSubResource()
{
Id = new ResourceIdentifier("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/loadBalancers/{existing-load-balancer-name}/backendAddressPools/{existing-backend-address-pool-name}" ),
}
},
LoadBalancerInboundNatPools =
{
new WritableSubResource()
{
Id = new ResourceIdentifier("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/loadBalancers/{existing-load-balancer-name}/inboundNatPools/{existing-nat-pool-name}" ),
}
},
}
},
EnableIPForwarding = true ,
}
},
},
},
Overprovision = true ,
};
ArmOperation<VirtualMachineScaleSetResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, virtualMachineScaleSetName, data);
VirtualMachineScaleSetResource result = lro.Value;
VirtualMachineScaleSetData resourceData = result.Data;
Console.WriteLine($"Succeeded on id: {resourceData.Id} " );
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
範例回覆
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_D1_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "ec0b21ca-51ec-414b-9323-f236ffc21479" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter" ,
"publisher" : "MicrosoftWindowsServer" ,
"version" : "latest" ,
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"loadBalancerInboundNatPools" : [
{
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/loadBalancers/myLb/inboundNatPools/lbNatPool"
}
],
"loadBalancerBackendAddressPools" : [
{
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/loadBalancers/myLb/backendAddressPools/lbBackendPool"
}
],
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_D1_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "ec0b21ca-51ec-414b-9323-f236ffc21479" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter" ,
"publisher" : "MicrosoftWindowsServer" ,
"version" : "latest" ,
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"loadBalancerInboundNatPools" : [
{
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/loadBalancers/myLb/inboundNatPools/lbNatPool"
}
],
"loadBalancerBackendAddressPools" : [
{
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/loadBalancers/myLb/backendAddressPools/lbBackendPool"
}
],
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
Create a scale set with Application Profile
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}?api-version=2022-11-01
{
"sku" : {
"tier" : "Standard",
"capacity" : 3,
"name" : "Standard_D1_v2"
},
"location" : "westus",
"properties" : {
"overprovision" : true,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter",
"publisher" : "MicrosoftWindowsServer",
"version" : "latest",
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite",
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"applicationProfile" : {
"galleryApplications" : [
{
"tags" : "myTag1",
"order" : 1,
"packageReferenceId" : "/subscriptions/32c17a9e-aa7b-4ba5-a45b-e324116b6fdb/resourceGroups/myresourceGroupName2/providers/Microsoft.Compute/galleries/myGallery1/applications/MyApplication1/versions/1.0",
"configurationReference" : "https://mystorageaccount.blob.core.windows.net/configurations/settings.config",
"treatFailureAsDeploymentFailure" : true,
"enableAutomaticUpgrade" : false
},
{
"packageReferenceId" : "/subscriptions/32c17a9e-aa7b-4ba5-a45b-e324116b6fdg/resourceGroups/myresourceGroupName3/providers/Microsoft.Compute/galleries/myGallery2/applications/MyApplication2/versions/1.1"
}
]
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}",
"adminUsername" : "{your-username}",
"adminPassword" : "{your-password}"
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"primary" : true,
"enableIPForwarding" : true,
"ipConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
}
}
]
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineScaleSetInner;
import com.azure.resourcemanager.compute.models.ApiEntityReference;
import com.azure.resourcemanager.compute.models.ApplicationProfile;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.Sku;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.UpgradeMode;
import com.azure.resourcemanager.compute.models.UpgradePolicy;
import com.azure.resourcemanager.compute.models.VMGalleryApplication;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetIpConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetManagedDiskParameters;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSDisk;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetStorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetVMProfile;
import java.util.Arrays;
public final class Main {
public static void createAScaleSetWithApplicationProfile (com.azure.resourcemanager.AzureResourceManager azure) {
azure
.virtualMachines()
.manager()
.serviceClient()
.getVirtualMachineScaleSets()
.createOrUpdate(
"myResourceGroup" ,
"{vmss-name}" ,
new VirtualMachineScaleSetInner()
.withLocation("westus" )
.withSku(new Sku().withName("Standard_D1_v2" ).withTier("Standard" ).withCapacity(3L ))
.withUpgradePolicy(new UpgradePolicy().withMode(UpgradeMode.MANUAL))
.withVirtualMachineProfile(
new VirtualMachineScaleSetVMProfile()
.withOsProfile(
new VirtualMachineScaleSetOSProfile()
.withComputerNamePrefix("{vmss-name}" )
.withAdminUsername("{your-username}" )
.withAdminPassword("fakeTokenPlaceholder" ))
.withStorageProfile(
new VirtualMachineScaleSetStorageProfile()
.withImageReference(
new ImageReference()
.withPublisher("MicrosoftWindowsServer" )
.withOffer("WindowsServer" )
.withSku("2016-Datacenter" )
.withVersion("latest" ))
.withOsDisk(
new VirtualMachineScaleSetOSDisk()
.withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)
.withManagedDisk(
new VirtualMachineScaleSetManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withNetworkProfile(
new VirtualMachineScaleSetNetworkProfile()
.withNetworkInterfaceConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetNetworkConfiguration()
.withName("{vmss-name}" )
.withPrimary(true )
.withIpConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetIpConfiguration()
.withName("{vmss-name}" )
.withSubnet(
new ApiEntityReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ))))
.withEnableIpForwarding(true ))))
.withApplicationProfile(
new ApplicationProfile()
.withGalleryApplications(
Arrays
.asList(
new VMGalleryApplication()
.withTags("myTag1" )
.withOrder(1 )
.withPackageReferenceId(
"/subscriptions/32c17a9e-aa7b-4ba5-a45b-e324116b6fdb/resourceGroups/myresourceGroupName2/providers/Microsoft.Compute/galleries/myGallery1/applications/MyApplication1/versions/1.0" )
.withConfigurationReference(
"https://mystorageaccount.blob.core.windows.net/configurations/settings.config" )
.withTreatFailureAsDeploymentFailure(true )
.withEnableAutomaticUpgrade(false ),
new VMGalleryApplication()
.withPackageReferenceId(
"/subscriptions/32c17a9e-aa7b-4ba5-a45b-e324116b6fdg/resourceGroups/myresourceGroupName3/providers/Microsoft.Compute/galleries/myGallery2/applications/MyApplication2/versions/1.1" )))))
.withOverprovision(true ),
com.azure.core.util.Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_scale_set_create_with_application_profile.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main () :
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="{subscription-id}" ,
)
response = client.virtual_machine_scale_sets.begin_create_or_update(
resource_group_name="myResourceGroup" ,
vm_scale_set_name="{vmss-name}" ,
parameters={
"location" : "westus" ,
"properties" : {
"overprovision" : True ,
"upgradePolicy" : {"mode" : "Manual" },
"virtualMachineProfile" : {
"applicationProfile" : {
"galleryApplications" : [
{
"configurationReference" : "https://mystorageaccount.blob.core.windows.net/configurations/settings.config" ,
"enableAutomaticUpgrade" : False ,
"order" : 1 ,
"packageReferenceId" : "/subscriptions/32c17a9e-aa7b-4ba5-a45b-e324116b6fdb/resourceGroups/myresourceGroupName2/providers/Microsoft.Compute/galleries/myGallery1/applications/MyApplication1/versions/1.0" ,
"tags" : "myTag1" ,
"treatFailureAsDeploymentFailure" : True ,
},
{
"packageReferenceId" : "/subscriptions/32c17a9e-aa7b-4ba5-a45b-e324116b6fdg/resourceGroups/myresourceGroupName3/providers/Microsoft.Compute/galleries/myGallery2/applications/MyApplication2/versions/1.1"
},
]
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"enableIPForwarding" : True ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
},
}
],
"primary" : True ,
},
}
]
},
"osProfile" : {
"adminPassword" : "{your-password}" ,
"adminUsername" : "{your-username}" ,
"computerNamePrefix" : "{vmss-name}" ,
},
"storageProfile" : {
"imageReference" : {
"offer" : "WindowsServer" ,
"publisher" : "MicrosoftWindowsServer" ,
"sku" : "2016-Datacenter" ,
"version" : "latest" ,
},
"osDisk" : {
"caching" : "ReadWrite" ,
"createOption" : "FromImage" ,
"managedDisk" : {"storageAccountType" : "Standard_LRS" },
},
},
},
},
"sku" : {"capacity" : 3 , "name" : "Standard_D1_v2" , "tier" : "Standard" },
},
).result()
print(response)
if __name__ == "__main__" :
main()
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4"
)
func ExampleVirtualMachineScaleSetsClient_BeginCreateOrUpdate_createAScaleSetWithApplicationProfile () {
cred, err := azidentity.NewDefaultAzureCredential(nil )
if err != nil {
log.Fatalf("failed to obtain a credential: %v" , err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("<subscription-id>" , cred, nil )
if err != nil {
log.Fatalf("failed to create client: %v" , err)
}
poller, err := clientFactory.NewVirtualMachineScaleSetsClient().BeginCreateOrUpdate(ctx, "myResourceGroup" , "{vmss-name}" , armcompute.VirtualMachineScaleSet{
Location: to.Ptr("westus" ),
Properties: &armcompute.VirtualMachineScaleSetProperties{
Overprovision: to.Ptr(true ),
UpgradePolicy: &armcompute.UpgradePolicy{
Mode: to.Ptr(armcompute.UpgradeModeManual),
},
VirtualMachineProfile: &armcompute.VirtualMachineScaleSetVMProfile{
ApplicationProfile: &armcompute.ApplicationProfile{
GalleryApplications: []*armcompute.VMGalleryApplication{
{
ConfigurationReference: to.Ptr("https://mystorageaccount.blob.core.windows.net/configurations/settings.config" ),
EnableAutomaticUpgrade: to.Ptr(false ),
Order: to.Ptr[int32 ](1 ),
PackageReferenceID: to.Ptr("/subscriptions/32c17a9e-aa7b-4ba5-a45b-e324116b6fdb/resourceGroups/myresourceGroupName2/providers/Microsoft.Compute/galleries/myGallery1/applications/MyApplication1/versions/1.0" ),
Tags: to.Ptr("myTag1" ),
TreatFailureAsDeploymentFailure: to.Ptr(true ),
},
{
PackageReferenceID: to.Ptr("/subscriptions/32c17a9e-aa7b-4ba5-a45b-e324116b6fdg/resourceGroups/myresourceGroupName3/providers/Microsoft.Compute/galleries/myGallery2/applications/MyApplication2/versions/1.1" ),
}},
},
NetworkProfile: &armcompute.VirtualMachineScaleSetNetworkProfile{
NetworkInterfaceConfigurations: []*armcompute.VirtualMachineScaleSetNetworkConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetNetworkConfigurationProperties{
EnableIPForwarding: to.Ptr(true ),
IPConfigurations: []*armcompute.VirtualMachineScaleSetIPConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetIPConfigurationProperties{
Subnet: &armcompute.APIEntityReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
},
},
}},
Primary: to.Ptr(true ),
},
}},
},
OSProfile: &armcompute.VirtualMachineScaleSetOSProfile{
AdminPassword: to.Ptr("{your-password}" ),
AdminUsername: to.Ptr("{your-username}" ),
ComputerNamePrefix: to.Ptr("{vmss-name}" ),
},
StorageProfile: &armcompute.VirtualMachineScaleSetStorageProfile{
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("WindowsServer" ),
Publisher: to.Ptr("MicrosoftWindowsServer" ),
SKU: to.Ptr("2016-Datacenter" ),
Version: to.Ptr("latest" ),
},
OSDisk: &armcompute.VirtualMachineScaleSetOSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.VirtualMachineScaleSetManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
},
},
SKU: &armcompute.SKU{
Name: to.Ptr("Standard_D1_v2" ),
Capacity: to.Ptr[int64 ](3 ),
Tier: to.Ptr("Standard" ),
},
}, nil )
if err != nil {
log.Fatalf("failed to finish the request: %v" , err)
}
res, err := poller.PollUntilDone(ctx, nil )
if err != nil {
log.Fatalf("failed to pull the result: %v" , err)
}
_ = res
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require ("@azure/arm-compute" );
const { DefaultAzureCredential } = require ("@azure/identity" );
async function createAScaleSetWithApplicationProfile ( ) {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID" ] || "{subscription-id}" ;
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP" ] || "myResourceGroup" ;
const vmScaleSetName = "{vmss-name}" ;
const parameters = {
location : "westus" ,
overprovision : true ,
sku : { name : "Standard_D1_v2" , capacity : 3 , tier : "Standard" },
upgradePolicy : { mode : "Manual" },
virtualMachineProfile : {
applicationProfile : {
galleryApplications : [
{
configurationReference :
"https://mystorageaccount.blob.core.windows.net/configurations/settings.config" ,
enableAutomaticUpgrade : false ,
order : 1 ,
packageReferenceId :
"/subscriptions/32c17a9e-aa7b-4ba5-a45b-e324116b6fdb/resourceGroups/myresourceGroupName2/providers/Microsoft.Compute/galleries/myGallery1/applications/MyApplication1/versions/1.0" ,
tags : "myTag1" ,
treatFailureAsDeploymentFailure : true ,
},
{
packageReferenceId :
"/subscriptions/32c17a9e-aa7b-4ba5-a45b-e324116b6fdg/resourceGroups/myresourceGroupName3/providers/Microsoft.Compute/galleries/myGallery2/applications/MyApplication2/versions/1.1" ,
},
],
},
networkProfile : {
networkInterfaceConfigurations : [
{
name : "{vmss-name}" ,
enableIPForwarding : true ,
ipConfigurations : [
{
name : "{vmss-name}" ,
subnet : {
id : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ,
},
},
],
primary : true ,
},
],
},
osProfile : {
adminPassword : "{your-password}" ,
adminUsername : "{your-username}" ,
computerNamePrefix : "{vmss-name}" ,
},
storageProfile : {
imageReference : {
offer : "WindowsServer" ,
publisher : "MicrosoftWindowsServer" ,
sku : "2016-Datacenter" ,
version : "latest" ,
},
osDisk : {
caching : "ReadWrite" ,
createOption : "FromImage" ,
managedDisk : { storageAccountType : "Standard_LRS" },
},
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachineScaleSets.beginCreateOrUpdateAndWait(
resourceGroupName,
vmScaleSetName,
parameters
);
console .log(result);
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Compute;
using Azure.ResourceManager.Compute.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Resources.Models;
TokenCredential cred = new DefaultAzureCredential();
ArmClient client = new ArmClient(cred);
string subscriptionId = "{subscription-id}" ;
string resourceGroupName = "myResourceGroup" ;
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
VirtualMachineScaleSetCollection collection = resourceGroupResource.GetVirtualMachineScaleSets();
string virtualMachineScaleSetName = "{vmss-name}" ;
VirtualMachineScaleSetData data = new VirtualMachineScaleSetData(new AzureLocation("westus" ))
{
Sku = new ComputeSku()
{
Name = "Standard_D1_v2" ,
Tier = "Standard" ,
Capacity = 3 ,
},
UpgradePolicy = new VirtualMachineScaleSetUpgradePolicy()
{
Mode = VirtualMachineScaleSetUpgradeMode.Manual,
},
VirtualMachineProfile = new VirtualMachineScaleSetVmProfile()
{
OSProfile = new VirtualMachineScaleSetOSProfile()
{
ComputerNamePrefix = "{vmss-name}" ,
AdminUsername = "{your-username}" ,
AdminPassword = "{your-password}" ,
},
StorageProfile = new VirtualMachineScaleSetStorageProfile()
{
ImageReference = new ImageReference()
{
Publisher = "MicrosoftWindowsServer" ,
Offer = "WindowsServer" ,
Sku = "2016-Datacenter" ,
Version = "latest" ,
},
OSDisk = new VirtualMachineScaleSetOSDisk(DiskCreateOptionType.FromImage)
{
Caching = CachingType.ReadWrite,
ManagedDisk = new VirtualMachineScaleSetManagedDisk()
{
StorageAccountType = StorageAccountType.StandardLrs,
},
},
},
NetworkProfile = new VirtualMachineScaleSetNetworkProfile()
{
NetworkInterfaceConfigurations =
{
new VirtualMachineScaleSetNetworkConfiguration("{vmss-name}" )
{
Primary = true ,
IPConfigurations =
{
new VirtualMachineScaleSetIPConfiguration("{vmss-name}" )
{
SubnetId = new ResourceIdentifier("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
}
},
EnableIPForwarding = true ,
}
},
},
GalleryApplications =
{
new VirtualMachineGalleryApplication("/subscriptions/32c17a9e-aa7b-4ba5-a45b-e324116b6fdb/resourceGroups/myresourceGroupName2/providers/Microsoft.Compute/galleries/myGallery1/applications/MyApplication1/versions/1.0" )
{
Tags = "myTag1" ,
Order = 1 ,
ConfigurationReference = "https://mystorageaccount.blob.core.windows.net/configurations/settings.config" ,
TreatFailureAsDeploymentFailure = true ,
EnableAutomaticUpgrade = false ,
},new VirtualMachineGalleryApplication("/subscriptions/32c17a9e-aa7b-4ba5-a45b-e324116b6fdg/resourceGroups/myresourceGroupName3/providers/Microsoft.Compute/galleries/myGallery2/applications/MyApplication2/versions/1.1" )
},
},
Overprovision = true ,
};
ArmOperation<VirtualMachineScaleSetResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, virtualMachineScaleSetName, data);
VirtualMachineScaleSetResource result = lro.Value;
VirtualMachineScaleSetData resourceData = result.Data;
Console.WriteLine($"Succeeded on id: {resourceData.Id} " );
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
範例回覆
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_D1_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "ffb27c5c-39a5-4d4e-b307-b32598689813" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter" ,
"publisher" : "MicrosoftWindowsServer" ,
"version" : "latest" ,
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"applicationProfile" : {
"galleryApplications" : [
{
"tags" : "myTag1" ,
"order" : 1 ,
"packageReferenceId" : "/subscriptions/32c17a9e-aa7b-4ba5-a45b-e324116b6fdb/resourceGroups/myresourceGroupName2/providers/Microsoft.Compute/galleries/myGallery1/applications/MyApplication1/versions/1.0" ,
"configurationReference" : "https://mystorageaccount.blob.core.windows.net/configurations/settings.config"
},
{
"packageReferenceId" : "/subscriptions/32c17a9e-aa7b-4ba5-a45b-e324116b6fdg/resourceGroups/myresourceGroupName3/providers/Microsoft.Compute/galleries/myGallery2/applications/MyApplication2/versions/1.1"
}
]
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_D1_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "ffb27c5c-39a5-4d4e-b307-b32598689813" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter" ,
"publisher" : "MicrosoftWindowsServer" ,
"version" : "latest" ,
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"applicationProfile" : {
"galleryApplications" : [
{
"tags" : "myTag1" ,
"order" : 1 ,
"packageReferenceId" : "/subscriptions/32c17a9e-aa7b-4ba5-a45b-e324116b6fdb/resourceGroups/myresourceGroupName2/providers/Microsoft.Compute/galleries/myGallery1/applications/MyApplication1/versions/1.0" ,
"configurationReference" : "https://mystorageaccount.blob.core.windows.net/configurations/settings.config"
},
{
"packageReferenceId" : "/subscriptions/32c17a9e-aa7b-4ba5-a45b-e324116b6fdg/resourceGroups/myresourceGroupName3/providers/Microsoft.Compute/galleries/myGallery2/applications/MyApplication2/versions/1.1"
}
]
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
Create a scale set with automatic repairs enabled
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}?api-version=2022-11-01
{
"sku" : {
"tier" : "Standard",
"capacity" : 3,
"name" : "Standard_D1_v2"
},
"location" : "westus",
"properties" : {
"overprovision" : true,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter",
"publisher" : "MicrosoftWindowsServer",
"version" : "latest",
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite",
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}",
"adminUsername" : "{your-username}",
"adminPassword" : "{your-password}"
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"primary" : true,
"enableIPForwarding" : true,
"ipConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
}
}
]
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"automaticRepairsPolicy" : {
"enabled" : true,
"gracePeriod" : "PT10M"
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineScaleSetInner;
import com.azure.resourcemanager.compute.models.ApiEntityReference;
import com.azure.resourcemanager.compute.models.AutomaticRepairsPolicy;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.Sku;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.UpgradeMode;
import com.azure.resourcemanager.compute.models.UpgradePolicy;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetIpConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetManagedDiskParameters;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSDisk;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetStorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetVMProfile;
import java.util.Arrays;
public final class Main {
public static void createAScaleSetWithAutomaticRepairsEnabled (
com.azure.resourcemanager.AzureResourceManager azure) {
azure
.virtualMachines()
.manager()
.serviceClient()
.getVirtualMachineScaleSets()
.createOrUpdate(
"myResourceGroup" ,
"{vmss-name}" ,
new VirtualMachineScaleSetInner()
.withLocation("westus" )
.withSku(new Sku().withName("Standard_D1_v2" ).withTier("Standard" ).withCapacity(3L ))
.withUpgradePolicy(new UpgradePolicy().withMode(UpgradeMode.MANUAL))
.withAutomaticRepairsPolicy(new AutomaticRepairsPolicy().withEnabled(true ).withGracePeriod("PT10M" ))
.withVirtualMachineProfile(
new VirtualMachineScaleSetVMProfile()
.withOsProfile(
new VirtualMachineScaleSetOSProfile()
.withComputerNamePrefix("{vmss-name}" )
.withAdminUsername("{your-username}" )
.withAdminPassword("fakeTokenPlaceholder" ))
.withStorageProfile(
new VirtualMachineScaleSetStorageProfile()
.withImageReference(
new ImageReference()
.withPublisher("MicrosoftWindowsServer" )
.withOffer("WindowsServer" )
.withSku("2016-Datacenter" )
.withVersion("latest" ))
.withOsDisk(
new VirtualMachineScaleSetOSDisk()
.withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)
.withManagedDisk(
new VirtualMachineScaleSetManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withNetworkProfile(
new VirtualMachineScaleSetNetworkProfile()
.withNetworkInterfaceConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetNetworkConfiguration()
.withName("{vmss-name}" )
.withPrimary(true )
.withIpConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetIpConfiguration()
.withName("{vmss-name}" )
.withSubnet(
new ApiEntityReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ))))
.withEnableIpForwarding(true )))))
.withOverprovision(true ),
com.azure.core.util.Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_scale_set_create_with_automatic_repairs.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main () :
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="{subscription-id}" ,
)
response = client.virtual_machine_scale_sets.begin_create_or_update(
resource_group_name="myResourceGroup" ,
vm_scale_set_name="{vmss-name}" ,
parameters={
"location" : "westus" ,
"properties" : {
"automaticRepairsPolicy" : {"enabled" : True , "gracePeriod" : "PT10M" },
"overprovision" : True ,
"upgradePolicy" : {"mode" : "Manual" },
"virtualMachineProfile" : {
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"enableIPForwarding" : True ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
},
}
],
"primary" : True ,
},
}
]
},
"osProfile" : {
"adminPassword" : "{your-password}" ,
"adminUsername" : "{your-username}" ,
"computerNamePrefix" : "{vmss-name}" ,
},
"storageProfile" : {
"imageReference" : {
"offer" : "WindowsServer" ,
"publisher" : "MicrosoftWindowsServer" ,
"sku" : "2016-Datacenter" ,
"version" : "latest" ,
},
"osDisk" : {
"caching" : "ReadWrite" ,
"createOption" : "FromImage" ,
"managedDisk" : {"storageAccountType" : "Standard_LRS" },
},
},
},
},
"sku" : {"capacity" : 3 , "name" : "Standard_D1_v2" , "tier" : "Standard" },
},
).result()
print(response)
if __name__ == "__main__" :
main()
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4"
)
func ExampleVirtualMachineScaleSetsClient_BeginCreateOrUpdate_createAScaleSetWithAutomaticRepairsEnabled () {
cred, err := azidentity.NewDefaultAzureCredential(nil )
if err != nil {
log.Fatalf("failed to obtain a credential: %v" , err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("<subscription-id>" , cred, nil )
if err != nil {
log.Fatalf("failed to create client: %v" , err)
}
poller, err := clientFactory.NewVirtualMachineScaleSetsClient().BeginCreateOrUpdate(ctx, "myResourceGroup" , "{vmss-name}" , armcompute.VirtualMachineScaleSet{
Location: to.Ptr("westus" ),
Properties: &armcompute.VirtualMachineScaleSetProperties{
AutomaticRepairsPolicy: &armcompute.AutomaticRepairsPolicy{
Enabled: to.Ptr(true ),
GracePeriod: to.Ptr("PT10M" ),
},
Overprovision: to.Ptr(true ),
UpgradePolicy: &armcompute.UpgradePolicy{
Mode: to.Ptr(armcompute.UpgradeModeManual),
},
VirtualMachineProfile: &armcompute.VirtualMachineScaleSetVMProfile{
NetworkProfile: &armcompute.VirtualMachineScaleSetNetworkProfile{
NetworkInterfaceConfigurations: []*armcompute.VirtualMachineScaleSetNetworkConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetNetworkConfigurationProperties{
EnableIPForwarding: to.Ptr(true ),
IPConfigurations: []*armcompute.VirtualMachineScaleSetIPConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetIPConfigurationProperties{
Subnet: &armcompute.APIEntityReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
},
},
}},
Primary: to.Ptr(true ),
},
}},
},
OSProfile: &armcompute.VirtualMachineScaleSetOSProfile{
AdminPassword: to.Ptr("{your-password}" ),
AdminUsername: to.Ptr("{your-username}" ),
ComputerNamePrefix: to.Ptr("{vmss-name}" ),
},
StorageProfile: &armcompute.VirtualMachineScaleSetStorageProfile{
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("WindowsServer" ),
Publisher: to.Ptr("MicrosoftWindowsServer" ),
SKU: to.Ptr("2016-Datacenter" ),
Version: to.Ptr("latest" ),
},
OSDisk: &armcompute.VirtualMachineScaleSetOSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.VirtualMachineScaleSetManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
},
},
SKU: &armcompute.SKU{
Name: to.Ptr("Standard_D1_v2" ),
Capacity: to.Ptr[int64 ](3 ),
Tier: to.Ptr("Standard" ),
},
}, nil )
if err != nil {
log.Fatalf("failed to finish the request: %v" , err)
}
res, err := poller.PollUntilDone(ctx, nil )
if err != nil {
log.Fatalf("failed to pull the result: %v" , err)
}
_ = res
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require ("@azure/arm-compute" );
const { DefaultAzureCredential } = require ("@azure/identity" );
async function createAScaleSetWithAutomaticRepairsEnabled ( ) {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID" ] || "{subscription-id}" ;
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP" ] || "myResourceGroup" ;
const vmScaleSetName = "{vmss-name}" ;
const parameters = {
automaticRepairsPolicy : { enabled : true , gracePeriod : "PT10M" },
location : "westus" ,
overprovision : true ,
sku : { name : "Standard_D1_v2" , capacity : 3 , tier : "Standard" },
upgradePolicy : { mode : "Manual" },
virtualMachineProfile : {
networkProfile : {
networkInterfaceConfigurations : [
{
name : "{vmss-name}" ,
enableIPForwarding : true ,
ipConfigurations : [
{
name : "{vmss-name}" ,
subnet : {
id : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ,
},
},
],
primary : true ,
},
],
},
osProfile : {
adminPassword : "{your-password}" ,
adminUsername : "{your-username}" ,
computerNamePrefix : "{vmss-name}" ,
},
storageProfile : {
imageReference : {
offer : "WindowsServer" ,
publisher : "MicrosoftWindowsServer" ,
sku : "2016-Datacenter" ,
version : "latest" ,
},
osDisk : {
caching : "ReadWrite" ,
createOption : "FromImage" ,
managedDisk : { storageAccountType : "Standard_LRS" },
},
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachineScaleSets.beginCreateOrUpdateAndWait(
resourceGroupName,
vmScaleSetName,
parameters
);
console .log(result);
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Compute;
using Azure.ResourceManager.Compute.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Resources.Models;
TokenCredential cred = new DefaultAzureCredential();
ArmClient client = new ArmClient(cred);
string subscriptionId = "{subscription-id}" ;
string resourceGroupName = "myResourceGroup" ;
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
VirtualMachineScaleSetCollection collection = resourceGroupResource.GetVirtualMachineScaleSets();
string virtualMachineScaleSetName = "{vmss-name}" ;
VirtualMachineScaleSetData data = new VirtualMachineScaleSetData(new AzureLocation("westus" ))
{
Sku = new ComputeSku()
{
Name = "Standard_D1_v2" ,
Tier = "Standard" ,
Capacity = 3 ,
},
UpgradePolicy = new VirtualMachineScaleSetUpgradePolicy()
{
Mode = VirtualMachineScaleSetUpgradeMode.Manual,
},
AutomaticRepairsPolicy = new AutomaticRepairsPolicy()
{
Enabled = true ,
GracePeriod = "PT10M" ,
},
VirtualMachineProfile = new VirtualMachineScaleSetVmProfile()
{
OSProfile = new VirtualMachineScaleSetOSProfile()
{
ComputerNamePrefix = "{vmss-name}" ,
AdminUsername = "{your-username}" ,
AdminPassword = "{your-password}" ,
},
StorageProfile = new VirtualMachineScaleSetStorageProfile()
{
ImageReference = new ImageReference()
{
Publisher = "MicrosoftWindowsServer" ,
Offer = "WindowsServer" ,
Sku = "2016-Datacenter" ,
Version = "latest" ,
},
OSDisk = new VirtualMachineScaleSetOSDisk(DiskCreateOptionType.FromImage)
{
Caching = CachingType.ReadWrite,
ManagedDisk = new VirtualMachineScaleSetManagedDisk()
{
StorageAccountType = StorageAccountType.StandardLrs,
},
},
},
NetworkProfile = new VirtualMachineScaleSetNetworkProfile()
{
NetworkInterfaceConfigurations =
{
new VirtualMachineScaleSetNetworkConfiguration("{vmss-name}" )
{
Primary = true ,
IPConfigurations =
{
new VirtualMachineScaleSetIPConfiguration("{vmss-name}" )
{
SubnetId = new ResourceIdentifier("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
}
},
EnableIPForwarding = true ,
}
},
},
},
Overprovision = true ,
};
ArmOperation<VirtualMachineScaleSetResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, virtualMachineScaleSetName, data);
VirtualMachineScaleSetResource result = lro.Value;
VirtualMachineScaleSetData resourceData = result.Data;
Console.WriteLine($"Succeeded on id: {resourceData.Id} " );
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
範例回覆
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_D1_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "d053ec5a-8da6-495f-ab13-38216503c6d7" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter" ,
"publisher" : "MicrosoftWindowsServer" ,
"version" : "latest" ,
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"automaticRepairsPolicy" : {
"enabled" : true ,
"gracePeriod" : "PT10M"
},
"provisioningState" : "Creating"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_D1_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "d053ec5a-8da6-495f-ab13-38216503c6d7" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter" ,
"publisher" : "MicrosoftWindowsServer" ,
"version" : "latest" ,
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"automaticRepairsPolicy" : {
"enabled" : true ,
"gracePeriod" : "PT10M"
},
"provisioningState" : "Creating"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
Create a scale set with boot diagnostics.
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}?api-version=2022-11-01
{
"sku" : {
"tier" : "Standard",
"capacity" : 3,
"name" : "Standard_D1_v2"
},
"location" : "westus",
"properties" : {
"overprovision" : true,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter",
"publisher" : "MicrosoftWindowsServer",
"version" : "latest",
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite",
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"diagnosticsProfile" : {
"bootDiagnostics" : {
"storageUri" : "http://{existing-storage-account-name}.blob.core.windows.net",
"enabled" : true
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}",
"adminUsername" : "{your-username}",
"adminPassword" : "{your-password}"
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"primary" : true,
"enableIPForwarding" : true,
"ipConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
}
}
]
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineScaleSetInner;
import com.azure.resourcemanager.compute.models.ApiEntityReference;
import com.azure.resourcemanager.compute.models.BootDiagnostics;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiagnosticsProfile;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.Sku;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.UpgradeMode;
import com.azure.resourcemanager.compute.models.UpgradePolicy;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetIpConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetManagedDiskParameters;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSDisk;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetStorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetVMProfile;
import java.util.Arrays;
public final class Main {
public static void createAScaleSetWithBootDiagnostics (com.azure.resourcemanager.AzureResourceManager azure) {
azure
.virtualMachines()
.manager()
.serviceClient()
.getVirtualMachineScaleSets()
.createOrUpdate(
"myResourceGroup" ,
"{vmss-name}" ,
new VirtualMachineScaleSetInner()
.withLocation("westus" )
.withSku(new Sku().withName("Standard_D1_v2" ).withTier("Standard" ).withCapacity(3L ))
.withUpgradePolicy(new UpgradePolicy().withMode(UpgradeMode.MANUAL))
.withVirtualMachineProfile(
new VirtualMachineScaleSetVMProfile()
.withOsProfile(
new VirtualMachineScaleSetOSProfile()
.withComputerNamePrefix("{vmss-name}" )
.withAdminUsername("{your-username}" )
.withAdminPassword("fakeTokenPlaceholder" ))
.withStorageProfile(
new VirtualMachineScaleSetStorageProfile()
.withImageReference(
new ImageReference()
.withPublisher("MicrosoftWindowsServer" )
.withOffer("WindowsServer" )
.withSku("2016-Datacenter" )
.withVersion("latest" ))
.withOsDisk(
new VirtualMachineScaleSetOSDisk()
.withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)
.withManagedDisk(
new VirtualMachineScaleSetManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withNetworkProfile(
new VirtualMachineScaleSetNetworkProfile()
.withNetworkInterfaceConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetNetworkConfiguration()
.withName("{vmss-name}" )
.withPrimary(true )
.withIpConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetIpConfiguration()
.withName("{vmss-name}" )
.withSubnet(
new ApiEntityReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ))))
.withEnableIpForwarding(true ))))
.withDiagnosticsProfile(
new DiagnosticsProfile()
.withBootDiagnostics(
new BootDiagnostics()
.withEnabled(true )
.withStorageUri(
"http://{existing-storage-account-name}.blob.core.windows.net" ))))
.withOverprovision(true ),
com.azure.core.util.Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_scale_set_create_with_boot_diagnostics.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main () :
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="{subscription-id}" ,
)
response = client.virtual_machine_scale_sets.begin_create_or_update(
resource_group_name="myResourceGroup" ,
vm_scale_set_name="{vmss-name}" ,
parameters={
"location" : "westus" ,
"properties" : {
"overprovision" : True ,
"upgradePolicy" : {"mode" : "Manual" },
"virtualMachineProfile" : {
"diagnosticsProfile" : {
"bootDiagnostics" : {
"enabled" : True ,
"storageUri" : "http://{existing-storage-account-name}.blob.core.windows.net" ,
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"enableIPForwarding" : True ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
},
}
],
"primary" : True ,
},
}
]
},
"osProfile" : {
"adminPassword" : "{your-password}" ,
"adminUsername" : "{your-username}" ,
"computerNamePrefix" : "{vmss-name}" ,
},
"storageProfile" : {
"imageReference" : {
"offer" : "WindowsServer" ,
"publisher" : "MicrosoftWindowsServer" ,
"sku" : "2016-Datacenter" ,
"version" : "latest" ,
},
"osDisk" : {
"caching" : "ReadWrite" ,
"createOption" : "FromImage" ,
"managedDisk" : {"storageAccountType" : "Standard_LRS" },
},
},
},
},
"sku" : {"capacity" : 3 , "name" : "Standard_D1_v2" , "tier" : "Standard" },
},
).result()
print(response)
if __name__ == "__main__" :
main()
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4"
)
func ExampleVirtualMachineScaleSetsClient_BeginCreateOrUpdate_createAScaleSetWithBootDiagnostics () {
cred, err := azidentity.NewDefaultAzureCredential(nil )
if err != nil {
log.Fatalf("failed to obtain a credential: %v" , err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("<subscription-id>" , cred, nil )
if err != nil {
log.Fatalf("failed to create client: %v" , err)
}
poller, err := clientFactory.NewVirtualMachineScaleSetsClient().BeginCreateOrUpdate(ctx, "myResourceGroup" , "{vmss-name}" , armcompute.VirtualMachineScaleSet{
Location: to.Ptr("westus" ),
Properties: &armcompute.VirtualMachineScaleSetProperties{
Overprovision: to.Ptr(true ),
UpgradePolicy: &armcompute.UpgradePolicy{
Mode: to.Ptr(armcompute.UpgradeModeManual),
},
VirtualMachineProfile: &armcompute.VirtualMachineScaleSetVMProfile{
DiagnosticsProfile: &armcompute.DiagnosticsProfile{
BootDiagnostics: &armcompute.BootDiagnostics{
Enabled: to.Ptr(true ),
StorageURI: to.Ptr("http://{existing-storage-account-name}.blob.core.windows.net" ),
},
},
NetworkProfile: &armcompute.VirtualMachineScaleSetNetworkProfile{
NetworkInterfaceConfigurations: []*armcompute.VirtualMachineScaleSetNetworkConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetNetworkConfigurationProperties{
EnableIPForwarding: to.Ptr(true ),
IPConfigurations: []*armcompute.VirtualMachineScaleSetIPConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetIPConfigurationProperties{
Subnet: &armcompute.APIEntityReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
},
},
}},
Primary: to.Ptr(true ),
},
}},
},
OSProfile: &armcompute.VirtualMachineScaleSetOSProfile{
AdminPassword: to.Ptr("{your-password}" ),
AdminUsername: to.Ptr("{your-username}" ),
ComputerNamePrefix: to.Ptr("{vmss-name}" ),
},
StorageProfile: &armcompute.VirtualMachineScaleSetStorageProfile{
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("WindowsServer" ),
Publisher: to.Ptr("MicrosoftWindowsServer" ),
SKU: to.Ptr("2016-Datacenter" ),
Version: to.Ptr("latest" ),
},
OSDisk: &armcompute.VirtualMachineScaleSetOSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.VirtualMachineScaleSetManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
},
},
SKU: &armcompute.SKU{
Name: to.Ptr("Standard_D1_v2" ),
Capacity: to.Ptr[int64 ](3 ),
Tier: to.Ptr("Standard" ),
},
}, nil )
if err != nil {
log.Fatalf("failed to finish the request: %v" , err)
}
res, err := poller.PollUntilDone(ctx, nil )
if err != nil {
log.Fatalf("failed to pull the result: %v" , err)
}
_ = res
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require ("@azure/arm-compute" );
const { DefaultAzureCredential } = require ("@azure/identity" );
async function createAScaleSetWithBootDiagnostics ( ) {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID" ] || "{subscription-id}" ;
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP" ] || "myResourceGroup" ;
const vmScaleSetName = "{vmss-name}" ;
const parameters = {
location : "westus" ,
overprovision : true ,
sku : { name : "Standard_D1_v2" , capacity : 3 , tier : "Standard" },
upgradePolicy : { mode : "Manual" },
virtualMachineProfile : {
diagnosticsProfile : {
bootDiagnostics : {
enabled : true ,
storageUri : "http://{existing-storage-account-name}.blob.core.windows.net" ,
},
},
networkProfile : {
networkInterfaceConfigurations : [
{
name : "{vmss-name}" ,
enableIPForwarding : true ,
ipConfigurations : [
{
name : "{vmss-name}" ,
subnet : {
id : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ,
},
},
],
primary : true ,
},
],
},
osProfile : {
adminPassword : "{your-password}" ,
adminUsername : "{your-username}" ,
computerNamePrefix : "{vmss-name}" ,
},
storageProfile : {
imageReference : {
offer : "WindowsServer" ,
publisher : "MicrosoftWindowsServer" ,
sku : "2016-Datacenter" ,
version : "latest" ,
},
osDisk : {
caching : "ReadWrite" ,
createOption : "FromImage" ,
managedDisk : { storageAccountType : "Standard_LRS" },
},
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachineScaleSets.beginCreateOrUpdateAndWait(
resourceGroupName,
vmScaleSetName,
parameters
);
console .log(result);
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Compute;
using Azure.ResourceManager.Compute.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Resources.Models;
TokenCredential cred = new DefaultAzureCredential();
ArmClient client = new ArmClient(cred);
string subscriptionId = "{subscription-id}" ;
string resourceGroupName = "myResourceGroup" ;
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
VirtualMachineScaleSetCollection collection = resourceGroupResource.GetVirtualMachineScaleSets();
string virtualMachineScaleSetName = "{vmss-name}" ;
VirtualMachineScaleSetData data = new VirtualMachineScaleSetData(new AzureLocation("westus" ))
{
Sku = new ComputeSku()
{
Name = "Standard_D1_v2" ,
Tier = "Standard" ,
Capacity = 3 ,
},
UpgradePolicy = new VirtualMachineScaleSetUpgradePolicy()
{
Mode = VirtualMachineScaleSetUpgradeMode.Manual,
},
VirtualMachineProfile = new VirtualMachineScaleSetVmProfile()
{
OSProfile = new VirtualMachineScaleSetOSProfile()
{
ComputerNamePrefix = "{vmss-name}" ,
AdminUsername = "{your-username}" ,
AdminPassword = "{your-password}" ,
},
StorageProfile = new VirtualMachineScaleSetStorageProfile()
{
ImageReference = new ImageReference()
{
Publisher = "MicrosoftWindowsServer" ,
Offer = "WindowsServer" ,
Sku = "2016-Datacenter" ,
Version = "latest" ,
},
OSDisk = new VirtualMachineScaleSetOSDisk(DiskCreateOptionType.FromImage)
{
Caching = CachingType.ReadWrite,
ManagedDisk = new VirtualMachineScaleSetManagedDisk()
{
StorageAccountType = StorageAccountType.StandardLrs,
},
},
},
NetworkProfile = new VirtualMachineScaleSetNetworkProfile()
{
NetworkInterfaceConfigurations =
{
new VirtualMachineScaleSetNetworkConfiguration("{vmss-name}" )
{
Primary = true ,
IPConfigurations =
{
new VirtualMachineScaleSetIPConfiguration("{vmss-name}" )
{
SubnetId = new ResourceIdentifier("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
}
},
EnableIPForwarding = true ,
}
},
},
BootDiagnostics = new BootDiagnostics()
{
Enabled = true ,
StorageUri = new Uri("http://{existing-storage-account-name}.blob.core.windows.net" ),
},
},
Overprovision = true ,
};
ArmOperation<VirtualMachineScaleSetResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, virtualMachineScaleSetName, data);
VirtualMachineScaleSetResource result = lro.Value;
VirtualMachineScaleSetData resourceData = result.Data;
Console.WriteLine($"Succeeded on id: {resourceData.Id} " );
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
範例回覆
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_D1_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "d053ec5a-8da6-495f-ab13-38216503c6d7" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter" ,
"publisher" : "MicrosoftWindowsServer" ,
"version" : "latest" ,
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"diagnosticsProfile" : {
"bootDiagnostics" : {
"storageUri" : "http://nsgdiagnostic.blob.core.windows.net" ,
"enabled" : true
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_D1_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "d053ec5a-8da6-495f-ab13-38216503c6d7" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter" ,
"publisher" : "MicrosoftWindowsServer" ,
"version" : "latest" ,
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"diagnosticsProfile" : {
"bootDiagnostics" : {
"storageUri" : "http://nsgdiagnostic.blob.core.windows.net" ,
"enabled" : true
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
Create a scale set with Disk Controller Type
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}?api-version=2022-11-01
{
"sku" : {
"tier" : "Standard",
"capacity" : 3,
"name" : "Standard_D1_v2"
},
"location" : "westus",
"properties" : {
"overprovision" : true,
"upgradePolicy" : {
"mode" : "Manual"
},
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter",
"publisher" : "MicrosoftWindowsServer",
"version" : "latest",
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite",
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
},
"diskControllerType" : "NVMe"
},
"userData" : "RXhhbXBsZSBVc2VyRGF0YQ==",
"hardwareProfile" : {
"vmSizeProperties" : {
"vCPUsAvailable" : 1,
"vCPUsPerCore" : 1
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}",
"adminUsername" : "{your-username}",
"adminPassword" : "{your-password}"
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"primary" : true,
"enableIPForwarding" : true,
"ipConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
}
}
]
}
}
]
}
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineScaleSetInner;
import com.azure.resourcemanager.compute.models.ApiEntityReference;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.Sku;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.UpgradeMode;
import com.azure.resourcemanager.compute.models.UpgradePolicy;
import com.azure.resourcemanager.compute.models.VMSizeProperties;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetHardwareProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetIpConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetManagedDiskParameters;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSDisk;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetStorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetVMProfile;
import java.util.Arrays;
public final class Main {
public static void createAScaleSetWithDiskControllerType (com.azure.resourcemanager.AzureResourceManager azure) {
azure
.virtualMachines()
.manager()
.serviceClient()
.getVirtualMachineScaleSets()
.createOrUpdate(
"myResourceGroup" ,
"{vmss-name}" ,
new VirtualMachineScaleSetInner()
.withLocation("westus" )
.withSku(new Sku().withName("Standard_D1_v2" ).withTier("Standard" ).withCapacity(3L ))
.withUpgradePolicy(new UpgradePolicy().withMode(UpgradeMode.MANUAL))
.withVirtualMachineProfile(
new VirtualMachineScaleSetVMProfile()
.withOsProfile(
new VirtualMachineScaleSetOSProfile()
.withComputerNamePrefix("{vmss-name}" )
.withAdminUsername("{your-username}" )
.withAdminPassword("fakeTokenPlaceholder" ))
.withStorageProfile(
new VirtualMachineScaleSetStorageProfile()
.withImageReference(
new ImageReference()
.withPublisher("MicrosoftWindowsServer" )
.withOffer("WindowsServer" )
.withSku("2016-Datacenter" )
.withVersion("latest" ))
.withOsDisk(
new VirtualMachineScaleSetOSDisk()
.withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)
.withManagedDisk(
new VirtualMachineScaleSetManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.STANDARD_LRS)))
.withDiskControllerType("NVMe" ))
.withNetworkProfile(
new VirtualMachineScaleSetNetworkProfile()
.withNetworkInterfaceConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetNetworkConfiguration()
.withName("{vmss-name}" )
.withPrimary(true )
.withIpConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetIpConfiguration()
.withName("{vmss-name}" )
.withSubnet(
new ApiEntityReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ))))
.withEnableIpForwarding(true ))))
.withUserData("RXhhbXBsZSBVc2VyRGF0YQ==" )
.withHardwareProfile(
new VirtualMachineScaleSetHardwareProfile()
.withVmSizeProperties(
new VMSizeProperties().withVCpusAvailable(1 ).withVCpusPerCore(1 ))))
.withOverprovision(true ),
com.azure.core.util.Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_scale_set_create_with_disk_controller_type.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main () :
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="{subscription-id}" ,
)
response = client.virtual_machine_scale_sets.begin_create_or_update(
resource_group_name="myResourceGroup" ,
vm_scale_set_name="{vmss-name}" ,
parameters={
"location" : "westus" ,
"properties" : {
"overprovision" : True ,
"upgradePolicy" : {"mode" : "Manual" },
"virtualMachineProfile" : {
"hardwareProfile" : {"vmSizeProperties" : {"vCPUsAvailable" : 1 , "vCPUsPerCore" : 1 }},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"enableIPForwarding" : True ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
},
}
],
"primary" : True ,
},
}
]
},
"osProfile" : {
"adminPassword" : "{your-password}" ,
"adminUsername" : "{your-username}" ,
"computerNamePrefix" : "{vmss-name}" ,
},
"storageProfile" : {
"diskControllerType" : "NVMe" ,
"imageReference" : {
"offer" : "WindowsServer" ,
"publisher" : "MicrosoftWindowsServer" ,
"sku" : "2016-Datacenter" ,
"version" : "latest" ,
},
"osDisk" : {
"caching" : "ReadWrite" ,
"createOption" : "FromImage" ,
"managedDisk" : {"storageAccountType" : "Standard_LRS" },
},
},
"userData" : "RXhhbXBsZSBVc2VyRGF0YQ==" ,
},
},
"sku" : {"capacity" : 3 , "name" : "Standard_D1_v2" , "tier" : "Standard" },
},
).result()
print(response)
if __name__ == "__main__" :
main()
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4"
)
func ExampleVirtualMachineScaleSetsClient_BeginCreateOrUpdate_createAScaleSetWithDiskControllerType () {
cred, err := azidentity.NewDefaultAzureCredential(nil )
if err != nil {
log.Fatalf("failed to obtain a credential: %v" , err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("<subscription-id>" , cred, nil )
if err != nil {
log.Fatalf("failed to create client: %v" , err)
}
poller, err := clientFactory.NewVirtualMachineScaleSetsClient().BeginCreateOrUpdate(ctx, "myResourceGroup" , "{vmss-name}" , armcompute.VirtualMachineScaleSet{
Location: to.Ptr("westus" ),
Properties: &armcompute.VirtualMachineScaleSetProperties{
Overprovision: to.Ptr(true ),
UpgradePolicy: &armcompute.UpgradePolicy{
Mode: to.Ptr(armcompute.UpgradeModeManual),
},
VirtualMachineProfile: &armcompute.VirtualMachineScaleSetVMProfile{
HardwareProfile: &armcompute.VirtualMachineScaleSetHardwareProfile{
VMSizeProperties: &armcompute.VMSizeProperties{
VCPUsAvailable: to.Ptr[int32 ](1 ),
VCPUsPerCore: to.Ptr[int32 ](1 ),
},
},
NetworkProfile: &armcompute.VirtualMachineScaleSetNetworkProfile{
NetworkInterfaceConfigurations: []*armcompute.VirtualMachineScaleSetNetworkConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetNetworkConfigurationProperties{
EnableIPForwarding: to.Ptr(true ),
IPConfigurations: []*armcompute.VirtualMachineScaleSetIPConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetIPConfigurationProperties{
Subnet: &armcompute.APIEntityReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
},
},
}},
Primary: to.Ptr(true ),
},
}},
},
OSProfile: &armcompute.VirtualMachineScaleSetOSProfile{
AdminPassword: to.Ptr("{your-password}" ),
AdminUsername: to.Ptr("{your-username}" ),
ComputerNamePrefix: to.Ptr("{vmss-name}" ),
},
StorageProfile: &armcompute.VirtualMachineScaleSetStorageProfile{
DiskControllerType: to.Ptr("NVMe" ),
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("WindowsServer" ),
Publisher: to.Ptr("MicrosoftWindowsServer" ),
SKU: to.Ptr("2016-Datacenter" ),
Version: to.Ptr("latest" ),
},
OSDisk: &armcompute.VirtualMachineScaleSetOSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.VirtualMachineScaleSetManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
UserData: to.Ptr("RXhhbXBsZSBVc2VyRGF0YQ==" ),
},
},
SKU: &armcompute.SKU{
Name: to.Ptr("Standard_D1_v2" ),
Capacity: to.Ptr[int64 ](3 ),
Tier: to.Ptr("Standard" ),
},
}, nil )
if err != nil {
log.Fatalf("failed to finish the request: %v" , err)
}
res, err := poller.PollUntilDone(ctx, nil )
if err != nil {
log.Fatalf("failed to pull the result: %v" , err)
}
_ = res
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require ("@azure/arm-compute" );
const { DefaultAzureCredential } = require ("@azure/identity" );
async function createAScaleSetWithDiskControllerType ( ) {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID" ] || "{subscription-id}" ;
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP" ] || "myResourceGroup" ;
const vmScaleSetName = "{vmss-name}" ;
const parameters = {
location : "westus" ,
overprovision : true ,
sku : { name : "Standard_D1_v2" , capacity : 3 , tier : "Standard" },
upgradePolicy : { mode : "Manual" },
virtualMachineProfile : {
hardwareProfile : {
vmSizeProperties : { vCPUsAvailable : 1 , vCPUsPerCore : 1 },
},
networkProfile : {
networkInterfaceConfigurations : [
{
name : "{vmss-name}" ,
enableIPForwarding : true ,
ipConfigurations : [
{
name : "{vmss-name}" ,
subnet : {
id : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ,
},
},
],
primary : true ,
},
],
},
osProfile : {
adminPassword : "{your-password}" ,
adminUsername : "{your-username}" ,
computerNamePrefix : "{vmss-name}" ,
},
storageProfile : {
diskControllerType : "NVMe" ,
imageReference : {
offer : "WindowsServer" ,
publisher : "MicrosoftWindowsServer" ,
sku : "2016-Datacenter" ,
version : "latest" ,
},
osDisk : {
caching : "ReadWrite" ,
createOption : "FromImage" ,
managedDisk : { storageAccountType : "Standard_LRS" },
},
},
userData : "RXhhbXBsZSBVc2VyRGF0YQ==" ,
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachineScaleSets.beginCreateOrUpdateAndWait(
resourceGroupName,
vmScaleSetName,
parameters
);
console .log(result);
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Compute;
using Azure.ResourceManager.Compute.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Resources.Models;
TokenCredential cred = new DefaultAzureCredential();
ArmClient client = new ArmClient(cred);
string subscriptionId = "{subscription-id}" ;
string resourceGroupName = "myResourceGroup" ;
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
VirtualMachineScaleSetCollection collection = resourceGroupResource.GetVirtualMachineScaleSets();
string virtualMachineScaleSetName = "{vmss-name}" ;
VirtualMachineScaleSetData data = new VirtualMachineScaleSetData(new AzureLocation("westus" ))
{
Sku = new ComputeSku()
{
Name = "Standard_D1_v2" ,
Tier = "Standard" ,
Capacity = 3 ,
},
UpgradePolicy = new VirtualMachineScaleSetUpgradePolicy()
{
Mode = VirtualMachineScaleSetUpgradeMode.Manual,
},
VirtualMachineProfile = new VirtualMachineScaleSetVmProfile()
{
OSProfile = new VirtualMachineScaleSetOSProfile()
{
ComputerNamePrefix = "{vmss-name}" ,
AdminUsername = "{your-username}" ,
AdminPassword = "{your-password}" ,
},
StorageProfile = new VirtualMachineScaleSetStorageProfile()
{
ImageReference = new ImageReference()
{
Publisher = "MicrosoftWindowsServer" ,
Offer = "WindowsServer" ,
Sku = "2016-Datacenter" ,
Version = "latest" ,
},
OSDisk = new VirtualMachineScaleSetOSDisk(DiskCreateOptionType.FromImage)
{
Caching = CachingType.ReadWrite,
ManagedDisk = new VirtualMachineScaleSetManagedDisk()
{
StorageAccountType = StorageAccountType.StandardLrs,
},
},
DiskControllerType = "NVMe" ,
},
NetworkProfile = new VirtualMachineScaleSetNetworkProfile()
{
NetworkInterfaceConfigurations =
{
new VirtualMachineScaleSetNetworkConfiguration("{vmss-name}" )
{
Primary = true ,
IPConfigurations =
{
new VirtualMachineScaleSetIPConfiguration("{vmss-name}" )
{
SubnetId = new ResourceIdentifier("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
}
},
EnableIPForwarding = true ,
}
},
},
UserData = "RXhhbXBsZSBVc2VyRGF0YQ==" ,
HardwareVmSizeProperties = new VirtualMachineSizeProperties()
{
VCpusAvailable = 1 ,
VCpusPerCore = 1 ,
},
},
Overprovision = true ,
};
ArmOperation<VirtualMachineScaleSetResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, virtualMachineScaleSetName, data);
VirtualMachineScaleSetResource result = lro.Value;
VirtualMachineScaleSetData resourceData = result.Data;
Console.WriteLine($"Succeeded on id: {resourceData.Id} " );
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
範例回覆
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_D1_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "d053ec5a-8da6-495f-ab13-38216503c6d7" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter" ,
"publisher" : "MicrosoftWindowsServer" ,
"version" : "latest" ,
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
},
"diskControllerType" : "NVMe"
},
"hardwareProfile" : {
"vmSizeProperties" : {
"vCPUsAvailable" : 1 ,
"vCPUsPerCore" : 1
}
},
"diagnosticsProfile" : {
"bootDiagnostics" : {
"storageUri" : "http://nsgdiagnostic.blob.core.windows.net" ,
"enabled" : true
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_D1_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "d053ec5a-8da6-495f-ab13-38216503c6d7" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter" ,
"publisher" : "MicrosoftWindowsServer" ,
"version" : "latest" ,
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
},
"diskControllerType" : "SCSI"
},
"hardwareProfile" : {
"vmSizeProperties" : {
"vCPUsAvailable" : 1 ,
"vCPUsPerCore" : 1
}
},
"diagnosticsProfile" : {
"bootDiagnostics" : {
"storageUri" : "http://nsgdiagnostic.blob.core.windows.net" ,
"enabled" : true
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
Create a scale set with DiskEncryptionSet resource in os disk and data disk.
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}?api-version=2022-11-01
{
"sku" : {
"tier" : "Standard",
"capacity" : 3,
"name" : "Standard_DS1_v2"
},
"properties" : {
"overprovision" : true,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/{existing-custom-image-name}"
},
"osDisk" : {
"caching" : "ReadWrite",
"managedDisk" : {
"storageAccountType" : "Standard_LRS",
"diskEncryptionSet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"
}
},
"createOption" : "FromImage"
},
"dataDisks" : [
{
"caching" : "ReadWrite",
"managedDisk" : {
"storageAccountType" : "Standard_LRS",
"diskEncryptionSet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"
}
},
"diskSizeGB" : 1023,
"createOption" : "Empty",
"lun" : 0
}
]
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}",
"adminUsername" : "{your-username}",
"adminPassword" : "{your-password}"
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"primary" : true,
"enableIPForwarding" : true,
"ipConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
}
}
]
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
}
},
"location" : "westus"
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineScaleSetInner;
import com.azure.resourcemanager.compute.models.ApiEntityReference;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.DiskEncryptionSetParameters;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.Sku;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.UpgradeMode;
import com.azure.resourcemanager.compute.models.UpgradePolicy;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetDataDisk;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetIpConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetManagedDiskParameters;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSDisk;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetStorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetVMProfile;
import java.util.Arrays;
public final class Main {
public static void createAScaleSetWithDiskEncryptionSetResourceInOsDiskAndDataDisk (
com.azure.resourcemanager.AzureResourceManager azure) {
azure
.virtualMachines()
.manager()
.serviceClient()
.getVirtualMachineScaleSets()
.createOrUpdate(
"myResourceGroup" ,
"{vmss-name}" ,
new VirtualMachineScaleSetInner()
.withLocation("westus" )
.withSku(new Sku().withName("Standard_DS1_v2" ).withTier("Standard" ).withCapacity(3L ))
.withUpgradePolicy(new UpgradePolicy().withMode(UpgradeMode.MANUAL))
.withVirtualMachineProfile(
new VirtualMachineScaleSetVMProfile()
.withOsProfile(
new VirtualMachineScaleSetOSProfile()
.withComputerNamePrefix("{vmss-name}" )
.withAdminUsername("{your-username}" )
.withAdminPassword("fakeTokenPlaceholder" ))
.withStorageProfile(
new VirtualMachineScaleSetStorageProfile()
.withImageReference(
new ImageReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/{existing-custom-image-name}" ))
.withOsDisk(
new VirtualMachineScaleSetOSDisk()
.withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)
.withManagedDisk(
new VirtualMachineScaleSetManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.STANDARD_LRS)
.withDiskEncryptionSet(
new DiskEncryptionSetParameters()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}" ))))
.withDataDisks(
Arrays
.asList(
new VirtualMachineScaleSetDataDisk()
.withLun(0 )
.withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.EMPTY)
.withDiskSizeGB(1023 )
.withManagedDisk(
new VirtualMachineScaleSetManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.STANDARD_LRS)
.withDiskEncryptionSet(
new DiskEncryptionSetParameters()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}" ))))))
.withNetworkProfile(
new VirtualMachineScaleSetNetworkProfile()
.withNetworkInterfaceConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetNetworkConfiguration()
.withName("{vmss-name}" )
.withPrimary(true )
.withIpConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetIpConfiguration()
.withName("{vmss-name}" )
.withSubnet(
new ApiEntityReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ))))
.withEnableIpForwarding(true )))))
.withOverprovision(true ),
com.azure.core.util.Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_scale_set_create_with_disk_encryption_set_resource.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main () :
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="{subscription-id}" ,
)
response = client.virtual_machine_scale_sets.begin_create_or_update(
resource_group_name="myResourceGroup" ,
vm_scale_set_name="{vmss-name}" ,
parameters={
"location" : "westus" ,
"properties" : {
"overprovision" : True ,
"upgradePolicy" : {"mode" : "Manual" },
"virtualMachineProfile" : {
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"enableIPForwarding" : True ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
},
}
],
"primary" : True ,
},
}
]
},
"osProfile" : {
"adminPassword" : "{your-password}" ,
"adminUsername" : "{your-username}" ,
"computerNamePrefix" : "{vmss-name}" ,
},
"storageProfile" : {
"dataDisks" : [
{
"caching" : "ReadWrite" ,
"createOption" : "Empty" ,
"diskSizeGB" : 1023 ,
"lun" : 0 ,
"managedDisk" : {
"diskEncryptionSet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"
},
"storageAccountType" : "Standard_LRS" ,
},
}
],
"imageReference" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/{existing-custom-image-name}"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"createOption" : "FromImage" ,
"managedDisk" : {
"diskEncryptionSet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"
},
"storageAccountType" : "Standard_LRS" ,
},
},
},
},
},
"sku" : {"capacity" : 3 , "name" : "Standard_DS1_v2" , "tier" : "Standard" },
},
).result()
print(response)
if __name__ == "__main__" :
main()
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4"
)
func ExampleVirtualMachineScaleSetsClient_BeginCreateOrUpdate_createAScaleSetWithDiskEncryptionSetResourceInOsDiskAndDataDisk () {
cred, err := azidentity.NewDefaultAzureCredential(nil )
if err != nil {
log.Fatalf("failed to obtain a credential: %v" , err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("<subscription-id>" , cred, nil )
if err != nil {
log.Fatalf("failed to create client: %v" , err)
}
poller, err := clientFactory.NewVirtualMachineScaleSetsClient().BeginCreateOrUpdate(ctx, "myResourceGroup" , "{vmss-name}" , armcompute.VirtualMachineScaleSet{
Location: to.Ptr("westus" ),
Properties: &armcompute.VirtualMachineScaleSetProperties{
Overprovision: to.Ptr(true ),
UpgradePolicy: &armcompute.UpgradePolicy{
Mode: to.Ptr(armcompute.UpgradeModeManual),
},
VirtualMachineProfile: &armcompute.VirtualMachineScaleSetVMProfile{
NetworkProfile: &armcompute.VirtualMachineScaleSetNetworkProfile{
NetworkInterfaceConfigurations: []*armcompute.VirtualMachineScaleSetNetworkConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetNetworkConfigurationProperties{
EnableIPForwarding: to.Ptr(true ),
IPConfigurations: []*armcompute.VirtualMachineScaleSetIPConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetIPConfigurationProperties{
Subnet: &armcompute.APIEntityReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
},
},
}},
Primary: to.Ptr(true ),
},
}},
},
OSProfile: &armcompute.VirtualMachineScaleSetOSProfile{
AdminPassword: to.Ptr("{your-password}" ),
AdminUsername: to.Ptr("{your-username}" ),
ComputerNamePrefix: to.Ptr("{vmss-name}" ),
},
StorageProfile: &armcompute.VirtualMachineScaleSetStorageProfile{
DataDisks: []*armcompute.VirtualMachineScaleSetDataDisk{
{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesEmpty),
DiskSizeGB: to.Ptr[int32 ](1023 ),
Lun: to.Ptr[int32 ](0 ),
ManagedDisk: &armcompute.VirtualMachineScaleSetManagedDiskParameters{
DiskEncryptionSet: &armcompute.DiskEncryptionSetParameters{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}" ),
},
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
}},
ImageReference: &armcompute.ImageReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/{existing-custom-image-name}" ),
},
OSDisk: &armcompute.VirtualMachineScaleSetOSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.VirtualMachineScaleSetManagedDiskParameters{
DiskEncryptionSet: &armcompute.DiskEncryptionSetParameters{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}" ),
},
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
},
},
SKU: &armcompute.SKU{
Name: to.Ptr("Standard_DS1_v2" ),
Capacity: to.Ptr[int64 ](3 ),
Tier: to.Ptr("Standard" ),
},
}, nil )
if err != nil {
log.Fatalf("failed to finish the request: %v" , err)
}
res, err := poller.PollUntilDone(ctx, nil )
if err != nil {
log.Fatalf("failed to pull the result: %v" , err)
}
_ = res
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require ("@azure/arm-compute" );
const { DefaultAzureCredential } = require ("@azure/identity" );
async function createAScaleSetWithDiskEncryptionSetResourceInOSDiskAndDataDisk ( ) {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID" ] || "{subscription-id}" ;
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP" ] || "myResourceGroup" ;
const vmScaleSetName = "{vmss-name}" ;
const parameters = {
location : "westus" ,
overprovision : true ,
sku : { name : "Standard_DS1_v2" , capacity : 3 , tier : "Standard" },
upgradePolicy : { mode : "Manual" },
virtualMachineProfile : {
networkProfile : {
networkInterfaceConfigurations : [
{
name : "{vmss-name}" ,
enableIPForwarding : true ,
ipConfigurations : [
{
name : "{vmss-name}" ,
subnet : {
id : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ,
},
},
],
primary : true ,
},
],
},
osProfile : {
adminPassword : "{your-password}" ,
adminUsername : "{your-username}" ,
computerNamePrefix : "{vmss-name}" ,
},
storageProfile : {
dataDisks : [
{
caching : "ReadWrite" ,
createOption : "Empty" ,
diskSizeGB : 1023 ,
lun : 0 ,
managedDisk : {
diskEncryptionSet : {
id : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}" ,
},
storageAccountType : "Standard_LRS" ,
},
},
],
imageReference : {
id : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/{existing-custom-image-name}" ,
},
osDisk : {
caching : "ReadWrite" ,
createOption : "FromImage" ,
managedDisk : {
diskEncryptionSet : {
id : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}" ,
},
storageAccountType : "Standard_LRS" ,
},
},
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachineScaleSets.beginCreateOrUpdateAndWait(
resourceGroupName,
vmScaleSetName,
parameters
);
console .log(result);
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Compute;
using Azure.ResourceManager.Compute.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Resources.Models;
TokenCredential cred = new DefaultAzureCredential();
ArmClient client = new ArmClient(cred);
string subscriptionId = "{subscription-id}" ;
string resourceGroupName = "myResourceGroup" ;
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
VirtualMachineScaleSetCollection collection = resourceGroupResource.GetVirtualMachineScaleSets();
string virtualMachineScaleSetName = "{vmss-name}" ;
VirtualMachineScaleSetData data = new VirtualMachineScaleSetData(new AzureLocation("westus" ))
{
Sku = new ComputeSku()
{
Name = "Standard_DS1_v2" ,
Tier = "Standard" ,
Capacity = 3 ,
},
UpgradePolicy = new VirtualMachineScaleSetUpgradePolicy()
{
Mode = VirtualMachineScaleSetUpgradeMode.Manual,
},
VirtualMachineProfile = new VirtualMachineScaleSetVmProfile()
{
OSProfile = new VirtualMachineScaleSetOSProfile()
{
ComputerNamePrefix = "{vmss-name}" ,
AdminUsername = "{your-username}" ,
AdminPassword = "{your-password}" ,
},
StorageProfile = new VirtualMachineScaleSetStorageProfile()
{
ImageReference = new ImageReference()
{
Id = new ResourceIdentifier("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/{existing-custom-image-name}" ),
},
OSDisk = new VirtualMachineScaleSetOSDisk(DiskCreateOptionType.FromImage)
{
Caching = CachingType.ReadWrite,
ManagedDisk = new VirtualMachineScaleSetManagedDisk()
{
StorageAccountType = StorageAccountType.StandardLrs,
DiskEncryptionSetId = new ResourceIdentifier("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}" ),
},
},
DataDisks =
{
new VirtualMachineScaleSetDataDisk(0 ,DiskCreateOptionType.Empty)
{
Caching = CachingType.ReadWrite,
DiskSizeGB = 1023 ,
ManagedDisk = new VirtualMachineScaleSetManagedDisk()
{
StorageAccountType = StorageAccountType.StandardLrs,
DiskEncryptionSetId = new ResourceIdentifier("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}" ),
},
}
},
},
NetworkProfile = new VirtualMachineScaleSetNetworkProfile()
{
NetworkInterfaceConfigurations =
{
new VirtualMachineScaleSetNetworkConfiguration("{vmss-name}" )
{
Primary = true ,
IPConfigurations =
{
new VirtualMachineScaleSetIPConfiguration("{vmss-name}" )
{
SubnetId = new ResourceIdentifier("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
}
},
EnableIPForwarding = true ,
}
},
},
},
Overprovision = true ,
};
ArmOperation<VirtualMachineScaleSetResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, virtualMachineScaleSetName, data);
VirtualMachineScaleSetResource result = lro.Value;
VirtualMachineScaleSetData resourceData = result.Data;
Console.WriteLine($"Succeeded on id: {resourceData.Id} " );
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
範例回覆
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_D1_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "afa2afa8-9e49-48fb-9d18-c86323b5d064" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/nsgcustom"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS" ,
"diskEncryptionSet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"
}
},
"createOption" : "FromImage"
},
"dataDisks" : [
{
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS" ,
"diskEncryptionSet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"
}
},
"diskSizeGB" : 1023 ,
"createOption" : "Empty" ,
"lun" : 0
}
]
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"linuxConfiguration" : {
"disablePasswordAuthentication" : false
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_D1_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "afa2afa8-9e49-48fb-9d18-c86323b5d064" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/nsgcustom"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS" ,
"diskEncryptionSet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"
}
},
"createOption" : "FromImage"
},
"dataDisks" : [
{
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS" ,
"diskEncryptionSet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"
}
},
"diskSizeGB" : 1023 ,
"createOption" : "Empty" ,
"lun" : 0
}
]
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"linuxConfiguration" : {
"disablePasswordAuthentication" : false
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
Create a scale set with empty data disks on each vm.
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}?api-version=2022-11-01
{
"sku" : {
"tier" : "Standard",
"capacity" : 3,
"name" : "Standard_D2_v2"
},
"location" : "westus",
"properties" : {
"overprovision" : true,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter",
"publisher" : "MicrosoftWindowsServer",
"version" : "latest",
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite",
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage",
"diskSizeGB" : 512
},
"dataDisks" : [
{
"diskSizeGB" : 1023,
"createOption" : "Empty",
"lun" : 0
},
{
"diskSizeGB" : 1023,
"createOption" : "Empty",
"lun" : 1
}
]
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}",
"adminUsername" : "{your-username}",
"adminPassword" : "{your-password}"
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"primary" : true,
"enableIPForwarding" : true,
"ipConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
}
}
]
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineScaleSetInner;
import com.azure.resourcemanager.compute.models.ApiEntityReference;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.Sku;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.UpgradeMode;
import com.azure.resourcemanager.compute.models.UpgradePolicy;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetDataDisk;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetIpConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetManagedDiskParameters;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSDisk;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetStorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetVMProfile;
import java.util.Arrays;
public final class Main {
public static void createAScaleSetWithEmptyDataDisksOnEachVm (com.azure.resourcemanager.AzureResourceManager azure) {
azure
.virtualMachines()
.manager()
.serviceClient()
.getVirtualMachineScaleSets()
.createOrUpdate(
"myResourceGroup" ,
"{vmss-name}" ,
new VirtualMachineScaleSetInner()
.withLocation("westus" )
.withSku(new Sku().withName("Standard_D2_v2" ).withTier("Standard" ).withCapacity(3L ))
.withUpgradePolicy(new UpgradePolicy().withMode(UpgradeMode.MANUAL))
.withVirtualMachineProfile(
new VirtualMachineScaleSetVMProfile()
.withOsProfile(
new VirtualMachineScaleSetOSProfile()
.withComputerNamePrefix("{vmss-name}" )
.withAdminUsername("{your-username}" )
.withAdminPassword("fakeTokenPlaceholder" ))
.withStorageProfile(
new VirtualMachineScaleSetStorageProfile()
.withImageReference(
new ImageReference()
.withPublisher("MicrosoftWindowsServer" )
.withOffer("WindowsServer" )
.withSku("2016-Datacenter" )
.withVersion("latest" ))
.withOsDisk(
new VirtualMachineScaleSetOSDisk()
.withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)
.withDiskSizeGB(512 )
.withManagedDisk(
new VirtualMachineScaleSetManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.STANDARD_LRS)))
.withDataDisks(
Arrays
.asList(
new VirtualMachineScaleSetDataDisk()
.withLun(0 )
.withCreateOption(DiskCreateOptionTypes.EMPTY)
.withDiskSizeGB(1023 ),
new VirtualMachineScaleSetDataDisk()
.withLun(1 )
.withCreateOption(DiskCreateOptionTypes.EMPTY)
.withDiskSizeGB(1023 ))))
.withNetworkProfile(
new VirtualMachineScaleSetNetworkProfile()
.withNetworkInterfaceConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetNetworkConfiguration()
.withName("{vmss-name}" )
.withPrimary(true )
.withIpConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetIpConfiguration()
.withName("{vmss-name}" )
.withSubnet(
new ApiEntityReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ))))
.withEnableIpForwarding(true )))))
.withOverprovision(true ),
com.azure.core.util.Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_scale_set_create_with_empty_data_disks_on_each_vm.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main () :
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="{subscription-id}" ,
)
response = client.virtual_machine_scale_sets.begin_create_or_update(
resource_group_name="myResourceGroup" ,
vm_scale_set_name="{vmss-name}" ,
parameters={
"location" : "westus" ,
"properties" : {
"overprovision" : True ,
"upgradePolicy" : {"mode" : "Manual" },
"virtualMachineProfile" : {
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"enableIPForwarding" : True ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
},
}
],
"primary" : True ,
},
}
]
},
"osProfile" : {
"adminPassword" : "{your-password}" ,
"adminUsername" : "{your-username}" ,
"computerNamePrefix" : "{vmss-name}" ,
},
"storageProfile" : {
"dataDisks" : [
{"createOption" : "Empty" , "diskSizeGB" : 1023 , "lun" : 0 },
{"createOption" : "Empty" , "diskSizeGB" : 1023 , "lun" : 1 },
],
"imageReference" : {
"offer" : "WindowsServer" ,
"publisher" : "MicrosoftWindowsServer" ,
"sku" : "2016-Datacenter" ,
"version" : "latest" ,
},
"osDisk" : {
"caching" : "ReadWrite" ,
"createOption" : "FromImage" ,
"diskSizeGB" : 512 ,
"managedDisk" : {"storageAccountType" : "Standard_LRS" },
},
},
},
},
"sku" : {"capacity" : 3 , "name" : "Standard_D2_v2" , "tier" : "Standard" },
},
).result()
print(response)
if __name__ == "__main__" :
main()
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4"
)
func ExampleVirtualMachineScaleSetsClient_BeginCreateOrUpdate_createAScaleSetWithEmptyDataDisksOnEachVm () {
cred, err := azidentity.NewDefaultAzureCredential(nil )
if err != nil {
log.Fatalf("failed to obtain a credential: %v" , err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("<subscription-id>" , cred, nil )
if err != nil {
log.Fatalf("failed to create client: %v" , err)
}
poller, err := clientFactory.NewVirtualMachineScaleSetsClient().BeginCreateOrUpdate(ctx, "myResourceGroup" , "{vmss-name}" , armcompute.VirtualMachineScaleSet{
Location: to.Ptr("westus" ),
Properties: &armcompute.VirtualMachineScaleSetProperties{
Overprovision: to.Ptr(true ),
UpgradePolicy: &armcompute.UpgradePolicy{
Mode: to.Ptr(armcompute.UpgradeModeManual),
},
VirtualMachineProfile: &armcompute.VirtualMachineScaleSetVMProfile{
NetworkProfile: &armcompute.VirtualMachineScaleSetNetworkProfile{
NetworkInterfaceConfigurations: []*armcompute.VirtualMachineScaleSetNetworkConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetNetworkConfigurationProperties{
EnableIPForwarding: to.Ptr(true ),
IPConfigurations: []*armcompute.VirtualMachineScaleSetIPConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetIPConfigurationProperties{
Subnet: &armcompute.APIEntityReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
},
},
}},
Primary: to.Ptr(true ),
},
}},
},
OSProfile: &armcompute.VirtualMachineScaleSetOSProfile{
AdminPassword: to.Ptr("{your-password}" ),
AdminUsername: to.Ptr("{your-username}" ),
ComputerNamePrefix: to.Ptr("{vmss-name}" ),
},
StorageProfile: &armcompute.VirtualMachineScaleSetStorageProfile{
DataDisks: []*armcompute.VirtualMachineScaleSetDataDisk{
{
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesEmpty),
DiskSizeGB: to.Ptr[int32 ](1023 ),
Lun: to.Ptr[int32 ](0 ),
},
{
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesEmpty),
DiskSizeGB: to.Ptr[int32 ](1023 ),
Lun: to.Ptr[int32 ](1 ),
}},
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("WindowsServer" ),
Publisher: to.Ptr("MicrosoftWindowsServer" ),
SKU: to.Ptr("2016-Datacenter" ),
Version: to.Ptr("latest" ),
},
OSDisk: &armcompute.VirtualMachineScaleSetOSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
DiskSizeGB: to.Ptr[int32 ](512 ),
ManagedDisk: &armcompute.VirtualMachineScaleSetManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
},
},
SKU: &armcompute.SKU{
Name: to.Ptr("Standard_D2_v2" ),
Capacity: to.Ptr[int64 ](3 ),
Tier: to.Ptr("Standard" ),
},
}, nil )
if err != nil {
log.Fatalf("failed to finish the request: %v" , err)
}
res, err := poller.PollUntilDone(ctx, nil )
if err != nil {
log.Fatalf("failed to pull the result: %v" , err)
}
_ = res
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require ("@azure/arm-compute" );
const { DefaultAzureCredential } = require ("@azure/identity" );
async function createAScaleSetWithEmptyDataDisksOnEachVM ( ) {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID" ] || "{subscription-id}" ;
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP" ] || "myResourceGroup" ;
const vmScaleSetName = "{vmss-name}" ;
const parameters = {
location : "westus" ,
overprovision : true ,
sku : { name : "Standard_D2_v2" , capacity : 3 , tier : "Standard" },
upgradePolicy : { mode : "Manual" },
virtualMachineProfile : {
networkProfile : {
networkInterfaceConfigurations : [
{
name : "{vmss-name}" ,
enableIPForwarding : true ,
ipConfigurations : [
{
name : "{vmss-name}" ,
subnet : {
id : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ,
},
},
],
primary : true ,
},
],
},
osProfile : {
adminPassword : "{your-password}" ,
adminUsername : "{your-username}" ,
computerNamePrefix : "{vmss-name}" ,
},
storageProfile : {
dataDisks : [
{ createOption : "Empty" , diskSizeGB : 1023 , lun : 0 },
{ createOption : "Empty" , diskSizeGB : 1023 , lun : 1 },
],
imageReference : {
offer : "WindowsServer" ,
publisher : "MicrosoftWindowsServer" ,
sku : "2016-Datacenter" ,
version : "latest" ,
},
osDisk : {
caching : "ReadWrite" ,
createOption : "FromImage" ,
diskSizeGB : 512 ,
managedDisk : { storageAccountType : "Standard_LRS" },
},
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachineScaleSets.beginCreateOrUpdateAndWait(
resourceGroupName,
vmScaleSetName,
parameters
);
console .log(result);
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Compute;
using Azure.ResourceManager.Compute.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Resources.Models;
TokenCredential cred = new DefaultAzureCredential();
ArmClient client = new ArmClient(cred);
string subscriptionId = "{subscription-id}" ;
string resourceGroupName = "myResourceGroup" ;
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
VirtualMachineScaleSetCollection collection = resourceGroupResource.GetVirtualMachineScaleSets();
string virtualMachineScaleSetName = "{vmss-name}" ;
VirtualMachineScaleSetData data = new VirtualMachineScaleSetData(new AzureLocation("westus" ))
{
Sku = new ComputeSku()
{
Name = "Standard_D2_v2" ,
Tier = "Standard" ,
Capacity = 3 ,
},
UpgradePolicy = new VirtualMachineScaleSetUpgradePolicy()
{
Mode = VirtualMachineScaleSetUpgradeMode.Manual,
},
VirtualMachineProfile = new VirtualMachineScaleSetVmProfile()
{
OSProfile = new VirtualMachineScaleSetOSProfile()
{
ComputerNamePrefix = "{vmss-name}" ,
AdminUsername = "{your-username}" ,
AdminPassword = "{your-password}" ,
},
StorageProfile = new VirtualMachineScaleSetStorageProfile()
{
ImageReference = new ImageReference()
{
Publisher = "MicrosoftWindowsServer" ,
Offer = "WindowsServer" ,
Sku = "2016-Datacenter" ,
Version = "latest" ,
},
OSDisk = new VirtualMachineScaleSetOSDisk(DiskCreateOptionType.FromImage)
{
Caching = CachingType.ReadWrite,
DiskSizeGB = 512 ,
ManagedDisk = new VirtualMachineScaleSetManagedDisk()
{
StorageAccountType = StorageAccountType.StandardLrs,
},
},
DataDisks =
{
new VirtualMachineScaleSetDataDisk(0 ,DiskCreateOptionType.Empty)
{
DiskSizeGB = 1023 ,
},new VirtualMachineScaleSetDataDisk(1 ,DiskCreateOptionType.Empty)
{
DiskSizeGB = 1023 ,
}
},
},
NetworkProfile = new VirtualMachineScaleSetNetworkProfile()
{
NetworkInterfaceConfigurations =
{
new VirtualMachineScaleSetNetworkConfiguration("{vmss-name}" )
{
Primary = true ,
IPConfigurations =
{
new VirtualMachineScaleSetIPConfiguration("{vmss-name}" )
{
SubnetId = new ResourceIdentifier("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
}
},
EnableIPForwarding = true ,
}
},
},
},
Overprovision = true ,
};
ArmOperation<VirtualMachineScaleSetResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, virtualMachineScaleSetName, data);
VirtualMachineScaleSetResource result = lro.Value;
VirtualMachineScaleSetData resourceData = result.Data;
Console.WriteLine($"Succeeded on id: {resourceData.Id} " );
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
範例回覆
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_D2_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "8042c376-4690-4c47-9fa2-fbdad70e32fa" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter" ,
"publisher" : "MicrosoftWindowsServer" ,
"version" : "latest" ,
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage" ,
"diskSizeGB" : 512
},
"dataDisks" : [
{
"caching" : "None" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "Empty" ,
"lun" : 0 ,
"diskSizeGB" : 1023
},
{
"caching" : "None" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "Empty" ,
"lun" : 1 ,
"diskSizeGB" : 1023
}
]
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Succeeded"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_D2_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "8042c376-4690-4c47-9fa2-fbdad70e32fa" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter" ,
"publisher" : "MicrosoftWindowsServer" ,
"version" : "latest" ,
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage" ,
"diskSizeGB" : 512
},
"dataDisks" : [
{
"caching" : "None" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "Empty" ,
"lun" : 0 ,
"diskSizeGB" : 1023
},
{
"caching" : "None" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "Empty" ,
"lun" : 1 ,
"diskSizeGB" : 1023
}
]
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
Create a scale set with ephemeral os disks using placement property.
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}?api-version=2022-11-01
{
"sku" : {
"tier" : "Standard",
"capacity" : 3,
"name" : "Standard_DS1_v2"
},
"properties" : {
"overprovision" : true,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "windows2016",
"publisher" : "microsoft-ads",
"version" : "latest",
"offer" : "windows-data-science-vm"
},
"osDisk" : {
"caching" : "ReadOnly",
"diffDiskSettings" : {
"option" : "Local",
"placement" : "ResourceDisk"
},
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}",
"adminUsername" : "{your-username}",
"adminPassword" : "{your-password}"
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"primary" : true,
"enableIPForwarding" : true,
"ipConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
}
}
]
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
}
},
"plan" : {
"publisher" : "microsoft-ads",
"product" : "windows-data-science-vm",
"name" : "windows2016"
},
"location" : "westus"
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineScaleSetInner;
import com.azure.resourcemanager.compute.models.ApiEntityReference;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiffDiskOptions;
import com.azure.resourcemanager.compute.models.DiffDiskPlacement;
import com.azure.resourcemanager.compute.models.DiffDiskSettings;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.Plan;
import com.azure.resourcemanager.compute.models.Sku;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.UpgradeMode;
import com.azure.resourcemanager.compute.models.UpgradePolicy;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetIpConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetManagedDiskParameters;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSDisk;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetStorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetVMProfile;
import java.util.Arrays;
public final class Main {
public static void createAScaleSetWithEphemeralOsDisksUsingPlacementProperty (
com.azure.resourcemanager.AzureResourceManager azure) {
azure
.virtualMachines()
.manager()
.serviceClient()
.getVirtualMachineScaleSets()
.createOrUpdate(
"myResourceGroup" ,
"{vmss-name}" ,
new VirtualMachineScaleSetInner()
.withLocation("westus" )
.withSku(new Sku().withName("Standard_DS1_v2" ).withTier("Standard" ).withCapacity(3L ))
.withPlan(
new Plan()
.withName("windows2016" )
.withPublisher("microsoft-ads" )
.withProduct("windows-data-science-vm" ))
.withUpgradePolicy(new UpgradePolicy().withMode(UpgradeMode.MANUAL))
.withVirtualMachineProfile(
new VirtualMachineScaleSetVMProfile()
.withOsProfile(
new VirtualMachineScaleSetOSProfile()
.withComputerNamePrefix("{vmss-name}" )
.withAdminUsername("{your-username}" )
.withAdminPassword("fakeTokenPlaceholder" ))
.withStorageProfile(
new VirtualMachineScaleSetStorageProfile()
.withImageReference(
new ImageReference()
.withPublisher("microsoft-ads" )
.withOffer("windows-data-science-vm" )
.withSku("windows2016" )
.withVersion("latest" ))
.withOsDisk(
new VirtualMachineScaleSetOSDisk()
.withCaching(CachingTypes.READ_ONLY)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)
.withDiffDiskSettings(
new DiffDiskSettings()
.withOption(DiffDiskOptions.LOCAL)
.withPlacement(DiffDiskPlacement.RESOURCE_DISK))
.withManagedDisk(
new VirtualMachineScaleSetManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withNetworkProfile(
new VirtualMachineScaleSetNetworkProfile()
.withNetworkInterfaceConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetNetworkConfiguration()
.withName("{vmss-name}" )
.withPrimary(true )
.withIpConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetIpConfiguration()
.withName("{vmss-name}" )
.withSubnet(
new ApiEntityReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ))))
.withEnableIpForwarding(true )))))
.withOverprovision(true ),
com.azure.core.util.Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_scale_set_create_a_with_diff_os_disk_using_diff_disk_placement.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main () :
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="{subscription-id}" ,
)
response = client.virtual_machine_scale_sets.begin_create_or_update(
resource_group_name="myResourceGroup" ,
vm_scale_set_name="{vmss-name}" ,
parameters={
"location" : "westus" ,
"plan" : {"name" : "windows2016" , "product" : "windows-data-science-vm" , "publisher" : "microsoft-ads" },
"properties" : {
"overprovision" : True ,
"upgradePolicy" : {"mode" : "Manual" },
"virtualMachineProfile" : {
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"enableIPForwarding" : True ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
},
}
],
"primary" : True ,
},
}
]
},
"osProfile" : {
"adminPassword" : "{your-password}" ,
"adminUsername" : "{your-username}" ,
"computerNamePrefix" : "{vmss-name}" ,
},
"storageProfile" : {
"imageReference" : {
"offer" : "windows-data-science-vm" ,
"publisher" : "microsoft-ads" ,
"sku" : "windows2016" ,
"version" : "latest" ,
},
"osDisk" : {
"caching" : "ReadOnly" ,
"createOption" : "FromImage" ,
"diffDiskSettings" : {"option" : "Local" , "placement" : "ResourceDisk" },
"managedDisk" : {"storageAccountType" : "Standard_LRS" },
},
},
},
},
"sku" : {"capacity" : 3 , "name" : "Standard_DS1_v2" , "tier" : "Standard" },
},
).result()
print(response)
if __name__ == "__main__" :
main()
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4"
)
func ExampleVirtualMachineScaleSetsClient_BeginCreateOrUpdate_createAScaleSetWithEphemeralOsDisksUsingPlacementProperty () {
cred, err := azidentity.NewDefaultAzureCredential(nil )
if err != nil {
log.Fatalf("failed to obtain a credential: %v" , err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("<subscription-id>" , cred, nil )
if err != nil {
log.Fatalf("failed to create client: %v" , err)
}
poller, err := clientFactory.NewVirtualMachineScaleSetsClient().BeginCreateOrUpdate(ctx, "myResourceGroup" , "{vmss-name}" , armcompute.VirtualMachineScaleSet{
Location: to.Ptr("westus" ),
Plan: &armcompute.Plan{
Name: to.Ptr("windows2016" ),
Product: to.Ptr("windows-data-science-vm" ),
Publisher: to.Ptr("microsoft-ads" ),
},
Properties: &armcompute.VirtualMachineScaleSetProperties{
Overprovision: to.Ptr(true ),
UpgradePolicy: &armcompute.UpgradePolicy{
Mode: to.Ptr(armcompute.UpgradeModeManual),
},
VirtualMachineProfile: &armcompute.VirtualMachineScaleSetVMProfile{
NetworkProfile: &armcompute.VirtualMachineScaleSetNetworkProfile{
NetworkInterfaceConfigurations: []*armcompute.VirtualMachineScaleSetNetworkConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetNetworkConfigurationProperties{
EnableIPForwarding: to.Ptr(true ),
IPConfigurations: []*armcompute.VirtualMachineScaleSetIPConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetIPConfigurationProperties{
Subnet: &armcompute.APIEntityReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
},
},
}},
Primary: to.Ptr(true ),
},
}},
},
OSProfile: &armcompute.VirtualMachineScaleSetOSProfile{
AdminPassword: to.Ptr("{your-password}" ),
AdminUsername: to.Ptr("{your-username}" ),
ComputerNamePrefix: to.Ptr("{vmss-name}" ),
},
StorageProfile: &armcompute.VirtualMachineScaleSetStorageProfile{
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("windows-data-science-vm" ),
Publisher: to.Ptr("microsoft-ads" ),
SKU: to.Ptr("windows2016" ),
Version: to.Ptr("latest" ),
},
OSDisk: &armcompute.VirtualMachineScaleSetOSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadOnly),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
DiffDiskSettings: &armcompute.DiffDiskSettings{
Option: to.Ptr(armcompute.DiffDiskOptionsLocal),
Placement: to.Ptr(armcompute.DiffDiskPlacementResourceDisk),
},
ManagedDisk: &armcompute.VirtualMachineScaleSetManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
},
},
SKU: &armcompute.SKU{
Name: to.Ptr("Standard_DS1_v2" ),
Capacity: to.Ptr[int64 ](3 ),
Tier: to.Ptr("Standard" ),
},
}, nil )
if err != nil {
log.Fatalf("failed to finish the request: %v" , err)
}
res, err := poller.PollUntilDone(ctx, nil )
if err != nil {
log.Fatalf("failed to pull the result: %v" , err)
}
_ = res
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require ("@azure/arm-compute" );
const { DefaultAzureCredential } = require ("@azure/identity" );
async function createAScaleSetWithEphemeralOSDisksUsingPlacementProperty ( ) {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID" ] || "{subscription-id}" ;
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP" ] || "myResourceGroup" ;
const vmScaleSetName = "{vmss-name}" ;
const parameters = {
location : "westus" ,
overprovision : true ,
plan : {
name : "windows2016" ,
product : "windows-data-science-vm" ,
publisher : "microsoft-ads" ,
},
sku : { name : "Standard_DS1_v2" , capacity : 3 , tier : "Standard" },
upgradePolicy : { mode : "Manual" },
virtualMachineProfile : {
networkProfile : {
networkInterfaceConfigurations : [
{
name : "{vmss-name}" ,
enableIPForwarding : true ,
ipConfigurations : [
{
name : "{vmss-name}" ,
subnet : {
id : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ,
},
},
],
primary : true ,
},
],
},
osProfile : {
adminPassword : "{your-password}" ,
adminUsername : "{your-username}" ,
computerNamePrefix : "{vmss-name}" ,
},
storageProfile : {
imageReference : {
offer : "windows-data-science-vm" ,
publisher : "microsoft-ads" ,
sku : "windows2016" ,
version : "latest" ,
},
osDisk : {
caching : "ReadOnly" ,
createOption : "FromImage" ,
diffDiskSettings : { option : "Local" , placement : "ResourceDisk" },
managedDisk : { storageAccountType : "Standard_LRS" },
},
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachineScaleSets.beginCreateOrUpdateAndWait(
resourceGroupName,
vmScaleSetName,
parameters
);
console .log(result);
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Compute;
using Azure.ResourceManager.Compute.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Resources.Models;
TokenCredential cred = new DefaultAzureCredential();
ArmClient client = new ArmClient(cred);
string subscriptionId = "{subscription-id}" ;
string resourceGroupName = "myResourceGroup" ;
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
VirtualMachineScaleSetCollection collection = resourceGroupResource.GetVirtualMachineScaleSets();
string virtualMachineScaleSetName = "{vmss-name}" ;
VirtualMachineScaleSetData data = new VirtualMachineScaleSetData(new AzureLocation("westus" ))
{
Sku = new ComputeSku()
{
Name = "Standard_DS1_v2" ,
Tier = "Standard" ,
Capacity = 3 ,
},
Plan = new ComputePlan()
{
Name = "windows2016" ,
Publisher = "microsoft-ads" ,
Product = "windows-data-science-vm" ,
},
UpgradePolicy = new VirtualMachineScaleSetUpgradePolicy()
{
Mode = VirtualMachineScaleSetUpgradeMode.Manual,
},
VirtualMachineProfile = new VirtualMachineScaleSetVmProfile()
{
OSProfile = new VirtualMachineScaleSetOSProfile()
{
ComputerNamePrefix = "{vmss-name}" ,
AdminUsername = "{your-username}" ,
AdminPassword = "{your-password}" ,
},
StorageProfile = new VirtualMachineScaleSetStorageProfile()
{
ImageReference = new ImageReference()
{
Publisher = "microsoft-ads" ,
Offer = "windows-data-science-vm" ,
Sku = "windows2016" ,
Version = "latest" ,
},
OSDisk = new VirtualMachineScaleSetOSDisk(DiskCreateOptionType.FromImage)
{
Caching = CachingType.ReadOnly,
DiffDiskSettings = new DiffDiskSettings()
{
Option = DiffDiskOption.Local,
Placement = DiffDiskPlacement.ResourceDisk,
},
ManagedDisk = new VirtualMachineScaleSetManagedDisk()
{
StorageAccountType = StorageAccountType.StandardLrs,
},
},
},
NetworkProfile = new VirtualMachineScaleSetNetworkProfile()
{
NetworkInterfaceConfigurations =
{
new VirtualMachineScaleSetNetworkConfiguration("{vmss-name}" )
{
Primary = true ,
IPConfigurations =
{
new VirtualMachineScaleSetIPConfiguration("{vmss-name}" )
{
SubnetId = new ResourceIdentifier("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
}
},
EnableIPForwarding = true ,
}
},
},
},
Overprovision = true ,
};
ArmOperation<VirtualMachineScaleSetResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, virtualMachineScaleSetName, data);
VirtualMachineScaleSetResource result = lro.Value;
VirtualMachineScaleSetData resourceData = result.Data;
Console.WriteLine($"Succeeded on id: {resourceData.Id} " );
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
範例回覆
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_DS1_v2"
},
"name" : "{vmss-name}" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}" ,
"plan" : {
"publisher" : "microsoft-ads" ,
"product" : "standard-data-science-vm" ,
"name" : "standard-data-science-vm"
},
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "b9e23088-6ffc-46e0-9e02-b0a6eeef47db" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "standard-data-science-vm" ,
"publisher" : "microsoft-ads" ,
"version" : "latest" ,
"offer" : "standard-data-science-vm"
},
"osDisk" : {
"caching" : "ReadOnly" ,
"diffDiskSettings" : {
"option" : "Local" ,
"placement" : "ResourceDisk"
},
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus"
}
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_DS1_v2"
},
"name" : "{vmss-name}" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}" ,
"plan" : {
"publisher" : "microsoft-ads" ,
"product" : "standard-data-science-vm" ,
"name" : "standard-data-science-vm"
},
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "b9e23088-6ffc-46e0-9e02-b0a6eeef47db" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "standard-data-science-vm" ,
"publisher" : "microsoft-ads" ,
"version" : "latest" ,
"offer" : "standard-data-science-vm"
},
"osDisk" : {
"caching" : "ReadOnly" ,
"diffDiskSettings" : {
"option" : "Local" ,
"placement" : "ResourceDisk"
},
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus"
}
Create a scale set with ephemeral os disks.
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}?api-version=2022-11-01
{
"sku" : {
"tier" : "Standard",
"capacity" : 3,
"name" : "Standard_DS1_v2"
},
"properties" : {
"overprovision" : true,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "windows2016",
"publisher" : "microsoft-ads",
"version" : "latest",
"offer" : "windows-data-science-vm"
},
"osDisk" : {
"caching" : "ReadOnly",
"diffDiskSettings" : {
"option" : "Local"
},
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}",
"adminUsername" : "{your-username}",
"adminPassword" : "{your-password}"
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"primary" : true,
"enableIPForwarding" : true,
"ipConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
}
}
]
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
}
},
"plan" : {
"publisher" : "microsoft-ads",
"product" : "windows-data-science-vm",
"name" : "windows2016"
},
"location" : "westus"
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineScaleSetInner;
import com.azure.resourcemanager.compute.models.ApiEntityReference;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiffDiskOptions;
import com.azure.resourcemanager.compute.models.DiffDiskSettings;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.Plan;
import com.azure.resourcemanager.compute.models.Sku;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.UpgradeMode;
import com.azure.resourcemanager.compute.models.UpgradePolicy;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetIpConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetManagedDiskParameters;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSDisk;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetStorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetVMProfile;
import java.util.Arrays;
public final class Main {
public static void createAScaleSetWithEphemeralOsDisks (com.azure.resourcemanager.AzureResourceManager azure) {
azure
.virtualMachines()
.manager()
.serviceClient()
.getVirtualMachineScaleSets()
.createOrUpdate(
"myResourceGroup" ,
"{vmss-name}" ,
new VirtualMachineScaleSetInner()
.withLocation("westus" )
.withSku(new Sku().withName("Standard_DS1_v2" ).withTier("Standard" ).withCapacity(3L ))
.withPlan(
new Plan()
.withName("windows2016" )
.withPublisher("microsoft-ads" )
.withProduct("windows-data-science-vm" ))
.withUpgradePolicy(new UpgradePolicy().withMode(UpgradeMode.MANUAL))
.withVirtualMachineProfile(
new VirtualMachineScaleSetVMProfile()
.withOsProfile(
new VirtualMachineScaleSetOSProfile()
.withComputerNamePrefix("{vmss-name}" )
.withAdminUsername("{your-username}" )
.withAdminPassword("fakeTokenPlaceholder" ))
.withStorageProfile(
new VirtualMachineScaleSetStorageProfile()
.withImageReference(
new ImageReference()
.withPublisher("microsoft-ads" )
.withOffer("windows-data-science-vm" )
.withSku("windows2016" )
.withVersion("latest" ))
.withOsDisk(
new VirtualMachineScaleSetOSDisk()
.withCaching(CachingTypes.READ_ONLY)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)
.withDiffDiskSettings(
new DiffDiskSettings().withOption(DiffDiskOptions.LOCAL))
.withManagedDisk(
new VirtualMachineScaleSetManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withNetworkProfile(
new VirtualMachineScaleSetNetworkProfile()
.withNetworkInterfaceConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetNetworkConfiguration()
.withName("{vmss-name}" )
.withPrimary(true )
.withIpConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetIpConfiguration()
.withName("{vmss-name}" )
.withSubnet(
new ApiEntityReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ))))
.withEnableIpForwarding(true )))))
.withOverprovision(true ),
com.azure.core.util.Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_scale_set_create_with_diff_os_disk.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main () :
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="{subscription-id}" ,
)
response = client.virtual_machine_scale_sets.begin_create_or_update(
resource_group_name="myResourceGroup" ,
vm_scale_set_name="{vmss-name}" ,
parameters={
"location" : "westus" ,
"plan" : {"name" : "windows2016" , "product" : "windows-data-science-vm" , "publisher" : "microsoft-ads" },
"properties" : {
"overprovision" : True ,
"upgradePolicy" : {"mode" : "Manual" },
"virtualMachineProfile" : {
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"enableIPForwarding" : True ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
},
}
],
"primary" : True ,
},
}
]
},
"osProfile" : {
"adminPassword" : "{your-password}" ,
"adminUsername" : "{your-username}" ,
"computerNamePrefix" : "{vmss-name}" ,
},
"storageProfile" : {
"imageReference" : {
"offer" : "windows-data-science-vm" ,
"publisher" : "microsoft-ads" ,
"sku" : "windows2016" ,
"version" : "latest" ,
},
"osDisk" : {
"caching" : "ReadOnly" ,
"createOption" : "FromImage" ,
"diffDiskSettings" : {"option" : "Local" },
"managedDisk" : {"storageAccountType" : "Standard_LRS" },
},
},
},
},
"sku" : {"capacity" : 3 , "name" : "Standard_DS1_v2" , "tier" : "Standard" },
},
).result()
print(response)
if __name__ == "__main__" :
main()
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4"
)
func ExampleVirtualMachineScaleSetsClient_BeginCreateOrUpdate_createAScaleSetWithEphemeralOsDisks () {
cred, err := azidentity.NewDefaultAzureCredential(nil )
if err != nil {
log.Fatalf("failed to obtain a credential: %v" , err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("<subscription-id>" , cred, nil )
if err != nil {
log.Fatalf("failed to create client: %v" , err)
}
poller, err := clientFactory.NewVirtualMachineScaleSetsClient().BeginCreateOrUpdate(ctx, "myResourceGroup" , "{vmss-name}" , armcompute.VirtualMachineScaleSet{
Location: to.Ptr("westus" ),
Plan: &armcompute.Plan{
Name: to.Ptr("windows2016" ),
Product: to.Ptr("windows-data-science-vm" ),
Publisher: to.Ptr("microsoft-ads" ),
},
Properties: &armcompute.VirtualMachineScaleSetProperties{
Overprovision: to.Ptr(true ),
UpgradePolicy: &armcompute.UpgradePolicy{
Mode: to.Ptr(armcompute.UpgradeModeManual),
},
VirtualMachineProfile: &armcompute.VirtualMachineScaleSetVMProfile{
NetworkProfile: &armcompute.VirtualMachineScaleSetNetworkProfile{
NetworkInterfaceConfigurations: []*armcompute.VirtualMachineScaleSetNetworkConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetNetworkConfigurationProperties{
EnableIPForwarding: to.Ptr(true ),
IPConfigurations: []*armcompute.VirtualMachineScaleSetIPConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetIPConfigurationProperties{
Subnet: &armcompute.APIEntityReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
},
},
}},
Primary: to.Ptr(true ),
},
}},
},
OSProfile: &armcompute.VirtualMachineScaleSetOSProfile{
AdminPassword: to.Ptr("{your-password}" ),
AdminUsername: to.Ptr("{your-username}" ),
ComputerNamePrefix: to.Ptr("{vmss-name}" ),
},
StorageProfile: &armcompute.VirtualMachineScaleSetStorageProfile{
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("windows-data-science-vm" ),
Publisher: to.Ptr("microsoft-ads" ),
SKU: to.Ptr("windows2016" ),
Version: to.Ptr("latest" ),
},
OSDisk: &armcompute.VirtualMachineScaleSetOSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadOnly),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
DiffDiskSettings: &armcompute.DiffDiskSettings{
Option: to.Ptr(armcompute.DiffDiskOptionsLocal),
},
ManagedDisk: &armcompute.VirtualMachineScaleSetManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
},
},
SKU: &armcompute.SKU{
Name: to.Ptr("Standard_DS1_v2" ),
Capacity: to.Ptr[int64 ](3 ),
Tier: to.Ptr("Standard" ),
},
}, nil )
if err != nil {
log.Fatalf("failed to finish the request: %v" , err)
}
res, err := poller.PollUntilDone(ctx, nil )
if err != nil {
log.Fatalf("failed to pull the result: %v" , err)
}
_ = res
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require ("@azure/arm-compute" );
const { DefaultAzureCredential } = require ("@azure/identity" );
async function createAScaleSetWithEphemeralOSDisks ( ) {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID" ] || "{subscription-id}" ;
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP" ] || "myResourceGroup" ;
const vmScaleSetName = "{vmss-name}" ;
const parameters = {
location : "westus" ,
overprovision : true ,
plan : {
name : "windows2016" ,
product : "windows-data-science-vm" ,
publisher : "microsoft-ads" ,
},
sku : { name : "Standard_DS1_v2" , capacity : 3 , tier : "Standard" },
upgradePolicy : { mode : "Manual" },
virtualMachineProfile : {
networkProfile : {
networkInterfaceConfigurations : [
{
name : "{vmss-name}" ,
enableIPForwarding : true ,
ipConfigurations : [
{
name : "{vmss-name}" ,
subnet : {
id : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ,
},
},
],
primary : true ,
},
],
},
osProfile : {
adminPassword : "{your-password}" ,
adminUsername : "{your-username}" ,
computerNamePrefix : "{vmss-name}" ,
},
storageProfile : {
imageReference : {
offer : "windows-data-science-vm" ,
publisher : "microsoft-ads" ,
sku : "windows2016" ,
version : "latest" ,
},
osDisk : {
caching : "ReadOnly" ,
createOption : "FromImage" ,
diffDiskSettings : { option : "Local" },
managedDisk : { storageAccountType : "Standard_LRS" },
},
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachineScaleSets.beginCreateOrUpdateAndWait(
resourceGroupName,
vmScaleSetName,
parameters
);
console .log(result);
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Compute;
using Azure.ResourceManager.Compute.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Resources.Models;
TokenCredential cred = new DefaultAzureCredential();
ArmClient client = new ArmClient(cred);
string subscriptionId = "{subscription-id}" ;
string resourceGroupName = "myResourceGroup" ;
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
VirtualMachineScaleSetCollection collection = resourceGroupResource.GetVirtualMachineScaleSets();
string virtualMachineScaleSetName = "{vmss-name}" ;
VirtualMachineScaleSetData data = new VirtualMachineScaleSetData(new AzureLocation("westus" ))
{
Sku = new ComputeSku()
{
Name = "Standard_DS1_v2" ,
Tier = "Standard" ,
Capacity = 3 ,
},
Plan = new ComputePlan()
{
Name = "windows2016" ,
Publisher = "microsoft-ads" ,
Product = "windows-data-science-vm" ,
},
UpgradePolicy = new VirtualMachineScaleSetUpgradePolicy()
{
Mode = VirtualMachineScaleSetUpgradeMode.Manual,
},
VirtualMachineProfile = new VirtualMachineScaleSetVmProfile()
{
OSProfile = new VirtualMachineScaleSetOSProfile()
{
ComputerNamePrefix = "{vmss-name}" ,
AdminUsername = "{your-username}" ,
AdminPassword = "{your-password}" ,
},
StorageProfile = new VirtualMachineScaleSetStorageProfile()
{
ImageReference = new ImageReference()
{
Publisher = "microsoft-ads" ,
Offer = "windows-data-science-vm" ,
Sku = "windows2016" ,
Version = "latest" ,
},
OSDisk = new VirtualMachineScaleSetOSDisk(DiskCreateOptionType.FromImage)
{
Caching = CachingType.ReadOnly,
DiffDiskSettings = new DiffDiskSettings()
{
Option = DiffDiskOption.Local,
},
ManagedDisk = new VirtualMachineScaleSetManagedDisk()
{
StorageAccountType = StorageAccountType.StandardLrs,
},
},
},
NetworkProfile = new VirtualMachineScaleSetNetworkProfile()
{
NetworkInterfaceConfigurations =
{
new VirtualMachineScaleSetNetworkConfiguration("{vmss-name}" )
{
Primary = true ,
IPConfigurations =
{
new VirtualMachineScaleSetIPConfiguration("{vmss-name}" )
{
SubnetId = new ResourceIdentifier("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
}
},
EnableIPForwarding = true ,
}
},
},
},
Overprovision = true ,
};
ArmOperation<VirtualMachineScaleSetResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, virtualMachineScaleSetName, data);
VirtualMachineScaleSetResource result = lro.Value;
VirtualMachineScaleSetData resourceData = result.Data;
Console.WriteLine($"Succeeded on id: {resourceData.Id} " );
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
範例回覆
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_DS1_v2"
},
"name" : "{vmss-name}" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}" ,
"plan" : {
"publisher" : "microsoft-ads" ,
"product" : "standard-data-science-vm" ,
"name" : "standard-data-science-vm"
},
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "b9e23088-6ffc-46e0-9e02-b0a6eeef47db" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "standard-data-science-vm" ,
"publisher" : "microsoft-ads" ,
"version" : "latest" ,
"offer" : "standard-data-science-vm"
},
"osDisk" : {
"caching" : "ReadOnly" ,
"diffDiskSettings" : {
"option" : "Local"
},
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus"
}
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_DS1_v2"
},
"name" : "{vmss-name}" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}" ,
"plan" : {
"publisher" : "microsoft-ads" ,
"product" : "standard-data-science-vm" ,
"name" : "standard-data-science-vm"
},
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "b9e23088-6ffc-46e0-9e02-b0a6eeef47db" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "standard-data-science-vm" ,
"publisher" : "microsoft-ads" ,
"version" : "latest" ,
"offer" : "standard-data-science-vm"
},
"osDisk" : {
"caching" : "ReadOnly" ,
"diffDiskSettings" : {
"option" : "Local"
},
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus"
}
Create a scale set with extension time budget.
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}?api-version=2022-11-01
{
"sku" : {
"tier" : "Standard",
"capacity" : 3,
"name" : "Standard_D1_v2"
},
"location" : "westus",
"properties" : {
"overprovision" : true,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter",
"publisher" : "MicrosoftWindowsServer",
"version" : "latest",
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite",
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"diagnosticsProfile" : {
"bootDiagnostics" : {
"storageUri" : "http://{existing-storage-account-name}.blob.core.windows.net",
"enabled" : true
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}",
"adminUsername" : "{your-username}",
"adminPassword" : "{your-password}"
},
"extensionProfile" : {
"extensions" : [
{
"name" : "{extension-name}",
"properties" : {
"autoUpgradeMinorVersion" : false,
"publisher" : "{extension-Publisher}",
"type" : "{extension-Type}",
"typeHandlerVersion" : "{handler-version}",
"settings" : {}
}
}
],
"extensionsTimeBudget" : "PT1H20M"
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"primary" : true,
"enableIPForwarding" : true,
"ipConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
}
}
]
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
}
}
}
import com.azure.core.management.serializer.SerializerFactory;
import com.azure.core.util.serializer.SerializerEncoding;
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineScaleSetExtensionInner;
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineScaleSetInner;
import com.azure.resourcemanager.compute.models.ApiEntityReference;
import com.azure.resourcemanager.compute.models.BootDiagnostics;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiagnosticsProfile;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.Sku;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.UpgradeMode;
import com.azure.resourcemanager.compute.models.UpgradePolicy;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetExtensionProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetIpConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetManagedDiskParameters;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSDisk;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetStorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetVMProfile;
import java.io.IOException;
import java.util.Arrays;
public final class Main {
public static void createAScaleSetWithExtensionTimeBudget (com.azure.resourcemanager.AzureResourceManager azure)
throws IOException {
azure
.virtualMachines()
.manager()
.serviceClient()
.getVirtualMachineScaleSets()
.createOrUpdate(
"myResourceGroup" ,
"{vmss-name}" ,
new VirtualMachineScaleSetInner()
.withLocation("westus" )
.withSku(new Sku().withName("Standard_D1_v2" ).withTier("Standard" ).withCapacity(3L ))
.withUpgradePolicy(new UpgradePolicy().withMode(UpgradeMode.MANUAL))
.withVirtualMachineProfile(
new VirtualMachineScaleSetVMProfile()
.withOsProfile(
new VirtualMachineScaleSetOSProfile()
.withComputerNamePrefix("{vmss-name}" )
.withAdminUsername("{your-username}" )
.withAdminPassword("fakeTokenPlaceholder" ))
.withStorageProfile(
new VirtualMachineScaleSetStorageProfile()
.withImageReference(
new ImageReference()
.withPublisher("MicrosoftWindowsServer" )
.withOffer("WindowsServer" )
.withSku("2016-Datacenter" )
.withVersion("latest" ))
.withOsDisk(
new VirtualMachineScaleSetOSDisk()
.withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)
.withManagedDisk(
new VirtualMachineScaleSetManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withNetworkProfile(
new VirtualMachineScaleSetNetworkProfile()
.withNetworkInterfaceConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetNetworkConfiguration()
.withName("{vmss-name}" )
.withPrimary(true )
.withIpConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetIpConfiguration()
.withName("{vmss-name}" )
.withSubnet(
new ApiEntityReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ))))
.withEnableIpForwarding(true ))))
.withDiagnosticsProfile(
new DiagnosticsProfile()
.withBootDiagnostics(
new BootDiagnostics()
.withEnabled(true )
.withStorageUri(
"http://{existing-storage-account-name}.blob.core.windows.net" )))
.withExtensionProfile(
new VirtualMachineScaleSetExtensionProfile()
.withExtensions(
Arrays
.asList(
new VirtualMachineScaleSetExtensionInner()
.withName("{extension-name}" )
.withPublisher("{extension-Publisher}" )
.withTypePropertiesType("{extension-Type}" )
.withTypeHandlerVersion("{handler-version}" )
.withAutoUpgradeMinorVersion(false )
.withSettings(
SerializerFactory
.createDefaultManagementSerializerAdapter()
.deserialize("{}" , Object.class, SerializerEncoding.JSON))))
.withExtensionsTimeBudget("PT1H20M" )))
.withOverprovision(true ),
com.azure.core.util.Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_scale_set_create_with_extensions_time_budget.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main () :
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="{subscription-id}" ,
)
response = client.virtual_machine_scale_sets.begin_create_or_update(
resource_group_name="myResourceGroup" ,
vm_scale_set_name="{vmss-name}" ,
parameters={
"location" : "westus" ,
"properties" : {
"overprovision" : True ,
"upgradePolicy" : {"mode" : "Manual" },
"virtualMachineProfile" : {
"diagnosticsProfile" : {
"bootDiagnostics" : {
"enabled" : True ,
"storageUri" : "http://{existing-storage-account-name}.blob.core.windows.net" ,
}
},
"extensionProfile" : {
"extensions" : [
{
"name" : "{extension-name}" ,
"properties" : {
"autoUpgradeMinorVersion" : False ,
"publisher" : "{extension-Publisher}" ,
"settings" : {},
"type" : "{extension-Type}" ,
"typeHandlerVersion" : "{handler-version}" ,
},
}
],
"extensionsTimeBudget" : "PT1H20M" ,
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"enableIPForwarding" : True ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
},
}
],
"primary" : True ,
},
}
]
},
"osProfile" : {
"adminPassword" : "{your-password}" ,
"adminUsername" : "{your-username}" ,
"computerNamePrefix" : "{vmss-name}" ,
},
"storageProfile" : {
"imageReference" : {
"offer" : "WindowsServer" ,
"publisher" : "MicrosoftWindowsServer" ,
"sku" : "2016-Datacenter" ,
"version" : "latest" ,
},
"osDisk" : {
"caching" : "ReadWrite" ,
"createOption" : "FromImage" ,
"managedDisk" : {"storageAccountType" : "Standard_LRS" },
},
},
},
},
"sku" : {"capacity" : 3 , "name" : "Standard_D1_v2" , "tier" : "Standard" },
},
).result()
print(response)
if __name__ == "__main__" :
main()
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4"
)
func ExampleVirtualMachineScaleSetsClient_BeginCreateOrUpdate_createAScaleSetWithExtensionTimeBudget () {
cred, err := azidentity.NewDefaultAzureCredential(nil )
if err != nil {
log.Fatalf("failed to obtain a credential: %v" , err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("<subscription-id>" , cred, nil )
if err != nil {
log.Fatalf("failed to create client: %v" , err)
}
poller, err := clientFactory.NewVirtualMachineScaleSetsClient().BeginCreateOrUpdate(ctx, "myResourceGroup" , "{vmss-name}" , armcompute.VirtualMachineScaleSet{
Location: to.Ptr("westus" ),
Properties: &armcompute.VirtualMachineScaleSetProperties{
Overprovision: to.Ptr(true ),
UpgradePolicy: &armcompute.UpgradePolicy{
Mode: to.Ptr(armcompute.UpgradeModeManual),
},
VirtualMachineProfile: &armcompute.VirtualMachineScaleSetVMProfile{
DiagnosticsProfile: &armcompute.DiagnosticsProfile{
BootDiagnostics: &armcompute.BootDiagnostics{
Enabled: to.Ptr(true ),
StorageURI: to.Ptr("http://{existing-storage-account-name}.blob.core.windows.net" ),
},
},
ExtensionProfile: &armcompute.VirtualMachineScaleSetExtensionProfile{
ExtensionsTimeBudget: to.Ptr("PT1H20M" ),
Extensions: []*armcompute.VirtualMachineScaleSetExtension{
{
Name: to.Ptr("{extension-name}" ),
Properties: &armcompute.VirtualMachineScaleSetExtensionProperties{
Type: to.Ptr("{extension-Type}" ),
AutoUpgradeMinorVersion: to.Ptr(false ),
Publisher: to.Ptr("{extension-Publisher}" ),
Settings: map [string ]any{},
TypeHandlerVersion: to.Ptr("{handler-version}" ),
},
}},
},
NetworkProfile: &armcompute.VirtualMachineScaleSetNetworkProfile{
NetworkInterfaceConfigurations: []*armcompute.VirtualMachineScaleSetNetworkConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetNetworkConfigurationProperties{
EnableIPForwarding: to.Ptr(true ),
IPConfigurations: []*armcompute.VirtualMachineScaleSetIPConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetIPConfigurationProperties{
Subnet: &armcompute.APIEntityReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
},
},
}},
Primary: to.Ptr(true ),
},
}},
},
OSProfile: &armcompute.VirtualMachineScaleSetOSProfile{
AdminPassword: to.Ptr("{your-password}" ),
AdminUsername: to.Ptr("{your-username}" ),
ComputerNamePrefix: to.Ptr("{vmss-name}" ),
},
StorageProfile: &armcompute.VirtualMachineScaleSetStorageProfile{
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("WindowsServer" ),
Publisher: to.Ptr("MicrosoftWindowsServer" ),
SKU: to.Ptr("2016-Datacenter" ),
Version: to.Ptr("latest" ),
},
OSDisk: &armcompute.VirtualMachineScaleSetOSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.VirtualMachineScaleSetManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
},
},
SKU: &armcompute.SKU{
Name: to.Ptr("Standard_D1_v2" ),
Capacity: to.Ptr[int64 ](3 ),
Tier: to.Ptr("Standard" ),
},
}, nil )
if err != nil {
log.Fatalf("failed to finish the request: %v" , err)
}
res, err := poller.PollUntilDone(ctx, nil )
if err != nil {
log.Fatalf("failed to pull the result: %v" , err)
}
_ = res
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require ("@azure/arm-compute" );
const { DefaultAzureCredential } = require ("@azure/identity" );
async function createAScaleSetWithExtensionTimeBudget ( ) {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID" ] || "{subscription-id}" ;
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP" ] || "myResourceGroup" ;
const vmScaleSetName = "{vmss-name}" ;
const parameters = {
location : "westus" ,
overprovision : true ,
sku : { name : "Standard_D1_v2" , capacity : 3 , tier : "Standard" },
upgradePolicy : { mode : "Manual" },
virtualMachineProfile : {
diagnosticsProfile : {
bootDiagnostics : {
enabled : true ,
storageUri : "http://{existing-storage-account-name}.blob.core.windows.net" ,
},
},
extensionProfile : {
extensionsTimeBudget : "PT1H20M" ,
extensions : [
{
name : "{extension-name}" ,
typePropertiesType : "{extension-Type}" ,
autoUpgradeMinorVersion : false ,
publisher : "{extension-Publisher}" ,
settings : {},
typeHandlerVersion : "{handler-version}" ,
},
],
},
networkProfile : {
networkInterfaceConfigurations : [
{
name : "{vmss-name}" ,
enableIPForwarding : true ,
ipConfigurations : [
{
name : "{vmss-name}" ,
subnet : {
id : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ,
},
},
],
primary : true ,
},
],
},
osProfile : {
adminPassword : "{your-password}" ,
adminUsername : "{your-username}" ,
computerNamePrefix : "{vmss-name}" ,
},
storageProfile : {
imageReference : {
offer : "WindowsServer" ,
publisher : "MicrosoftWindowsServer" ,
sku : "2016-Datacenter" ,
version : "latest" ,
},
osDisk : {
caching : "ReadWrite" ,
createOption : "FromImage" ,
managedDisk : { storageAccountType : "Standard_LRS" },
},
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachineScaleSets.beginCreateOrUpdateAndWait(
resourceGroupName,
vmScaleSetName,
parameters
);
console .log(result);
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Compute;
using Azure.ResourceManager.Compute.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Resources.Models;
TokenCredential cred = new DefaultAzureCredential();
ArmClient client = new ArmClient(cred);
string subscriptionId = "{subscription-id}" ;
string resourceGroupName = "myResourceGroup" ;
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
VirtualMachineScaleSetCollection collection = resourceGroupResource.GetVirtualMachineScaleSets();
string virtualMachineScaleSetName = "{vmss-name}" ;
VirtualMachineScaleSetData data = new VirtualMachineScaleSetData(new AzureLocation("westus" ))
{
Sku = new ComputeSku()
{
Name = "Standard_D1_v2" ,
Tier = "Standard" ,
Capacity = 3 ,
},
UpgradePolicy = new VirtualMachineScaleSetUpgradePolicy()
{
Mode = VirtualMachineScaleSetUpgradeMode.Manual,
},
VirtualMachineProfile = new VirtualMachineScaleSetVmProfile()
{
OSProfile = new VirtualMachineScaleSetOSProfile()
{
ComputerNamePrefix = "{vmss-name}" ,
AdminUsername = "{your-username}" ,
AdminPassword = "{your-password}" ,
},
StorageProfile = new VirtualMachineScaleSetStorageProfile()
{
ImageReference = new ImageReference()
{
Publisher = "MicrosoftWindowsServer" ,
Offer = "WindowsServer" ,
Sku = "2016-Datacenter" ,
Version = "latest" ,
},
OSDisk = new VirtualMachineScaleSetOSDisk(DiskCreateOptionType.FromImage)
{
Caching = CachingType.ReadWrite,
ManagedDisk = new VirtualMachineScaleSetManagedDisk()
{
StorageAccountType = StorageAccountType.StandardLrs,
},
},
},
NetworkProfile = new VirtualMachineScaleSetNetworkProfile()
{
NetworkInterfaceConfigurations =
{
new VirtualMachineScaleSetNetworkConfiguration("{vmss-name}" )
{
Primary = true ,
IPConfigurations =
{
new VirtualMachineScaleSetIPConfiguration("{vmss-name}" )
{
SubnetId = new ResourceIdentifier("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
}
},
EnableIPForwarding = true ,
}
},
},
BootDiagnostics = new BootDiagnostics()
{
Enabled = true ,
StorageUri = new Uri("http://{existing-storage-account-name}.blob.core.windows.net" ),
},
ExtensionProfile = new VirtualMachineScaleSetExtensionProfile()
{
Extensions =
{
new VirtualMachineScaleSetExtensionData()
{
Publisher = "{extension-Publisher}" ,
ExtensionType = "{extension-Type}" ,
TypeHandlerVersion = "{handler-version}" ,
AutoUpgradeMinorVersion = false ,
Settings = BinaryData.FromObjectAsJson(new Dictionary<string , object >()
{
}),
}
},
ExtensionsTimeBudget = "PT1H20M" ,
},
},
Overprovision = true ,
};
ArmOperation<VirtualMachineScaleSetResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, virtualMachineScaleSetName, data);
VirtualMachineScaleSetResource result = lro.Value;
VirtualMachineScaleSetData resourceData = result.Data;
Console.WriteLine($"Succeeded on id: {resourceData.Id} " );
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
範例回覆
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_D1_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "d053ec5a-8da6-495f-ab13-38216503c6d7" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter" ,
"publisher" : "MicrosoftWindowsServer" ,
"version" : "latest" ,
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"diagnosticsProfile" : {
"bootDiagnostics" : {
"storageUri" : "http://nsgdiagnostic.blob.core.windows.net" ,
"enabled" : true
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"extensionProfile" : {
"extensions" : [
{
"name" : "{extension-name}" ,
"properties" : {
"autoUpgradeMinorVersion" : false ,
"publisher" : "{extension-Publisher}" ,
"type" : "{extension-Type}" ,
"typeHandlerVersion" : "{handler-version}" ,
"settings" : {}
}
}
],
"extensionsTimeBudget" : "PT1H20M"
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_D1_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "d053ec5a-8da6-495f-ab13-38216503c6d7" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter" ,
"publisher" : "MicrosoftWindowsServer" ,
"version" : "latest" ,
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"diagnosticsProfile" : {
"bootDiagnostics" : {
"storageUri" : "http://nsgdiagnostic.blob.core.windows.net" ,
"enabled" : true
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"extensionProfile" : {
"extensions" : [
{
"name" : "{extension-name}" ,
"properties" : {
"autoUpgradeMinorVersion" : false ,
"publisher" : "{extension-Publisher}" ,
"type" : "{extension-Type}" ,
"typeHandlerVersion" : "{handler-version}" ,
"settings" : {}
}
}
],
"extensionsTimeBudget" : "PT1H20M"
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
Create a scale set with Fpga Network Interfaces.
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}?api-version=2022-11-01
{
"sku" : {
"tier" : "Standard",
"capacity" : 3,
"name" : "Standard_D1_v2"
},
"location" : "westus",
"properties" : {
"overprovision" : true,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/{existing-custom-image-name}"
},
"osDisk" : {
"caching" : "ReadWrite",
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}",
"adminUsername" : "{your-username}",
"adminPassword" : "{your-password}"
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"primary" : true,
"enableIPForwarding" : true,
"ipConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
}
}
]
}
},
{
"name" : "{fpgaNic-Name}",
"properties" : {
"primary" : false,
"enableAcceleratedNetworking" : false,
"enableIPForwarding" : false,
"enableFpga" : true,
"ipConfigurations" : [
{
"name" : "{fpgaNic-Name}",
"properties" : {
"primary" : true,
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-fpga-subnet-name}"
},
"privateIPAddressVersion" : "IPv4"
}
}
]
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineScaleSetInner;
import com.azure.resourcemanager.compute.models.ApiEntityReference;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.IpVersion;
import com.azure.resourcemanager.compute.models.Sku;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.UpgradeMode;
import com.azure.resourcemanager.compute.models.UpgradePolicy;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetIpConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetManagedDiskParameters;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSDisk;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetStorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetVMProfile;
import java.util.Arrays;
public final class Main {
public static void createAScaleSetWithFpgaNetworkInterfaces (com.azure.resourcemanager.AzureResourceManager azure) {
azure
.virtualMachines()
.manager()
.serviceClient()
.getVirtualMachineScaleSets()
.createOrUpdate(
"myResourceGroup" ,
"{vmss-name}" ,
new VirtualMachineScaleSetInner()
.withLocation("westus" )
.withSku(new Sku().withName("Standard_D1_v2" ).withTier("Standard" ).withCapacity(3L ))
.withUpgradePolicy(new UpgradePolicy().withMode(UpgradeMode.MANUAL))
.withVirtualMachineProfile(
new VirtualMachineScaleSetVMProfile()
.withOsProfile(
new VirtualMachineScaleSetOSProfile()
.withComputerNamePrefix("{vmss-name}" )
.withAdminUsername("{your-username}" )
.withAdminPassword("fakeTokenPlaceholder" ))
.withStorageProfile(
new VirtualMachineScaleSetStorageProfile()
.withImageReference(
new ImageReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/{existing-custom-image-name}" ))
.withOsDisk(
new VirtualMachineScaleSetOSDisk()
.withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)
.withManagedDisk(
new VirtualMachineScaleSetManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withNetworkProfile(
new VirtualMachineScaleSetNetworkProfile()
.withNetworkInterfaceConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetNetworkConfiguration()
.withName("{vmss-name}" )
.withPrimary(true )
.withIpConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetIpConfiguration()
.withName("{vmss-name}" )
.withSubnet(
new ApiEntityReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ))))
.withEnableIpForwarding(true ),
new VirtualMachineScaleSetNetworkConfiguration()
.withName("{fpgaNic-Name}" )
.withPrimary(false )
.withEnableAcceleratedNetworking(false )
.withEnableFpga(true )
.withIpConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetIpConfiguration()
.withName("{fpgaNic-Name}" )
.withSubnet(
new ApiEntityReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-fpga-subnet-name}" ))
.withPrimary(true )
.withPrivateIpAddressVersion(IpVersion.IPV4)))
.withEnableIpForwarding(false )))))
.withOverprovision(true ),
com.azure.core.util.Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_scale_set_create_from_with_fpga_network_interface.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main () :
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="{subscription-id}" ,
)
response = client.virtual_machine_scale_sets.begin_create_or_update(
resource_group_name="myResourceGroup" ,
vm_scale_set_name="{vmss-name}" ,
parameters={
"location" : "westus" ,
"properties" : {
"overprovision" : True ,
"upgradePolicy" : {"mode" : "Manual" },
"virtualMachineProfile" : {
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"enableIPForwarding" : True ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
},
}
],
"primary" : True ,
},
},
{
"name" : "{fpgaNic-Name}" ,
"properties" : {
"enableAcceleratedNetworking" : False ,
"enableFpga" : True ,
"enableIPForwarding" : False ,
"ipConfigurations" : [
{
"name" : "{fpgaNic-Name}" ,
"properties" : {
"primary" : True ,
"privateIPAddressVersion" : "IPv4" ,
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-fpga-subnet-name}"
},
},
}
],
"primary" : False ,
},
},
]
},
"osProfile" : {
"adminPassword" : "{your-password}" ,
"adminUsername" : "{your-username}" ,
"computerNamePrefix" : "{vmss-name}" ,
},
"storageProfile" : {
"imageReference" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/{existing-custom-image-name}"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"createOption" : "FromImage" ,
"managedDisk" : {"storageAccountType" : "Standard_LRS" },
},
},
},
},
"sku" : {"capacity" : 3 , "name" : "Standard_D1_v2" , "tier" : "Standard" },
},
).result()
print(response)
if __name__ == "__main__" :
main()
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4"
)
func ExampleVirtualMachineScaleSetsClient_BeginCreateOrUpdate_createAScaleSetWithFpgaNetworkInterfaces () {
cred, err := azidentity.NewDefaultAzureCredential(nil )
if err != nil {
log.Fatalf("failed to obtain a credential: %v" , err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("<subscription-id>" , cred, nil )
if err != nil {
log.Fatalf("failed to create client: %v" , err)
}
poller, err := clientFactory.NewVirtualMachineScaleSetsClient().BeginCreateOrUpdate(ctx, "myResourceGroup" , "{vmss-name}" , armcompute.VirtualMachineScaleSet{
Location: to.Ptr("westus" ),
Properties: &armcompute.VirtualMachineScaleSetProperties{
Overprovision: to.Ptr(true ),
UpgradePolicy: &armcompute.UpgradePolicy{
Mode: to.Ptr(armcompute.UpgradeModeManual),
},
VirtualMachineProfile: &armcompute.VirtualMachineScaleSetVMProfile{
NetworkProfile: &armcompute.VirtualMachineScaleSetNetworkProfile{
NetworkInterfaceConfigurations: []*armcompute.VirtualMachineScaleSetNetworkConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetNetworkConfigurationProperties{
EnableIPForwarding: to.Ptr(true ),
IPConfigurations: []*armcompute.VirtualMachineScaleSetIPConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetIPConfigurationProperties{
Subnet: &armcompute.APIEntityReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
},
},
}},
Primary: to.Ptr(true ),
},
},
{
Name: to.Ptr("{fpgaNic-Name}" ),
Properties: &armcompute.VirtualMachineScaleSetNetworkConfigurationProperties{
EnableAcceleratedNetworking: to.Ptr(false ),
EnableFpga: to.Ptr(true ),
EnableIPForwarding: to.Ptr(false ),
IPConfigurations: []*armcompute.VirtualMachineScaleSetIPConfiguration{
{
Name: to.Ptr("{fpgaNic-Name}" ),
Properties: &armcompute.VirtualMachineScaleSetIPConfigurationProperties{
Primary: to.Ptr(true ),
PrivateIPAddressVersion: to.Ptr(armcompute.IPVersionIPv4),
Subnet: &armcompute.APIEntityReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-fpga-subnet-name}" ),
},
},
}},
Primary: to.Ptr(false ),
},
}},
},
OSProfile: &armcompute.VirtualMachineScaleSetOSProfile{
AdminPassword: to.Ptr("{your-password}" ),
AdminUsername: to.Ptr("{your-username}" ),
ComputerNamePrefix: to.Ptr("{vmss-name}" ),
},
StorageProfile: &armcompute.VirtualMachineScaleSetStorageProfile{
ImageReference: &armcompute.ImageReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/{existing-custom-image-name}" ),
},
OSDisk: &armcompute.VirtualMachineScaleSetOSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.VirtualMachineScaleSetManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
},
},
SKU: &armcompute.SKU{
Name: to.Ptr("Standard_D1_v2" ),
Capacity: to.Ptr[int64 ](3 ),
Tier: to.Ptr("Standard" ),
},
}, nil )
if err != nil {
log.Fatalf("failed to finish the request: %v" , err)
}
res, err := poller.PollUntilDone(ctx, nil )
if err != nil {
log.Fatalf("failed to pull the result: %v" , err)
}
_ = res
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require ("@azure/arm-compute" );
const { DefaultAzureCredential } = require ("@azure/identity" );
async function createAScaleSetWithFpgaNetworkInterfaces ( ) {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID" ] || "{subscription-id}" ;
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP" ] || "myResourceGroup" ;
const vmScaleSetName = "{vmss-name}" ;
const parameters = {
location : "westus" ,
overprovision : true ,
sku : { name : "Standard_D1_v2" , capacity : 3 , tier : "Standard" },
upgradePolicy : { mode : "Manual" },
virtualMachineProfile : {
networkProfile : {
networkInterfaceConfigurations : [
{
name : "{vmss-name}" ,
enableIPForwarding : true ,
ipConfigurations : [
{
name : "{vmss-name}" ,
subnet : {
id : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ,
},
},
],
primary : true ,
},
{
name : "{fpgaNic-Name}" ,
enableAcceleratedNetworking : false ,
enableFpga : true ,
enableIPForwarding : false ,
ipConfigurations : [
{
name : "{fpgaNic-Name}" ,
primary : true ,
privateIPAddressVersion : "IPv4" ,
subnet : {
id : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-fpga-subnet-name}" ,
},
},
],
primary : false ,
},
],
},
osProfile : {
adminPassword : "{your-password}" ,
adminUsername : "{your-username}" ,
computerNamePrefix : "{vmss-name}" ,
},
storageProfile : {
imageReference : {
id : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/{existing-custom-image-name}" ,
},
osDisk : {
caching : "ReadWrite" ,
createOption : "FromImage" ,
managedDisk : { storageAccountType : "Standard_LRS" },
},
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachineScaleSets.beginCreateOrUpdateAndWait(
resourceGroupName,
vmScaleSetName,
parameters
);
console .log(result);
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Compute;
using Azure.ResourceManager.Compute.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Resources.Models;
TokenCredential cred = new DefaultAzureCredential();
ArmClient client = new ArmClient(cred);
string subscriptionId = "{subscription-id}" ;
string resourceGroupName = "myResourceGroup" ;
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
VirtualMachineScaleSetCollection collection = resourceGroupResource.GetVirtualMachineScaleSets();
string virtualMachineScaleSetName = "{vmss-name}" ;
VirtualMachineScaleSetData data = new VirtualMachineScaleSetData(new AzureLocation("westus" ))
{
Sku = new ComputeSku()
{
Name = "Standard_D1_v2" ,
Tier = "Standard" ,
Capacity = 3 ,
},
UpgradePolicy = new VirtualMachineScaleSetUpgradePolicy()
{
Mode = VirtualMachineScaleSetUpgradeMode.Manual,
},
VirtualMachineProfile = new VirtualMachineScaleSetVmProfile()
{
OSProfile = new VirtualMachineScaleSetOSProfile()
{
ComputerNamePrefix = "{vmss-name}" ,
AdminUsername = "{your-username}" ,
AdminPassword = "{your-password}" ,
},
StorageProfile = new VirtualMachineScaleSetStorageProfile()
{
ImageReference = new ImageReference()
{
Id = new ResourceIdentifier("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/{existing-custom-image-name}" ),
},
OSDisk = new VirtualMachineScaleSetOSDisk(DiskCreateOptionType.FromImage)
{
Caching = CachingType.ReadWrite,
ManagedDisk = new VirtualMachineScaleSetManagedDisk()
{
StorageAccountType = StorageAccountType.StandardLrs,
},
},
},
NetworkProfile = new VirtualMachineScaleSetNetworkProfile()
{
NetworkInterfaceConfigurations =
{
new VirtualMachineScaleSetNetworkConfiguration("{vmss-name}" )
{
Primary = true ,
IPConfigurations =
{
new VirtualMachineScaleSetIPConfiguration("{vmss-name}" )
{
SubnetId = new ResourceIdentifier("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
}
},
EnableIPForwarding = true ,
},new VirtualMachineScaleSetNetworkConfiguration("{fpgaNic-Name}" )
{
Primary = false ,
EnableAcceleratedNetworking = false ,
EnableFpga = true ,
IPConfigurations =
{
new VirtualMachineScaleSetIPConfiguration("{fpgaNic-Name}" )
{
SubnetId = new ResourceIdentifier("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-fpga-subnet-name}" ),
Primary = true ,
PrivateIPAddressVersion = IPVersion.IPv4,
}
},
EnableIPForwarding = false ,
}
},
},
},
Overprovision = true ,
};
ArmOperation<VirtualMachineScaleSetResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, virtualMachineScaleSetName, data);
VirtualMachineScaleSetResource result = lro.Value;
VirtualMachineScaleSetData resourceData = result.Data;
Console.WriteLine($"Succeeded on id: {resourceData.Id} " );
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
範例回覆
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_D1_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "afa2afa8-9e49-48fb-9d18-c86323b5d064" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/nsgcustom"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"linuxConfiguration" : {
"disablePasswordAuthentication" : false
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
},
{
"name" : "{fpgaNic-Name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : false ,
"enableFpga" : true ,
"ipConfigurations" : [
{
"name" : "{fpgaNic-Name}" ,
"properties" : {
"primary" : true ,
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-fpga-subnet-name}"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_D1_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "afa2afa8-9e49-48fb-9d18-c86323b5d064" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/nsgcustom"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"linuxConfiguration" : {
"disablePasswordAuthentication" : false
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
},
{
"name" : "{fpgaNic-Name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : false ,
"enableFpga" : true ,
"ipConfigurations" : [
{
"name" : "{fpgaNic-Name}" ,
"properties" : {
"primary" : true ,
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-fpga-subnet-name}"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
Create a scale set with Host Encryption using encryptionAtHost property.
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}?api-version=2022-11-01
{
"sku" : {
"tier" : "Standard",
"capacity" : 3,
"name" : "Standard_DS1_v2"
},
"properties" : {
"overprovision" : true,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "windows2016",
"publisher" : "microsoft-ads",
"version" : "latest",
"offer" : "windows-data-science-vm"
},
"osDisk" : {
"caching" : "ReadOnly",
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"securityProfile" : {
"encryptionAtHost" : true
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}",
"adminUsername" : "{your-username}",
"adminPassword" : "{your-password}"
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"primary" : true,
"enableIPForwarding" : true,
"ipConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
}
}
]
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
}
},
"plan" : {
"publisher" : "microsoft-ads",
"product" : "windows-data-science-vm",
"name" : "windows2016"
},
"location" : "westus"
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineScaleSetInner;
import com.azure.resourcemanager.compute.models.ApiEntityReference;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.Plan;
import com.azure.resourcemanager.compute.models.SecurityProfile;
import com.azure.resourcemanager.compute.models.Sku;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.UpgradeMode;
import com.azure.resourcemanager.compute.models.UpgradePolicy;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetIpConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetManagedDiskParameters;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSDisk;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetStorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetVMProfile;
import java.util.Arrays;
public final class Main {
public static void createAScaleSetWithHostEncryptionUsingEncryptionAtHostProperty (
com.azure.resourcemanager.AzureResourceManager azure) {
azure
.virtualMachines()
.manager()
.serviceClient()
.getVirtualMachineScaleSets()
.createOrUpdate(
"myResourceGroup" ,
"{vmss-name}" ,
new VirtualMachineScaleSetInner()
.withLocation("westus" )
.withSku(new Sku().withName("Standard_DS1_v2" ).withTier("Standard" ).withCapacity(3L ))
.withPlan(
new Plan()
.withName("windows2016" )
.withPublisher("microsoft-ads" )
.withProduct("windows-data-science-vm" ))
.withUpgradePolicy(new UpgradePolicy().withMode(UpgradeMode.MANUAL))
.withVirtualMachineProfile(
new VirtualMachineScaleSetVMProfile()
.withOsProfile(
new VirtualMachineScaleSetOSProfile()
.withComputerNamePrefix("{vmss-name}" )
.withAdminUsername("{your-username}" )
.withAdminPassword("fakeTokenPlaceholder" ))
.withStorageProfile(
new VirtualMachineScaleSetStorageProfile()
.withImageReference(
new ImageReference()
.withPublisher("microsoft-ads" )
.withOffer("windows-data-science-vm" )
.withSku("windows2016" )
.withVersion("latest" ))
.withOsDisk(
new VirtualMachineScaleSetOSDisk()
.withCaching(CachingTypes.READ_ONLY)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)
.withManagedDisk(
new VirtualMachineScaleSetManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withNetworkProfile(
new VirtualMachineScaleSetNetworkProfile()
.withNetworkInterfaceConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetNetworkConfiguration()
.withName("{vmss-name}" )
.withPrimary(true )
.withIpConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetIpConfiguration()
.withName("{vmss-name}" )
.withSubnet(
new ApiEntityReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ))))
.withEnableIpForwarding(true ))))
.withSecurityProfile(new SecurityProfile().withEncryptionAtHost(true )))
.withOverprovision(true ),
com.azure.core.util.Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_scale_set_create_with_encryption_at_host.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main () :
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="{subscription-id}" ,
)
response = client.virtual_machine_scale_sets.begin_create_or_update(
resource_group_name="myResourceGroup" ,
vm_scale_set_name="{vmss-name}" ,
parameters={
"location" : "westus" ,
"plan" : {"name" : "windows2016" , "product" : "windows-data-science-vm" , "publisher" : "microsoft-ads" },
"properties" : {
"overprovision" : True ,
"upgradePolicy" : {"mode" : "Manual" },
"virtualMachineProfile" : {
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"enableIPForwarding" : True ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
},
}
],
"primary" : True ,
},
}
]
},
"osProfile" : {
"adminPassword" : "{your-password}" ,
"adminUsername" : "{your-username}" ,
"computerNamePrefix" : "{vmss-name}" ,
},
"securityProfile" : {"encryptionAtHost" : True },
"storageProfile" : {
"imageReference" : {
"offer" : "windows-data-science-vm" ,
"publisher" : "microsoft-ads" ,
"sku" : "windows2016" ,
"version" : "latest" ,
},
"osDisk" : {
"caching" : "ReadOnly" ,
"createOption" : "FromImage" ,
"managedDisk" : {"storageAccountType" : "Standard_LRS" },
},
},
},
},
"sku" : {"capacity" : 3 , "name" : "Standard_DS1_v2" , "tier" : "Standard" },
},
).result()
print(response)
if __name__ == "__main__" :
main()
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4"
)
func ExampleVirtualMachineScaleSetsClient_BeginCreateOrUpdate_createAScaleSetWithHostEncryptionUsingEncryptionAtHostProperty () {
cred, err := azidentity.NewDefaultAzureCredential(nil )
if err != nil {
log.Fatalf("failed to obtain a credential: %v" , err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("<subscription-id>" , cred, nil )
if err != nil {
log.Fatalf("failed to create client: %v" , err)
}
poller, err := clientFactory.NewVirtualMachineScaleSetsClient().BeginCreateOrUpdate(ctx, "myResourceGroup" , "{vmss-name}" , armcompute.VirtualMachineScaleSet{
Location: to.Ptr("westus" ),
Plan: &armcompute.Plan{
Name: to.Ptr("windows2016" ),
Product: to.Ptr("windows-data-science-vm" ),
Publisher: to.Ptr("microsoft-ads" ),
},
Properties: &armcompute.VirtualMachineScaleSetProperties{
Overprovision: to.Ptr(true ),
UpgradePolicy: &armcompute.UpgradePolicy{
Mode: to.Ptr(armcompute.UpgradeModeManual),
},
VirtualMachineProfile: &armcompute.VirtualMachineScaleSetVMProfile{
NetworkProfile: &armcompute.VirtualMachineScaleSetNetworkProfile{
NetworkInterfaceConfigurations: []*armcompute.VirtualMachineScaleSetNetworkConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetNetworkConfigurationProperties{
EnableIPForwarding: to.Ptr(true ),
IPConfigurations: []*armcompute.VirtualMachineScaleSetIPConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetIPConfigurationProperties{
Subnet: &armcompute.APIEntityReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
},
},
}},
Primary: to.Ptr(true ),
},
}},
},
OSProfile: &armcompute.VirtualMachineScaleSetOSProfile{
AdminPassword: to.Ptr("{your-password}" ),
AdminUsername: to.Ptr("{your-username}" ),
ComputerNamePrefix: to.Ptr("{vmss-name}" ),
},
SecurityProfile: &armcompute.SecurityProfile{
EncryptionAtHost: to.Ptr(true ),
},
StorageProfile: &armcompute.VirtualMachineScaleSetStorageProfile{
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("windows-data-science-vm" ),
Publisher: to.Ptr("microsoft-ads" ),
SKU: to.Ptr("windows2016" ),
Version: to.Ptr("latest" ),
},
OSDisk: &armcompute.VirtualMachineScaleSetOSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadOnly),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.VirtualMachineScaleSetManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
},
},
SKU: &armcompute.SKU{
Name: to.Ptr("Standard_DS1_v2" ),
Capacity: to.Ptr[int64 ](3 ),
Tier: to.Ptr("Standard" ),
},
}, nil )
if err != nil {
log.Fatalf("failed to finish the request: %v" , err)
}
res, err := poller.PollUntilDone(ctx, nil )
if err != nil {
log.Fatalf("failed to pull the result: %v" , err)
}
_ = res
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require ("@azure/arm-compute" );
const { DefaultAzureCredential } = require ("@azure/identity" );
async function createAScaleSetWithHostEncryptionUsingEncryptionAtHostProperty ( ) {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID" ] || "{subscription-id}" ;
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP" ] || "myResourceGroup" ;
const vmScaleSetName = "{vmss-name}" ;
const parameters = {
location : "westus" ,
overprovision : true ,
plan : {
name : "windows2016" ,
product : "windows-data-science-vm" ,
publisher : "microsoft-ads" ,
},
sku : { name : "Standard_DS1_v2" , capacity : 3 , tier : "Standard" },
upgradePolicy : { mode : "Manual" },
virtualMachineProfile : {
networkProfile : {
networkInterfaceConfigurations : [
{
name : "{vmss-name}" ,
enableIPForwarding : true ,
ipConfigurations : [
{
name : "{vmss-name}" ,
subnet : {
id : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ,
},
},
],
primary : true ,
},
],
},
osProfile : {
adminPassword : "{your-password}" ,
adminUsername : "{your-username}" ,
computerNamePrefix : "{vmss-name}" ,
},
securityProfile : { encryptionAtHost : true },
storageProfile : {
imageReference : {
offer : "windows-data-science-vm" ,
publisher : "microsoft-ads" ,
sku : "windows2016" ,
version : "latest" ,
},
osDisk : {
caching : "ReadOnly" ,
createOption : "FromImage" ,
managedDisk : { storageAccountType : "Standard_LRS" },
},
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachineScaleSets.beginCreateOrUpdateAndWait(
resourceGroupName,
vmScaleSetName,
parameters
);
console .log(result);
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Compute;
using Azure.ResourceManager.Compute.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Resources.Models;
TokenCredential cred = new DefaultAzureCredential();
ArmClient client = new ArmClient(cred);
string subscriptionId = "{subscription-id}" ;
string resourceGroupName = "myResourceGroup" ;
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
VirtualMachineScaleSetCollection collection = resourceGroupResource.GetVirtualMachineScaleSets();
string virtualMachineScaleSetName = "{vmss-name}" ;
VirtualMachineScaleSetData data = new VirtualMachineScaleSetData(new AzureLocation("westus" ))
{
Sku = new ComputeSku()
{
Name = "Standard_DS1_v2" ,
Tier = "Standard" ,
Capacity = 3 ,
},
Plan = new ComputePlan()
{
Name = "windows2016" ,
Publisher = "microsoft-ads" ,
Product = "windows-data-science-vm" ,
},
UpgradePolicy = new VirtualMachineScaleSetUpgradePolicy()
{
Mode = VirtualMachineScaleSetUpgradeMode.Manual,
},
VirtualMachineProfile = new VirtualMachineScaleSetVmProfile()
{
OSProfile = new VirtualMachineScaleSetOSProfile()
{
ComputerNamePrefix = "{vmss-name}" ,
AdminUsername = "{your-username}" ,
AdminPassword = "{your-password}" ,
},
StorageProfile = new VirtualMachineScaleSetStorageProfile()
{
ImageReference = new ImageReference()
{
Publisher = "microsoft-ads" ,
Offer = "windows-data-science-vm" ,
Sku = "windows2016" ,
Version = "latest" ,
},
OSDisk = new VirtualMachineScaleSetOSDisk(DiskCreateOptionType.FromImage)
{
Caching = CachingType.ReadOnly,
ManagedDisk = new VirtualMachineScaleSetManagedDisk()
{
StorageAccountType = StorageAccountType.StandardLrs,
},
},
},
NetworkProfile = new VirtualMachineScaleSetNetworkProfile()
{
NetworkInterfaceConfigurations =
{
new VirtualMachineScaleSetNetworkConfiguration("{vmss-name}" )
{
Primary = true ,
IPConfigurations =
{
new VirtualMachineScaleSetIPConfiguration("{vmss-name}" )
{
SubnetId = new ResourceIdentifier("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
}
},
EnableIPForwarding = true ,
}
},
},
SecurityProfile = new SecurityProfile()
{
EncryptionAtHost = true ,
},
},
Overprovision = true ,
};
ArmOperation<VirtualMachineScaleSetResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, virtualMachineScaleSetName, data);
VirtualMachineScaleSetResource result = lro.Value;
VirtualMachineScaleSetData resourceData = result.Data;
Console.WriteLine($"Succeeded on id: {resourceData.Id} " );
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
範例回覆
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_DS1_v2"
},
"name" : "{vmss-name}" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}" ,
"plan" : {
"publisher" : "microsoft-ads" ,
"product" : "standard-data-science-vm" ,
"name" : "standard-data-science-vm"
},
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "b9e23088-6ffc-46e0-9e02-b0a6eeef47db" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "standard-data-science-vm" ,
"publisher" : "microsoft-ads" ,
"version" : "latest" ,
"offer" : "standard-data-science-vm"
},
"osDisk" : {
"caching" : "ReadOnly" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"securityProfile" : {
"encryptionAtHost" : true
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus"
}
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_DS1_v2"
},
"name" : "{vmss-name}" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}" ,
"plan" : {
"publisher" : "microsoft-ads" ,
"product" : "standard-data-science-vm" ,
"name" : "standard-data-science-vm"
},
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "b9e23088-6ffc-46e0-9e02-b0a6eeef47db" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "standard-data-science-vm" ,
"publisher" : "microsoft-ads" ,
"version" : "latest" ,
"offer" : "standard-data-science-vm"
},
"osDisk" : {
"caching" : "ReadOnly" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"securityProfile" : {
"encryptionAtHost" : true
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus"
}
Create a scale set with managed boot diagnostics.
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}?api-version=2022-11-01
{
"sku" : {
"tier" : "Standard",
"capacity" : 3,
"name" : "Standard_D1_v2"
},
"location" : "westus",
"properties" : {
"overprovision" : true,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter",
"publisher" : "MicrosoftWindowsServer",
"version" : "latest",
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite",
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"diagnosticsProfile" : {
"bootDiagnostics" : {
"enabled" : true
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}",
"adminUsername" : "{your-username}",
"adminPassword" : "{your-password}"
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"primary" : true,
"enableIPForwarding" : true,
"ipConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
}
}
]
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineScaleSetInner;
import com.azure.resourcemanager.compute.models.ApiEntityReference;
import com.azure.resourcemanager.compute.models.BootDiagnostics;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiagnosticsProfile;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.Sku;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.UpgradeMode;
import com.azure.resourcemanager.compute.models.UpgradePolicy;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetIpConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetManagedDiskParameters;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSDisk;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetStorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetVMProfile;
import java.util.Arrays;
public final class Main {
public static void createAScaleSetWithManagedBootDiagnostics (com.azure.resourcemanager.AzureResourceManager azure) {
azure
.virtualMachines()
.manager()
.serviceClient()
.getVirtualMachineScaleSets()
.createOrUpdate(
"myResourceGroup" ,
"{vmss-name}" ,
new VirtualMachineScaleSetInner()
.withLocation("westus" )
.withSku(new Sku().withName("Standard_D1_v2" ).withTier("Standard" ).withCapacity(3L ))
.withUpgradePolicy(new UpgradePolicy().withMode(UpgradeMode.MANUAL))
.withVirtualMachineProfile(
new VirtualMachineScaleSetVMProfile()
.withOsProfile(
new VirtualMachineScaleSetOSProfile()
.withComputerNamePrefix("{vmss-name}" )
.withAdminUsername("{your-username}" )
.withAdminPassword("fakeTokenPlaceholder" ))
.withStorageProfile(
new VirtualMachineScaleSetStorageProfile()
.withImageReference(
new ImageReference()
.withPublisher("MicrosoftWindowsServer" )
.withOffer("WindowsServer" )
.withSku("2016-Datacenter" )
.withVersion("latest" ))
.withOsDisk(
new VirtualMachineScaleSetOSDisk()
.withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)
.withManagedDisk(
new VirtualMachineScaleSetManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withNetworkProfile(
new VirtualMachineScaleSetNetworkProfile()
.withNetworkInterfaceConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetNetworkConfiguration()
.withName("{vmss-name}" )
.withPrimary(true )
.withIpConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetIpConfiguration()
.withName("{vmss-name}" )
.withSubnet(
new ApiEntityReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ))))
.withEnableIpForwarding(true ))))
.withDiagnosticsProfile(
new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics().withEnabled(true ))))
.withOverprovision(true ),
com.azure.core.util.Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_scale_set_create_with_managed_boot_diagnostics.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main () :
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="{subscription-id}" ,
)
response = client.virtual_machine_scale_sets.begin_create_or_update(
resource_group_name="myResourceGroup" ,
vm_scale_set_name="{vmss-name}" ,
parameters={
"location" : "westus" ,
"properties" : {
"overprovision" : True ,
"upgradePolicy" : {"mode" : "Manual" },
"virtualMachineProfile" : {
"diagnosticsProfile" : {"bootDiagnostics" : {"enabled" : True }},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"enableIPForwarding" : True ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
},
}
],
"primary" : True ,
},
}
]
},
"osProfile" : {
"adminPassword" : "{your-password}" ,
"adminUsername" : "{your-username}" ,
"computerNamePrefix" : "{vmss-name}" ,
},
"storageProfile" : {
"imageReference" : {
"offer" : "WindowsServer" ,
"publisher" : "MicrosoftWindowsServer" ,
"sku" : "2016-Datacenter" ,
"version" : "latest" ,
},
"osDisk" : {
"caching" : "ReadWrite" ,
"createOption" : "FromImage" ,
"managedDisk" : {"storageAccountType" : "Standard_LRS" },
},
},
},
},
"sku" : {"capacity" : 3 , "name" : "Standard_D1_v2" , "tier" : "Standard" },
},
).result()
print(response)
if __name__ == "__main__" :
main()
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4"
)
func ExampleVirtualMachineScaleSetsClient_BeginCreateOrUpdate_createAScaleSetWithManagedBootDiagnostics () {
cred, err := azidentity.NewDefaultAzureCredential(nil )
if err != nil {
log.Fatalf("failed to obtain a credential: %v" , err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("<subscription-id>" , cred, nil )
if err != nil {
log.Fatalf("failed to create client: %v" , err)
}
poller, err := clientFactory.NewVirtualMachineScaleSetsClient().BeginCreateOrUpdate(ctx, "myResourceGroup" , "{vmss-name}" , armcompute.VirtualMachineScaleSet{
Location: to.Ptr("westus" ),
Properties: &armcompute.VirtualMachineScaleSetProperties{
Overprovision: to.Ptr(true ),
UpgradePolicy: &armcompute.UpgradePolicy{
Mode: to.Ptr(armcompute.UpgradeModeManual),
},
VirtualMachineProfile: &armcompute.VirtualMachineScaleSetVMProfile{
DiagnosticsProfile: &armcompute.DiagnosticsProfile{
BootDiagnostics: &armcompute.BootDiagnostics{
Enabled: to.Ptr(true ),
},
},
NetworkProfile: &armcompute.VirtualMachineScaleSetNetworkProfile{
NetworkInterfaceConfigurations: []*armcompute.VirtualMachineScaleSetNetworkConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetNetworkConfigurationProperties{
EnableIPForwarding: to.Ptr(true ),
IPConfigurations: []*armcompute.VirtualMachineScaleSetIPConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetIPConfigurationProperties{
Subnet: &armcompute.APIEntityReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
},
},
}},
Primary: to.Ptr(true ),
},
}},
},
OSProfile: &armcompute.VirtualMachineScaleSetOSProfile{
AdminPassword: to.Ptr("{your-password}" ),
AdminUsername: to.Ptr("{your-username}" ),
ComputerNamePrefix: to.Ptr("{vmss-name}" ),
},
StorageProfile: &armcompute.VirtualMachineScaleSetStorageProfile{
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("WindowsServer" ),
Publisher: to.Ptr("MicrosoftWindowsServer" ),
SKU: to.Ptr("2016-Datacenter" ),
Version: to.Ptr("latest" ),
},
OSDisk: &armcompute.VirtualMachineScaleSetOSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.VirtualMachineScaleSetManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
},
},
SKU: &armcompute.SKU{
Name: to.Ptr("Standard_D1_v2" ),
Capacity: to.Ptr[int64 ](3 ),
Tier: to.Ptr("Standard" ),
},
}, nil )
if err != nil {
log.Fatalf("failed to finish the request: %v" , err)
}
res, err := poller.PollUntilDone(ctx, nil )
if err != nil {
log.Fatalf("failed to pull the result: %v" , err)
}
_ = res
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require ("@azure/arm-compute" );
const { DefaultAzureCredential } = require ("@azure/identity" );
async function createAScaleSetWithManagedBootDiagnostics ( ) {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID" ] || "{subscription-id}" ;
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP" ] || "myResourceGroup" ;
const vmScaleSetName = "{vmss-name}" ;
const parameters = {
location : "westus" ,
overprovision : true ,
sku : { name : "Standard_D1_v2" , capacity : 3 , tier : "Standard" },
upgradePolicy : { mode : "Manual" },
virtualMachineProfile : {
diagnosticsProfile : { bootDiagnostics : { enabled : true } },
networkProfile : {
networkInterfaceConfigurations : [
{
name : "{vmss-name}" ,
enableIPForwarding : true ,
ipConfigurations : [
{
name : "{vmss-name}" ,
subnet : {
id : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ,
},
},
],
primary : true ,
},
],
},
osProfile : {
adminPassword : "{your-password}" ,
adminUsername : "{your-username}" ,
computerNamePrefix : "{vmss-name}" ,
},
storageProfile : {
imageReference : {
offer : "WindowsServer" ,
publisher : "MicrosoftWindowsServer" ,
sku : "2016-Datacenter" ,
version : "latest" ,
},
osDisk : {
caching : "ReadWrite" ,
createOption : "FromImage" ,
managedDisk : { storageAccountType : "Standard_LRS" },
},
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachineScaleSets.beginCreateOrUpdateAndWait(
resourceGroupName,
vmScaleSetName,
parameters
);
console .log(result);
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Compute;
using Azure.ResourceManager.Compute.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Resources.Models;
TokenCredential cred = new DefaultAzureCredential();
ArmClient client = new ArmClient(cred);
string subscriptionId = "{subscription-id}" ;
string resourceGroupName = "myResourceGroup" ;
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
VirtualMachineScaleSetCollection collection = resourceGroupResource.GetVirtualMachineScaleSets();
string virtualMachineScaleSetName = "{vmss-name}" ;
VirtualMachineScaleSetData data = new VirtualMachineScaleSetData(new AzureLocation("westus" ))
{
Sku = new ComputeSku()
{
Name = "Standard_D1_v2" ,
Tier = "Standard" ,
Capacity = 3 ,
},
UpgradePolicy = new VirtualMachineScaleSetUpgradePolicy()
{
Mode = VirtualMachineScaleSetUpgradeMode.Manual,
},
VirtualMachineProfile = new VirtualMachineScaleSetVmProfile()
{
OSProfile = new VirtualMachineScaleSetOSProfile()
{
ComputerNamePrefix = "{vmss-name}" ,
AdminUsername = "{your-username}" ,
AdminPassword = "{your-password}" ,
},
StorageProfile = new VirtualMachineScaleSetStorageProfile()
{
ImageReference = new ImageReference()
{
Publisher = "MicrosoftWindowsServer" ,
Offer = "WindowsServer" ,
Sku = "2016-Datacenter" ,
Version = "latest" ,
},
OSDisk = new VirtualMachineScaleSetOSDisk(DiskCreateOptionType.FromImage)
{
Caching = CachingType.ReadWrite,
ManagedDisk = new VirtualMachineScaleSetManagedDisk()
{
StorageAccountType = StorageAccountType.StandardLrs,
},
},
},
NetworkProfile = new VirtualMachineScaleSetNetworkProfile()
{
NetworkInterfaceConfigurations =
{
new VirtualMachineScaleSetNetworkConfiguration("{vmss-name}" )
{
Primary = true ,
IPConfigurations =
{
new VirtualMachineScaleSetIPConfiguration("{vmss-name}" )
{
SubnetId = new ResourceIdentifier("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
}
},
EnableIPForwarding = true ,
}
},
},
BootDiagnostics = new BootDiagnostics()
{
Enabled = true ,
},
},
Overprovision = true ,
};
ArmOperation<VirtualMachineScaleSetResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, virtualMachineScaleSetName, data);
VirtualMachineScaleSetResource result = lro.Value;
VirtualMachineScaleSetData resourceData = result.Data;
Console.WriteLine($"Succeeded on id: {resourceData.Id} " );
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
範例回覆
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_D1_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "d053ec5a-8da6-495f-ab13-38216503c6d7" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter" ,
"publisher" : "MicrosoftWindowsServer" ,
"version" : "latest" ,
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"diagnosticsProfile" : {
"bootDiagnostics" : {
"enabled" : true
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_D1_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "d053ec5a-8da6-495f-ab13-38216503c6d7" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter" ,
"publisher" : "MicrosoftWindowsServer" ,
"version" : "latest" ,
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"diagnosticsProfile" : {
"bootDiagnostics" : {
"enabled" : true
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
Create a scale set with OS image scheduled events enabled.
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}?api-version=2022-11-01
{
"sku" : {
"tier" : "Standard",
"capacity" : 3,
"name" : "Standard_D1_v2"
},
"location" : "westus",
"properties" : {
"overprovision" : true,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter",
"publisher" : "MicrosoftWindowsServer",
"version" : "latest",
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite",
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}",
"adminUsername" : "{your-username}",
"adminPassword" : "{your-password}"
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"primary" : true,
"enableIPForwarding" : true,
"ipConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
}
}
]
}
}
]
},
"scheduledEventsProfile" : {
"osImageNotificationProfile" : {
"enable" : true,
"notBeforeTimeout" : "PT15M"
}
}
},
"upgradePolicy" : {
"mode" : "Manual"
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineScaleSetInner;
import com.azure.resourcemanager.compute.models.ApiEntityReference;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.OSImageNotificationProfile;
import com.azure.resourcemanager.compute.models.ScheduledEventsProfile;
import com.azure.resourcemanager.compute.models.Sku;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.UpgradeMode;
import com.azure.resourcemanager.compute.models.UpgradePolicy;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetIpConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetManagedDiskParameters;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSDisk;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetStorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetVMProfile;
import java.util.Arrays;
public final class Main {
public static void createAScaleSetWithOSImageScheduledEventsEnabled (
com.azure.resourcemanager.AzureResourceManager azure) {
azure
.virtualMachines()
.manager()
.serviceClient()
.getVirtualMachineScaleSets()
.createOrUpdate(
"myResourceGroup" ,
"{vmss-name}" ,
new VirtualMachineScaleSetInner()
.withLocation("westus" )
.withSku(new Sku().withName("Standard_D1_v2" ).withTier("Standard" ).withCapacity(3L ))
.withUpgradePolicy(new UpgradePolicy().withMode(UpgradeMode.MANUAL))
.withVirtualMachineProfile(
new VirtualMachineScaleSetVMProfile()
.withOsProfile(
new VirtualMachineScaleSetOSProfile()
.withComputerNamePrefix("{vmss-name}" )
.withAdminUsername("{your-username}" )
.withAdminPassword("fakeTokenPlaceholder" ))
.withStorageProfile(
new VirtualMachineScaleSetStorageProfile()
.withImageReference(
new ImageReference()
.withPublisher("MicrosoftWindowsServer" )
.withOffer("WindowsServer" )
.withSku("2016-Datacenter" )
.withVersion("latest" ))
.withOsDisk(
new VirtualMachineScaleSetOSDisk()
.withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)
.withManagedDisk(
new VirtualMachineScaleSetManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withNetworkProfile(
new VirtualMachineScaleSetNetworkProfile()
.withNetworkInterfaceConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetNetworkConfiguration()
.withName("{vmss-name}" )
.withPrimary(true )
.withIpConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetIpConfiguration()
.withName("{vmss-name}" )
.withSubnet(
new ApiEntityReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ))))
.withEnableIpForwarding(true ))))
.withScheduledEventsProfile(
new ScheduledEventsProfile()
.withOsImageNotificationProfile(
new OSImageNotificationProfile()
.withNotBeforeTimeout("PT15M" )
.withEnable(true ))))
.withOverprovision(true ),
com.azure.core.util.Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_scale_set_create_with_os_image_scheduled_event_enabled.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main () :
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="{subscription-id}" ,
)
response = client.virtual_machine_scale_sets.begin_create_or_update(
resource_group_name="myResourceGroup" ,
vm_scale_set_name="{vmss-name}" ,
parameters={
"location" : "westus" ,
"properties" : {
"overprovision" : True ,
"upgradePolicy" : {"mode" : "Manual" },
"virtualMachineProfile" : {
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"enableIPForwarding" : True ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
},
}
],
"primary" : True ,
},
}
]
},
"osProfile" : {
"adminPassword" : "{your-password}" ,
"adminUsername" : "{your-username}" ,
"computerNamePrefix" : "{vmss-name}" ,
},
"scheduledEventsProfile" : {
"osImageNotificationProfile" : {"enable" : True , "notBeforeTimeout" : "PT15M" }
},
"storageProfile" : {
"imageReference" : {
"offer" : "WindowsServer" ,
"publisher" : "MicrosoftWindowsServer" ,
"sku" : "2016-Datacenter" ,
"version" : "latest" ,
},
"osDisk" : {
"caching" : "ReadWrite" ,
"createOption" : "FromImage" ,
"managedDisk" : {"storageAccountType" : "Standard_LRS" },
},
},
},
},
"sku" : {"capacity" : 3 , "name" : "Standard_D1_v2" , "tier" : "Standard" },
},
).result()
print(response)
if __name__ == "__main__" :
main()
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4"
)
func ExampleVirtualMachineScaleSetsClient_BeginCreateOrUpdate_createAScaleSetWithOsImageScheduledEventsEnabled () {
cred, err := azidentity.NewDefaultAzureCredential(nil )
if err != nil {
log.Fatalf("failed to obtain a credential: %v" , err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("<subscription-id>" , cred, nil )
if err != nil {
log.Fatalf("failed to create client: %v" , err)
}
poller, err := clientFactory.NewVirtualMachineScaleSetsClient().BeginCreateOrUpdate(ctx, "myResourceGroup" , "{vmss-name}" , armcompute.VirtualMachineScaleSet{
Location: to.Ptr("westus" ),
Properties: &armcompute.VirtualMachineScaleSetProperties{
Overprovision: to.Ptr(true ),
UpgradePolicy: &armcompute.UpgradePolicy{
Mode: to.Ptr(armcompute.UpgradeModeManual),
},
VirtualMachineProfile: &armcompute.VirtualMachineScaleSetVMProfile{
NetworkProfile: &armcompute.VirtualMachineScaleSetNetworkProfile{
NetworkInterfaceConfigurations: []*armcompute.VirtualMachineScaleSetNetworkConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetNetworkConfigurationProperties{
EnableIPForwarding: to.Ptr(true ),
IPConfigurations: []*armcompute.VirtualMachineScaleSetIPConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetIPConfigurationProperties{
Subnet: &armcompute.APIEntityReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
},
},
}},
Primary: to.Ptr(true ),
},
}},
},
OSProfile: &armcompute.VirtualMachineScaleSetOSProfile{
AdminPassword: to.Ptr("{your-password}" ),
AdminUsername: to.Ptr("{your-username}" ),
ComputerNamePrefix: to.Ptr("{vmss-name}" ),
},
ScheduledEventsProfile: &armcompute.ScheduledEventsProfile{
OSImageNotificationProfile: &armcompute.OSImageNotificationProfile{
Enable: to.Ptr(true ),
NotBeforeTimeout: to.Ptr("PT15M" ),
},
},
StorageProfile: &armcompute.VirtualMachineScaleSetStorageProfile{
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("WindowsServer" ),
Publisher: to.Ptr("MicrosoftWindowsServer" ),
SKU: to.Ptr("2016-Datacenter" ),
Version: to.Ptr("latest" ),
},
OSDisk: &armcompute.VirtualMachineScaleSetOSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.VirtualMachineScaleSetManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
},
},
SKU: &armcompute.SKU{
Name: to.Ptr("Standard_D1_v2" ),
Capacity: to.Ptr[int64 ](3 ),
Tier: to.Ptr("Standard" ),
},
}, nil )
if err != nil {
log.Fatalf("failed to finish the request: %v" , err)
}
res, err := poller.PollUntilDone(ctx, nil )
if err != nil {
log.Fatalf("failed to pull the result: %v" , err)
}
_ = res
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require ("@azure/arm-compute" );
const { DefaultAzureCredential } = require ("@azure/identity" );
async function createAScaleSetWithOSImageScheduledEventsEnabled ( ) {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID" ] || "{subscription-id}" ;
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP" ] || "myResourceGroup" ;
const vmScaleSetName = "{vmss-name}" ;
const parameters = {
location : "westus" ,
overprovision : true ,
sku : { name : "Standard_D1_v2" , capacity : 3 , tier : "Standard" },
upgradePolicy : { mode : "Manual" },
virtualMachineProfile : {
networkProfile : {
networkInterfaceConfigurations : [
{
name : "{vmss-name}" ,
enableIPForwarding : true ,
ipConfigurations : [
{
name : "{vmss-name}" ,
subnet : {
id : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ,
},
},
],
primary : true ,
},
],
},
osProfile : {
adminPassword : "{your-password}" ,
adminUsername : "{your-username}" ,
computerNamePrefix : "{vmss-name}" ,
},
scheduledEventsProfile : {
osImageNotificationProfile : { enable : true , notBeforeTimeout : "PT15M" },
},
storageProfile : {
imageReference : {
offer : "WindowsServer" ,
publisher : "MicrosoftWindowsServer" ,
sku : "2016-Datacenter" ,
version : "latest" ,
},
osDisk : {
caching : "ReadWrite" ,
createOption : "FromImage" ,
managedDisk : { storageAccountType : "Standard_LRS" },
},
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachineScaleSets.beginCreateOrUpdateAndWait(
resourceGroupName,
vmScaleSetName,
parameters
);
console .log(result);
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Compute;
using Azure.ResourceManager.Compute.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Resources.Models;
TokenCredential cred = new DefaultAzureCredential();
ArmClient client = new ArmClient(cred);
string subscriptionId = "{subscription-id}" ;
string resourceGroupName = "myResourceGroup" ;
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
VirtualMachineScaleSetCollection collection = resourceGroupResource.GetVirtualMachineScaleSets();
string virtualMachineScaleSetName = "{vmss-name}" ;
VirtualMachineScaleSetData data = new VirtualMachineScaleSetData(new AzureLocation("westus" ))
{
Sku = new ComputeSku()
{
Name = "Standard_D1_v2" ,
Tier = "Standard" ,
Capacity = 3 ,
},
UpgradePolicy = new VirtualMachineScaleSetUpgradePolicy()
{
Mode = VirtualMachineScaleSetUpgradeMode.Manual,
},
VirtualMachineProfile = new VirtualMachineScaleSetVmProfile()
{
OSProfile = new VirtualMachineScaleSetOSProfile()
{
ComputerNamePrefix = "{vmss-name}" ,
AdminUsername = "{your-username}" ,
AdminPassword = "{your-password}" ,
},
StorageProfile = new VirtualMachineScaleSetStorageProfile()
{
ImageReference = new ImageReference()
{
Publisher = "MicrosoftWindowsServer" ,
Offer = "WindowsServer" ,
Sku = "2016-Datacenter" ,
Version = "latest" ,
},
OSDisk = new VirtualMachineScaleSetOSDisk(DiskCreateOptionType.FromImage)
{
Caching = CachingType.ReadWrite,
ManagedDisk = new VirtualMachineScaleSetManagedDisk()
{
StorageAccountType = StorageAccountType.StandardLrs,
},
},
},
NetworkProfile = new VirtualMachineScaleSetNetworkProfile()
{
NetworkInterfaceConfigurations =
{
new VirtualMachineScaleSetNetworkConfiguration("{vmss-name}" )
{
Primary = true ,
IPConfigurations =
{
new VirtualMachineScaleSetIPConfiguration("{vmss-name}" )
{
SubnetId = new ResourceIdentifier("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
}
},
EnableIPForwarding = true ,
}
},
},
ScheduledEventsProfile = new ComputeScheduledEventsProfile()
{
OSImageNotificationProfile = new OSImageNotificationProfile()
{
NotBeforeTimeout = "PT15M" ,
Enable = true ,
},
},
},
Overprovision = true ,
};
ArmOperation<VirtualMachineScaleSetResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, virtualMachineScaleSetName, data);
VirtualMachineScaleSetResource result = lro.Value;
VirtualMachineScaleSetData resourceData = result.Data;
Console.WriteLine($"Succeeded on id: {resourceData.Id} " );
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
範例回覆
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_D1_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "d053ec5a-8da6-495f-ab13-38216503c6d7" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter" ,
"publisher" : "MicrosoftWindowsServer" ,
"version" : "latest" ,
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
},
"scheduledEventsProfile" : {
"osImageNotificationProfile" : {
"enable" : true ,
"notBeforeTimeout" : "PT15M"
}
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_D1_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "d053ec5a-8da6-495f-ab13-38216503c6d7" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter" ,
"publisher" : "MicrosoftWindowsServer" ,
"version" : "latest" ,
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
},
"scheduledEventsProfile" : {
"osImageNotificationProfile" : {
"enable" : true ,
"notBeforeTimeout" : "PT15M"
}
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
Create a scale set with password authentication.
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}?api-version=2022-11-01
{
"sku" : {
"tier" : "Standard",
"capacity" : 3,
"name" : "Standard_D1_v2"
},
"location" : "westus",
"properties" : {
"overprovision" : true,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter",
"publisher" : "MicrosoftWindowsServer",
"version" : "latest",
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite",
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}",
"adminUsername" : "{your-username}",
"adminPassword" : "{your-password}"
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"primary" : true,
"enableIPForwarding" : true,
"ipConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
}
}
]
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineScaleSetInner;
import com.azure.resourcemanager.compute.models.ApiEntityReference;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.Sku;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.UpgradeMode;
import com.azure.resourcemanager.compute.models.UpgradePolicy;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetIpConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetManagedDiskParameters;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSDisk;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetStorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetVMProfile;
import java.util.Arrays;
public final class Main {
public static void createAScaleSetWithPasswordAuthentication (com.azure.resourcemanager.AzureResourceManager azure) {
azure
.virtualMachines()
.manager()
.serviceClient()
.getVirtualMachineScaleSets()
.createOrUpdate(
"myResourceGroup" ,
"{vmss-name}" ,
new VirtualMachineScaleSetInner()
.withLocation("westus" )
.withSku(new Sku().withName("Standard_D1_v2" ).withTier("Standard" ).withCapacity(3L ))
.withUpgradePolicy(new UpgradePolicy().withMode(UpgradeMode.MANUAL))
.withVirtualMachineProfile(
new VirtualMachineScaleSetVMProfile()
.withOsProfile(
new VirtualMachineScaleSetOSProfile()
.withComputerNamePrefix("{vmss-name}" )
.withAdminUsername("{your-username}" )
.withAdminPassword("fakeTokenPlaceholder" ))
.withStorageProfile(
new VirtualMachineScaleSetStorageProfile()
.withImageReference(
new ImageReference()
.withPublisher("MicrosoftWindowsServer" )
.withOffer("WindowsServer" )
.withSku("2016-Datacenter" )
.withVersion("latest" ))
.withOsDisk(
new VirtualMachineScaleSetOSDisk()
.withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)
.withManagedDisk(
new VirtualMachineScaleSetManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withNetworkProfile(
new VirtualMachineScaleSetNetworkProfile()
.withNetworkInterfaceConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetNetworkConfiguration()
.withName("{vmss-name}" )
.withPrimary(true )
.withIpConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetIpConfiguration()
.withName("{vmss-name}" )
.withSubnet(
new ApiEntityReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ))))
.withEnableIpForwarding(true )))))
.withOverprovision(true ),
com.azure.core.util.Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_scale_set_create_with_password_authentication.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main () :
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="{subscription-id}" ,
)
response = client.virtual_machine_scale_sets.begin_create_or_update(
resource_group_name="myResourceGroup" ,
vm_scale_set_name="{vmss-name}" ,
parameters={
"location" : "westus" ,
"properties" : {
"overprovision" : True ,
"upgradePolicy" : {"mode" : "Manual" },
"virtualMachineProfile" : {
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"enableIPForwarding" : True ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
},
}
],
"primary" : True ,
},
}
]
},
"osProfile" : {
"adminPassword" : "{your-password}" ,
"adminUsername" : "{your-username}" ,
"computerNamePrefix" : "{vmss-name}" ,
},
"storageProfile" : {
"imageReference" : {
"offer" : "WindowsServer" ,
"publisher" : "MicrosoftWindowsServer" ,
"sku" : "2016-Datacenter" ,
"version" : "latest" ,
},
"osDisk" : {
"caching" : "ReadWrite" ,
"createOption" : "FromImage" ,
"managedDisk" : {"storageAccountType" : "Standard_LRS" },
},
},
},
},
"sku" : {"capacity" : 3 , "name" : "Standard_D1_v2" , "tier" : "Standard" },
},
).result()
print(response)
if __name__ == "__main__" :
main()
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4"
)
func ExampleVirtualMachineScaleSetsClient_BeginCreateOrUpdate_createAScaleSetWithPasswordAuthentication () {
cred, err := azidentity.NewDefaultAzureCredential(nil )
if err != nil {
log.Fatalf("failed to obtain a credential: %v" , err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("<subscription-id>" , cred, nil )
if err != nil {
log.Fatalf("failed to create client: %v" , err)
}
poller, err := clientFactory.NewVirtualMachineScaleSetsClient().BeginCreateOrUpdate(ctx, "myResourceGroup" , "{vmss-name}" , armcompute.VirtualMachineScaleSet{
Location: to.Ptr("westus" ),
Properties: &armcompute.VirtualMachineScaleSetProperties{
Overprovision: to.Ptr(true ),
UpgradePolicy: &armcompute.UpgradePolicy{
Mode: to.Ptr(armcompute.UpgradeModeManual),
},
VirtualMachineProfile: &armcompute.VirtualMachineScaleSetVMProfile{
NetworkProfile: &armcompute.VirtualMachineScaleSetNetworkProfile{
NetworkInterfaceConfigurations: []*armcompute.VirtualMachineScaleSetNetworkConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetNetworkConfigurationProperties{
EnableIPForwarding: to.Ptr(true ),
IPConfigurations: []*armcompute.VirtualMachineScaleSetIPConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetIPConfigurationProperties{
Subnet: &armcompute.APIEntityReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
},
},
}},
Primary: to.Ptr(true ),
},
}},
},
OSProfile: &armcompute.VirtualMachineScaleSetOSProfile{
AdminPassword: to.Ptr("{your-password}" ),
AdminUsername: to.Ptr("{your-username}" ),
ComputerNamePrefix: to.Ptr("{vmss-name}" ),
},
StorageProfile: &armcompute.VirtualMachineScaleSetStorageProfile{
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("WindowsServer" ),
Publisher: to.Ptr("MicrosoftWindowsServer" ),
SKU: to.Ptr("2016-Datacenter" ),
Version: to.Ptr("latest" ),
},
OSDisk: &armcompute.VirtualMachineScaleSetOSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.VirtualMachineScaleSetManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
},
},
SKU: &armcompute.SKU{
Name: to.Ptr("Standard_D1_v2" ),
Capacity: to.Ptr[int64 ](3 ),
Tier: to.Ptr("Standard" ),
},
}, nil )
if err != nil {
log.Fatalf("failed to finish the request: %v" , err)
}
res, err := poller.PollUntilDone(ctx, nil )
if err != nil {
log.Fatalf("failed to pull the result: %v" , err)
}
_ = res
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require ("@azure/arm-compute" );
const { DefaultAzureCredential } = require ("@azure/identity" );
async function createAScaleSetWithPasswordAuthentication ( ) {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID" ] || "{subscription-id}" ;
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP" ] || "myResourceGroup" ;
const vmScaleSetName = "{vmss-name}" ;
const parameters = {
location : "westus" ,
overprovision : true ,
sku : { name : "Standard_D1_v2" , capacity : 3 , tier : "Standard" },
upgradePolicy : { mode : "Manual" },
virtualMachineProfile : {
networkProfile : {
networkInterfaceConfigurations : [
{
name : "{vmss-name}" ,
enableIPForwarding : true ,
ipConfigurations : [
{
name : "{vmss-name}" ,
subnet : {
id : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ,
},
},
],
primary : true ,
},
],
},
osProfile : {
adminPassword : "{your-password}" ,
adminUsername : "{your-username}" ,
computerNamePrefix : "{vmss-name}" ,
},
storageProfile : {
imageReference : {
offer : "WindowsServer" ,
publisher : "MicrosoftWindowsServer" ,
sku : "2016-Datacenter" ,
version : "latest" ,
},
osDisk : {
caching : "ReadWrite" ,
createOption : "FromImage" ,
managedDisk : { storageAccountType : "Standard_LRS" },
},
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachineScaleSets.beginCreateOrUpdateAndWait(
resourceGroupName,
vmScaleSetName,
parameters
);
console .log(result);
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Compute;
using Azure.ResourceManager.Compute.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Resources.Models;
TokenCredential cred = new DefaultAzureCredential();
ArmClient client = new ArmClient(cred);
string subscriptionId = "{subscription-id}" ;
string resourceGroupName = "myResourceGroup" ;
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
VirtualMachineScaleSetCollection collection = resourceGroupResource.GetVirtualMachineScaleSets();
string virtualMachineScaleSetName = "{vmss-name}" ;
VirtualMachineScaleSetData data = new VirtualMachineScaleSetData(new AzureLocation("westus" ))
{
Sku = new ComputeSku()
{
Name = "Standard_D1_v2" ,
Tier = "Standard" ,
Capacity = 3 ,
},
UpgradePolicy = new VirtualMachineScaleSetUpgradePolicy()
{
Mode = VirtualMachineScaleSetUpgradeMode.Manual,
},
VirtualMachineProfile = new VirtualMachineScaleSetVmProfile()
{
OSProfile = new VirtualMachineScaleSetOSProfile()
{
ComputerNamePrefix = "{vmss-name}" ,
AdminUsername = "{your-username}" ,
AdminPassword = "{your-password}" ,
},
StorageProfile = new VirtualMachineScaleSetStorageProfile()
{
ImageReference = new ImageReference()
{
Publisher = "MicrosoftWindowsServer" ,
Offer = "WindowsServer" ,
Sku = "2016-Datacenter" ,
Version = "latest" ,
},
OSDisk = new VirtualMachineScaleSetOSDisk(DiskCreateOptionType.FromImage)
{
Caching = CachingType.ReadWrite,
ManagedDisk = new VirtualMachineScaleSetManagedDisk()
{
StorageAccountType = StorageAccountType.StandardLrs,
},
},
},
NetworkProfile = new VirtualMachineScaleSetNetworkProfile()
{
NetworkInterfaceConfigurations =
{
new VirtualMachineScaleSetNetworkConfiguration("{vmss-name}" )
{
Primary = true ,
IPConfigurations =
{
new VirtualMachineScaleSetIPConfiguration("{vmss-name}" )
{
SubnetId = new ResourceIdentifier("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
}
},
EnableIPForwarding = true ,
}
},
},
},
Overprovision = true ,
};
ArmOperation<VirtualMachineScaleSetResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, virtualMachineScaleSetName, data);
VirtualMachineScaleSetResource result = lro.Value;
VirtualMachineScaleSetData resourceData = result.Data;
Console.WriteLine($"Succeeded on id: {resourceData.Id} " );
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
範例回覆
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_D1_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "ffb27c5c-39a5-4d4e-b307-b32598689813" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter" ,
"publisher" : "MicrosoftWindowsServer" ,
"version" : "latest" ,
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_D1_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "ffb27c5c-39a5-4d4e-b307-b32598689813" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter" ,
"publisher" : "MicrosoftWindowsServer" ,
"version" : "latest" ,
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
Create a scale set with premium storage.
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}?api-version=2022-11-01
{
"sku" : {
"tier" : "Standard",
"capacity" : 3,
"name" : "Standard_D1_v2"
},
"location" : "westus",
"properties" : {
"overprovision" : true,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter",
"publisher" : "MicrosoftWindowsServer",
"version" : "latest",
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite",
"managedDisk" : {
"storageAccountType" : "Premium_LRS"
},
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}",
"adminUsername" : "{your-username}",
"adminPassword" : "{your-password}"
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"primary" : true,
"enableIPForwarding" : true,
"ipConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
}
}
]
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineScaleSetInner;
import com.azure.resourcemanager.compute.models.ApiEntityReference;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.Sku;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.UpgradeMode;
import com.azure.resourcemanager.compute.models.UpgradePolicy;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetIpConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetManagedDiskParameters;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSDisk;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetStorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetVMProfile;
import java.util.Arrays;
public final class Main {
public static void createAScaleSetWithPremiumStorage (com.azure.resourcemanager.AzureResourceManager azure) {
azure
.virtualMachines()
.manager()
.serviceClient()
.getVirtualMachineScaleSets()
.createOrUpdate(
"myResourceGroup" ,
"{vmss-name}" ,
new VirtualMachineScaleSetInner()
.withLocation("westus" )
.withSku(new Sku().withName("Standard_D1_v2" ).withTier("Standard" ).withCapacity(3L ))
.withUpgradePolicy(new UpgradePolicy().withMode(UpgradeMode.MANUAL))
.withVirtualMachineProfile(
new VirtualMachineScaleSetVMProfile()
.withOsProfile(
new VirtualMachineScaleSetOSProfile()
.withComputerNamePrefix("{vmss-name}" )
.withAdminUsername("{your-username}" )
.withAdminPassword("fakeTokenPlaceholder" ))
.withStorageProfile(
new VirtualMachineScaleSetStorageProfile()
.withImageReference(
new ImageReference()
.withPublisher("MicrosoftWindowsServer" )
.withOffer("WindowsServer" )
.withSku("2016-Datacenter" )
.withVersion("latest" ))
.withOsDisk(
new VirtualMachineScaleSetOSDisk()
.withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)
.withManagedDisk(
new VirtualMachineScaleSetManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withNetworkProfile(
new VirtualMachineScaleSetNetworkProfile()
.withNetworkInterfaceConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetNetworkConfiguration()
.withName("{vmss-name}" )
.withPrimary(true )
.withIpConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetIpConfiguration()
.withName("{vmss-name}" )
.withSubnet(
new ApiEntityReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ))))
.withEnableIpForwarding(true )))))
.withOverprovision(true ),
com.azure.core.util.Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_scale_set_create_with_premium_storage.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main () :
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="{subscription-id}" ,
)
response = client.virtual_machine_scale_sets.begin_create_or_update(
resource_group_name="myResourceGroup" ,
vm_scale_set_name="{vmss-name}" ,
parameters={
"location" : "westus" ,
"properties" : {
"overprovision" : True ,
"upgradePolicy" : {"mode" : "Manual" },
"virtualMachineProfile" : {
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"enableIPForwarding" : True ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
},
}
],
"primary" : True ,
},
}
]
},
"osProfile" : {
"adminPassword" : "{your-password}" ,
"adminUsername" : "{your-username}" ,
"computerNamePrefix" : "{vmss-name}" ,
},
"storageProfile" : {
"imageReference" : {
"offer" : "WindowsServer" ,
"publisher" : "MicrosoftWindowsServer" ,
"sku" : "2016-Datacenter" ,
"version" : "latest" ,
},
"osDisk" : {
"caching" : "ReadWrite" ,
"createOption" : "FromImage" ,
"managedDisk" : {"storageAccountType" : "Premium_LRS" },
},
},
},
},
"sku" : {"capacity" : 3 , "name" : "Standard_D1_v2" , "tier" : "Standard" },
},
).result()
print(response)
if __name__ == "__main__" :
main()
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4"
)
func ExampleVirtualMachineScaleSetsClient_BeginCreateOrUpdate_createAScaleSetWithPremiumStorage () {
cred, err := azidentity.NewDefaultAzureCredential(nil )
if err != nil {
log.Fatalf("failed to obtain a credential: %v" , err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("<subscription-id>" , cred, nil )
if err != nil {
log.Fatalf("failed to create client: %v" , err)
}
poller, err := clientFactory.NewVirtualMachineScaleSetsClient().BeginCreateOrUpdate(ctx, "myResourceGroup" , "{vmss-name}" , armcompute.VirtualMachineScaleSet{
Location: to.Ptr("westus" ),
Properties: &armcompute.VirtualMachineScaleSetProperties{
Overprovision: to.Ptr(true ),
UpgradePolicy: &armcompute.UpgradePolicy{
Mode: to.Ptr(armcompute.UpgradeModeManual),
},
VirtualMachineProfile: &armcompute.VirtualMachineScaleSetVMProfile{
NetworkProfile: &armcompute.VirtualMachineScaleSetNetworkProfile{
NetworkInterfaceConfigurations: []*armcompute.VirtualMachineScaleSetNetworkConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetNetworkConfigurationProperties{
EnableIPForwarding: to.Ptr(true ),
IPConfigurations: []*armcompute.VirtualMachineScaleSetIPConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetIPConfigurationProperties{
Subnet: &armcompute.APIEntityReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
},
},
}},
Primary: to.Ptr(true ),
},
}},
},
OSProfile: &armcompute.VirtualMachineScaleSetOSProfile{
AdminPassword: to.Ptr("{your-password}" ),
AdminUsername: to.Ptr("{your-username}" ),
ComputerNamePrefix: to.Ptr("{vmss-name}" ),
},
StorageProfile: &armcompute.VirtualMachineScaleSetStorageProfile{
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("WindowsServer" ),
Publisher: to.Ptr("MicrosoftWindowsServer" ),
SKU: to.Ptr("2016-Datacenter" ),
Version: to.Ptr("latest" ),
},
OSDisk: &armcompute.VirtualMachineScaleSetOSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.VirtualMachineScaleSetManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesPremiumLRS),
},
},
},
},
},
SKU: &armcompute.SKU{
Name: to.Ptr("Standard_D1_v2" ),
Capacity: to.Ptr[int64 ](3 ),
Tier: to.Ptr("Standard" ),
},
}, nil )
if err != nil {
log.Fatalf("failed to finish the request: %v" , err)
}
res, err := poller.PollUntilDone(ctx, nil )
if err != nil {
log.Fatalf("failed to pull the result: %v" , err)
}
_ = res
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require ("@azure/arm-compute" );
const { DefaultAzureCredential } = require ("@azure/identity" );
async function createAScaleSetWithPremiumStorage ( ) {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID" ] || "{subscription-id}" ;
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP" ] || "myResourceGroup" ;
const vmScaleSetName = "{vmss-name}" ;
const parameters = {
location : "westus" ,
overprovision : true ,
sku : { name : "Standard_D1_v2" , capacity : 3 , tier : "Standard" },
upgradePolicy : { mode : "Manual" },
virtualMachineProfile : {
networkProfile : {
networkInterfaceConfigurations : [
{
name : "{vmss-name}" ,
enableIPForwarding : true ,
ipConfigurations : [
{
name : "{vmss-name}" ,
subnet : {
id : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ,
},
},
],
primary : true ,
},
],
},
osProfile : {
adminPassword : "{your-password}" ,
adminUsername : "{your-username}" ,
computerNamePrefix : "{vmss-name}" ,
},
storageProfile : {
imageReference : {
offer : "WindowsServer" ,
publisher : "MicrosoftWindowsServer" ,
sku : "2016-Datacenter" ,
version : "latest" ,
},
osDisk : {
caching : "ReadWrite" ,
createOption : "FromImage" ,
managedDisk : { storageAccountType : "Premium_LRS" },
},
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachineScaleSets.beginCreateOrUpdateAndWait(
resourceGroupName,
vmScaleSetName,
parameters
);
console .log(result);
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Compute;
using Azure.ResourceManager.Compute.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Resources.Models;
TokenCredential cred = new DefaultAzureCredential();
ArmClient client = new ArmClient(cred);
string subscriptionId = "{subscription-id}" ;
string resourceGroupName = "myResourceGroup" ;
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
VirtualMachineScaleSetCollection collection = resourceGroupResource.GetVirtualMachineScaleSets();
string virtualMachineScaleSetName = "{vmss-name}" ;
VirtualMachineScaleSetData data = new VirtualMachineScaleSetData(new AzureLocation("westus" ))
{
Sku = new ComputeSku()
{
Name = "Standard_D1_v2" ,
Tier = "Standard" ,
Capacity = 3 ,
},
UpgradePolicy = new VirtualMachineScaleSetUpgradePolicy()
{
Mode = VirtualMachineScaleSetUpgradeMode.Manual,
},
VirtualMachineProfile = new VirtualMachineScaleSetVmProfile()
{
OSProfile = new VirtualMachineScaleSetOSProfile()
{
ComputerNamePrefix = "{vmss-name}" ,
AdminUsername = "{your-username}" ,
AdminPassword = "{your-password}" ,
},
StorageProfile = new VirtualMachineScaleSetStorageProfile()
{
ImageReference = new ImageReference()
{
Publisher = "MicrosoftWindowsServer" ,
Offer = "WindowsServer" ,
Sku = "2016-Datacenter" ,
Version = "latest" ,
},
OSDisk = new VirtualMachineScaleSetOSDisk(DiskCreateOptionType.FromImage)
{
Caching = CachingType.ReadWrite,
ManagedDisk = new VirtualMachineScaleSetManagedDisk()
{
StorageAccountType = StorageAccountType.PremiumLrs,
},
},
},
NetworkProfile = new VirtualMachineScaleSetNetworkProfile()
{
NetworkInterfaceConfigurations =
{
new VirtualMachineScaleSetNetworkConfiguration("{vmss-name}" )
{
Primary = true ,
IPConfigurations =
{
new VirtualMachineScaleSetIPConfiguration("{vmss-name}" )
{
SubnetId = new ResourceIdentifier("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
}
},
EnableIPForwarding = true ,
}
},
},
},
Overprovision = true ,
};
ArmOperation<VirtualMachineScaleSetResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, virtualMachineScaleSetName, data);
VirtualMachineScaleSetResource result = lro.Value;
VirtualMachineScaleSetData resourceData = result.Data;
Console.WriteLine($"Succeeded on id: {resourceData.Id} " );
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
範例回覆
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_DS1_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "19fd38a2-f50a-42c6-9dc7-3f9cf3791225" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter" ,
"publisher" : "MicrosoftWindowsServer" ,
"version" : "latest" ,
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Premium_LRS"
},
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_DS1_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "19fd38a2-f50a-42c6-9dc7-3f9cf3791225" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter" ,
"publisher" : "MicrosoftWindowsServer" ,
"version" : "latest" ,
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Premium_LRS"
},
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
Create a scale set with priority mix policy
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}?api-version=2022-11-01
{
"sku" : {
"tier" : "Standard",
"capacity" : 10,
"name" : "Standard_A8m_v2"
},
"location" : "westus",
"properties" : {
"singlePlacementGroup" : false,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter",
"publisher" : "MicrosoftWindowsServer",
"version" : "latest",
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite",
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}",
"adminUsername" : "{your-username}",
"adminPassword" : "{your-password}"
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"primary" : true,
"enableIPForwarding" : true,
"ipConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
}
}
]
}
}
]
},
"priority" : "Spot",
"evictionPolicy" : "Deallocate",
"billingProfile" : {
"maxPrice" : -1
}
},
"orchestrationMode" : "Flexible",
"priorityMixPolicy" : {
"baseRegularPriorityCount" : 4,
"regularPriorityPercentageAboveBase" : 50
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineScaleSetInner;
import com.azure.resourcemanager.compute.models.ApiEntityReference;
import com.azure.resourcemanager.compute.models.BillingProfile;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.OrchestrationMode;
import com.azure.resourcemanager.compute.models.PriorityMixPolicy;
import com.azure.resourcemanager.compute.models.Sku;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.VirtualMachineEvictionPolicyTypes;
import com.azure.resourcemanager.compute.models.VirtualMachinePriorityTypes;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetIpConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetManagedDiskParameters;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSDisk;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetStorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetVMProfile;
import java.util.Arrays;
public final class Main {
public static void createAScaleSetWithPriorityMixPolicy (com.azure.resourcemanager.AzureResourceManager azure) {
azure
.virtualMachines()
.manager()
.serviceClient()
.getVirtualMachineScaleSets()
.createOrUpdate(
"myResourceGroup" ,
"{vmss-name}" ,
new VirtualMachineScaleSetInner()
.withLocation("westus" )
.withSku(new Sku().withName("Standard_A8m_v2" ).withTier("Standard" ).withCapacity(10L ))
.withVirtualMachineProfile(
new VirtualMachineScaleSetVMProfile()
.withOsProfile(
new VirtualMachineScaleSetOSProfile()
.withComputerNamePrefix("{vmss-name}" )
.withAdminUsername("{your-username}" )
.withAdminPassword("fakeTokenPlaceholder" ))
.withStorageProfile(
new VirtualMachineScaleSetStorageProfile()
.withImageReference(
new ImageReference()
.withPublisher("MicrosoftWindowsServer" )
.withOffer("WindowsServer" )
.withSku("2016-Datacenter" )
.withVersion("latest" ))
.withOsDisk(
new VirtualMachineScaleSetOSDisk()
.withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)
.withManagedDisk(
new VirtualMachineScaleSetManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withNetworkProfile(
new VirtualMachineScaleSetNetworkProfile()
.withNetworkInterfaceConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetNetworkConfiguration()
.withName("{vmss-name}" )
.withPrimary(true )
.withIpConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetIpConfiguration()
.withName("{vmss-name}" )
.withSubnet(
new ApiEntityReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ))))
.withEnableIpForwarding(true ))))
.withPriority(VirtualMachinePriorityTypes.SPOT)
.withEvictionPolicy(VirtualMachineEvictionPolicyTypes.DEALLOCATE)
.withBillingProfile(new BillingProfile().withMaxPrice(-1.0 D)))
.withSinglePlacementGroup(false )
.withOrchestrationMode(OrchestrationMode.FLEXIBLE)
.withPriorityMixPolicy(
new PriorityMixPolicy()
.withBaseRegularPriorityCount(4 )
.withRegularPriorityPercentageAboveBase(50 )),
com.azure.core.util.Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_scale_set_create_with_priority_mix_policy.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main () :
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="{subscription-id}" ,
)
response = client.virtual_machine_scale_sets.begin_create_or_update(
resource_group_name="myResourceGroup" ,
vm_scale_set_name="{vmss-name}" ,
parameters={
"location" : "westus" ,
"properties" : {
"orchestrationMode" : "Flexible" ,
"priorityMixPolicy" : {"baseRegularPriorityCount" : 4 , "regularPriorityPercentageAboveBase" : 50 },
"singlePlacementGroup" : False ,
"virtualMachineProfile" : {
"billingProfile" : {"maxPrice" : -1 },
"evictionPolicy" : "Deallocate" ,
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"enableIPForwarding" : True ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
},
}
],
"primary" : True ,
},
}
]
},
"osProfile" : {
"adminPassword" : "{your-password}" ,
"adminUsername" : "{your-username}" ,
"computerNamePrefix" : "{vmss-name}" ,
},
"priority" : "Spot" ,
"storageProfile" : {
"imageReference" : {
"offer" : "WindowsServer" ,
"publisher" : "MicrosoftWindowsServer" ,
"sku" : "2016-Datacenter" ,
"version" : "latest" ,
},
"osDisk" : {
"caching" : "ReadWrite" ,
"createOption" : "FromImage" ,
"managedDisk" : {"storageAccountType" : "Standard_LRS" },
},
},
},
},
"sku" : {"capacity" : 10 , "name" : "Standard_A8m_v2" , "tier" : "Standard" },
},
).result()
print(response)
if __name__ == "__main__" :
main()
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4"
)
func ExampleVirtualMachineScaleSetsClient_BeginCreateOrUpdate_createAScaleSetWithPriorityMixPolicy () {
cred, err := azidentity.NewDefaultAzureCredential(nil )
if err != nil {
log.Fatalf("failed to obtain a credential: %v" , err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("<subscription-id>" , cred, nil )
if err != nil {
log.Fatalf("failed to create client: %v" , err)
}
poller, err := clientFactory.NewVirtualMachineScaleSetsClient().BeginCreateOrUpdate(ctx, "myResourceGroup" , "{vmss-name}" , armcompute.VirtualMachineScaleSet{
Location: to.Ptr("westus" ),
Properties: &armcompute.VirtualMachineScaleSetProperties{
OrchestrationMode: to.Ptr(armcompute.OrchestrationModeFlexible),
PriorityMixPolicy: &armcompute.PriorityMixPolicy{
BaseRegularPriorityCount: to.Ptr[int32 ](4 ),
RegularPriorityPercentageAboveBase: to.Ptr[int32 ](50 ),
},
SinglePlacementGroup: to.Ptr(false ),
VirtualMachineProfile: &armcompute.VirtualMachineScaleSetVMProfile{
BillingProfile: &armcompute.BillingProfile{
MaxPrice: to.Ptr[float64 ](-1 ),
},
EvictionPolicy: to.Ptr(armcompute.VirtualMachineEvictionPolicyTypesDeallocate),
NetworkProfile: &armcompute.VirtualMachineScaleSetNetworkProfile{
NetworkInterfaceConfigurations: []*armcompute.VirtualMachineScaleSetNetworkConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetNetworkConfigurationProperties{
EnableIPForwarding: to.Ptr(true ),
IPConfigurations: []*armcompute.VirtualMachineScaleSetIPConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetIPConfigurationProperties{
Subnet: &armcompute.APIEntityReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
},
},
}},
Primary: to.Ptr(true ),
},
}},
},
OSProfile: &armcompute.VirtualMachineScaleSetOSProfile{
AdminPassword: to.Ptr("{your-password}" ),
AdminUsername: to.Ptr("{your-username}" ),
ComputerNamePrefix: to.Ptr("{vmss-name}" ),
},
Priority: to.Ptr(armcompute.VirtualMachinePriorityTypesSpot),
StorageProfile: &armcompute.VirtualMachineScaleSetStorageProfile{
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("WindowsServer" ),
Publisher: to.Ptr("MicrosoftWindowsServer" ),
SKU: to.Ptr("2016-Datacenter" ),
Version: to.Ptr("latest" ),
},
OSDisk: &armcompute.VirtualMachineScaleSetOSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.VirtualMachineScaleSetManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
},
},
SKU: &armcompute.SKU{
Name: to.Ptr("Standard_A8m_v2" ),
Capacity: to.Ptr[int64 ](10 ),
Tier: to.Ptr("Standard" ),
},
}, nil )
if err != nil {
log.Fatalf("failed to finish the request: %v" , err)
}
res, err := poller.PollUntilDone(ctx, nil )
if err != nil {
log.Fatalf("failed to pull the result: %v" , err)
}
_ = res
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require ("@azure/arm-compute" );
const { DefaultAzureCredential } = require ("@azure/identity" );
async function createAScaleSetWithPriorityMixPolicy ( ) {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID" ] || "{subscription-id}" ;
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP" ] || "myResourceGroup" ;
const vmScaleSetName = "{vmss-name}" ;
const parameters = {
location : "westus" ,
orchestrationMode : "Flexible" ,
priorityMixPolicy : {
baseRegularPriorityCount : 4 ,
regularPriorityPercentageAboveBase : 50 ,
},
singlePlacementGroup : false ,
sku : { name : "Standard_A8m_v2" , capacity : 10 , tier : "Standard" },
virtualMachineProfile : {
billingProfile : { maxPrice : -1 },
evictionPolicy : "Deallocate" ,
networkProfile : {
networkInterfaceConfigurations : [
{
name : "{vmss-name}" ,
enableIPForwarding : true ,
ipConfigurations : [
{
name : "{vmss-name}" ,
subnet : {
id : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ,
},
},
],
primary : true ,
},
],
},
osProfile : {
adminPassword : "{your-password}" ,
adminUsername : "{your-username}" ,
computerNamePrefix : "{vmss-name}" ,
},
priority : "Spot" ,
storageProfile : {
imageReference : {
offer : "WindowsServer" ,
publisher : "MicrosoftWindowsServer" ,
sku : "2016-Datacenter" ,
version : "latest" ,
},
osDisk : {
caching : "ReadWrite" ,
createOption : "FromImage" ,
managedDisk : { storageAccountType : "Standard_LRS" },
},
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachineScaleSets.beginCreateOrUpdateAndWait(
resourceGroupName,
vmScaleSetName,
parameters
);
console .log(result);
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Compute;
using Azure.ResourceManager.Compute.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Resources.Models;
TokenCredential cred = new DefaultAzureCredential();
ArmClient client = new ArmClient(cred);
string subscriptionId = "{subscription-id}" ;
string resourceGroupName = "myResourceGroup" ;
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
VirtualMachineScaleSetCollection collection = resourceGroupResource.GetVirtualMachineScaleSets();
string virtualMachineScaleSetName = "{vmss-name}" ;
VirtualMachineScaleSetData data = new VirtualMachineScaleSetData(new AzureLocation("westus" ))
{
Sku = new ComputeSku()
{
Name = "Standard_A8m_v2" ,
Tier = "Standard" ,
Capacity = 10 ,
},
VirtualMachineProfile = new VirtualMachineScaleSetVmProfile()
{
OSProfile = new VirtualMachineScaleSetOSProfile()
{
ComputerNamePrefix = "{vmss-name}" ,
AdminUsername = "{your-username}" ,
AdminPassword = "{your-password}" ,
},
StorageProfile = new VirtualMachineScaleSetStorageProfile()
{
ImageReference = new ImageReference()
{
Publisher = "MicrosoftWindowsServer" ,
Offer = "WindowsServer" ,
Sku = "2016-Datacenter" ,
Version = "latest" ,
},
OSDisk = new VirtualMachineScaleSetOSDisk(DiskCreateOptionType.FromImage)
{
Caching = CachingType.ReadWrite,
ManagedDisk = new VirtualMachineScaleSetManagedDisk()
{
StorageAccountType = StorageAccountType.StandardLrs,
},
},
},
NetworkProfile = new VirtualMachineScaleSetNetworkProfile()
{
NetworkInterfaceConfigurations =
{
new VirtualMachineScaleSetNetworkConfiguration("{vmss-name}" )
{
Primary = true ,
IPConfigurations =
{
new VirtualMachineScaleSetIPConfiguration("{vmss-name}" )
{
SubnetId = new ResourceIdentifier("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
}
},
EnableIPForwarding = true ,
}
},
},
Priority = VirtualMachinePriorityType.Spot,
EvictionPolicy = VirtualMachineEvictionPolicyType.Deallocate,
BillingMaxPrice = -1 ,
},
SinglePlacementGroup = false ,
OrchestrationMode = OrchestrationMode.Flexible,
PriorityMixPolicy = new VirtualMachineScaleSetPriorityMixPolicy()
{
BaseRegularPriorityCount = 4 ,
RegularPriorityPercentageAboveBase = 50 ,
},
};
ArmOperation<VirtualMachineScaleSetResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, virtualMachineScaleSetName, data);
VirtualMachineScaleSetResource result = lro.Value;
VirtualMachineScaleSetData resourceData = result.Data;
Console.WriteLine($"Succeeded on id: {resourceData.Id} " );
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
範例回覆
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 10 ,
"name" : "Standard_A8m_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : false ,
"uniqueId" : "d053ec5a-8da6-495f-ab13-38216503c6d7" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter" ,
"publisher" : "MicrosoftWindowsServer" ,
"version" : "latest" ,
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
},
"priority" : "Spot" ,
"evictionPolicy" : "Deallocate" ,
"billingProfile" : {
"maxPrice" : -1
}
},
"orchestrationMode" : "Flexible" ,
"priorityMixPolicy" : {
"baseRegularPriorityCount" : 4 ,
"regularPriorityPercentageAboveBase" : 50
},
"provisioningState" : "Creating"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 10 ,
"name" : "Standard_A8m_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : false ,
"uniqueId" : "d053ec5a-8da6-495f-ab13-38216503c6d7" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter" ,
"publisher" : "MicrosoftWindowsServer" ,
"version" : "latest" ,
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
},
"priority" : "Spot" ,
"evictionPolicy" : "Deallocate" ,
"billingProfile" : {
"maxPrice" : -1
}
},
"orchestrationMode" : "Flexible" ,
"priorityMixPolicy" : {
"baseRegularPriorityCount" : 4 ,
"regularPriorityPercentageAboveBase" : 50
},
"provisioningState" : "Creating"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
Create a scale set with scaleInPolicy.
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}?api-version=2022-11-01
{
"sku" : {
"tier" : "Standard",
"capacity" : 3,
"name" : "Standard_D1_v2"
},
"location" : "westus",
"properties" : {
"overprovision" : true,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter",
"publisher" : "MicrosoftWindowsServer",
"version" : "latest",
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite",
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}",
"adminUsername" : "{your-username}",
"adminPassword" : "{your-password}"
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"primary" : true,
"enableIPForwarding" : true,
"ipConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
}
}
]
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"scaleInPolicy" : {
"rules" : [
"OldestVM"
],
"forceDeletion" : true
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineScaleSetInner;
import com.azure.resourcemanager.compute.models.ApiEntityReference;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.ScaleInPolicy;
import com.azure.resourcemanager.compute.models.Sku;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.UpgradeMode;
import com.azure.resourcemanager.compute.models.UpgradePolicy;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetIpConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetManagedDiskParameters;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSDisk;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetScaleInRules;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetStorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetVMProfile;
import java.util.Arrays;
public final class Main {
public static void createAScaleSetWithScaleInPolicy (com.azure.resourcemanager.AzureResourceManager azure) {
azure
.virtualMachines()
.manager()
.serviceClient()
.getVirtualMachineScaleSets()
.createOrUpdate(
"myResourceGroup" ,
"{vmss-name}" ,
new VirtualMachineScaleSetInner()
.withLocation("westus" )
.withSku(new Sku().withName("Standard_D1_v2" ).withTier("Standard" ).withCapacity(3L ))
.withUpgradePolicy(new UpgradePolicy().withMode(UpgradeMode.MANUAL))
.withVirtualMachineProfile(
new VirtualMachineScaleSetVMProfile()
.withOsProfile(
new VirtualMachineScaleSetOSProfile()
.withComputerNamePrefix("{vmss-name}" )
.withAdminUsername("{your-username}" )
.withAdminPassword("fakeTokenPlaceholder" ))
.withStorageProfile(
new VirtualMachineScaleSetStorageProfile()
.withImageReference(
new ImageReference()
.withPublisher("MicrosoftWindowsServer" )
.withOffer("WindowsServer" )
.withSku("2016-Datacenter" )
.withVersion("latest" ))
.withOsDisk(
new VirtualMachineScaleSetOSDisk()
.withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)
.withManagedDisk(
new VirtualMachineScaleSetManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withNetworkProfile(
new VirtualMachineScaleSetNetworkProfile()
.withNetworkInterfaceConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetNetworkConfiguration()
.withName("{vmss-name}" )
.withPrimary(true )
.withIpConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetIpConfiguration()
.withName("{vmss-name}" )
.withSubnet(
new ApiEntityReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ))))
.withEnableIpForwarding(true )))))
.withOverprovision(true )
.withScaleInPolicy(
new ScaleInPolicy()
.withRules(Arrays.asList(VirtualMachineScaleSetScaleInRules.OLDEST_VM))
.withForceDeletion(true )),
com.azure.core.util.Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_scale_set_create_with_scale_in_policy.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main () :
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="{subscription-id}" ,
)
response = client.virtual_machine_scale_sets.begin_create_or_update(
resource_group_name="myResourceGroup" ,
vm_scale_set_name="{vmss-name}" ,
parameters={
"location" : "westus" ,
"properties" : {
"overprovision" : True ,
"scaleInPolicy" : {"forceDeletion" : True , "rules" : ["OldestVM" ]},
"upgradePolicy" : {"mode" : "Manual" },
"virtualMachineProfile" : {
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"enableIPForwarding" : True ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
},
}
],
"primary" : True ,
},
}
]
},
"osProfile" : {
"adminPassword" : "{your-password}" ,
"adminUsername" : "{your-username}" ,
"computerNamePrefix" : "{vmss-name}" ,
},
"storageProfile" : {
"imageReference" : {
"offer" : "WindowsServer" ,
"publisher" : "MicrosoftWindowsServer" ,
"sku" : "2016-Datacenter" ,
"version" : "latest" ,
},
"osDisk" : {
"caching" : "ReadWrite" ,
"createOption" : "FromImage" ,
"managedDisk" : {"storageAccountType" : "Standard_LRS" },
},
},
},
},
"sku" : {"capacity" : 3 , "name" : "Standard_D1_v2" , "tier" : "Standard" },
},
).result()
print(response)
if __name__ == "__main__" :
main()
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4"
)
func ExampleVirtualMachineScaleSetsClient_BeginCreateOrUpdate_createAScaleSetWithScaleInPolicy () {
cred, err := azidentity.NewDefaultAzureCredential(nil )
if err != nil {
log.Fatalf("failed to obtain a credential: %v" , err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("<subscription-id>" , cred, nil )
if err != nil {
log.Fatalf("failed to create client: %v" , err)
}
poller, err := clientFactory.NewVirtualMachineScaleSetsClient().BeginCreateOrUpdate(ctx, "myResourceGroup" , "{vmss-name}" , armcompute.VirtualMachineScaleSet{
Location: to.Ptr("westus" ),
Properties: &armcompute.VirtualMachineScaleSetProperties{
Overprovision: to.Ptr(true ),
ScaleInPolicy: &armcompute.ScaleInPolicy{
ForceDeletion: to.Ptr(true ),
Rules: []*armcompute.VirtualMachineScaleSetScaleInRules{
to.Ptr(armcompute.VirtualMachineScaleSetScaleInRulesOldestVM)},
},
UpgradePolicy: &armcompute.UpgradePolicy{
Mode: to.Ptr(armcompute.UpgradeModeManual),
},
VirtualMachineProfile: &armcompute.VirtualMachineScaleSetVMProfile{
NetworkProfile: &armcompute.VirtualMachineScaleSetNetworkProfile{
NetworkInterfaceConfigurations: []*armcompute.VirtualMachineScaleSetNetworkConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetNetworkConfigurationProperties{
EnableIPForwarding: to.Ptr(true ),
IPConfigurations: []*armcompute.VirtualMachineScaleSetIPConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetIPConfigurationProperties{
Subnet: &armcompute.APIEntityReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
},
},
}},
Primary: to.Ptr(true ),
},
}},
},
OSProfile: &armcompute.VirtualMachineScaleSetOSProfile{
AdminPassword: to.Ptr("{your-password}" ),
AdminUsername: to.Ptr("{your-username}" ),
ComputerNamePrefix: to.Ptr("{vmss-name}" ),
},
StorageProfile: &armcompute.VirtualMachineScaleSetStorageProfile{
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("WindowsServer" ),
Publisher: to.Ptr("MicrosoftWindowsServer" ),
SKU: to.Ptr("2016-Datacenter" ),
Version: to.Ptr("latest" ),
},
OSDisk: &armcompute.VirtualMachineScaleSetOSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.VirtualMachineScaleSetManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
},
},
SKU: &armcompute.SKU{
Name: to.Ptr("Standard_D1_v2" ),
Capacity: to.Ptr[int64 ](3 ),
Tier: to.Ptr("Standard" ),
},
}, nil )
if err != nil {
log.Fatalf("failed to finish the request: %v" , err)
}
res, err := poller.PollUntilDone(ctx, nil )
if err != nil {
log.Fatalf("failed to pull the result: %v" , err)
}
_ = res
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require ("@azure/arm-compute" );
const { DefaultAzureCredential } = require ("@azure/identity" );
async function createAScaleSetWithScaleInPolicy ( ) {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID" ] || "{subscription-id}" ;
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP" ] || "myResourceGroup" ;
const vmScaleSetName = "{vmss-name}" ;
const parameters = {
location : "westus" ,
overprovision : true ,
scaleInPolicy : { forceDeletion : true , rules : ["OldestVM" ] },
sku : { name : "Standard_D1_v2" , capacity : 3 , tier : "Standard" },
upgradePolicy : { mode : "Manual" },
virtualMachineProfile : {
networkProfile : {
networkInterfaceConfigurations : [
{
name : "{vmss-name}" ,
enableIPForwarding : true ,
ipConfigurations : [
{
name : "{vmss-name}" ,
subnet : {
id : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ,
},
},
],
primary : true ,
},
],
},
osProfile : {
adminPassword : "{your-password}" ,
adminUsername : "{your-username}" ,
computerNamePrefix : "{vmss-name}" ,
},
storageProfile : {
imageReference : {
offer : "WindowsServer" ,
publisher : "MicrosoftWindowsServer" ,
sku : "2016-Datacenter" ,
version : "latest" ,
},
osDisk : {
caching : "ReadWrite" ,
createOption : "FromImage" ,
managedDisk : { storageAccountType : "Standard_LRS" },
},
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachineScaleSets.beginCreateOrUpdateAndWait(
resourceGroupName,
vmScaleSetName,
parameters
);
console .log(result);
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Compute;
using Azure.ResourceManager.Compute.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Resources.Models;
TokenCredential cred = new DefaultAzureCredential();
ArmClient client = new ArmClient(cred);
string subscriptionId = "{subscription-id}" ;
string resourceGroupName = "myResourceGroup" ;
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
VirtualMachineScaleSetCollection collection = resourceGroupResource.GetVirtualMachineScaleSets();
string virtualMachineScaleSetName = "{vmss-name}" ;
VirtualMachineScaleSetData data = new VirtualMachineScaleSetData(new AzureLocation("westus" ))
{
Sku = new ComputeSku()
{
Name = "Standard_D1_v2" ,
Tier = "Standard" ,
Capacity = 3 ,
},
UpgradePolicy = new VirtualMachineScaleSetUpgradePolicy()
{
Mode = VirtualMachineScaleSetUpgradeMode.Manual,
},
VirtualMachineProfile = new VirtualMachineScaleSetVmProfile()
{
OSProfile = new VirtualMachineScaleSetOSProfile()
{
ComputerNamePrefix = "{vmss-name}" ,
AdminUsername = "{your-username}" ,
AdminPassword = "{your-password}" ,
},
StorageProfile = new VirtualMachineScaleSetStorageProfile()
{
ImageReference = new ImageReference()
{
Publisher = "MicrosoftWindowsServer" ,
Offer = "WindowsServer" ,
Sku = "2016-Datacenter" ,
Version = "latest" ,
},
OSDisk = new VirtualMachineScaleSetOSDisk(DiskCreateOptionType.FromImage)
{
Caching = CachingType.ReadWrite,
ManagedDisk = new VirtualMachineScaleSetManagedDisk()
{
StorageAccountType = StorageAccountType.StandardLrs,
},
},
},
NetworkProfile = new VirtualMachineScaleSetNetworkProfile()
{
NetworkInterfaceConfigurations =
{
new VirtualMachineScaleSetNetworkConfiguration("{vmss-name}" )
{
Primary = true ,
IPConfigurations =
{
new VirtualMachineScaleSetIPConfiguration("{vmss-name}" )
{
SubnetId = new ResourceIdentifier("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
}
},
EnableIPForwarding = true ,
}
},
},
},
Overprovision = true ,
ScaleInPolicy = new ScaleInPolicy()
{
Rules =
{
VirtualMachineScaleSetScaleInRule.OldestVm
},
ForceDeletion = true ,
},
};
ArmOperation<VirtualMachineScaleSetResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, virtualMachineScaleSetName, data);
VirtualMachineScaleSetResource result = lro.Value;
VirtualMachineScaleSetData resourceData = result.Data;
Console.WriteLine($"Succeeded on id: {resourceData.Id} " );
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
範例回覆
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_D1_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "d053ec5a-8da6-495f-ab13-38216503c6d7" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter" ,
"publisher" : "MicrosoftWindowsServer" ,
"version" : "latest" ,
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"scaleInPolicy" : {
"rules" : [
"OldestVM"
],
"forceDeletion" : true
},
"provisioningState" : "Creating"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_D1_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "d053ec5a-8da6-495f-ab13-38216503c6d7" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter" ,
"publisher" : "MicrosoftWindowsServer" ,
"version" : "latest" ,
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"scaleInPolicy" : {
"rules" : [
"OldestVM"
],
"forceDeletion" : true
},
"provisioningState" : "Creating"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
Create a scale set with SecurityType as ConfidentialVM
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}?api-version=2022-11-01
{
"sku" : {
"tier" : "Standard",
"capacity" : 3,
"name" : "Standard_DC2as_v5"
},
"properties" : {
"overprovision" : true,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "windows-cvm",
"publisher" : "MicrosoftWindowsServer",
"version" : "17763.2183.2109130127",
"offer" : "2019-datacenter-cvm"
},
"osDisk" : {
"caching" : "ReadOnly",
"managedDisk" : {
"storageAccountType" : "StandardSSD_LRS",
"securityProfile" : {
"securityEncryptionType" : "VMGuestStateOnly"
}
},
"createOption" : "FromImage"
}
},
"securityProfile" : {
"uefiSettings" : {
"secureBootEnabled" : true,
"vTpmEnabled" : true
},
"securityType" : "ConfidentialVM"
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}",
"adminUsername" : "{your-username}",
"adminPassword" : "{your-password}"
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"primary" : true,
"enableIPForwarding" : true,
"ipConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
}
}
]
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
}
},
"location" : "westus"
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineScaleSetInner;
import com.azure.resourcemanager.compute.models.ApiEntityReference;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.SecurityEncryptionTypes;
import com.azure.resourcemanager.compute.models.SecurityProfile;
import com.azure.resourcemanager.compute.models.SecurityTypes;
import com.azure.resourcemanager.compute.models.Sku;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.UefiSettings;
import com.azure.resourcemanager.compute.models.UpgradeMode;
import com.azure.resourcemanager.compute.models.UpgradePolicy;
import com.azure.resourcemanager.compute.models.VMDiskSecurityProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetIpConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetManagedDiskParameters;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSDisk;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetStorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetVMProfile;
import java.util.Arrays;
public final class Main {
public static void createAScaleSetWithSecurityTypeAsConfidentialVM (
com.azure.resourcemanager.AzureResourceManager azure) {
azure
.virtualMachines()
.manager()
.serviceClient()
.getVirtualMachineScaleSets()
.createOrUpdate(
"myResourceGroup" ,
"{vmss-name}" ,
new VirtualMachineScaleSetInner()
.withLocation("westus" )
.withSku(new Sku().withName("Standard_DC2as_v5" ).withTier("Standard" ).withCapacity(3L ))
.withUpgradePolicy(new UpgradePolicy().withMode(UpgradeMode.MANUAL))
.withVirtualMachineProfile(
new VirtualMachineScaleSetVMProfile()
.withOsProfile(
new VirtualMachineScaleSetOSProfile()
.withComputerNamePrefix("{vmss-name}" )
.withAdminUsername("{your-username}" )
.withAdminPassword("fakeTokenPlaceholder" ))
.withStorageProfile(
new VirtualMachineScaleSetStorageProfile()
.withImageReference(
new ImageReference()
.withPublisher("MicrosoftWindowsServer" )
.withOffer("2019-datacenter-cvm" )
.withSku("windows-cvm" )
.withVersion("17763.2183.2109130127" ))
.withOsDisk(
new VirtualMachineScaleSetOSDisk()
.withCaching(CachingTypes.READ_ONLY)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)
.withManagedDisk(
new VirtualMachineScaleSetManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.STANDARD_SSD_LRS)
.withSecurityProfile(
new VMDiskSecurityProfile()
.withSecurityEncryptionType(
SecurityEncryptionTypes.VMGUEST_STATE_ONLY)))))
.withNetworkProfile(
new VirtualMachineScaleSetNetworkProfile()
.withNetworkInterfaceConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetNetworkConfiguration()
.withName("{vmss-name}" )
.withPrimary(true )
.withIpConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetIpConfiguration()
.withName("{vmss-name}" )
.withSubnet(
new ApiEntityReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ))))
.withEnableIpForwarding(true ))))
.withSecurityProfile(
new SecurityProfile()
.withUefiSettings(
new UefiSettings().withSecureBootEnabled(true ).withVTpmEnabled(true ))
.withSecurityType(SecurityTypes.CONFIDENTIAL_VM)))
.withOverprovision(true ),
com.azure.core.util.Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_scale_set_create_with_security_type_confidential_vm.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main () :
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="{subscription-id}" ,
)
response = client.virtual_machine_scale_sets.begin_create_or_update(
resource_group_name="myResourceGroup" ,
vm_scale_set_name="{vmss-name}" ,
parameters={
"location" : "westus" ,
"properties" : {
"overprovision" : True ,
"upgradePolicy" : {"mode" : "Manual" },
"virtualMachineProfile" : {
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"enableIPForwarding" : True ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
},
}
],
"primary" : True ,
},
}
]
},
"osProfile" : {
"adminPassword" : "{your-password}" ,
"adminUsername" : "{your-username}" ,
"computerNamePrefix" : "{vmss-name}" ,
},
"securityProfile" : {
"securityType" : "ConfidentialVM" ,
"uefiSettings" : {"secureBootEnabled" : True , "vTpmEnabled" : True },
},
"storageProfile" : {
"imageReference" : {
"offer" : "2019-datacenter-cvm" ,
"publisher" : "MicrosoftWindowsServer" ,
"sku" : "windows-cvm" ,
"version" : "17763.2183.2109130127" ,
},
"osDisk" : {
"caching" : "ReadOnly" ,
"createOption" : "FromImage" ,
"managedDisk" : {
"securityProfile" : {"securityEncryptionType" : "VMGuestStateOnly" },
"storageAccountType" : "StandardSSD_LRS" ,
},
},
},
},
},
"sku" : {"capacity" : 3 , "name" : "Standard_DC2as_v5" , "tier" : "Standard" },
},
).result()
print(response)
if __name__ == "__main__" :
main()
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4"
)
func ExampleVirtualMachineScaleSetsClient_BeginCreateOrUpdate_createAScaleSetWithSecurityTypeAsConfidentialVm () {
cred, err := azidentity.NewDefaultAzureCredential(nil )
if err != nil {
log.Fatalf("failed to obtain a credential: %v" , err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("<subscription-id>" , cred, nil )
if err != nil {
log.Fatalf("failed to create client: %v" , err)
}
poller, err := clientFactory.NewVirtualMachineScaleSetsClient().BeginCreateOrUpdate(ctx, "myResourceGroup" , "{vmss-name}" , armcompute.VirtualMachineScaleSet{
Location: to.Ptr("westus" ),
Properties: &armcompute.VirtualMachineScaleSetProperties{
Overprovision: to.Ptr(true ),
UpgradePolicy: &armcompute.UpgradePolicy{
Mode: to.Ptr(armcompute.UpgradeModeManual),
},
VirtualMachineProfile: &armcompute.VirtualMachineScaleSetVMProfile{
NetworkProfile: &armcompute.VirtualMachineScaleSetNetworkProfile{
NetworkInterfaceConfigurations: []*armcompute.VirtualMachineScaleSetNetworkConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetNetworkConfigurationProperties{
EnableIPForwarding: to.Ptr(true ),
IPConfigurations: []*armcompute.VirtualMachineScaleSetIPConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetIPConfigurationProperties{
Subnet: &armcompute.APIEntityReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
},
},
}},
Primary: to.Ptr(true ),
},
}},
},
OSProfile: &armcompute.VirtualMachineScaleSetOSProfile{
AdminPassword: to.Ptr("{your-password}" ),
AdminUsername: to.Ptr("{your-username}" ),
ComputerNamePrefix: to.Ptr("{vmss-name}" ),
},
SecurityProfile: &armcompute.SecurityProfile{
SecurityType: to.Ptr(armcompute.SecurityTypesConfidentialVM),
UefiSettings: &armcompute.UefiSettings{
SecureBootEnabled: to.Ptr(true ),
VTpmEnabled: to.Ptr(true ),
},
},
StorageProfile: &armcompute.VirtualMachineScaleSetStorageProfile{
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("2019-datacenter-cvm" ),
Publisher: to.Ptr("MicrosoftWindowsServer" ),
SKU: to.Ptr("windows-cvm" ),
Version: to.Ptr("17763.2183.2109130127" ),
},
OSDisk: &armcompute.VirtualMachineScaleSetOSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadOnly),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.VirtualMachineScaleSetManagedDiskParameters{
SecurityProfile: &armcompute.VMDiskSecurityProfile{
SecurityEncryptionType: to.Ptr(armcompute.SecurityEncryptionTypesVMGuestStateOnly),
},
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardSSDLRS),
},
},
},
},
},
SKU: &armcompute.SKU{
Name: to.Ptr("Standard_DC2as_v5" ),
Capacity: to.Ptr[int64 ](3 ),
Tier: to.Ptr("Standard" ),
},
}, nil )
if err != nil {
log.Fatalf("failed to finish the request: %v" , err)
}
res, err := poller.PollUntilDone(ctx, nil )
if err != nil {
log.Fatalf("failed to pull the result: %v" , err)
}
_ = res
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require ("@azure/arm-compute" );
const { DefaultAzureCredential } = require ("@azure/identity" );
async function createAScaleSetWithSecurityTypeAsConfidentialVM ( ) {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID" ] || "{subscription-id}" ;
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP" ] || "myResourceGroup" ;
const vmScaleSetName = "{vmss-name}" ;
const parameters = {
location : "westus" ,
overprovision : true ,
sku : { name : "Standard_DC2as_v5" , capacity : 3 , tier : "Standard" },
upgradePolicy : { mode : "Manual" },
virtualMachineProfile : {
networkProfile : {
networkInterfaceConfigurations : [
{
name : "{vmss-name}" ,
enableIPForwarding : true ,
ipConfigurations : [
{
name : "{vmss-name}" ,
subnet : {
id : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ,
},
},
],
primary : true ,
},
],
},
osProfile : {
adminPassword : "{your-password}" ,
adminUsername : "{your-username}" ,
computerNamePrefix : "{vmss-name}" ,
},
securityProfile : {
securityType : "ConfidentialVM" ,
uefiSettings : { secureBootEnabled : true , vTpmEnabled : true },
},
storageProfile : {
imageReference : {
offer : "2019-datacenter-cvm" ,
publisher : "MicrosoftWindowsServer" ,
sku : "windows-cvm" ,
version : "17763.2183.2109130127" ,
},
osDisk : {
caching : "ReadOnly" ,
createOption : "FromImage" ,
managedDisk : {
securityProfile : { securityEncryptionType : "VMGuestStateOnly" },
storageAccountType : "StandardSSD_LRS" ,
},
},
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachineScaleSets.beginCreateOrUpdateAndWait(
resourceGroupName,
vmScaleSetName,
parameters
);
console .log(result);
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Compute;
using Azure.ResourceManager.Compute.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Resources.Models;
TokenCredential cred = new DefaultAzureCredential();
ArmClient client = new ArmClient(cred);
string subscriptionId = "{subscription-id}" ;
string resourceGroupName = "myResourceGroup" ;
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
VirtualMachineScaleSetCollection collection = resourceGroupResource.GetVirtualMachineScaleSets();
string virtualMachineScaleSetName = "{vmss-name}" ;
VirtualMachineScaleSetData data = new VirtualMachineScaleSetData(new AzureLocation("westus" ))
{
Sku = new ComputeSku()
{
Name = "Standard_DC2as_v5" ,
Tier = "Standard" ,
Capacity = 3 ,
},
UpgradePolicy = new VirtualMachineScaleSetUpgradePolicy()
{
Mode = VirtualMachineScaleSetUpgradeMode.Manual,
},
VirtualMachineProfile = new VirtualMachineScaleSetVmProfile()
{
OSProfile = new VirtualMachineScaleSetOSProfile()
{
ComputerNamePrefix = "{vmss-name}" ,
AdminUsername = "{your-username}" ,
AdminPassword = "{your-password}" ,
},
StorageProfile = new VirtualMachineScaleSetStorageProfile()
{
ImageReference = new ImageReference()
{
Publisher = "MicrosoftWindowsServer" ,
Offer = "2019-datacenter-cvm" ,
Sku = "windows-cvm" ,
Version = "17763.2183.2109130127" ,
},
OSDisk = new VirtualMachineScaleSetOSDisk(DiskCreateOptionType.FromImage)
{
Caching = CachingType.ReadOnly,
ManagedDisk = new VirtualMachineScaleSetManagedDisk()
{
StorageAccountType = StorageAccountType.StandardSsdLrs,
SecurityProfile = new VirtualMachineDiskSecurityProfile()
{
SecurityEncryptionType = SecurityEncryptionType.VmGuestStateOnly,
},
},
},
},
NetworkProfile = new VirtualMachineScaleSetNetworkProfile()
{
NetworkInterfaceConfigurations =
{
new VirtualMachineScaleSetNetworkConfiguration("{vmss-name}" )
{
Primary = true ,
IPConfigurations =
{
new VirtualMachineScaleSetIPConfiguration("{vmss-name}" )
{
SubnetId = new ResourceIdentifier("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
}
},
EnableIPForwarding = true ,
}
},
},
SecurityProfile = new SecurityProfile()
{
UefiSettings = new UefiSettings()
{
IsSecureBootEnabled = true ,
IsVirtualTpmEnabled = true ,
},
SecurityType = SecurityType.ConfidentialVm,
},
},
Overprovision = true ,
};
ArmOperation<VirtualMachineScaleSetResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, virtualMachineScaleSetName, data);
VirtualMachineScaleSetResource result = lro.Value;
VirtualMachineScaleSetData resourceData = result.Data;
Console.WriteLine($"Succeeded on id: {resourceData.Id} " );
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
範例回覆
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_DC2as_v5"
},
"name" : "{vmss-name}" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "b9e23088-6ffc-46e0-9e02-b0a6eeef47db" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "windows-cvm" ,
"publisher" : "MicrosoftWindowsServer" ,
"version" : "17763.2183.2109130127" ,
"offer" : "2019-datacenter-cvm"
},
"osDisk" : {
"caching" : "ReadOnly" ,
"managedDisk" : {
"storageAccountType" : "StandardSSD_LRS" ,
"securityProfile" : {
"securityEncryptionType" : "VMGuestStateOnly"
}
},
"createOption" : "FromImage"
}
},
"securityProfile" : {
"uefiSettings" : {
"secureBootEnabled" : true ,
"vTpmEnabled" : true
},
"securityType" : "ConfidentialVM"
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus"
}
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_DC2as_v5"
},
"name" : "{vmss-name}" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "b9e23088-6ffc-46e0-9e02-b0a6eeef47db" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "windows-cvm" ,
"publisher" : "MicrosoftWindowsServer" ,
"version" : "17763.2183.2109130127" ,
"offer" : "2019-datacenter-cvm"
},
"osDisk" : {
"caching" : "ReadOnly" ,
"managedDisk" : {
"storageAccountType" : "StandardSSD_LRS" ,
"securityProfile" : {
"securityEncryptionType" : "VMGuestStateOnly"
}
},
"createOption" : "FromImage"
}
},
"securityProfile" : {
"uefiSettings" : {
"secureBootEnabled" : true ,
"vTpmEnabled" : true
},
"securityType" : "ConfidentialVM"
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus"
}
Create a scale set with Service Artifact Reference
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}?api-version=2022-11-01
{
"sku" : {
"tier" : "Standard",
"capacity" : 3,
"name" : "Standard_A1"
},
"location" : "eastus2euap",
"properties" : {
"overprovision" : true,
"virtualMachineProfile" : {
"serviceArtifactReference" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/myGalleryName/serviceArtifacts/serviceArtifactName/vmArtifactsProfiles/vmArtifactsProfilesName"
},
"storageProfile" : {
"imageReference" : {
"sku" : "2022-Datacenter",
"publisher" : "MicrosoftWindowsServer",
"version" : "latest",
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite",
"createOption" : "FromImage",
"name" : "osDisk"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}",
"adminUsername" : "{your-username}",
"adminPassword" : "{your-password}"
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"primary" : true,
"enableIPForwarding" : true,
"ipConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
}
}
]
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Automatic",
"automaticOSUpgradePolicy" : {
"enableAutomaticOSUpgrade" : true
}
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineScaleSetInner;
import com.azure.resourcemanager.compute.models.ApiEntityReference;
import com.azure.resourcemanager.compute.models.AutomaticOSUpgradePolicy;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.ServiceArtifactReference;
import com.azure.resourcemanager.compute.models.Sku;
import com.azure.resourcemanager.compute.models.UpgradeMode;
import com.azure.resourcemanager.compute.models.UpgradePolicy;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetIpConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSDisk;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetStorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetVMProfile;
import java.util.Arrays;
public final class Main {
public static void createAScaleSetWithServiceArtifactReference (
com.azure.resourcemanager.AzureResourceManager azure) {
azure
.virtualMachines()
.manager()
.serviceClient()
.getVirtualMachineScaleSets()
.createOrUpdate(
"myResourceGroup" ,
"{vmss-name}" ,
new VirtualMachineScaleSetInner()
.withLocation("eastus2euap" )
.withSku(new Sku().withName("Standard_A1" ).withTier("Standard" ).withCapacity(3L ))
.withUpgradePolicy(
new UpgradePolicy()
.withMode(UpgradeMode.AUTOMATIC)
.withAutomaticOSUpgradePolicy(
new AutomaticOSUpgradePolicy().withEnableAutomaticOSUpgrade(true )))
.withVirtualMachineProfile(
new VirtualMachineScaleSetVMProfile()
.withOsProfile(
new VirtualMachineScaleSetOSProfile()
.withComputerNamePrefix("{vmss-name}" )
.withAdminUsername("{your-username}" )
.withAdminPassword("fakeTokenPlaceholder" ))
.withStorageProfile(
new VirtualMachineScaleSetStorageProfile()
.withImageReference(
new ImageReference()
.withPublisher("MicrosoftWindowsServer" )
.withOffer("WindowsServer" )
.withSku("2022-Datacenter" )
.withVersion("latest" ))
.withOsDisk(
new VirtualMachineScaleSetOSDisk()
.withName("osDisk" )
.withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)))
.withNetworkProfile(
new VirtualMachineScaleSetNetworkProfile()
.withNetworkInterfaceConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetNetworkConfiguration()
.withName("{vmss-name}" )
.withPrimary(true )
.withIpConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetIpConfiguration()
.withName("{vmss-name}" )
.withSubnet(
new ApiEntityReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ))))
.withEnableIpForwarding(true ))))
.withServiceArtifactReference(
new ServiceArtifactReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/myGalleryName/serviceArtifacts/serviceArtifactName/vmArtifactsProfiles/vmArtifactsProfilesName" )))
.withOverprovision(true ),
com.azure.core.util.Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_scale_set_create_with_service_artifact_reference.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main () :
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="{subscription-id}" ,
)
response = client.virtual_machine_scale_sets.begin_create_or_update(
resource_group_name="myResourceGroup" ,
vm_scale_set_name="{vmss-name}" ,
parameters={
"location" : "eastus2euap" ,
"properties" : {
"overprovision" : True ,
"upgradePolicy" : {"automaticOSUpgradePolicy" : {"enableAutomaticOSUpgrade" : True }, "mode" : "Automatic" },
"virtualMachineProfile" : {
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"enableIPForwarding" : True ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
},
}
],
"primary" : True ,
},
}
]
},
"osProfile" : {
"adminPassword" : "{your-password}" ,
"adminUsername" : "{your-username}" ,
"computerNamePrefix" : "{vmss-name}" ,
},
"serviceArtifactReference" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/myGalleryName/serviceArtifacts/serviceArtifactName/vmArtifactsProfiles/vmArtifactsProfilesName"
},
"storageProfile" : {
"imageReference" : {
"offer" : "WindowsServer" ,
"publisher" : "MicrosoftWindowsServer" ,
"sku" : "2022-Datacenter" ,
"version" : "latest" ,
},
"osDisk" : {"caching" : "ReadWrite" , "createOption" : "FromImage" , "name" : "osDisk" },
},
},
},
"sku" : {"capacity" : 3 , "name" : "Standard_A1" , "tier" : "Standard" },
},
).result()
print(response)
if __name__ == "__main__" :
main()
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4"
)
func ExampleVirtualMachineScaleSetsClient_BeginCreateOrUpdate_createAScaleSetWithServiceArtifactReference () {
cred, err := azidentity.NewDefaultAzureCredential(nil )
if err != nil {
log.Fatalf("failed to obtain a credential: %v" , err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("<subscription-id>" , cred, nil )
if err != nil {
log.Fatalf("failed to create client: %v" , err)
}
poller, err := clientFactory.NewVirtualMachineScaleSetsClient().BeginCreateOrUpdate(ctx, "myResourceGroup" , "{vmss-name}" , armcompute.VirtualMachineScaleSet{
Location: to.Ptr("eastus2euap" ),
Properties: &armcompute.VirtualMachineScaleSetProperties{
Overprovision: to.Ptr(true ),
UpgradePolicy: &armcompute.UpgradePolicy{
AutomaticOSUpgradePolicy: &armcompute.AutomaticOSUpgradePolicy{
EnableAutomaticOSUpgrade: to.Ptr(true ),
},
Mode: to.Ptr(armcompute.UpgradeModeAutomatic),
},
VirtualMachineProfile: &armcompute.VirtualMachineScaleSetVMProfile{
NetworkProfile: &armcompute.VirtualMachineScaleSetNetworkProfile{
NetworkInterfaceConfigurations: []*armcompute.VirtualMachineScaleSetNetworkConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetNetworkConfigurationProperties{
EnableIPForwarding: to.Ptr(true ),
IPConfigurations: []*armcompute.VirtualMachineScaleSetIPConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetIPConfigurationProperties{
Subnet: &armcompute.APIEntityReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
},
},
}},
Primary: to.Ptr(true ),
},
}},
},
OSProfile: &armcompute.VirtualMachineScaleSetOSProfile{
AdminPassword: to.Ptr("{your-password}" ),
AdminUsername: to.Ptr("{your-username}" ),
ComputerNamePrefix: to.Ptr("{vmss-name}" ),
},
ServiceArtifactReference: &armcompute.ServiceArtifactReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/myGalleryName/serviceArtifacts/serviceArtifactName/vmArtifactsProfiles/vmArtifactsProfilesName" ),
},
StorageProfile: &armcompute.VirtualMachineScaleSetStorageProfile{
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("WindowsServer" ),
Publisher: to.Ptr("MicrosoftWindowsServer" ),
SKU: to.Ptr("2022-Datacenter" ),
Version: to.Ptr("latest" ),
},
OSDisk: &armcompute.VirtualMachineScaleSetOSDisk{
Name: to.Ptr("osDisk" ),
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
},
},
},
},
SKU: &armcompute.SKU{
Name: to.Ptr("Standard_A1" ),
Capacity: to.Ptr[int64 ](3 ),
Tier: to.Ptr("Standard" ),
},
}, nil )
if err != nil {
log.Fatalf("failed to finish the request: %v" , err)
}
res, err := poller.PollUntilDone(ctx, nil )
if err != nil {
log.Fatalf("failed to pull the result: %v" , err)
}
_ = res
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require ("@azure/arm-compute" );
const { DefaultAzureCredential } = require ("@azure/identity" );
async function createAScaleSetWithServiceArtifactReference ( ) {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID" ] || "{subscription-id}" ;
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP" ] || "myResourceGroup" ;
const vmScaleSetName = "{vmss-name}" ;
const parameters = {
location : "eastus2euap" ,
overprovision : true ,
sku : { name : "Standard_A1" , capacity : 3 , tier : "Standard" },
upgradePolicy : {
automaticOSUpgradePolicy : { enableAutomaticOSUpgrade : true },
mode : "Automatic" ,
},
virtualMachineProfile : {
networkProfile : {
networkInterfaceConfigurations : [
{
name : "{vmss-name}" ,
enableIPForwarding : true ,
ipConfigurations : [
{
name : "{vmss-name}" ,
subnet : {
id : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ,
},
},
],
primary : true ,
},
],
},
osProfile : {
adminPassword : "{your-password}" ,
adminUsername : "{your-username}" ,
computerNamePrefix : "{vmss-name}" ,
},
serviceArtifactReference : {
id : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/myGalleryName/serviceArtifacts/serviceArtifactName/vmArtifactsProfiles/vmArtifactsProfilesName" ,
},
storageProfile : {
imageReference : {
offer : "WindowsServer" ,
publisher : "MicrosoftWindowsServer" ,
sku : "2022-Datacenter" ,
version : "latest" ,
},
osDisk : {
name : "osDisk" ,
caching : "ReadWrite" ,
createOption : "FromImage" ,
},
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachineScaleSets.beginCreateOrUpdateAndWait(
resourceGroupName,
vmScaleSetName,
parameters
);
console .log(result);
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Compute;
using Azure.ResourceManager.Compute.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Resources.Models;
TokenCredential cred = new DefaultAzureCredential();
ArmClient client = new ArmClient(cred);
string subscriptionId = "{subscription-id}" ;
string resourceGroupName = "myResourceGroup" ;
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
VirtualMachineScaleSetCollection collection = resourceGroupResource.GetVirtualMachineScaleSets();
string virtualMachineScaleSetName = "{vmss-name}" ;
VirtualMachineScaleSetData data = new VirtualMachineScaleSetData(new AzureLocation("eastus2euap" ))
{
Sku = new ComputeSku()
{
Name = "Standard_A1" ,
Tier = "Standard" ,
Capacity = 3 ,
},
UpgradePolicy = new VirtualMachineScaleSetUpgradePolicy()
{
Mode = VirtualMachineScaleSetUpgradeMode.Automatic,
AutomaticOSUpgradePolicy = new AutomaticOSUpgradePolicy()
{
EnableAutomaticOSUpgrade = true ,
},
},
VirtualMachineProfile = new VirtualMachineScaleSetVmProfile()
{
OSProfile = new VirtualMachineScaleSetOSProfile()
{
ComputerNamePrefix = "{vmss-name}" ,
AdminUsername = "{your-username}" ,
AdminPassword = "{your-password}" ,
},
StorageProfile = new VirtualMachineScaleSetStorageProfile()
{
ImageReference = new ImageReference()
{
Publisher = "MicrosoftWindowsServer" ,
Offer = "WindowsServer" ,
Sku = "2022-Datacenter" ,
Version = "latest" ,
},
OSDisk = new VirtualMachineScaleSetOSDisk(DiskCreateOptionType.FromImage)
{
Name = "osDisk" ,
Caching = CachingType.ReadWrite,
},
},
NetworkProfile = new VirtualMachineScaleSetNetworkProfile()
{
NetworkInterfaceConfigurations =
{
new VirtualMachineScaleSetNetworkConfiguration("{vmss-name}" )
{
Primary = true ,
IPConfigurations =
{
new VirtualMachineScaleSetIPConfiguration("{vmss-name}" )
{
SubnetId = new ResourceIdentifier("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
}
},
EnableIPForwarding = true ,
}
},
},
ServiceArtifactReferenceId = new ResourceIdentifier("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/myGalleryName/serviceArtifacts/serviceArtifactName/vmArtifactsProfiles/vmArtifactsProfilesName" ),
},
Overprovision = true ,
};
ArmOperation<VirtualMachineScaleSetResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, virtualMachineScaleSetName, data);
VirtualMachineScaleSetResource result = lro.Value;
VirtualMachineScaleSetData resourceData = result.Data;
Console.WriteLine($"Succeeded on id: {resourceData.Id} " );
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
範例回覆
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_A1"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "77b7df9a-32fe-45e3-8911-60ac9c9b9c64" ,
"virtualMachineProfile" : {
"serviceArtifactReference" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/myGalleryName/serviceArtifacts/serviceArtifactName/vmArtifactsProfiles/vmArtifactsProfilesName"
},
"storageProfile" : {
"imageReference" : {
"sku" : "2022-Datacenter" ,
"publisher" : "MicrosoftWindowsServer" ,
"version" : "latest" ,
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"name" : "osDisk" ,
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Automatic" ,
"automaticOSUpgradePolicy" : {
"enableAutomaticOSUpgrade" : true
}
},
"provisioningState" : "Creating"
},
"location" : "eastus2euap" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_A1"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "77b7df9a-32fe-45e3-8911-60ac9c9b9c64" ,
"virtualMachineProfile" : {
"serviceArtifactReference" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/myGalleryName/serviceArtifacts/serviceArtifactName/vmArtifactsProfiles/vmArtifactsProfilesName"
},
"storageProfile" : {
"imageReference" : {
"sku" : "2022-Datacenter" ,
"publisher" : "MicrosoftWindowsServer" ,
"version" : "latest" ,
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"name" : "osDisk" ,
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Automatic" ,
"automaticOSUpgradePolicy" : {
"enableAutomaticOSUpgrade" : true
}
},
"provisioningState" : "Creating"
},
"location" : "eastus2euap" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
Create a scale set with spot restore policy
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}?api-version=2022-11-01
{
"sku" : {
"tier" : "Standard",
"capacity" : 2,
"name" : "Standard_A8m_v2"
},
"location" : "westus",
"properties" : {
"overprovision" : true,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter",
"publisher" : "MicrosoftWindowsServer",
"version" : "latest",
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite",
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}",
"adminUsername" : "{your-username}",
"adminPassword" : "{your-password}"
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"primary" : true,
"enableIPForwarding" : true,
"ipConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
}
}
]
}
}
]
},
"priority" : "Spot",
"evictionPolicy" : "Deallocate",
"billingProfile" : {
"maxPrice" : -1
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"spotRestorePolicy" : {
"enabled" : true,
"restoreTimeout" : "PT1H"
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineScaleSetInner;
import com.azure.resourcemanager.compute.models.ApiEntityReference;
import com.azure.resourcemanager.compute.models.BillingProfile;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.Sku;
import com.azure.resourcemanager.compute.models.SpotRestorePolicy;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.UpgradeMode;
import com.azure.resourcemanager.compute.models.UpgradePolicy;
import com.azure.resourcemanager.compute.models.VirtualMachineEvictionPolicyTypes;
import com.azure.resourcemanager.compute.models.VirtualMachinePriorityTypes;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetIpConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetManagedDiskParameters;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSDisk;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetStorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetVMProfile;
import java.util.Arrays;
public final class Main {
public static void createAScaleSetWithSpotRestorePolicy (com.azure.resourcemanager.AzureResourceManager azure) {
azure
.virtualMachines()
.manager()
.serviceClient()
.getVirtualMachineScaleSets()
.createOrUpdate(
"myResourceGroup" ,
"{vmss-name}" ,
new VirtualMachineScaleSetInner()
.withLocation("westus" )
.withSku(new Sku().withName("Standard_A8m_v2" ).withTier("Standard" ).withCapacity(2L ))
.withUpgradePolicy(new UpgradePolicy().withMode(UpgradeMode.MANUAL))
.withVirtualMachineProfile(
new VirtualMachineScaleSetVMProfile()
.withOsProfile(
new VirtualMachineScaleSetOSProfile()
.withComputerNamePrefix("{vmss-name}" )
.withAdminUsername("{your-username}" )
.withAdminPassword("fakeTokenPlaceholder" ))
.withStorageProfile(
new VirtualMachineScaleSetStorageProfile()
.withImageReference(
new ImageReference()
.withPublisher("MicrosoftWindowsServer" )
.withOffer("WindowsServer" )
.withSku("2016-Datacenter" )
.withVersion("latest" ))
.withOsDisk(
new VirtualMachineScaleSetOSDisk()
.withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)
.withManagedDisk(
new VirtualMachineScaleSetManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withNetworkProfile(
new VirtualMachineScaleSetNetworkProfile()
.withNetworkInterfaceConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetNetworkConfiguration()
.withName("{vmss-name}" )
.withPrimary(true )
.withIpConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetIpConfiguration()
.withName("{vmss-name}" )
.withSubnet(
new ApiEntityReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ))))
.withEnableIpForwarding(true ))))
.withPriority(VirtualMachinePriorityTypes.SPOT)
.withEvictionPolicy(VirtualMachineEvictionPolicyTypes.DEALLOCATE)
.withBillingProfile(new BillingProfile().withMaxPrice(-1.0 D)))
.withOverprovision(true )
.withSpotRestorePolicy(new SpotRestorePolicy().withEnabled(true ).withRestoreTimeout("PT1H" )),
com.azure.core.util.Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_scale_set_create_with_spot_restore_policy.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main () :
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="{subscription-id}" ,
)
response = client.virtual_machine_scale_sets.begin_create_or_update(
resource_group_name="myResourceGroup" ,
vm_scale_set_name="{vmss-name}" ,
parameters={
"location" : "westus" ,
"properties" : {
"overprovision" : True ,
"spotRestorePolicy" : {"enabled" : True , "restoreTimeout" : "PT1H" },
"upgradePolicy" : {"mode" : "Manual" },
"virtualMachineProfile" : {
"billingProfile" : {"maxPrice" : -1 },
"evictionPolicy" : "Deallocate" ,
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"enableIPForwarding" : True ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
},
}
],
"primary" : True ,
},
}
]
},
"osProfile" : {
"adminPassword" : "{your-password}" ,
"adminUsername" : "{your-username}" ,
"computerNamePrefix" : "{vmss-name}" ,
},
"priority" : "Spot" ,
"storageProfile" : {
"imageReference" : {
"offer" : "WindowsServer" ,
"publisher" : "MicrosoftWindowsServer" ,
"sku" : "2016-Datacenter" ,
"version" : "latest" ,
},
"osDisk" : {
"caching" : "ReadWrite" ,
"createOption" : "FromImage" ,
"managedDisk" : {"storageAccountType" : "Standard_LRS" },
},
},
},
},
"sku" : {"capacity" : 2 , "name" : "Standard_A8m_v2" , "tier" : "Standard" },
},
).result()
print(response)
if __name__ == "__main__" :
main()
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4"
)
func ExampleVirtualMachineScaleSetsClient_BeginCreateOrUpdate_createAScaleSetWithSpotRestorePolicy () {
cred, err := azidentity.NewDefaultAzureCredential(nil )
if err != nil {
log.Fatalf("failed to obtain a credential: %v" , err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("<subscription-id>" , cred, nil )
if err != nil {
log.Fatalf("failed to create client: %v" , err)
}
poller, err := clientFactory.NewVirtualMachineScaleSetsClient().BeginCreateOrUpdate(ctx, "myResourceGroup" , "{vmss-name}" , armcompute.VirtualMachineScaleSet{
Location: to.Ptr("westus" ),
Properties: &armcompute.VirtualMachineScaleSetProperties{
Overprovision: to.Ptr(true ),
SpotRestorePolicy: &armcompute.SpotRestorePolicy{
Enabled: to.Ptr(true ),
RestoreTimeout: to.Ptr("PT1H" ),
},
UpgradePolicy: &armcompute.UpgradePolicy{
Mode: to.Ptr(armcompute.UpgradeModeManual),
},
VirtualMachineProfile: &armcompute.VirtualMachineScaleSetVMProfile{
BillingProfile: &armcompute.BillingProfile{
MaxPrice: to.Ptr[float64 ](-1 ),
},
EvictionPolicy: to.Ptr(armcompute.VirtualMachineEvictionPolicyTypesDeallocate),
NetworkProfile: &armcompute.VirtualMachineScaleSetNetworkProfile{
NetworkInterfaceConfigurations: []*armcompute.VirtualMachineScaleSetNetworkConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetNetworkConfigurationProperties{
EnableIPForwarding: to.Ptr(true ),
IPConfigurations: []*armcompute.VirtualMachineScaleSetIPConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetIPConfigurationProperties{
Subnet: &armcompute.APIEntityReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
},
},
}},
Primary: to.Ptr(true ),
},
}},
},
OSProfile: &armcompute.VirtualMachineScaleSetOSProfile{
AdminPassword: to.Ptr("{your-password}" ),
AdminUsername: to.Ptr("{your-username}" ),
ComputerNamePrefix: to.Ptr("{vmss-name}" ),
},
Priority: to.Ptr(armcompute.VirtualMachinePriorityTypesSpot),
StorageProfile: &armcompute.VirtualMachineScaleSetStorageProfile{
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("WindowsServer" ),
Publisher: to.Ptr("MicrosoftWindowsServer" ),
SKU: to.Ptr("2016-Datacenter" ),
Version: to.Ptr("latest" ),
},
OSDisk: &armcompute.VirtualMachineScaleSetOSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.VirtualMachineScaleSetManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
},
},
SKU: &armcompute.SKU{
Name: to.Ptr("Standard_A8m_v2" ),
Capacity: to.Ptr[int64 ](2 ),
Tier: to.Ptr("Standard" ),
},
}, nil )
if err != nil {
log.Fatalf("failed to finish the request: %v" , err)
}
res, err := poller.PollUntilDone(ctx, nil )
if err != nil {
log.Fatalf("failed to pull the result: %v" , err)
}
_ = res
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require ("@azure/arm-compute" );
const { DefaultAzureCredential } = require ("@azure/identity" );
async function createAScaleSetWithSpotRestorePolicy ( ) {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID" ] || "{subscription-id}" ;
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP" ] || "myResourceGroup" ;
const vmScaleSetName = "{vmss-name}" ;
const parameters = {
location : "westus" ,
overprovision : true ,
sku : { name : "Standard_A8m_v2" , capacity : 2 , tier : "Standard" },
spotRestorePolicy : { enabled : true , restoreTimeout : "PT1H" },
upgradePolicy : { mode : "Manual" },
virtualMachineProfile : {
billingProfile : { maxPrice : -1 },
evictionPolicy : "Deallocate" ,
networkProfile : {
networkInterfaceConfigurations : [
{
name : "{vmss-name}" ,
enableIPForwarding : true ,
ipConfigurations : [
{
name : "{vmss-name}" ,
subnet : {
id : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ,
},
},
],
primary : true ,
},
],
},
osProfile : {
adminPassword : "{your-password}" ,
adminUsername : "{your-username}" ,
computerNamePrefix : "{vmss-name}" ,
},
priority : "Spot" ,
storageProfile : {
imageReference : {
offer : "WindowsServer" ,
publisher : "MicrosoftWindowsServer" ,
sku : "2016-Datacenter" ,
version : "latest" ,
},
osDisk : {
caching : "ReadWrite" ,
createOption : "FromImage" ,
managedDisk : { storageAccountType : "Standard_LRS" },
},
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachineScaleSets.beginCreateOrUpdateAndWait(
resourceGroupName,
vmScaleSetName,
parameters
);
console .log(result);
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Compute;
using Azure.ResourceManager.Compute.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Resources.Models;
TokenCredential cred = new DefaultAzureCredential();
ArmClient client = new ArmClient(cred);
string subscriptionId = "{subscription-id}" ;
string resourceGroupName = "myResourceGroup" ;
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
VirtualMachineScaleSetCollection collection = resourceGroupResource.GetVirtualMachineScaleSets();
string virtualMachineScaleSetName = "{vmss-name}" ;
VirtualMachineScaleSetData data = new VirtualMachineScaleSetData(new AzureLocation("westus" ))
{
Sku = new ComputeSku()
{
Name = "Standard_A8m_v2" ,
Tier = "Standard" ,
Capacity = 2 ,
},
UpgradePolicy = new VirtualMachineScaleSetUpgradePolicy()
{
Mode = VirtualMachineScaleSetUpgradeMode.Manual,
},
VirtualMachineProfile = new VirtualMachineScaleSetVmProfile()
{
OSProfile = new VirtualMachineScaleSetOSProfile()
{
ComputerNamePrefix = "{vmss-name}" ,
AdminUsername = "{your-username}" ,
AdminPassword = "{your-password}" ,
},
StorageProfile = new VirtualMachineScaleSetStorageProfile()
{
ImageReference = new ImageReference()
{
Publisher = "MicrosoftWindowsServer" ,
Offer = "WindowsServer" ,
Sku = "2016-Datacenter" ,
Version = "latest" ,
},
OSDisk = new VirtualMachineScaleSetOSDisk(DiskCreateOptionType.FromImage)
{
Caching = CachingType.ReadWrite,
ManagedDisk = new VirtualMachineScaleSetManagedDisk()
{
StorageAccountType = StorageAccountType.StandardLrs,
},
},
},
NetworkProfile = new VirtualMachineScaleSetNetworkProfile()
{
NetworkInterfaceConfigurations =
{
new VirtualMachineScaleSetNetworkConfiguration("{vmss-name}" )
{
Primary = true ,
IPConfigurations =
{
new VirtualMachineScaleSetIPConfiguration("{vmss-name}" )
{
SubnetId = new ResourceIdentifier("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
}
},
EnableIPForwarding = true ,
}
},
},
Priority = VirtualMachinePriorityType.Spot,
EvictionPolicy = VirtualMachineEvictionPolicyType.Deallocate,
BillingMaxPrice = -1 ,
},
Overprovision = true ,
SpotRestorePolicy = new SpotRestorePolicy()
{
Enabled = true ,
RestoreTimeout = "PT1H" ,
},
};
ArmOperation<VirtualMachineScaleSetResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, virtualMachineScaleSetName, data);
VirtualMachineScaleSetResource result = lro.Value;
VirtualMachineScaleSetData resourceData = result.Data;
Console.WriteLine($"Succeeded on id: {resourceData.Id} " );
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
範例回覆
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 2 ,
"name" : "Standard_A8m_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "d053ec5a-8da6-495f-ab13-38216503c6d7" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter" ,
"publisher" : "MicrosoftWindowsServer" ,
"version" : "latest" ,
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
},
"priority" : "Spot" ,
"evictionPolicy" : "Deallocate" ,
"billingProfile" : {
"maxPrice" : -1
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"spotRestorePolicy" : {
"enabled" : true ,
"restoreTimeout" : "PT1H"
},
"provisioningState" : "Creating"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 2 ,
"name" : "Standard_A8m_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "d053ec5a-8da6-495f-ab13-38216503c6d7" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter" ,
"publisher" : "MicrosoftWindowsServer" ,
"version" : "latest" ,
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
},
"priority" : "Spot" ,
"evictionPolicy" : "Deallocate" ,
"billingProfile" : {
"maxPrice" : -1
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"spotRestorePolicy" : {
"enabled" : true ,
"restoreTimeout" : "PT1H"
},
"provisioningState" : "Creating"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
Create a scale set with ssh authentication.
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}?api-version=2022-11-01
{
"sku" : {
"tier" : "Standard",
"capacity" : 3,
"name" : "Standard_D1_v2"
},
"location" : "westus",
"properties" : {
"overprovision" : true,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter",
"publisher" : "MicrosoftWindowsServer",
"version" : "latest",
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite",
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}",
"adminUsername" : "{your-username}",
"linuxConfiguration" : {
"ssh" : {
"publicKeys" : [
{
"path" : "/home/{your-username}/.ssh/authorized_keys",
"keyData" : "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCeClRAk2ipUs/l5voIsDC5q9RI+YSRd1Bvd/O+axgY4WiBzG+4FwJWZm/mLLe5DoOdHQwmU2FrKXZSW4w2sYE70KeWnrFViCOX5MTVvJgPE8ClugNl8RWth/tU849DvM9sT7vFgfVSHcAS2yDRyDlueii+8nF2ym8XWAPltFVCyLHRsyBp5YPqK8JFYIa1eybKsY3hEAxRCA+/7bq8et+Gj3coOsuRmrehav7rE6N12Pb80I6ofa6SM5XNYq4Xk0iYNx7R3kdz0Jj9XgZYWjAHjJmT0gTRoOnt6upOuxK7xI/ykWrllgpXrCPu3Ymz+c+ujaqcxDopnAl2lmf69/J1"
}
]
},
"disablePasswordAuthentication" : true
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"primary" : true,
"enableIPForwarding" : true,
"ipConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
}
}
]
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineScaleSetInner;
import com.azure.resourcemanager.compute.models.ApiEntityReference;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.LinuxConfiguration;
import com.azure.resourcemanager.compute.models.Sku;
import com.azure.resourcemanager.compute.models.SshConfiguration;
import com.azure.resourcemanager.compute.models.SshPublicKey;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.UpgradeMode;
import com.azure.resourcemanager.compute.models.UpgradePolicy;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetIpConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetManagedDiskParameters;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSDisk;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetStorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetVMProfile;
import java.util.Arrays;
public final class Main {
public static void createAScaleSetWithSshAuthentication (com.azure.resourcemanager.AzureResourceManager azure) {
azure
.virtualMachines()
.manager()
.serviceClient()
.getVirtualMachineScaleSets()
.createOrUpdate(
"myResourceGroup" ,
"{vmss-name}" ,
new VirtualMachineScaleSetInner()
.withLocation("westus" )
.withSku(new Sku().withName("Standard_D1_v2" ).withTier("Standard" ).withCapacity(3L ))
.withUpgradePolicy(new UpgradePolicy().withMode(UpgradeMode.MANUAL))
.withVirtualMachineProfile(
new VirtualMachineScaleSetVMProfile()
.withOsProfile(
new VirtualMachineScaleSetOSProfile()
.withComputerNamePrefix("{vmss-name}" )
.withAdminUsername("{your-username}" )
.withLinuxConfiguration(
new LinuxConfiguration()
.withDisablePasswordAuthentication(true )
.withSsh(
new SshConfiguration()
.withPublicKeys(
Arrays
.asList(
new SshPublicKey()
.withPath(
"/home/{your-username}/.ssh/authorized_keys" )
.withKeyData("fakeTokenPlaceholder" ))))))
.withStorageProfile(
new VirtualMachineScaleSetStorageProfile()
.withImageReference(
new ImageReference()
.withPublisher("MicrosoftWindowsServer" )
.withOffer("WindowsServer" )
.withSku("2016-Datacenter" )
.withVersion("latest" ))
.withOsDisk(
new VirtualMachineScaleSetOSDisk()
.withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)
.withManagedDisk(
new VirtualMachineScaleSetManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withNetworkProfile(
new VirtualMachineScaleSetNetworkProfile()
.withNetworkInterfaceConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetNetworkConfiguration()
.withName("{vmss-name}" )
.withPrimary(true )
.withIpConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetIpConfiguration()
.withName("{vmss-name}" )
.withSubnet(
new ApiEntityReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ))))
.withEnableIpForwarding(true )))))
.withOverprovision(true ),
com.azure.core.util.Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_scale_set_create_with_ssh_authentication.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main () :
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="{subscription-id}" ,
)
response = client.virtual_machine_scale_sets.begin_create_or_update(
resource_group_name="myResourceGroup" ,
vm_scale_set_name="{vmss-name}" ,
parameters={
"location" : "westus" ,
"properties" : {
"overprovision" : True ,
"upgradePolicy" : {"mode" : "Manual" },
"virtualMachineProfile" : {
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"enableIPForwarding" : True ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
},
}
],
"primary" : True ,
},
}
]
},
"osProfile" : {
"adminUsername" : "{your-username}" ,
"computerNamePrefix" : "{vmss-name}" ,
"linuxConfiguration" : {
"disablePasswordAuthentication" : True ,
"ssh" : {
"publicKeys" : [
{
"keyData" : "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCeClRAk2ipUs/l5voIsDC5q9RI+YSRd1Bvd/O+axgY4WiBzG+4FwJWZm/mLLe5DoOdHQwmU2FrKXZSW4w2sYE70KeWnrFViCOX5MTVvJgPE8ClugNl8RWth/tU849DvM9sT7vFgfVSHcAS2yDRyDlueii+8nF2ym8XWAPltFVCyLHRsyBp5YPqK8JFYIa1eybKsY3hEAxRCA+/7bq8et+Gj3coOsuRmrehav7rE6N12Pb80I6ofa6SM5XNYq4Xk0iYNx7R3kdz0Jj9XgZYWjAHjJmT0gTRoOnt6upOuxK7xI/ykWrllgpXrCPu3Ymz+c+ujaqcxDopnAl2lmf69/J1" ,
"path" : "/home/{your-username}/.ssh/authorized_keys" ,
}
]
},
},
},
"storageProfile" : {
"imageReference" : {
"offer" : "WindowsServer" ,
"publisher" : "MicrosoftWindowsServer" ,
"sku" : "2016-Datacenter" ,
"version" : "latest" ,
},
"osDisk" : {
"caching" : "ReadWrite" ,
"createOption" : "FromImage" ,
"managedDisk" : {"storageAccountType" : "Standard_LRS" },
},
},
},
},
"sku" : {"capacity" : 3 , "name" : "Standard_D1_v2" , "tier" : "Standard" },
},
).result()
print(response)
if __name__ == "__main__" :
main()
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4"
)
func ExampleVirtualMachineScaleSetsClient_BeginCreateOrUpdate_createAScaleSetWithSshAuthentication () {
cred, err := azidentity.NewDefaultAzureCredential(nil )
if err != nil {
log.Fatalf("failed to obtain a credential: %v" , err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("<subscription-id>" , cred, nil )
if err != nil {
log.Fatalf("failed to create client: %v" , err)
}
poller, err := clientFactory.NewVirtualMachineScaleSetsClient().BeginCreateOrUpdate(ctx, "myResourceGroup" , "{vmss-name}" , armcompute.VirtualMachineScaleSet{
Location: to.Ptr("westus" ),
Properties: &armcompute.VirtualMachineScaleSetProperties{
Overprovision: to.Ptr(true ),
UpgradePolicy: &armcompute.UpgradePolicy{
Mode: to.Ptr(armcompute.UpgradeModeManual),
},
VirtualMachineProfile: &armcompute.VirtualMachineScaleSetVMProfile{
NetworkProfile: &armcompute.VirtualMachineScaleSetNetworkProfile{
NetworkInterfaceConfigurations: []*armcompute.VirtualMachineScaleSetNetworkConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetNetworkConfigurationProperties{
EnableIPForwarding: to.Ptr(true ),
IPConfigurations: []*armcompute.VirtualMachineScaleSetIPConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetIPConfigurationProperties{
Subnet: &armcompute.APIEntityReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
},
},
}},
Primary: to.Ptr(true ),
},
}},
},
OSProfile: &armcompute.VirtualMachineScaleSetOSProfile{
AdminUsername: to.Ptr("{your-username}" ),
ComputerNamePrefix: to.Ptr("{vmss-name}" ),
LinuxConfiguration: &armcompute.LinuxConfiguration{
DisablePasswordAuthentication: to.Ptr(true ),
SSH: &armcompute.SSHConfiguration{
PublicKeys: []*armcompute.SSHPublicKey{
{
Path: to.Ptr("/home/{your-username}/.ssh/authorized_keys" ),
KeyData: to.Ptr("ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCeClRAk2ipUs/l5voIsDC5q9RI+YSRd1Bvd/O+axgY4WiBzG+4FwJWZm/mLLe5DoOdHQwmU2FrKXZSW4w2sYE70KeWnrFViCOX5MTVvJgPE8ClugNl8RWth/tU849DvM9sT7vFgfVSHcAS2yDRyDlueii+8nF2ym8XWAPltFVCyLHRsyBp5YPqK8JFYIa1eybKsY3hEAxRCA+/7bq8et+Gj3coOsuRmrehav7rE6N12Pb80I6ofa6SM5XNYq4Xk0iYNx7R3kdz0Jj9XgZYWjAHjJmT0gTRoOnt6upOuxK7xI/ykWrllgpXrCPu3Ymz+c+ujaqcxDopnAl2lmf69/J1" ),
}},
},
},
},
StorageProfile: &armcompute.VirtualMachineScaleSetStorageProfile{
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("WindowsServer" ),
Publisher: to.Ptr("MicrosoftWindowsServer" ),
SKU: to.Ptr("2016-Datacenter" ),
Version: to.Ptr("latest" ),
},
OSDisk: &armcompute.VirtualMachineScaleSetOSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.VirtualMachineScaleSetManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
},
},
SKU: &armcompute.SKU{
Name: to.Ptr("Standard_D1_v2" ),
Capacity: to.Ptr[int64 ](3 ),
Tier: to.Ptr("Standard" ),
},
}, nil )
if err != nil {
log.Fatalf("failed to finish the request: %v" , err)
}
res, err := poller.PollUntilDone(ctx, nil )
if err != nil {
log.Fatalf("failed to pull the result: %v" , err)
}
_ = res
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require ("@azure/arm-compute" );
const { DefaultAzureCredential } = require ("@azure/identity" );
async function createAScaleSetWithSshAuthentication ( ) {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID" ] || "{subscription-id}" ;
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP" ] || "myResourceGroup" ;
const vmScaleSetName = "{vmss-name}" ;
const parameters = {
location : "westus" ,
overprovision : true ,
sku : { name : "Standard_D1_v2" , capacity : 3 , tier : "Standard" },
upgradePolicy : { mode : "Manual" },
virtualMachineProfile : {
networkProfile : {
networkInterfaceConfigurations : [
{
name : "{vmss-name}" ,
enableIPForwarding : true ,
ipConfigurations : [
{
name : "{vmss-name}" ,
subnet : {
id : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ,
},
},
],
primary : true ,
},
],
},
osProfile : {
adminUsername : "{your-username}" ,
computerNamePrefix : "{vmss-name}" ,
linuxConfiguration : {
disablePasswordAuthentication : true ,
ssh : {
publicKeys : [
{
path : "/home/{your-username}/.ssh/authorized_keys" ,
keyData :
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCeClRAk2ipUs/l5voIsDC5q9RI+YSRd1Bvd/O+axgY4WiBzG+4FwJWZm/mLLe5DoOdHQwmU2FrKXZSW4w2sYE70KeWnrFViCOX5MTVvJgPE8ClugNl8RWth/tU849DvM9sT7vFgfVSHcAS2yDRyDlueii+8nF2ym8XWAPltFVCyLHRsyBp5YPqK8JFYIa1eybKsY3hEAxRCA+/7bq8et+Gj3coOsuRmrehav7rE6N12Pb80I6ofa6SM5XNYq4Xk0iYNx7R3kdz0Jj9XgZYWjAHjJmT0gTRoOnt6upOuxK7xI/ykWrllgpXrCPu3Ymz+c+ujaqcxDopnAl2lmf69/J1" ,
},
],
},
},
},
storageProfile : {
imageReference : {
offer : "WindowsServer" ,
publisher : "MicrosoftWindowsServer" ,
sku : "2016-Datacenter" ,
version : "latest" ,
},
osDisk : {
caching : "ReadWrite" ,
createOption : "FromImage" ,
managedDisk : { storageAccountType : "Standard_LRS" },
},
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachineScaleSets.beginCreateOrUpdateAndWait(
resourceGroupName,
vmScaleSetName,
parameters
);
console .log(result);
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Compute;
using Azure.ResourceManager.Compute.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Resources.Models;
TokenCredential cred = new DefaultAzureCredential();
ArmClient client = new ArmClient(cred);
string subscriptionId = "{subscription-id}" ;
string resourceGroupName = "myResourceGroup" ;
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
VirtualMachineScaleSetCollection collection = resourceGroupResource.GetVirtualMachineScaleSets();
string virtualMachineScaleSetName = "{vmss-name}" ;
VirtualMachineScaleSetData data = new VirtualMachineScaleSetData(new AzureLocation("westus" ))
{
Sku = new ComputeSku()
{
Name = "Standard_D1_v2" ,
Tier = "Standard" ,
Capacity = 3 ,
},
UpgradePolicy = new VirtualMachineScaleSetUpgradePolicy()
{
Mode = VirtualMachineScaleSetUpgradeMode.Manual,
},
VirtualMachineProfile = new VirtualMachineScaleSetVmProfile()
{
OSProfile = new VirtualMachineScaleSetOSProfile()
{
ComputerNamePrefix = "{vmss-name}" ,
AdminUsername = "{your-username}" ,
LinuxConfiguration = new LinuxConfiguration()
{
IsPasswordAuthenticationDisabled = true ,
SshPublicKeys =
{
new SshPublicKeyConfiguration()
{
Path = "/home/{your-username}/.ssh/authorized_keys" ,
KeyData = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCeClRAk2ipUs/l5voIsDC5q9RI+YSRd1Bvd/O+axgY4WiBzG+4FwJWZm/mLLe5DoOdHQwmU2FrKXZSW4w2sYE70KeWnrFViCOX5MTVvJgPE8ClugNl8RWth/tU849DvM9sT7vFgfVSHcAS2yDRyDlueii+8nF2ym8XWAPltFVCyLHRsyBp5YPqK8JFYIa1eybKsY3hEAxRCA+/7bq8et+Gj3coOsuRmrehav7rE6N12Pb80I6ofa6SM5XNYq4Xk0iYNx7R3kdz0Jj9XgZYWjAHjJmT0gTRoOnt6upOuxK7xI/ykWrllgpXrCPu3Ymz+c+ujaqcxDopnAl2lmf69/J1" ,
}
},
},
},
StorageProfile = new VirtualMachineScaleSetStorageProfile()
{
ImageReference = new ImageReference()
{
Publisher = "MicrosoftWindowsServer" ,
Offer = "WindowsServer" ,
Sku = "2016-Datacenter" ,
Version = "latest" ,
},
OSDisk = new VirtualMachineScaleSetOSDisk(DiskCreateOptionType.FromImage)
{
Caching = CachingType.ReadWrite,
ManagedDisk = new VirtualMachineScaleSetManagedDisk()
{
StorageAccountType = StorageAccountType.StandardLrs,
},
},
},
NetworkProfile = new VirtualMachineScaleSetNetworkProfile()
{
NetworkInterfaceConfigurations =
{
new VirtualMachineScaleSetNetworkConfiguration("{vmss-name}" )
{
Primary = true ,
IPConfigurations =
{
new VirtualMachineScaleSetIPConfiguration("{vmss-name}" )
{
SubnetId = new ResourceIdentifier("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
}
},
EnableIPForwarding = true ,
}
},
},
},
Overprovision = true ,
};
ArmOperation<VirtualMachineScaleSetResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, virtualMachineScaleSetName, data);
VirtualMachineScaleSetResource result = lro.Value;
VirtualMachineScaleSetData resourceData = result.Data;
Console.WriteLine($"Succeeded on id: {resourceData.Id} " );
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
範例回覆
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_D1_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "fb73af19-0090-467c-9ced-b00bceab1c45" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "16.04-LTS" ,
"publisher" : "Canonical" ,
"version" : "latest" ,
"offer" : "UbuntuServer"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"linuxConfiguration" : {
"ssh" : {
"publicKeys" : [
{
"path" : "/home/{your-username}/.ssh/authorized_keys" ,
"keyData" : "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCeClRAk2ipUs/l5voIsDC5q9RI+YSRd1Bvd/O+axgY4WiBzG+4FwJWZm/mLLe5DoOdHQwmU2FrKXZSW4w2sYE70KeWnrFViCOX5MTVvJgPE8ClugNl8RWth/tU849DvM9sT7vFgfVSHcAS2yDRyDlueii+8nF2ym8XWAPltFVCyLHRsyBp5YPqK8JFYIa1eybKsY3hEAxRCA+/7bq8et+Gj3coOsuRmrehav7rE6N12Pb80I6ofa6SM5XNYq4Xk0iYNx7R3kdz0Jj9XgZYWjAHjJmT0gTRoOnt6upOuxK7xI/ykWrllgpXrCPu3Ymz+c+ujaqcxDopnAl2lmf69/J1"
}
]
},
"disablePasswordAuthentication" : true
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_D1_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "fb73af19-0090-467c-9ced-b00bceab1c45" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "16.04-LTS" ,
"publisher" : "Canonical" ,
"version" : "latest" ,
"offer" : "UbuntuServer"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"linuxConfiguration" : {
"ssh" : {
"publicKeys" : [
{
"path" : "/home/{your-username}/.ssh/authorized_keys" ,
"keyData" : "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCeClRAk2ipUs/l5voIsDC5q9RI+YSRd1Bvd/O+axgY4WiBzG+4FwJWZm/mLLe5DoOdHQwmU2FrKXZSW4w2sYE70KeWnrFViCOX5MTVvJgPE8ClugNl8RWth/tU849DvM9sT7vFgfVSHcAS2yDRyDlueii+8nF2ym8XWAPltFVCyLHRsyBp5YPqK8JFYIa1eybKsY3hEAxRCA+/7bq8et+Gj3coOsuRmrehav7rE6N12Pb80I6ofa6SM5XNYq4Xk0iYNx7R3kdz0Jj9XgZYWjAHjJmT0gTRoOnt6upOuxK7xI/ykWrllgpXrCPu3Ymz+c+ujaqcxDopnAl2lmf69/J1"
}
]
},
"disablePasswordAuthentication" : true
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
Create a scale set with terminate scheduled events enabled.
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}?api-version=2022-11-01
{
"sku" : {
"tier" : "Standard",
"capacity" : 3,
"name" : "Standard_D1_v2"
},
"location" : "westus",
"properties" : {
"overprovision" : true,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter",
"publisher" : "MicrosoftWindowsServer",
"version" : "latest",
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite",
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}",
"adminUsername" : "{your-username}",
"adminPassword" : "{your-password}"
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"primary" : true,
"enableIPForwarding" : true,
"ipConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
}
}
]
}
}
]
},
"scheduledEventsProfile" : {
"terminateNotificationProfile" : {
"enable" : true,
"notBeforeTimeout" : "PT5M"
}
}
},
"upgradePolicy" : {
"mode" : "Manual"
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineScaleSetInner;
import com.azure.resourcemanager.compute.models.ApiEntityReference;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.ScheduledEventsProfile;
import com.azure.resourcemanager.compute.models.Sku;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.TerminateNotificationProfile;
import com.azure.resourcemanager.compute.models.UpgradeMode;
import com.azure.resourcemanager.compute.models.UpgradePolicy;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetIpConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetManagedDiskParameters;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSDisk;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetStorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetVMProfile;
import java.util.Arrays;
public final class Main {
public static void createAScaleSetWithTerminateScheduledEventsEnabled (
com.azure.resourcemanager.AzureResourceManager azure) {
azure
.virtualMachines()
.manager()
.serviceClient()
.getVirtualMachineScaleSets()
.createOrUpdate(
"myResourceGroup" ,
"{vmss-name}" ,
new VirtualMachineScaleSetInner()
.withLocation("westus" )
.withSku(new Sku().withName("Standard_D1_v2" ).withTier("Standard" ).withCapacity(3L ))
.withUpgradePolicy(new UpgradePolicy().withMode(UpgradeMode.MANUAL))
.withVirtualMachineProfile(
new VirtualMachineScaleSetVMProfile()
.withOsProfile(
new VirtualMachineScaleSetOSProfile()
.withComputerNamePrefix("{vmss-name}" )
.withAdminUsername("{your-username}" )
.withAdminPassword("fakeTokenPlaceholder" ))
.withStorageProfile(
new VirtualMachineScaleSetStorageProfile()
.withImageReference(
new ImageReference()
.withPublisher("MicrosoftWindowsServer" )
.withOffer("WindowsServer" )
.withSku("2016-Datacenter" )
.withVersion("latest" ))
.withOsDisk(
new VirtualMachineScaleSetOSDisk()
.withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)
.withManagedDisk(
new VirtualMachineScaleSetManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withNetworkProfile(
new VirtualMachineScaleSetNetworkProfile()
.withNetworkInterfaceConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetNetworkConfiguration()
.withName("{vmss-name}" )
.withPrimary(true )
.withIpConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetIpConfiguration()
.withName("{vmss-name}" )
.withSubnet(
new ApiEntityReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ))))
.withEnableIpForwarding(true ))))
.withScheduledEventsProfile(
new ScheduledEventsProfile()
.withTerminateNotificationProfile(
new TerminateNotificationProfile()
.withNotBeforeTimeout("PT5M" )
.withEnable(true ))))
.withOverprovision(true ),
com.azure.core.util.Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_scale_set_create_with_terminate_scheduled_event_enabled.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main () :
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="{subscription-id}" ,
)
response = client.virtual_machine_scale_sets.begin_create_or_update(
resource_group_name="myResourceGroup" ,
vm_scale_set_name="{vmss-name}" ,
parameters={
"location" : "westus" ,
"properties" : {
"overprovision" : True ,
"upgradePolicy" : {"mode" : "Manual" },
"virtualMachineProfile" : {
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"enableIPForwarding" : True ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
},
}
],
"primary" : True ,
},
}
]
},
"osProfile" : {
"adminPassword" : "{your-password}" ,
"adminUsername" : "{your-username}" ,
"computerNamePrefix" : "{vmss-name}" ,
},
"scheduledEventsProfile" : {
"terminateNotificationProfile" : {"enable" : True , "notBeforeTimeout" : "PT5M" }
},
"storageProfile" : {
"imageReference" : {
"offer" : "WindowsServer" ,
"publisher" : "MicrosoftWindowsServer" ,
"sku" : "2016-Datacenter" ,
"version" : "latest" ,
},
"osDisk" : {
"caching" : "ReadWrite" ,
"createOption" : "FromImage" ,
"managedDisk" : {"storageAccountType" : "Standard_LRS" },
},
},
},
},
"sku" : {"capacity" : 3 , "name" : "Standard_D1_v2" , "tier" : "Standard" },
},
).result()
print(response)
if __name__ == "__main__" :
main()
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4"
)
func ExampleVirtualMachineScaleSetsClient_BeginCreateOrUpdate_createAScaleSetWithTerminateScheduledEventsEnabled () {
cred, err := azidentity.NewDefaultAzureCredential(nil )
if err != nil {
log.Fatalf("failed to obtain a credential: %v" , err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("<subscription-id>" , cred, nil )
if err != nil {
log.Fatalf("failed to create client: %v" , err)
}
poller, err := clientFactory.NewVirtualMachineScaleSetsClient().BeginCreateOrUpdate(ctx, "myResourceGroup" , "{vmss-name}" , armcompute.VirtualMachineScaleSet{
Location: to.Ptr("westus" ),
Properties: &armcompute.VirtualMachineScaleSetProperties{
Overprovision: to.Ptr(true ),
UpgradePolicy: &armcompute.UpgradePolicy{
Mode: to.Ptr(armcompute.UpgradeModeManual),
},
VirtualMachineProfile: &armcompute.VirtualMachineScaleSetVMProfile{
NetworkProfile: &armcompute.VirtualMachineScaleSetNetworkProfile{
NetworkInterfaceConfigurations: []*armcompute.VirtualMachineScaleSetNetworkConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetNetworkConfigurationProperties{
EnableIPForwarding: to.Ptr(true ),
IPConfigurations: []*armcompute.VirtualMachineScaleSetIPConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetIPConfigurationProperties{
Subnet: &armcompute.APIEntityReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
},
},
}},
Primary: to.Ptr(true ),
},
}},
},
OSProfile: &armcompute.VirtualMachineScaleSetOSProfile{
AdminPassword: to.Ptr("{your-password}" ),
AdminUsername: to.Ptr("{your-username}" ),
ComputerNamePrefix: to.Ptr("{vmss-name}" ),
},
ScheduledEventsProfile: &armcompute.ScheduledEventsProfile{
TerminateNotificationProfile: &armcompute.TerminateNotificationProfile{
Enable: to.Ptr(true ),
NotBeforeTimeout: to.Ptr("PT5M" ),
},
},
StorageProfile: &armcompute.VirtualMachineScaleSetStorageProfile{
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("WindowsServer" ),
Publisher: to.Ptr("MicrosoftWindowsServer" ),
SKU: to.Ptr("2016-Datacenter" ),
Version: to.Ptr("latest" ),
},
OSDisk: &armcompute.VirtualMachineScaleSetOSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.VirtualMachineScaleSetManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
},
},
SKU: &armcompute.SKU{
Name: to.Ptr("Standard_D1_v2" ),
Capacity: to.Ptr[int64 ](3 ),
Tier: to.Ptr("Standard" ),
},
}, nil )
if err != nil {
log.Fatalf("failed to finish the request: %v" , err)
}
res, err := poller.PollUntilDone(ctx, nil )
if err != nil {
log.Fatalf("failed to pull the result: %v" , err)
}
_ = res
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require ("@azure/arm-compute" );
const { DefaultAzureCredential } = require ("@azure/identity" );
async function createAScaleSetWithTerminateScheduledEventsEnabled ( ) {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID" ] || "{subscription-id}" ;
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP" ] || "myResourceGroup" ;
const vmScaleSetName = "{vmss-name}" ;
const parameters = {
location : "westus" ,
overprovision : true ,
sku : { name : "Standard_D1_v2" , capacity : 3 , tier : "Standard" },
upgradePolicy : { mode : "Manual" },
virtualMachineProfile : {
networkProfile : {
networkInterfaceConfigurations : [
{
name : "{vmss-name}" ,
enableIPForwarding : true ,
ipConfigurations : [
{
name : "{vmss-name}" ,
subnet : {
id : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ,
},
},
],
primary : true ,
},
],
},
osProfile : {
adminPassword : "{your-password}" ,
adminUsername : "{your-username}" ,
computerNamePrefix : "{vmss-name}" ,
},
scheduledEventsProfile : {
terminateNotificationProfile : { enable : true , notBeforeTimeout : "PT5M" },
},
storageProfile : {
imageReference : {
offer : "WindowsServer" ,
publisher : "MicrosoftWindowsServer" ,
sku : "2016-Datacenter" ,
version : "latest" ,
},
osDisk : {
caching : "ReadWrite" ,
createOption : "FromImage" ,
managedDisk : { storageAccountType : "Standard_LRS" },
},
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachineScaleSets.beginCreateOrUpdateAndWait(
resourceGroupName,
vmScaleSetName,
parameters
);
console .log(result);
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Compute;
using Azure.ResourceManager.Compute.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Resources.Models;
TokenCredential cred = new DefaultAzureCredential();
ArmClient client = new ArmClient(cred);
string subscriptionId = "{subscription-id}" ;
string resourceGroupName = "myResourceGroup" ;
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
VirtualMachineScaleSetCollection collection = resourceGroupResource.GetVirtualMachineScaleSets();
string virtualMachineScaleSetName = "{vmss-name}" ;
VirtualMachineScaleSetData data = new VirtualMachineScaleSetData(new AzureLocation("westus" ))
{
Sku = new ComputeSku()
{
Name = "Standard_D1_v2" ,
Tier = "Standard" ,
Capacity = 3 ,
},
UpgradePolicy = new VirtualMachineScaleSetUpgradePolicy()
{
Mode = VirtualMachineScaleSetUpgradeMode.Manual,
},
VirtualMachineProfile = new VirtualMachineScaleSetVmProfile()
{
OSProfile = new VirtualMachineScaleSetOSProfile()
{
ComputerNamePrefix = "{vmss-name}" ,
AdminUsername = "{your-username}" ,
AdminPassword = "{your-password}" ,
},
StorageProfile = new VirtualMachineScaleSetStorageProfile()
{
ImageReference = new ImageReference()
{
Publisher = "MicrosoftWindowsServer" ,
Offer = "WindowsServer" ,
Sku = "2016-Datacenter" ,
Version = "latest" ,
},
OSDisk = new VirtualMachineScaleSetOSDisk(DiskCreateOptionType.FromImage)
{
Caching = CachingType.ReadWrite,
ManagedDisk = new VirtualMachineScaleSetManagedDisk()
{
StorageAccountType = StorageAccountType.StandardLrs,
},
},
},
NetworkProfile = new VirtualMachineScaleSetNetworkProfile()
{
NetworkInterfaceConfigurations =
{
new VirtualMachineScaleSetNetworkConfiguration("{vmss-name}" )
{
Primary = true ,
IPConfigurations =
{
new VirtualMachineScaleSetIPConfiguration("{vmss-name}" )
{
SubnetId = new ResourceIdentifier("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
}
},
EnableIPForwarding = true ,
}
},
},
ScheduledEventsProfile = new ComputeScheduledEventsProfile()
{
TerminateNotificationProfile = new TerminateNotificationProfile()
{
NotBeforeTimeout = "PT5M" ,
Enable = true ,
},
},
},
Overprovision = true ,
};
ArmOperation<VirtualMachineScaleSetResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, virtualMachineScaleSetName, data);
VirtualMachineScaleSetResource result = lro.Value;
VirtualMachineScaleSetData resourceData = result.Data;
Console.WriteLine($"Succeeded on id: {resourceData.Id} " );
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
範例回覆
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_D1_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "d053ec5a-8da6-495f-ab13-38216503c6d7" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter" ,
"publisher" : "MicrosoftWindowsServer" ,
"version" : "latest" ,
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
},
"scheduledEventsProfile" : {
"terminateNotificationProfile" : {
"enable" : true ,
"notBeforeTimeout" : "PT5M"
}
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_D1_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "d053ec5a-8da6-495f-ab13-38216503c6d7" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter" ,
"publisher" : "MicrosoftWindowsServer" ,
"version" : "latest" ,
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
},
"scheduledEventsProfile" : {
"terminateNotificationProfile" : {
"enable" : true ,
"notBeforeTimeout" : "PT5M"
}
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
Create a scale set with Uefi Settings of secureBoot and vTPM.
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}?api-version=2022-11-01
{
"sku" : {
"tier" : "Standard",
"capacity" : 3,
"name" : "Standard_D2s_v3"
},
"properties" : {
"overprovision" : true,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "windows10-tvm",
"publisher" : "MicrosoftWindowsServer",
"version" : "18363.592.2001092016",
"offer" : "windowsserver-gen2preview-preview"
},
"osDisk" : {
"caching" : "ReadOnly",
"managedDisk" : {
"storageAccountType" : "StandardSSD_LRS"
},
"createOption" : "FromImage"
}
},
"securityProfile" : {
"uefiSettings" : {
"secureBootEnabled" : true,
"vTpmEnabled" : true
},
"securityType" : "TrustedLaunch"
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}",
"adminUsername" : "{your-username}",
"adminPassword" : "{your-password}"
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"primary" : true,
"enableIPForwarding" : true,
"ipConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
}
}
]
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
}
},
"location" : "westus"
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineScaleSetInner;
import com.azure.resourcemanager.compute.models.ApiEntityReference;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.SecurityProfile;
import com.azure.resourcemanager.compute.models.SecurityTypes;
import com.azure.resourcemanager.compute.models.Sku;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.UefiSettings;
import com.azure.resourcemanager.compute.models.UpgradeMode;
import com.azure.resourcemanager.compute.models.UpgradePolicy;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetIpConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetManagedDiskParameters;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSDisk;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetStorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetVMProfile;
import java.util.Arrays;
public final class Main {
public static void createAScaleSetWithUefiSettingsOfSecureBootAndVTPM (
com.azure.resourcemanager.AzureResourceManager azure) {
azure
.virtualMachines()
.manager()
.serviceClient()
.getVirtualMachineScaleSets()
.createOrUpdate(
"myResourceGroup" ,
"{vmss-name}" ,
new VirtualMachineScaleSetInner()
.withLocation("westus" )
.withSku(new Sku().withName("Standard_D2s_v3" ).withTier("Standard" ).withCapacity(3L ))
.withUpgradePolicy(new UpgradePolicy().withMode(UpgradeMode.MANUAL))
.withVirtualMachineProfile(
new VirtualMachineScaleSetVMProfile()
.withOsProfile(
new VirtualMachineScaleSetOSProfile()
.withComputerNamePrefix("{vmss-name}" )
.withAdminUsername("{your-username}" )
.withAdminPassword("fakeTokenPlaceholder" ))
.withStorageProfile(
new VirtualMachineScaleSetStorageProfile()
.withImageReference(
new ImageReference()
.withPublisher("MicrosoftWindowsServer" )
.withOffer("windowsserver-gen2preview-preview" )
.withSku("windows10-tvm" )
.withVersion("18363.592.2001092016" ))
.withOsDisk(
new VirtualMachineScaleSetOSDisk()
.withCaching(CachingTypes.READ_ONLY)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)
.withManagedDisk(
new VirtualMachineScaleSetManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.STANDARD_SSD_LRS))))
.withNetworkProfile(
new VirtualMachineScaleSetNetworkProfile()
.withNetworkInterfaceConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetNetworkConfiguration()
.withName("{vmss-name}" )
.withPrimary(true )
.withIpConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetIpConfiguration()
.withName("{vmss-name}" )
.withSubnet(
new ApiEntityReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ))))
.withEnableIpForwarding(true ))))
.withSecurityProfile(
new SecurityProfile()
.withUefiSettings(
new UefiSettings().withSecureBootEnabled(true ).withVTpmEnabled(true ))
.withSecurityType(SecurityTypes.TRUSTED_LAUNCH)))
.withOverprovision(true ),
com.azure.core.util.Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_scale_set_create_with_uefi_settings.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main () :
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="{subscription-id}" ,
)
response = client.virtual_machine_scale_sets.begin_create_or_update(
resource_group_name="myResourceGroup" ,
vm_scale_set_name="{vmss-name}" ,
parameters={
"location" : "westus" ,
"properties" : {
"overprovision" : True ,
"upgradePolicy" : {"mode" : "Manual" },
"virtualMachineProfile" : {
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"enableIPForwarding" : True ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
},
}
],
"primary" : True ,
},
}
]
},
"osProfile" : {
"adminPassword" : "{your-password}" ,
"adminUsername" : "{your-username}" ,
"computerNamePrefix" : "{vmss-name}" ,
},
"securityProfile" : {
"securityType" : "TrustedLaunch" ,
"uefiSettings" : {"secureBootEnabled" : True , "vTpmEnabled" : True },
},
"storageProfile" : {
"imageReference" : {
"offer" : "windowsserver-gen2preview-preview" ,
"publisher" : "MicrosoftWindowsServer" ,
"sku" : "windows10-tvm" ,
"version" : "18363.592.2001092016" ,
},
"osDisk" : {
"caching" : "ReadOnly" ,
"createOption" : "FromImage" ,
"managedDisk" : {"storageAccountType" : "StandardSSD_LRS" },
},
},
},
},
"sku" : {"capacity" : 3 , "name" : "Standard_D2s_v3" , "tier" : "Standard" },
},
).result()
print(response)
if __name__ == "__main__" :
main()
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4"
)
func ExampleVirtualMachineScaleSetsClient_BeginCreateOrUpdate_createAScaleSetWithUefiSettingsOfSecureBootAndVTpm () {
cred, err := azidentity.NewDefaultAzureCredential(nil )
if err != nil {
log.Fatalf("failed to obtain a credential: %v" , err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("<subscription-id>" , cred, nil )
if err != nil {
log.Fatalf("failed to create client: %v" , err)
}
poller, err := clientFactory.NewVirtualMachineScaleSetsClient().BeginCreateOrUpdate(ctx, "myResourceGroup" , "{vmss-name}" , armcompute.VirtualMachineScaleSet{
Location: to.Ptr("westus" ),
Properties: &armcompute.VirtualMachineScaleSetProperties{
Overprovision: to.Ptr(true ),
UpgradePolicy: &armcompute.UpgradePolicy{
Mode: to.Ptr(armcompute.UpgradeModeManual),
},
VirtualMachineProfile: &armcompute.VirtualMachineScaleSetVMProfile{
NetworkProfile: &armcompute.VirtualMachineScaleSetNetworkProfile{
NetworkInterfaceConfigurations: []*armcompute.VirtualMachineScaleSetNetworkConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetNetworkConfigurationProperties{
EnableIPForwarding: to.Ptr(true ),
IPConfigurations: []*armcompute.VirtualMachineScaleSetIPConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetIPConfigurationProperties{
Subnet: &armcompute.APIEntityReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
},
},
}},
Primary: to.Ptr(true ),
},
}},
},
OSProfile: &armcompute.VirtualMachineScaleSetOSProfile{
AdminPassword: to.Ptr("{your-password}" ),
AdminUsername: to.Ptr("{your-username}" ),
ComputerNamePrefix: to.Ptr("{vmss-name}" ),
},
SecurityProfile: &armcompute.SecurityProfile{
SecurityType: to.Ptr(armcompute.SecurityTypesTrustedLaunch),
UefiSettings: &armcompute.UefiSettings{
SecureBootEnabled: to.Ptr(true ),
VTpmEnabled: to.Ptr(true ),
},
},
StorageProfile: &armcompute.VirtualMachineScaleSetStorageProfile{
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("windowsserver-gen2preview-preview" ),
Publisher: to.Ptr("MicrosoftWindowsServer" ),
SKU: to.Ptr("windows10-tvm" ),
Version: to.Ptr("18363.592.2001092016" ),
},
OSDisk: &armcompute.VirtualMachineScaleSetOSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadOnly),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.VirtualMachineScaleSetManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardSSDLRS),
},
},
},
},
},
SKU: &armcompute.SKU{
Name: to.Ptr("Standard_D2s_v3" ),
Capacity: to.Ptr[int64 ](3 ),
Tier: to.Ptr("Standard" ),
},
}, nil )
if err != nil {
log.Fatalf("failed to finish the request: %v" , err)
}
res, err := poller.PollUntilDone(ctx, nil )
if err != nil {
log.Fatalf("failed to pull the result: %v" , err)
}
_ = res
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require ("@azure/arm-compute" );
const { DefaultAzureCredential } = require ("@azure/identity" );
async function createAScaleSetWithUefiSettingsOfSecureBootAndVTpm ( ) {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID" ] || "{subscription-id}" ;
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP" ] || "myResourceGroup" ;
const vmScaleSetName = "{vmss-name}" ;
const parameters = {
location : "westus" ,
overprovision : true ,
sku : { name : "Standard_D2s_v3" , capacity : 3 , tier : "Standard" },
upgradePolicy : { mode : "Manual" },
virtualMachineProfile : {
networkProfile : {
networkInterfaceConfigurations : [
{
name : "{vmss-name}" ,
enableIPForwarding : true ,
ipConfigurations : [
{
name : "{vmss-name}" ,
subnet : {
id : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ,
},
},
],
primary : true ,
},
],
},
osProfile : {
adminPassword : "{your-password}" ,
adminUsername : "{your-username}" ,
computerNamePrefix : "{vmss-name}" ,
},
securityProfile : {
securityType : "TrustedLaunch" ,
uefiSettings : { secureBootEnabled : true , vTpmEnabled : true },
},
storageProfile : {
imageReference : {
offer : "windowsserver-gen2preview-preview" ,
publisher : "MicrosoftWindowsServer" ,
sku : "windows10-tvm" ,
version : "18363.592.2001092016" ,
},
osDisk : {
caching : "ReadOnly" ,
createOption : "FromImage" ,
managedDisk : { storageAccountType : "StandardSSD_LRS" },
},
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachineScaleSets.beginCreateOrUpdateAndWait(
resourceGroupName,
vmScaleSetName,
parameters
);
console .log(result);
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Compute;
using Azure.ResourceManager.Compute.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Resources.Models;
TokenCredential cred = new DefaultAzureCredential();
ArmClient client = new ArmClient(cred);
string subscriptionId = "{subscription-id}" ;
string resourceGroupName = "myResourceGroup" ;
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
VirtualMachineScaleSetCollection collection = resourceGroupResource.GetVirtualMachineScaleSets();
string virtualMachineScaleSetName = "{vmss-name}" ;
VirtualMachineScaleSetData data = new VirtualMachineScaleSetData(new AzureLocation("westus" ))
{
Sku = new ComputeSku()
{
Name = "Standard_D2s_v3" ,
Tier = "Standard" ,
Capacity = 3 ,
},
UpgradePolicy = new VirtualMachineScaleSetUpgradePolicy()
{
Mode = VirtualMachineScaleSetUpgradeMode.Manual,
},
VirtualMachineProfile = new VirtualMachineScaleSetVmProfile()
{
OSProfile = new VirtualMachineScaleSetOSProfile()
{
ComputerNamePrefix = "{vmss-name}" ,
AdminUsername = "{your-username}" ,
AdminPassword = "{your-password}" ,
},
StorageProfile = new VirtualMachineScaleSetStorageProfile()
{
ImageReference = new ImageReference()
{
Publisher = "MicrosoftWindowsServer" ,
Offer = "windowsserver-gen2preview-preview" ,
Sku = "windows10-tvm" ,
Version = "18363.592.2001092016" ,
},
OSDisk = new VirtualMachineScaleSetOSDisk(DiskCreateOptionType.FromImage)
{
Caching = CachingType.ReadOnly,
ManagedDisk = new VirtualMachineScaleSetManagedDisk()
{
StorageAccountType = StorageAccountType.StandardSsdLrs,
},
},
},
NetworkProfile = new VirtualMachineScaleSetNetworkProfile()
{
NetworkInterfaceConfigurations =
{
new VirtualMachineScaleSetNetworkConfiguration("{vmss-name}" )
{
Primary = true ,
IPConfigurations =
{
new VirtualMachineScaleSetIPConfiguration("{vmss-name}" )
{
SubnetId = new ResourceIdentifier("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
}
},
EnableIPForwarding = true ,
}
},
},
SecurityProfile = new SecurityProfile()
{
UefiSettings = new UefiSettings()
{
IsSecureBootEnabled = true ,
IsVirtualTpmEnabled = true ,
},
SecurityType = SecurityType.TrustedLaunch,
},
},
Overprovision = true ,
};
ArmOperation<VirtualMachineScaleSetResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, virtualMachineScaleSetName, data);
VirtualMachineScaleSetResource result = lro.Value;
VirtualMachineScaleSetData resourceData = result.Data;
Console.WriteLine($"Succeeded on id: {resourceData.Id} " );
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
範例回覆
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_D2s_v3"
},
"name" : "{vmss-name}" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "b9e23088-6ffc-46e0-9e02-b0a6eeef47db" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "windows10-tvm" ,
"publisher" : "MicrosoftWindowsServer" ,
"version" : "18363.592.2001092016" ,
"offer" : "windowsserver-gen2preview-preview"
},
"osDisk" : {
"caching" : "ReadOnly" ,
"managedDisk" : {
"storageAccountType" : "StandardSSD_LRS"
},
"createOption" : "FromImage"
}
},
"securityProfile" : {
"uefiSettings" : {
"secureBootEnabled" : true ,
"vTpmEnabled" : true
},
"securityType" : "TrustedLaunch"
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus"
}
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_D2s_v3"
},
"name" : "{vmss-name}" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "b9e23088-6ffc-46e0-9e02-b0a6eeef47db" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "windows10-tvm" ,
"publisher" : "MicrosoftWindowsServer" ,
"version" : "18363.592.2001092016" ,
"offer" : "windowsserver-gen2preview-preview"
},
"osDisk" : {
"caching" : "ReadOnly" ,
"managedDisk" : {
"storageAccountType" : "StandardSSD_LRS"
},
"createOption" : "FromImage"
}
},
"securityProfile" : {
"uefiSettings" : {
"secureBootEnabled" : true ,
"vTpmEnabled" : true
},
"securityType" : "TrustedLaunch"
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus"
}
Create a scale set with userData.
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}?api-version=2022-11-01
{
"sku" : {
"tier" : "Standard",
"capacity" : 3,
"name" : "Standard_D1_v2"
},
"location" : "westus",
"properties" : {
"overprovision" : true,
"upgradePolicy" : {
"mode" : "Manual"
},
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter",
"publisher" : "MicrosoftWindowsServer",
"version" : "latest",
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite",
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"userData" : "RXhhbXBsZSBVc2VyRGF0YQ==",
"osProfile" : {
"computerNamePrefix" : "{vmss-name}",
"adminUsername" : "{your-username}",
"adminPassword" : "{your-password}"
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"primary" : true,
"enableIPForwarding" : true,
"ipConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
}
}
]
}
}
]
}
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineScaleSetInner;
import com.azure.resourcemanager.compute.models.ApiEntityReference;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.Sku;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.UpgradeMode;
import com.azure.resourcemanager.compute.models.UpgradePolicy;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetIpConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetManagedDiskParameters;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSDisk;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetStorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetVMProfile;
import java.util.Arrays;
public final class Main {
public static void createAScaleSetWithUserData (com.azure.resourcemanager.AzureResourceManager azure) {
azure
.virtualMachines()
.manager()
.serviceClient()
.getVirtualMachineScaleSets()
.createOrUpdate(
"myResourceGroup" ,
"{vmss-name}" ,
new VirtualMachineScaleSetInner()
.withLocation("westus" )
.withSku(new Sku().withName("Standard_D1_v2" ).withTier("Standard" ).withCapacity(3L ))
.withUpgradePolicy(new UpgradePolicy().withMode(UpgradeMode.MANUAL))
.withVirtualMachineProfile(
new VirtualMachineScaleSetVMProfile()
.withOsProfile(
new VirtualMachineScaleSetOSProfile()
.withComputerNamePrefix("{vmss-name}" )
.withAdminUsername("{your-username}" )
.withAdminPassword("fakeTokenPlaceholder" ))
.withStorageProfile(
new VirtualMachineScaleSetStorageProfile()
.withImageReference(
new ImageReference()
.withPublisher("MicrosoftWindowsServer" )
.withOffer("WindowsServer" )
.withSku("2016-Datacenter" )
.withVersion("latest" ))
.withOsDisk(
new VirtualMachineScaleSetOSDisk()
.withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)
.withManagedDisk(
new VirtualMachineScaleSetManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withNetworkProfile(
new VirtualMachineScaleSetNetworkProfile()
.withNetworkInterfaceConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetNetworkConfiguration()
.withName("{vmss-name}" )
.withPrimary(true )
.withIpConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetIpConfiguration()
.withName("{vmss-name}" )
.withSubnet(
new ApiEntityReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ))))
.withEnableIpForwarding(true ))))
.withUserData("RXhhbXBsZSBVc2VyRGF0YQ==" ))
.withOverprovision(true ),
com.azure.core.util.Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_scale_set_create_with_user_data.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main () :
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="{subscription-id}" ,
)
response = client.virtual_machine_scale_sets.begin_create_or_update(
resource_group_name="myResourceGroup" ,
vm_scale_set_name="{vmss-name}" ,
parameters={
"location" : "westus" ,
"properties" : {
"overprovision" : True ,
"upgradePolicy" : {"mode" : "Manual" },
"virtualMachineProfile" : {
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"enableIPForwarding" : True ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
},
}
],
"primary" : True ,
},
}
]
},
"osProfile" : {
"adminPassword" : "{your-password}" ,
"adminUsername" : "{your-username}" ,
"computerNamePrefix" : "{vmss-name}" ,
},
"storageProfile" : {
"imageReference" : {
"offer" : "WindowsServer" ,
"publisher" : "MicrosoftWindowsServer" ,
"sku" : "2016-Datacenter" ,
"version" : "latest" ,
},
"osDisk" : {
"caching" : "ReadWrite" ,
"createOption" : "FromImage" ,
"managedDisk" : {"storageAccountType" : "Standard_LRS" },
},
},
"userData" : "RXhhbXBsZSBVc2VyRGF0YQ==" ,
},
},
"sku" : {"capacity" : 3 , "name" : "Standard_D1_v2" , "tier" : "Standard" },
},
).result()
print(response)
if __name__ == "__main__" :
main()
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4"
)
func ExampleVirtualMachineScaleSetsClient_BeginCreateOrUpdate_createAScaleSetWithUserData () {
cred, err := azidentity.NewDefaultAzureCredential(nil )
if err != nil {
log.Fatalf("failed to obtain a credential: %v" , err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("<subscription-id>" , cred, nil )
if err != nil {
log.Fatalf("failed to create client: %v" , err)
}
poller, err := clientFactory.NewVirtualMachineScaleSetsClient().BeginCreateOrUpdate(ctx, "myResourceGroup" , "{vmss-name}" , armcompute.VirtualMachineScaleSet{
Location: to.Ptr("westus" ),
Properties: &armcompute.VirtualMachineScaleSetProperties{
Overprovision: to.Ptr(true ),
UpgradePolicy: &armcompute.UpgradePolicy{
Mode: to.Ptr(armcompute.UpgradeModeManual),
},
VirtualMachineProfile: &armcompute.VirtualMachineScaleSetVMProfile{
NetworkProfile: &armcompute.VirtualMachineScaleSetNetworkProfile{
NetworkInterfaceConfigurations: []*armcompute.VirtualMachineScaleSetNetworkConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetNetworkConfigurationProperties{
EnableIPForwarding: to.Ptr(true ),
IPConfigurations: []*armcompute.VirtualMachineScaleSetIPConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetIPConfigurationProperties{
Subnet: &armcompute.APIEntityReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
},
},
}},
Primary: to.Ptr(true ),
},
}},
},
OSProfile: &armcompute.VirtualMachineScaleSetOSProfile{
AdminPassword: to.Ptr("{your-password}" ),
AdminUsername: to.Ptr("{your-username}" ),
ComputerNamePrefix: to.Ptr("{vmss-name}" ),
},
StorageProfile: &armcompute.VirtualMachineScaleSetStorageProfile{
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("WindowsServer" ),
Publisher: to.Ptr("MicrosoftWindowsServer" ),
SKU: to.Ptr("2016-Datacenter" ),
Version: to.Ptr("latest" ),
},
OSDisk: &armcompute.VirtualMachineScaleSetOSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.VirtualMachineScaleSetManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
UserData: to.Ptr("RXhhbXBsZSBVc2VyRGF0YQ==" ),
},
},
SKU: &armcompute.SKU{
Name: to.Ptr("Standard_D1_v2" ),
Capacity: to.Ptr[int64 ](3 ),
Tier: to.Ptr("Standard" ),
},
}, nil )
if err != nil {
log.Fatalf("failed to finish the request: %v" , err)
}
res, err := poller.PollUntilDone(ctx, nil )
if err != nil {
log.Fatalf("failed to pull the result: %v" , err)
}
_ = res
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require ("@azure/arm-compute" );
const { DefaultAzureCredential } = require ("@azure/identity" );
async function createAScaleSetWithUserData ( ) {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID" ] || "{subscription-id}" ;
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP" ] || "myResourceGroup" ;
const vmScaleSetName = "{vmss-name}" ;
const parameters = {
location : "westus" ,
overprovision : true ,
sku : { name : "Standard_D1_v2" , capacity : 3 , tier : "Standard" },
upgradePolicy : { mode : "Manual" },
virtualMachineProfile : {
networkProfile : {
networkInterfaceConfigurations : [
{
name : "{vmss-name}" ,
enableIPForwarding : true ,
ipConfigurations : [
{
name : "{vmss-name}" ,
subnet : {
id : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ,
},
},
],
primary : true ,
},
],
},
osProfile : {
adminPassword : "{your-password}" ,
adminUsername : "{your-username}" ,
computerNamePrefix : "{vmss-name}" ,
},
storageProfile : {
imageReference : {
offer : "WindowsServer" ,
publisher : "MicrosoftWindowsServer" ,
sku : "2016-Datacenter" ,
version : "latest" ,
},
osDisk : {
caching : "ReadWrite" ,
createOption : "FromImage" ,
managedDisk : { storageAccountType : "Standard_LRS" },
},
},
userData : "RXhhbXBsZSBVc2VyRGF0YQ==" ,
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachineScaleSets.beginCreateOrUpdateAndWait(
resourceGroupName,
vmScaleSetName,
parameters
);
console .log(result);
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Compute;
using Azure.ResourceManager.Compute.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Resources.Models;
TokenCredential cred = new DefaultAzureCredential();
ArmClient client = new ArmClient(cred);
string subscriptionId = "{subscription-id}" ;
string resourceGroupName = "myResourceGroup" ;
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
VirtualMachineScaleSetCollection collection = resourceGroupResource.GetVirtualMachineScaleSets();
string virtualMachineScaleSetName = "{vmss-name}" ;
VirtualMachineScaleSetData data = new VirtualMachineScaleSetData(new AzureLocation("westus" ))
{
Sku = new ComputeSku()
{
Name = "Standard_D1_v2" ,
Tier = "Standard" ,
Capacity = 3 ,
},
UpgradePolicy = new VirtualMachineScaleSetUpgradePolicy()
{
Mode = VirtualMachineScaleSetUpgradeMode.Manual,
},
VirtualMachineProfile = new VirtualMachineScaleSetVmProfile()
{
OSProfile = new VirtualMachineScaleSetOSProfile()
{
ComputerNamePrefix = "{vmss-name}" ,
AdminUsername = "{your-username}" ,
AdminPassword = "{your-password}" ,
},
StorageProfile = new VirtualMachineScaleSetStorageProfile()
{
ImageReference = new ImageReference()
{
Publisher = "MicrosoftWindowsServer" ,
Offer = "WindowsServer" ,
Sku = "2016-Datacenter" ,
Version = "latest" ,
},
OSDisk = new VirtualMachineScaleSetOSDisk(DiskCreateOptionType.FromImage)
{
Caching = CachingType.ReadWrite,
ManagedDisk = new VirtualMachineScaleSetManagedDisk()
{
StorageAccountType = StorageAccountType.StandardLrs,
},
},
},
NetworkProfile = new VirtualMachineScaleSetNetworkProfile()
{
NetworkInterfaceConfigurations =
{
new VirtualMachineScaleSetNetworkConfiguration("{vmss-name}" )
{
Primary = true ,
IPConfigurations =
{
new VirtualMachineScaleSetIPConfiguration("{vmss-name}" )
{
SubnetId = new ResourceIdentifier("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
}
},
EnableIPForwarding = true ,
}
},
},
UserData = "RXhhbXBsZSBVc2VyRGF0YQ==" ,
},
Overprovision = true ,
};
ArmOperation<VirtualMachineScaleSetResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, virtualMachineScaleSetName, data);
VirtualMachineScaleSetResource result = lro.Value;
VirtualMachineScaleSetData resourceData = result.Data;
Console.WriteLine($"Succeeded on id: {resourceData.Id} " );
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
範例回覆
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_D1_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "d053ec5a-8da6-495f-ab13-38216503c6d7" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter" ,
"publisher" : "MicrosoftWindowsServer" ,
"version" : "latest" ,
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"diagnosticsProfile" : {
"bootDiagnostics" : {
"storageUri" : "http://nsgdiagnostic.blob.core.windows.net" ,
"enabled" : true
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_D1_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "d053ec5a-8da6-495f-ab13-38216503c6d7" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter" ,
"publisher" : "MicrosoftWindowsServer" ,
"version" : "latest" ,
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"diagnosticsProfile" : {
"bootDiagnostics" : {
"storageUri" : "http://nsgdiagnostic.blob.core.windows.net" ,
"enabled" : true
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
Create a scale set with virtual machines in different zones.
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}?api-version=2022-11-01
{
"sku" : {
"tier" : "Standard",
"capacity" : 2,
"name" : "Standard_A1_v2"
},
"location" : "centralus",
"properties" : {
"overprovision" : true,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter",
"publisher" : "MicrosoftWindowsServer",
"version" : "latest",
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite",
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage",
"diskSizeGB" : 512
},
"dataDisks" : [
{
"diskSizeGB" : 1023,
"createOption" : "Empty",
"lun" : 0
},
{
"diskSizeGB" : 1023,
"createOption" : "Empty",
"lun" : 1
}
]
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}",
"adminUsername" : "{your-username}",
"adminPassword" : "{your-password}"
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"primary" : true,
"enableIPForwarding" : true,
"ipConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
}
}
]
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Automatic"
}
},
"zones" : [
"1",
"3"
]
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineScaleSetInner;
import com.azure.resourcemanager.compute.models.ApiEntityReference;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.Sku;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.UpgradeMode;
import com.azure.resourcemanager.compute.models.UpgradePolicy;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetDataDisk;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetIpConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetManagedDiskParameters;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSDisk;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetStorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetVMProfile;
import java.util.Arrays;
public final class Main {
public static void createAScaleSetWithVirtualMachinesInDifferentZones (
com.azure.resourcemanager.AzureResourceManager azure) {
azure
.virtualMachines()
.manager()
.serviceClient()
.getVirtualMachineScaleSets()
.createOrUpdate(
"myResourceGroup" ,
"{vmss-name}" ,
new VirtualMachineScaleSetInner()
.withLocation("centralus" )
.withSku(new Sku().withName("Standard_A1_v2" ).withTier("Standard" ).withCapacity(2L ))
.withZones(Arrays.asList("1" , "3" ))
.withUpgradePolicy(new UpgradePolicy().withMode(UpgradeMode.AUTOMATIC))
.withVirtualMachineProfile(
new VirtualMachineScaleSetVMProfile()
.withOsProfile(
new VirtualMachineScaleSetOSProfile()
.withComputerNamePrefix("{vmss-name}" )
.withAdminUsername("{your-username}" )
.withAdminPassword("fakeTokenPlaceholder" ))
.withStorageProfile(
new VirtualMachineScaleSetStorageProfile()
.withImageReference(
new ImageReference()
.withPublisher("MicrosoftWindowsServer" )
.withOffer("WindowsServer" )
.withSku("2016-Datacenter" )
.withVersion("latest" ))
.withOsDisk(
new VirtualMachineScaleSetOSDisk()
.withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)
.withDiskSizeGB(512 )
.withManagedDisk(
new VirtualMachineScaleSetManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.STANDARD_LRS)))
.withDataDisks(
Arrays
.asList(
new VirtualMachineScaleSetDataDisk()
.withLun(0 )
.withCreateOption(DiskCreateOptionTypes.EMPTY)
.withDiskSizeGB(1023 ),
new VirtualMachineScaleSetDataDisk()
.withLun(1 )
.withCreateOption(DiskCreateOptionTypes.EMPTY)
.withDiskSizeGB(1023 ))))
.withNetworkProfile(
new VirtualMachineScaleSetNetworkProfile()
.withNetworkInterfaceConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetNetworkConfiguration()
.withName("{vmss-name}" )
.withPrimary(true )
.withIpConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetIpConfiguration()
.withName("{vmss-name}" )
.withSubnet(
new ApiEntityReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ))))
.withEnableIpForwarding(true )))))
.withOverprovision(true ),
com.azure.core.util.Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_scale_set_create_with_vms_in_different_zones.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main () :
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="{subscription-id}" ,
)
response = client.virtual_machine_scale_sets.begin_create_or_update(
resource_group_name="myResourceGroup" ,
vm_scale_set_name="{vmss-name}" ,
parameters={
"location" : "centralus" ,
"properties" : {
"overprovision" : True ,
"upgradePolicy" : {"mode" : "Automatic" },
"virtualMachineProfile" : {
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"enableIPForwarding" : True ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
},
}
],
"primary" : True ,
},
}
]
},
"osProfile" : {
"adminPassword" : "{your-password}" ,
"adminUsername" : "{your-username}" ,
"computerNamePrefix" : "{vmss-name}" ,
},
"storageProfile" : {
"dataDisks" : [
{"createOption" : "Empty" , "diskSizeGB" : 1023 , "lun" : 0 },
{"createOption" : "Empty" , "diskSizeGB" : 1023 , "lun" : 1 },
],
"imageReference" : {
"offer" : "WindowsServer" ,
"publisher" : "MicrosoftWindowsServer" ,
"sku" : "2016-Datacenter" ,
"version" : "latest" ,
},
"osDisk" : {
"caching" : "ReadWrite" ,
"createOption" : "FromImage" ,
"diskSizeGB" : 512 ,
"managedDisk" : {"storageAccountType" : "Standard_LRS" },
},
},
},
},
"sku" : {"capacity" : 2 , "name" : "Standard_A1_v2" , "tier" : "Standard" },
"zones" : ["1" , "3" ],
},
).result()
print(response)
if __name__ == "__main__" :
main()
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4"
)
func ExampleVirtualMachineScaleSetsClient_BeginCreateOrUpdate_createAScaleSetWithVirtualMachinesInDifferentZones () {
cred, err := azidentity.NewDefaultAzureCredential(nil )
if err != nil {
log.Fatalf("failed to obtain a credential: %v" , err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("<subscription-id>" , cred, nil )
if err != nil {
log.Fatalf("failed to create client: %v" , err)
}
poller, err := clientFactory.NewVirtualMachineScaleSetsClient().BeginCreateOrUpdate(ctx, "myResourceGroup" , "{vmss-name}" , armcompute.VirtualMachineScaleSet{
Location: to.Ptr("centralus" ),
Properties: &armcompute.VirtualMachineScaleSetProperties{
Overprovision: to.Ptr(true ),
UpgradePolicy: &armcompute.UpgradePolicy{
Mode: to.Ptr(armcompute.UpgradeModeAutomatic),
},
VirtualMachineProfile: &armcompute.VirtualMachineScaleSetVMProfile{
NetworkProfile: &armcompute.VirtualMachineScaleSetNetworkProfile{
NetworkInterfaceConfigurations: []*armcompute.VirtualMachineScaleSetNetworkConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetNetworkConfigurationProperties{
EnableIPForwarding: to.Ptr(true ),
IPConfigurations: []*armcompute.VirtualMachineScaleSetIPConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetIPConfigurationProperties{
Subnet: &armcompute.APIEntityReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
},
},
}},
Primary: to.Ptr(true ),
},
}},
},
OSProfile: &armcompute.VirtualMachineScaleSetOSProfile{
AdminPassword: to.Ptr("{your-password}" ),
AdminUsername: to.Ptr("{your-username}" ),
ComputerNamePrefix: to.Ptr("{vmss-name}" ),
},
StorageProfile: &armcompute.VirtualMachineScaleSetStorageProfile{
DataDisks: []*armcompute.VirtualMachineScaleSetDataDisk{
{
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesEmpty),
DiskSizeGB: to.Ptr[int32 ](1023 ),
Lun: to.Ptr[int32 ](0 ),
},
{
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesEmpty),
DiskSizeGB: to.Ptr[int32 ](1023 ),
Lun: to.Ptr[int32 ](1 ),
}},
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("WindowsServer" ),
Publisher: to.Ptr("MicrosoftWindowsServer" ),
SKU: to.Ptr("2016-Datacenter" ),
Version: to.Ptr("latest" ),
},
OSDisk: &armcompute.VirtualMachineScaleSetOSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
DiskSizeGB: to.Ptr[int32 ](512 ),
ManagedDisk: &armcompute.VirtualMachineScaleSetManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
},
},
SKU: &armcompute.SKU{
Name: to.Ptr("Standard_A1_v2" ),
Capacity: to.Ptr[int64 ](2 ),
Tier: to.Ptr("Standard" ),
},
Zones: []*string {
to.Ptr("1" ),
to.Ptr("3" )},
}, nil )
if err != nil {
log.Fatalf("failed to finish the request: %v" , err)
}
res, err := poller.PollUntilDone(ctx, nil )
if err != nil {
log.Fatalf("failed to pull the result: %v" , err)
}
_ = res
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require ("@azure/arm-compute" );
const { DefaultAzureCredential } = require ("@azure/identity" );
async function createAScaleSetWithVirtualMachinesInDifferentZones ( ) {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID" ] || "{subscription-id}" ;
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP" ] || "myResourceGroup" ;
const vmScaleSetName = "{vmss-name}" ;
const parameters = {
location : "centralus" ,
overprovision : true ,
sku : { name : "Standard_A1_v2" , capacity : 2 , tier : "Standard" },
upgradePolicy : { mode : "Automatic" },
virtualMachineProfile : {
networkProfile : {
networkInterfaceConfigurations : [
{
name : "{vmss-name}" ,
enableIPForwarding : true ,
ipConfigurations : [
{
name : "{vmss-name}" ,
subnet : {
id : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ,
},
},
],
primary : true ,
},
],
},
osProfile : {
adminPassword : "{your-password}" ,
adminUsername : "{your-username}" ,
computerNamePrefix : "{vmss-name}" ,
},
storageProfile : {
dataDisks : [
{ createOption : "Empty" , diskSizeGB : 1023 , lun : 0 },
{ createOption : "Empty" , diskSizeGB : 1023 , lun : 1 },
],
imageReference : {
offer : "WindowsServer" ,
publisher : "MicrosoftWindowsServer" ,
sku : "2016-Datacenter" ,
version : "latest" ,
},
osDisk : {
caching : "ReadWrite" ,
createOption : "FromImage" ,
diskSizeGB : 512 ,
managedDisk : { storageAccountType : "Standard_LRS" },
},
},
},
zones : ["1" , "3" ],
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachineScaleSets.beginCreateOrUpdateAndWait(
resourceGroupName,
vmScaleSetName,
parameters
);
console .log(result);
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Compute;
using Azure.ResourceManager.Compute.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Resources.Models;
TokenCredential cred = new DefaultAzureCredential();
ArmClient client = new ArmClient(cred);
string subscriptionId = "{subscription-id}" ;
string resourceGroupName = "myResourceGroup" ;
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
VirtualMachineScaleSetCollection collection = resourceGroupResource.GetVirtualMachineScaleSets();
string virtualMachineScaleSetName = "{vmss-name}" ;
VirtualMachineScaleSetData data = new VirtualMachineScaleSetData(new AzureLocation("centralus" ))
{
Sku = new ComputeSku()
{
Name = "Standard_A1_v2" ,
Tier = "Standard" ,
Capacity = 2 ,
},
Zones =
{
"1" ,"3"
},
UpgradePolicy = new VirtualMachineScaleSetUpgradePolicy()
{
Mode = VirtualMachineScaleSetUpgradeMode.Automatic,
},
VirtualMachineProfile = new VirtualMachineScaleSetVmProfile()
{
OSProfile = new VirtualMachineScaleSetOSProfile()
{
ComputerNamePrefix = "{vmss-name}" ,
AdminUsername = "{your-username}" ,
AdminPassword = "{your-password}" ,
},
StorageProfile = new VirtualMachineScaleSetStorageProfile()
{
ImageReference = new ImageReference()
{
Publisher = "MicrosoftWindowsServer" ,
Offer = "WindowsServer" ,
Sku = "2016-Datacenter" ,
Version = "latest" ,
},
OSDisk = new VirtualMachineScaleSetOSDisk(DiskCreateOptionType.FromImage)
{
Caching = CachingType.ReadWrite,
DiskSizeGB = 512 ,
ManagedDisk = new VirtualMachineScaleSetManagedDisk()
{
StorageAccountType = StorageAccountType.StandardLrs,
},
},
DataDisks =
{
new VirtualMachineScaleSetDataDisk(0 ,DiskCreateOptionType.Empty)
{
DiskSizeGB = 1023 ,
},new VirtualMachineScaleSetDataDisk(1 ,DiskCreateOptionType.Empty)
{
DiskSizeGB = 1023 ,
}
},
},
NetworkProfile = new VirtualMachineScaleSetNetworkProfile()
{
NetworkInterfaceConfigurations =
{
new VirtualMachineScaleSetNetworkConfiguration("{vmss-name}" )
{
Primary = true ,
IPConfigurations =
{
new VirtualMachineScaleSetIPConfiguration("{vmss-name}" )
{
SubnetId = new ResourceIdentifier("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
}
},
EnableIPForwarding = true ,
}
},
},
},
Overprovision = true ,
};
ArmOperation<VirtualMachineScaleSetResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, virtualMachineScaleSetName, data);
VirtualMachineScaleSetResource result = lro.Value;
VirtualMachineScaleSetData resourceData = result.Data;
Console.WriteLine($"Succeeded on id: {resourceData.Id} " );
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
範例回覆
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 2 ,
"name" : "Standard_A1_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : false ,
"overprovision" : true ,
"uniqueId" : "8042c376-4690-4c47-9fa2-fbdad70e32fa" ,
"zoneBalance" : false ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter" ,
"publisher" : "MicrosoftWindowsServer" ,
"version" : "latest" ,
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage" ,
"diskSizeGB" : 512
},
"dataDisks" : [
{
"caching" : "None" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "Empty" ,
"lun" : 0 ,
"diskSizeGB" : 1023
},
{
"caching" : "None" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "Empty" ,
"lun" : 1 ,
"diskSizeGB" : 1023
}
]
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Automatic"
},
"provisioningState" : "Succeeded"
},
"zones" : [
"1" ,
"3"
],
"location" : "centralus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 2 ,
"name" : "Standard_A1_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : false ,
"overprovision" : true ,
"uniqueId" : "8042c376-4690-4c47-9fa2-fbdad70e32fa" ,
"zoneBalance" : false ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter" ,
"publisher" : "MicrosoftWindowsServer" ,
"version" : "latest" ,
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage" ,
"diskSizeGB" : 512
},
"dataDisks" : [
{
"caching" : "None" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "Empty" ,
"lun" : 0 ,
"diskSizeGB" : 1023
},
{
"caching" : "None" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "Empty" ,
"lun" : 1 ,
"diskSizeGB" : 1023
}
]
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Automatic"
},
"provisioningState" : "Creating"
},
"zones" : [
"1" ,
"3"
],
"location" : "centralus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
Create a scale set with vm size properties
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}?api-version=2022-11-01
{
"sku" : {
"tier" : "Standard",
"capacity" : 3,
"name" : "Standard_D1_v2"
},
"location" : "westus",
"properties" : {
"overprovision" : true,
"upgradePolicy" : {
"mode" : "Manual"
},
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter",
"publisher" : "MicrosoftWindowsServer",
"version" : "latest",
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite",
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"userData" : "RXhhbXBsZSBVc2VyRGF0YQ==",
"hardwareProfile" : {
"vmSizeProperties" : {
"vCPUsAvailable" : 1,
"vCPUsPerCore" : 1
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}",
"adminUsername" : "{your-username}",
"adminPassword" : "{your-password}"
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"primary" : true,
"enableIPForwarding" : true,
"ipConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
}
}
]
}
}
]
}
}
}
}
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineScaleSetInner;
import com.azure.resourcemanager.compute.models.ApiEntityReference;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.Sku;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.UpgradeMode;
import com.azure.resourcemanager.compute.models.UpgradePolicy;
import com.azure.resourcemanager.compute.models.VMSizeProperties;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetHardwareProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetIpConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetManagedDiskParameters;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSDisk;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetStorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetVMProfile;
import java.util.Arrays;
public final class Main {
public static void createAScaleSetWithVmSizeProperties (com.azure.resourcemanager.AzureResourceManager azure) {
azure
.virtualMachines()
.manager()
.serviceClient()
.getVirtualMachineScaleSets()
.createOrUpdate(
"myResourceGroup" ,
"{vmss-name}" ,
new VirtualMachineScaleSetInner()
.withLocation("westus" )
.withSku(new Sku().withName("Standard_D1_v2" ).withTier("Standard" ).withCapacity(3L ))
.withUpgradePolicy(new UpgradePolicy().withMode(UpgradeMode.MANUAL))
.withVirtualMachineProfile(
new VirtualMachineScaleSetVMProfile()
.withOsProfile(
new VirtualMachineScaleSetOSProfile()
.withComputerNamePrefix("{vmss-name}" )
.withAdminUsername("{your-username}" )
.withAdminPassword("fakeTokenPlaceholder" ))
.withStorageProfile(
new VirtualMachineScaleSetStorageProfile()
.withImageReference(
new ImageReference()
.withPublisher("MicrosoftWindowsServer" )
.withOffer("WindowsServer" )
.withSku("2016-Datacenter" )
.withVersion("latest" ))
.withOsDisk(
new VirtualMachineScaleSetOSDisk()
.withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)
.withManagedDisk(
new VirtualMachineScaleSetManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withNetworkProfile(
new VirtualMachineScaleSetNetworkProfile()
.withNetworkInterfaceConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetNetworkConfiguration()
.withName("{vmss-name}" )
.withPrimary(true )
.withIpConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetIpConfiguration()
.withName("{vmss-name}" )
.withSubnet(
new ApiEntityReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ))))
.withEnableIpForwarding(true ))))
.withUserData("RXhhbXBsZSBVc2VyRGF0YQ==" )
.withHardwareProfile(
new VirtualMachineScaleSetHardwareProfile()
.withVmSizeProperties(
new VMSizeProperties().withVCpusAvailable(1 ).withVCpusPerCore(1 ))))
.withOverprovision(true ),
com.azure.core.util.Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_scale_set_create_with_vm_size_properties.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main () :
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="{subscription-id}" ,
)
response = client.virtual_machine_scale_sets.begin_create_or_update(
resource_group_name="myResourceGroup" ,
vm_scale_set_name="{vmss-name}" ,
parameters={
"location" : "westus" ,
"properties" : {
"overprovision" : True ,
"upgradePolicy" : {"mode" : "Manual" },
"virtualMachineProfile" : {
"hardwareProfile" : {"vmSizeProperties" : {"vCPUsAvailable" : 1 , "vCPUsPerCore" : 1 }},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"enableIPForwarding" : True ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
},
}
],
"primary" : True ,
},
}
]
},
"osProfile" : {
"adminPassword" : "{your-password}" ,
"adminUsername" : "{your-username}" ,
"computerNamePrefix" : "{vmss-name}" ,
},
"storageProfile" : {
"imageReference" : {
"offer" : "WindowsServer" ,
"publisher" : "MicrosoftWindowsServer" ,
"sku" : "2016-Datacenter" ,
"version" : "latest" ,
},
"osDisk" : {
"caching" : "ReadWrite" ,
"createOption" : "FromImage" ,
"managedDisk" : {"storageAccountType" : "Standard_LRS" },
},
},
"userData" : "RXhhbXBsZSBVc2VyRGF0YQ==" ,
},
},
"sku" : {"capacity" : 3 , "name" : "Standard_D1_v2" , "tier" : "Standard" },
},
).result()
print(response)
if __name__ == "__main__" :
main()
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4"
)
func ExampleVirtualMachineScaleSetsClient_BeginCreateOrUpdate_createAScaleSetWithVmSizeProperties () {
cred, err := azidentity.NewDefaultAzureCredential(nil )
if err != nil {
log.Fatalf("failed to obtain a credential: %v" , err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("<subscription-id>" , cred, nil )
if err != nil {
log.Fatalf("failed to create client: %v" , err)
}
poller, err := clientFactory.NewVirtualMachineScaleSetsClient().BeginCreateOrUpdate(ctx, "myResourceGroup" , "{vmss-name}" , armcompute.VirtualMachineScaleSet{
Location: to.Ptr("westus" ),
Properties: &armcompute.VirtualMachineScaleSetProperties{
Overprovision: to.Ptr(true ),
UpgradePolicy: &armcompute.UpgradePolicy{
Mode: to.Ptr(armcompute.UpgradeModeManual),
},
VirtualMachineProfile: &armcompute.VirtualMachineScaleSetVMProfile{
HardwareProfile: &armcompute.VirtualMachineScaleSetHardwareProfile{
VMSizeProperties: &armcompute.VMSizeProperties{
VCPUsAvailable: to.Ptr[int32 ](1 ),
VCPUsPerCore: to.Ptr[int32 ](1 ),
},
},
NetworkProfile: &armcompute.VirtualMachineScaleSetNetworkProfile{
NetworkInterfaceConfigurations: []*armcompute.VirtualMachineScaleSetNetworkConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetNetworkConfigurationProperties{
EnableIPForwarding: to.Ptr(true ),
IPConfigurations: []*armcompute.VirtualMachineScaleSetIPConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetIPConfigurationProperties{
Subnet: &armcompute.APIEntityReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
},
},
}},
Primary: to.Ptr(true ),
},
}},
},
OSProfile: &armcompute.VirtualMachineScaleSetOSProfile{
AdminPassword: to.Ptr("{your-password}" ),
AdminUsername: to.Ptr("{your-username}" ),
ComputerNamePrefix: to.Ptr("{vmss-name}" ),
},
StorageProfile: &armcompute.VirtualMachineScaleSetStorageProfile{
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("WindowsServer" ),
Publisher: to.Ptr("MicrosoftWindowsServer" ),
SKU: to.Ptr("2016-Datacenter" ),
Version: to.Ptr("latest" ),
},
OSDisk: &armcompute.VirtualMachineScaleSetOSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.VirtualMachineScaleSetManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
UserData: to.Ptr("RXhhbXBsZSBVc2VyRGF0YQ==" ),
},
},
SKU: &armcompute.SKU{
Name: to.Ptr("Standard_D1_v2" ),
Capacity: to.Ptr[int64 ](3 ),
Tier: to.Ptr("Standard" ),
},
}, nil )
if err != nil {
log.Fatalf("failed to finish the request: %v" , err)
}
res, err := poller.PollUntilDone(ctx, nil )
if err != nil {
log.Fatalf("failed to pull the result: %v" , err)
}
_ = res
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require ("@azure/arm-compute" );
const { DefaultAzureCredential } = require ("@azure/identity" );
async function createAScaleSetWithVMSizeProperties ( ) {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID" ] || "{subscription-id}" ;
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP" ] || "myResourceGroup" ;
const vmScaleSetName = "{vmss-name}" ;
const parameters = {
location : "westus" ,
overprovision : true ,
sku : { name : "Standard_D1_v2" , capacity : 3 , tier : "Standard" },
upgradePolicy : { mode : "Manual" },
virtualMachineProfile : {
hardwareProfile : {
vmSizeProperties : { vCPUsAvailable : 1 , vCPUsPerCore : 1 },
},
networkProfile : {
networkInterfaceConfigurations : [
{
name : "{vmss-name}" ,
enableIPForwarding : true ,
ipConfigurations : [
{
name : "{vmss-name}" ,
subnet : {
id : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ,
},
},
],
primary : true ,
},
],
},
osProfile : {
adminPassword : "{your-password}" ,
adminUsername : "{your-username}" ,
computerNamePrefix : "{vmss-name}" ,
},
storageProfile : {
imageReference : {
offer : "WindowsServer" ,
publisher : "MicrosoftWindowsServer" ,
sku : "2016-Datacenter" ,
version : "latest" ,
},
osDisk : {
caching : "ReadWrite" ,
createOption : "FromImage" ,
managedDisk : { storageAccountType : "Standard_LRS" },
},
},
userData : "RXhhbXBsZSBVc2VyRGF0YQ==" ,
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachineScaleSets.beginCreateOrUpdateAndWait(
resourceGroupName,
vmScaleSetName,
parameters
);
console .log(result);
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Compute;
using Azure.ResourceManager.Compute.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Resources.Models;
TokenCredential cred = new DefaultAzureCredential();
ArmClient client = new ArmClient(cred);
string subscriptionId = "{subscription-id}" ;
string resourceGroupName = "myResourceGroup" ;
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
VirtualMachineScaleSetCollection collection = resourceGroupResource.GetVirtualMachineScaleSets();
string virtualMachineScaleSetName = "{vmss-name}" ;
VirtualMachineScaleSetData data = new VirtualMachineScaleSetData(new AzureLocation("westus" ))
{
Sku = new ComputeSku()
{
Name = "Standard_D1_v2" ,
Tier = "Standard" ,
Capacity = 3 ,
},
UpgradePolicy = new VirtualMachineScaleSetUpgradePolicy()
{
Mode = VirtualMachineScaleSetUpgradeMode.Manual,
},
VirtualMachineProfile = new VirtualMachineScaleSetVmProfile()
{
OSProfile = new VirtualMachineScaleSetOSProfile()
{
ComputerNamePrefix = "{vmss-name}" ,
AdminUsername = "{your-username}" ,
AdminPassword = "{your-password}" ,
},
StorageProfile = new VirtualMachineScaleSetStorageProfile()
{
ImageReference = new ImageReference()
{
Publisher = "MicrosoftWindowsServer" ,
Offer = "WindowsServer" ,
Sku = "2016-Datacenter" ,
Version = "latest" ,
},
OSDisk = new VirtualMachineScaleSetOSDisk(DiskCreateOptionType.FromImage)
{
Caching = CachingType.ReadWrite,
ManagedDisk = new VirtualMachineScaleSetManagedDisk()
{
StorageAccountType = StorageAccountType.StandardLrs,
},
},
},
NetworkProfile = new VirtualMachineScaleSetNetworkProfile()
{
NetworkInterfaceConfigurations =
{
new VirtualMachineScaleSetNetworkConfiguration("{vmss-name}" )
{
Primary = true ,
IPConfigurations =
{
new VirtualMachineScaleSetIPConfiguration("{vmss-name}" )
{
SubnetId = new ResourceIdentifier("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
}
},
EnableIPForwarding = true ,
}
},
},
UserData = "RXhhbXBsZSBVc2VyRGF0YQ==" ,
HardwareVmSizeProperties = new VirtualMachineSizeProperties()
{
VCpusAvailable = 1 ,
VCpusPerCore = 1 ,
},
},
Overprovision = true ,
};
ArmOperation<VirtualMachineScaleSetResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, virtualMachineScaleSetName, data);
VirtualMachineScaleSetResource result = lro.Value;
VirtualMachineScaleSetData resourceData = result.Data;
Console.WriteLine($"Succeeded on id: {resourceData.Id} " );
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
範例回覆
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_D1_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "d053ec5a-8da6-495f-ab13-38216503c6d7" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter" ,
"publisher" : "MicrosoftWindowsServer" ,
"version" : "latest" ,
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"hardwareProfile" : {
"vmSizeProperties" : {
"vCPUsAvailable" : 1 ,
"vCPUsPerCore" : 1
}
},
"diagnosticsProfile" : {
"bootDiagnostics" : {
"storageUri" : "http://nsgdiagnostic.blob.core.windows.net" ,
"enabled" : true
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_D1_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "d053ec5a-8da6-495f-ab13-38216503c6d7" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter" ,
"publisher" : "MicrosoftWindowsServer" ,
"version" : "latest" ,
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"hardwareProfile" : {
"vmSizeProperties" : {
"vCPUsAvailable" : 1 ,
"vCPUsPerCore" : 1
}
},
"diagnosticsProfile" : {
"bootDiagnostics" : {
"storageUri" : "http://nsgdiagnostic.blob.core.windows.net" ,
"enabled" : true
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
Create a VMSS with an extension that has suppressFailures enabled
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}?api-version=2022-11-01
{
"sku" : {
"tier" : "Standard",
"capacity" : 3,
"name" : "Standard_D1_v2"
},
"location" : "westus",
"properties" : {
"overprovision" : true,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter",
"publisher" : "MicrosoftWindowsServer",
"version" : "latest",
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite",
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"diagnosticsProfile" : {
"bootDiagnostics" : {
"storageUri" : "http://{existing-storage-account-name}.blob.core.windows.net",
"enabled" : true
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}",
"adminUsername" : "{your-username}",
"adminPassword" : "{your-password}"
},
"extensionProfile" : {
"extensions" : [
{
"name" : "{extension-name}",
"properties" : {
"autoUpgradeMinorVersion" : false,
"publisher" : "{extension-Publisher}",
"type" : "{extension-Type}",
"typeHandlerVersion" : "{handler-version}",
"settings" : {},
"suppressFailures" : true
}
}
]
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"primary" : true,
"enableIPForwarding" : true,
"ipConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
}
}
]
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
}
}
}
import com.azure.core.management.serializer.SerializerFactory;
import com.azure.core.util.serializer.SerializerEncoding;
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineScaleSetExtensionInner;
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineScaleSetInner;
import com.azure.resourcemanager.compute.models.ApiEntityReference;
import com.azure.resourcemanager.compute.models.BootDiagnostics;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiagnosticsProfile;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.Sku;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.UpgradeMode;
import com.azure.resourcemanager.compute.models.UpgradePolicy;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetExtensionProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetIpConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetManagedDiskParameters;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSDisk;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetStorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetVMProfile;
import java.io.IOException;
import java.util.Arrays;
public final class Main {
public static void createAVMSSWithAnExtensionThatHasSuppressFailuresEnabled (
com.azure.resourcemanager.AzureResourceManager azure) throws IOException {
azure
.virtualMachines()
.manager()
.serviceClient()
.getVirtualMachineScaleSets()
.createOrUpdate(
"myResourceGroup" ,
"{vmss-name}" ,
new VirtualMachineScaleSetInner()
.withLocation("westus" )
.withSku(new Sku().withName("Standard_D1_v2" ).withTier("Standard" ).withCapacity(3L ))
.withUpgradePolicy(new UpgradePolicy().withMode(UpgradeMode.MANUAL))
.withVirtualMachineProfile(
new VirtualMachineScaleSetVMProfile()
.withOsProfile(
new VirtualMachineScaleSetOSProfile()
.withComputerNamePrefix("{vmss-name}" )
.withAdminUsername("{your-username}" )
.withAdminPassword("fakeTokenPlaceholder" ))
.withStorageProfile(
new VirtualMachineScaleSetStorageProfile()
.withImageReference(
new ImageReference()
.withPublisher("MicrosoftWindowsServer" )
.withOffer("WindowsServer" )
.withSku("2016-Datacenter" )
.withVersion("latest" ))
.withOsDisk(
new VirtualMachineScaleSetOSDisk()
.withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)
.withManagedDisk(
new VirtualMachineScaleSetManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withNetworkProfile(
new VirtualMachineScaleSetNetworkProfile()
.withNetworkInterfaceConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetNetworkConfiguration()
.withName("{vmss-name}" )
.withPrimary(true )
.withIpConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetIpConfiguration()
.withName("{vmss-name}" )
.withSubnet(
new ApiEntityReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ))))
.withEnableIpForwarding(true ))))
.withDiagnosticsProfile(
new DiagnosticsProfile()
.withBootDiagnostics(
new BootDiagnostics()
.withEnabled(true )
.withStorageUri(
"http://{existing-storage-account-name}.blob.core.windows.net" )))
.withExtensionProfile(
new VirtualMachineScaleSetExtensionProfile()
.withExtensions(
Arrays
.asList(
new VirtualMachineScaleSetExtensionInner()
.withName("{extension-name}" )
.withPublisher("{extension-Publisher}" )
.withTypePropertiesType("{extension-Type}" )
.withTypeHandlerVersion("{handler-version}" )
.withAutoUpgradeMinorVersion(false )
.withSettings(
SerializerFactory
.createDefaultManagementSerializerAdapter()
.deserialize("{}" , Object.class, SerializerEncoding.JSON))
.withSuppressFailures(true )))))
.withOverprovision(true ),
com.azure.core.util.Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_scale_set_create_with_extensions_suppress_failures_enabled.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main () :
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="{subscription-id}" ,
)
response = client.virtual_machine_scale_sets.begin_create_or_update(
resource_group_name="myResourceGroup" ,
vm_scale_set_name="{vmss-name}" ,
parameters={
"location" : "westus" ,
"properties" : {
"overprovision" : True ,
"upgradePolicy" : {"mode" : "Manual" },
"virtualMachineProfile" : {
"diagnosticsProfile" : {
"bootDiagnostics" : {
"enabled" : True ,
"storageUri" : "http://{existing-storage-account-name}.blob.core.windows.net" ,
}
},
"extensionProfile" : {
"extensions" : [
{
"name" : "{extension-name}" ,
"properties" : {
"autoUpgradeMinorVersion" : False ,
"publisher" : "{extension-Publisher}" ,
"settings" : {},
"suppressFailures" : True ,
"type" : "{extension-Type}" ,
"typeHandlerVersion" : "{handler-version}" ,
},
}
]
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"enableIPForwarding" : True ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
},
}
],
"primary" : True ,
},
}
]
},
"osProfile" : {
"adminPassword" : "{your-password}" ,
"adminUsername" : "{your-username}" ,
"computerNamePrefix" : "{vmss-name}" ,
},
"storageProfile" : {
"imageReference" : {
"offer" : "WindowsServer" ,
"publisher" : "MicrosoftWindowsServer" ,
"sku" : "2016-Datacenter" ,
"version" : "latest" ,
},
"osDisk" : {
"caching" : "ReadWrite" ,
"createOption" : "FromImage" ,
"managedDisk" : {"storageAccountType" : "Standard_LRS" },
},
},
},
},
"sku" : {"capacity" : 3 , "name" : "Standard_D1_v2" , "tier" : "Standard" },
},
).result()
print(response)
if __name__ == "__main__" :
main()
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4"
)
func ExampleVirtualMachineScaleSetsClient_BeginCreateOrUpdate_createAVmssWithAnExtensionThatHasSuppressFailuresEnabled () {
cred, err := azidentity.NewDefaultAzureCredential(nil )
if err != nil {
log.Fatalf("failed to obtain a credential: %v" , err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("<subscription-id>" , cred, nil )
if err != nil {
log.Fatalf("failed to create client: %v" , err)
}
poller, err := clientFactory.NewVirtualMachineScaleSetsClient().BeginCreateOrUpdate(ctx, "myResourceGroup" , "{vmss-name}" , armcompute.VirtualMachineScaleSet{
Location: to.Ptr("westus" ),
Properties: &armcompute.VirtualMachineScaleSetProperties{
Overprovision: to.Ptr(true ),
UpgradePolicy: &armcompute.UpgradePolicy{
Mode: to.Ptr(armcompute.UpgradeModeManual),
},
VirtualMachineProfile: &armcompute.VirtualMachineScaleSetVMProfile{
DiagnosticsProfile: &armcompute.DiagnosticsProfile{
BootDiagnostics: &armcompute.BootDiagnostics{
Enabled: to.Ptr(true ),
StorageURI: to.Ptr("http://{existing-storage-account-name}.blob.core.windows.net" ),
},
},
ExtensionProfile: &armcompute.VirtualMachineScaleSetExtensionProfile{
Extensions: []*armcompute.VirtualMachineScaleSetExtension{
{
Name: to.Ptr("{extension-name}" ),
Properties: &armcompute.VirtualMachineScaleSetExtensionProperties{
Type: to.Ptr("{extension-Type}" ),
AutoUpgradeMinorVersion: to.Ptr(false ),
Publisher: to.Ptr("{extension-Publisher}" ),
Settings: map [string ]any{},
SuppressFailures: to.Ptr(true ),
TypeHandlerVersion: to.Ptr("{handler-version}" ),
},
}},
},
NetworkProfile: &armcompute.VirtualMachineScaleSetNetworkProfile{
NetworkInterfaceConfigurations: []*armcompute.VirtualMachineScaleSetNetworkConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetNetworkConfigurationProperties{
EnableIPForwarding: to.Ptr(true ),
IPConfigurations: []*armcompute.VirtualMachineScaleSetIPConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetIPConfigurationProperties{
Subnet: &armcompute.APIEntityReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
},
},
}},
Primary: to.Ptr(true ),
},
}},
},
OSProfile: &armcompute.VirtualMachineScaleSetOSProfile{
AdminPassword: to.Ptr("{your-password}" ),
AdminUsername: to.Ptr("{your-username}" ),
ComputerNamePrefix: to.Ptr("{vmss-name}" ),
},
StorageProfile: &armcompute.VirtualMachineScaleSetStorageProfile{
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("WindowsServer" ),
Publisher: to.Ptr("MicrosoftWindowsServer" ),
SKU: to.Ptr("2016-Datacenter" ),
Version: to.Ptr("latest" ),
},
OSDisk: &armcompute.VirtualMachineScaleSetOSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.VirtualMachineScaleSetManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
},
},
SKU: &armcompute.SKU{
Name: to.Ptr("Standard_D1_v2" ),
Capacity: to.Ptr[int64 ](3 ),
Tier: to.Ptr("Standard" ),
},
}, nil )
if err != nil {
log.Fatalf("failed to finish the request: %v" , err)
}
res, err := poller.PollUntilDone(ctx, nil )
if err != nil {
log.Fatalf("failed to pull the result: %v" , err)
}
_ = res
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require ("@azure/arm-compute" );
const { DefaultAzureCredential } = require ("@azure/identity" );
async function createAVmssWithAnExtensionThatHasSuppressFailuresEnabled ( ) {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID" ] || "{subscription-id}" ;
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP" ] || "myResourceGroup" ;
const vmScaleSetName = "{vmss-name}" ;
const parameters = {
location : "westus" ,
overprovision : true ,
sku : { name : "Standard_D1_v2" , capacity : 3 , tier : "Standard" },
upgradePolicy : { mode : "Manual" },
virtualMachineProfile : {
diagnosticsProfile : {
bootDiagnostics : {
enabled : true ,
storageUri : "http://{existing-storage-account-name}.blob.core.windows.net" ,
},
},
extensionProfile : {
extensions : [
{
name : "{extension-name}" ,
typePropertiesType : "{extension-Type}" ,
autoUpgradeMinorVersion : false ,
publisher : "{extension-Publisher}" ,
settings : {},
suppressFailures : true ,
typeHandlerVersion : "{handler-version}" ,
},
],
},
networkProfile : {
networkInterfaceConfigurations : [
{
name : "{vmss-name}" ,
enableIPForwarding : true ,
ipConfigurations : [
{
name : "{vmss-name}" ,
subnet : {
id : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ,
},
},
],
primary : true ,
},
],
},
osProfile : {
adminPassword : "{your-password}" ,
adminUsername : "{your-username}" ,
computerNamePrefix : "{vmss-name}" ,
},
storageProfile : {
imageReference : {
offer : "WindowsServer" ,
publisher : "MicrosoftWindowsServer" ,
sku : "2016-Datacenter" ,
version : "latest" ,
},
osDisk : {
caching : "ReadWrite" ,
createOption : "FromImage" ,
managedDisk : { storageAccountType : "Standard_LRS" },
},
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachineScaleSets.beginCreateOrUpdateAndWait(
resourceGroupName,
vmScaleSetName,
parameters
);
console .log(result);
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Compute;
using Azure.ResourceManager.Compute.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Resources.Models;
TokenCredential cred = new DefaultAzureCredential();
ArmClient client = new ArmClient(cred);
string subscriptionId = "{subscription-id}" ;
string resourceGroupName = "myResourceGroup" ;
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
VirtualMachineScaleSetCollection collection = resourceGroupResource.GetVirtualMachineScaleSets();
string virtualMachineScaleSetName = "{vmss-name}" ;
VirtualMachineScaleSetData data = new VirtualMachineScaleSetData(new AzureLocation("westus" ))
{
Sku = new ComputeSku()
{
Name = "Standard_D1_v2" ,
Tier = "Standard" ,
Capacity = 3 ,
},
UpgradePolicy = new VirtualMachineScaleSetUpgradePolicy()
{
Mode = VirtualMachineScaleSetUpgradeMode.Manual,
},
VirtualMachineProfile = new VirtualMachineScaleSetVmProfile()
{
OSProfile = new VirtualMachineScaleSetOSProfile()
{
ComputerNamePrefix = "{vmss-name}" ,
AdminUsername = "{your-username}" ,
AdminPassword = "{your-password}" ,
},
StorageProfile = new VirtualMachineScaleSetStorageProfile()
{
ImageReference = new ImageReference()
{
Publisher = "MicrosoftWindowsServer" ,
Offer = "WindowsServer" ,
Sku = "2016-Datacenter" ,
Version = "latest" ,
},
OSDisk = new VirtualMachineScaleSetOSDisk(DiskCreateOptionType.FromImage)
{
Caching = CachingType.ReadWrite,
ManagedDisk = new VirtualMachineScaleSetManagedDisk()
{
StorageAccountType = StorageAccountType.StandardLrs,
},
},
},
NetworkProfile = new VirtualMachineScaleSetNetworkProfile()
{
NetworkInterfaceConfigurations =
{
new VirtualMachineScaleSetNetworkConfiguration("{vmss-name}" )
{
Primary = true ,
IPConfigurations =
{
new VirtualMachineScaleSetIPConfiguration("{vmss-name}" )
{
SubnetId = new ResourceIdentifier("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
}
},
EnableIPForwarding = true ,
}
},
},
BootDiagnostics = new BootDiagnostics()
{
Enabled = true ,
StorageUri = new Uri("http://{existing-storage-account-name}.blob.core.windows.net" ),
},
ExtensionProfile = new VirtualMachineScaleSetExtensionProfile()
{
Extensions =
{
new VirtualMachineScaleSetExtensionData()
{
Publisher = "{extension-Publisher}" ,
ExtensionType = "{extension-Type}" ,
TypeHandlerVersion = "{handler-version}" ,
AutoUpgradeMinorVersion = false ,
Settings = BinaryData.FromObjectAsJson(new Dictionary<string , object >()
{
}),
SuppressFailures = true ,
}
},
},
},
Overprovision = true ,
};
ArmOperation<VirtualMachineScaleSetResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, virtualMachineScaleSetName, data);
VirtualMachineScaleSetResource result = lro.Value;
VirtualMachineScaleSetData resourceData = result.Data;
Console.WriteLine($"Succeeded on id: {resourceData.Id} " );
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
範例回覆
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_D1_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "d053ec5a-8da6-495f-ab13-38216503c6d7" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter" ,
"publisher" : "MicrosoftWindowsServer" ,
"version" : "latest" ,
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"diagnosticsProfile" : {
"bootDiagnostics" : {
"storageUri" : "http://nsgdiagnostic.blob.core.windows.net" ,
"enabled" : true
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"extensionProfile" : {
"extensions" : [
{
"name" : "{extension-name}" ,
"properties" : {
"autoUpgradeMinorVersion" : false ,
"publisher" : "{extension-Publisher}" ,
"type" : "{extension-Type}" ,
"typeHandlerVersion" : "{handler-version}" ,
"settings" : {},
"suppressFailures" : true
}
}
]
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_D1_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "d053ec5a-8da6-495f-ab13-38216503c6d7" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter" ,
"publisher" : "MicrosoftWindowsServer" ,
"version" : "latest" ,
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"diagnosticsProfile" : {
"bootDiagnostics" : {
"storageUri" : "http://nsgdiagnostic.blob.core.windows.net" ,
"enabled" : true
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"extensionProfile" : {
"extensions" : [
{
"name" : "{extension-name}" ,
"properties" : {
"autoUpgradeMinorVersion" : false ,
"publisher" : "{extension-Publisher}" ,
"type" : "{extension-Type}" ,
"typeHandlerVersion" : "{handler-version}" ,
"settings" : {},
"suppressFailures" : true
}
}
]
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
Create a VMSS with an extension with protectedSettingsFromKeyVault
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}?api-version=2022-11-01
{
"sku" : {
"tier" : "Standard",
"capacity" : 3,
"name" : "Standard_D1_v2"
},
"location" : "westus",
"properties" : {
"overprovision" : true,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter",
"publisher" : "MicrosoftWindowsServer",
"version" : "latest",
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite",
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"diagnosticsProfile" : {
"bootDiagnostics" : {
"storageUri" : "http://{existing-storage-account-name}.blob.core.windows.net",
"enabled" : true
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}",
"adminUsername" : "{your-username}",
"adminPassword" : "{your-password}"
},
"extensionProfile" : {
"extensions" : [
{
"name" : "{extension-name}",
"properties" : {
"autoUpgradeMinorVersion" : false,
"publisher" : "{extension-Publisher}",
"type" : "{extension-Type}",
"typeHandlerVersion" : "{handler-version}",
"settings" : {},
"protectedSettingsFromKeyVault" : {
"sourceVault" : {
"id" : "/subscriptions/a53f7094-a16c-47af-abe4-b05c05d0d79a/resourceGroups/myResourceGroup/providers/Microsoft.KeyVault/vaults/kvName"
},
"secretUrl" : "https://kvName.vault.azure.net/secrets/secretName/79b88b3a6f5440ffb2e73e44a0db712e"
}
}
}
]
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"primary" : true,
"enableIPForwarding" : true,
"ipConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
}
}
]
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
}
}
}
import com.azure.core.management.SubResource;
import com.azure.core.management.serializer.SerializerFactory;
import com.azure.core.util.serializer.SerializerEncoding;
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineScaleSetExtensionInner;
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineScaleSetInner;
import com.azure.resourcemanager.compute.models.ApiEntityReference;
import com.azure.resourcemanager.compute.models.BootDiagnostics;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DiagnosticsProfile;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.KeyVaultSecretReference;
import com.azure.resourcemanager.compute.models.Sku;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.UpgradeMode;
import com.azure.resourcemanager.compute.models.UpgradePolicy;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetExtensionProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetIpConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetManagedDiskParameters;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSDisk;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetStorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetVMProfile;
import java.io.IOException;
import java.util.Arrays;
public final class Main {
public static void createAVMSSWithAnExtensionWithProtectedSettingsFromKeyVault (
com.azure.resourcemanager.AzureResourceManager azure) throws IOException {
azure
.virtualMachines()
.manager()
.serviceClient()
.getVirtualMachineScaleSets()
.createOrUpdate(
"myResourceGroup" ,
"{vmss-name}" ,
new VirtualMachineScaleSetInner()
.withLocation("westus" )
.withSku(new Sku().withName("Standard_D1_v2" ).withTier("Standard" ).withCapacity(3L ))
.withUpgradePolicy(new UpgradePolicy().withMode(UpgradeMode.MANUAL))
.withVirtualMachineProfile(
new VirtualMachineScaleSetVMProfile()
.withOsProfile(
new VirtualMachineScaleSetOSProfile()
.withComputerNamePrefix("{vmss-name}" )
.withAdminUsername("{your-username}" )
.withAdminPassword("fakeTokenPlaceholder" ))
.withStorageProfile(
new VirtualMachineScaleSetStorageProfile()
.withImageReference(
new ImageReference()
.withPublisher("MicrosoftWindowsServer" )
.withOffer("WindowsServer" )
.withSku("2016-Datacenter" )
.withVersion("latest" ))
.withOsDisk(
new VirtualMachineScaleSetOSDisk()
.withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)
.withManagedDisk(
new VirtualMachineScaleSetManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withNetworkProfile(
new VirtualMachineScaleSetNetworkProfile()
.withNetworkInterfaceConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetNetworkConfiguration()
.withName("{vmss-name}" )
.withPrimary(true )
.withIpConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetIpConfiguration()
.withName("{vmss-name}" )
.withSubnet(
new ApiEntityReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ))))
.withEnableIpForwarding(true ))))
.withDiagnosticsProfile(
new DiagnosticsProfile()
.withBootDiagnostics(
new BootDiagnostics()
.withEnabled(true )
.withStorageUri(
"http://{existing-storage-account-name}.blob.core.windows.net" )))
.withExtensionProfile(
new VirtualMachineScaleSetExtensionProfile()
.withExtensions(
Arrays
.asList(
new VirtualMachineScaleSetExtensionInner()
.withName("{extension-name}" )
.withPublisher("{extension-Publisher}" )
.withTypePropertiesType("{extension-Type}" )
.withTypeHandlerVersion("{handler-version}" )
.withAutoUpgradeMinorVersion(false )
.withSettings(
SerializerFactory
.createDefaultManagementSerializerAdapter()
.deserialize("{}" , Object.class, SerializerEncoding.JSON))
.withProtectedSettingsFromKeyVault(
new KeyVaultSecretReference()
.withSecretUrl("fakeTokenPlaceholder" )
.withSourceVault(
new SubResource()
.withId(
"/subscriptions/a53f7094-a16c-47af-abe4-b05c05d0d79a/resourceGroups/myResourceGroup/providers/Microsoft.KeyVault/vaults/kvName" )))))))
.withOverprovision(true ),
com.azure.core.util.Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_scale_set_create_with_protected_settings_from_key_vault.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main () :
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="{subscription-id}" ,
)
response = client.virtual_machine_scale_sets.begin_create_or_update(
resource_group_name="myResourceGroup" ,
vm_scale_set_name="{vmss-name}" ,
parameters={
"location" : "westus" ,
"properties" : {
"overprovision" : True ,
"upgradePolicy" : {"mode" : "Manual" },
"virtualMachineProfile" : {
"diagnosticsProfile" : {
"bootDiagnostics" : {
"enabled" : True ,
"storageUri" : "http://{existing-storage-account-name}.blob.core.windows.net" ,
}
},
"extensionProfile" : {
"extensions" : [
{
"name" : "{extension-name}" ,
"properties" : {
"autoUpgradeMinorVersion" : False ,
"protectedSettingsFromKeyVault" : {
"secretUrl" : "https://kvName.vault.azure.net/secrets/secretName/79b88b3a6f5440ffb2e73e44a0db712e" ,
"sourceVault" : {
"id" : "/subscriptions/a53f7094-a16c-47af-abe4-b05c05d0d79a/resourceGroups/myResourceGroup/providers/Microsoft.KeyVault/vaults/kvName"
},
},
"publisher" : "{extension-Publisher}" ,
"settings" : {},
"type" : "{extension-Type}" ,
"typeHandlerVersion" : "{handler-version}" ,
},
}
]
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"enableIPForwarding" : True ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
},
}
],
"primary" : True ,
},
}
]
},
"osProfile" : {
"adminPassword" : "{your-password}" ,
"adminUsername" : "{your-username}" ,
"computerNamePrefix" : "{vmss-name}" ,
},
"storageProfile" : {
"imageReference" : {
"offer" : "WindowsServer" ,
"publisher" : "MicrosoftWindowsServer" ,
"sku" : "2016-Datacenter" ,
"version" : "latest" ,
},
"osDisk" : {
"caching" : "ReadWrite" ,
"createOption" : "FromImage" ,
"managedDisk" : {"storageAccountType" : "Standard_LRS" },
},
},
},
},
"sku" : {"capacity" : 3 , "name" : "Standard_D1_v2" , "tier" : "Standard" },
},
).result()
print(response)
if __name__ == "__main__" :
main()
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4"
)
func ExampleVirtualMachineScaleSetsClient_BeginCreateOrUpdate_createAVmssWithAnExtensionWithProtectedSettingsFromKeyVault () {
cred, err := azidentity.NewDefaultAzureCredential(nil )
if err != nil {
log.Fatalf("failed to obtain a credential: %v" , err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("<subscription-id>" , cred, nil )
if err != nil {
log.Fatalf("failed to create client: %v" , err)
}
poller, err := clientFactory.NewVirtualMachineScaleSetsClient().BeginCreateOrUpdate(ctx, "myResourceGroup" , "{vmss-name}" , armcompute.VirtualMachineScaleSet{
Location: to.Ptr("westus" ),
Properties: &armcompute.VirtualMachineScaleSetProperties{
Overprovision: to.Ptr(true ),
UpgradePolicy: &armcompute.UpgradePolicy{
Mode: to.Ptr(armcompute.UpgradeModeManual),
},
VirtualMachineProfile: &armcompute.VirtualMachineScaleSetVMProfile{
DiagnosticsProfile: &armcompute.DiagnosticsProfile{
BootDiagnostics: &armcompute.BootDiagnostics{
Enabled: to.Ptr(true ),
StorageURI: to.Ptr("http://{existing-storage-account-name}.blob.core.windows.net" ),
},
},
ExtensionProfile: &armcompute.VirtualMachineScaleSetExtensionProfile{
Extensions: []*armcompute.VirtualMachineScaleSetExtension{
{
Name: to.Ptr("{extension-name}" ),
Properties: &armcompute.VirtualMachineScaleSetExtensionProperties{
Type: to.Ptr("{extension-Type}" ),
AutoUpgradeMinorVersion: to.Ptr(false ),
ProtectedSettingsFromKeyVault: &armcompute.KeyVaultSecretReference{
SecretURL: to.Ptr("https://kvName.vault.azure.net/secrets/secretName/79b88b3a6f5440ffb2e73e44a0db712e" ),
SourceVault: &armcompute.SubResource{
ID: to.Ptr("/subscriptions/a53f7094-a16c-47af-abe4-b05c05d0d79a/resourceGroups/myResourceGroup/providers/Microsoft.KeyVault/vaults/kvName" ),
},
},
Publisher: to.Ptr("{extension-Publisher}" ),
Settings: map [string ]any{},
TypeHandlerVersion: to.Ptr("{handler-version}" ),
},
}},
},
NetworkProfile: &armcompute.VirtualMachineScaleSetNetworkProfile{
NetworkInterfaceConfigurations: []*armcompute.VirtualMachineScaleSetNetworkConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetNetworkConfigurationProperties{
EnableIPForwarding: to.Ptr(true ),
IPConfigurations: []*armcompute.VirtualMachineScaleSetIPConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetIPConfigurationProperties{
Subnet: &armcompute.APIEntityReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
},
},
}},
Primary: to.Ptr(true ),
},
}},
},
OSProfile: &armcompute.VirtualMachineScaleSetOSProfile{
AdminPassword: to.Ptr("{your-password}" ),
AdminUsername: to.Ptr("{your-username}" ),
ComputerNamePrefix: to.Ptr("{vmss-name}" ),
},
StorageProfile: &armcompute.VirtualMachineScaleSetStorageProfile{
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("WindowsServer" ),
Publisher: to.Ptr("MicrosoftWindowsServer" ),
SKU: to.Ptr("2016-Datacenter" ),
Version: to.Ptr("latest" ),
},
OSDisk: &armcompute.VirtualMachineScaleSetOSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.VirtualMachineScaleSetManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
},
},
SKU: &armcompute.SKU{
Name: to.Ptr("Standard_D1_v2" ),
Capacity: to.Ptr[int64 ](3 ),
Tier: to.Ptr("Standard" ),
},
}, nil )
if err != nil {
log.Fatalf("failed to finish the request: %v" , err)
}
res, err := poller.PollUntilDone(ctx, nil )
if err != nil {
log.Fatalf("failed to pull the result: %v" , err)
}
_ = res
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require ("@azure/arm-compute" );
const { DefaultAzureCredential } = require ("@azure/identity" );
async function createAVmssWithAnExtensionWithProtectedSettingsFromKeyVault ( ) {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID" ] || "{subscription-id}" ;
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP" ] || "myResourceGroup" ;
const vmScaleSetName = "{vmss-name}" ;
const parameters = {
location : "westus" ,
overprovision : true ,
sku : { name : "Standard_D1_v2" , capacity : 3 , tier : "Standard" },
upgradePolicy : { mode : "Manual" },
virtualMachineProfile : {
diagnosticsProfile : {
bootDiagnostics : {
enabled : true ,
storageUri : "http://{existing-storage-account-name}.blob.core.windows.net" ,
},
},
extensionProfile : {
extensions : [
{
name : "{extension-name}" ,
typePropertiesType : "{extension-Type}" ,
autoUpgradeMinorVersion : false ,
protectedSettingsFromKeyVault : {
secretUrl :
"https://kvName.vault.azure.net/secrets/secretName/79b88b3a6f5440ffb2e73e44a0db712e" ,
sourceVault : {
id : "/subscriptions/a53f7094-a16c-47af-abe4-b05c05d0d79a/resourceGroups/myResourceGroup/providers/Microsoft.KeyVault/vaults/kvName" ,
},
},
publisher : "{extension-Publisher}" ,
settings : {},
typeHandlerVersion : "{handler-version}" ,
},
],
},
networkProfile : {
networkInterfaceConfigurations : [
{
name : "{vmss-name}" ,
enableIPForwarding : true ,
ipConfigurations : [
{
name : "{vmss-name}" ,
subnet : {
id : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ,
},
},
],
primary : true ,
},
],
},
osProfile : {
adminPassword : "{your-password}" ,
adminUsername : "{your-username}" ,
computerNamePrefix : "{vmss-name}" ,
},
storageProfile : {
imageReference : {
offer : "WindowsServer" ,
publisher : "MicrosoftWindowsServer" ,
sku : "2016-Datacenter" ,
version : "latest" ,
},
osDisk : {
caching : "ReadWrite" ,
createOption : "FromImage" ,
managedDisk : { storageAccountType : "Standard_LRS" },
},
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachineScaleSets.beginCreateOrUpdateAndWait(
resourceGroupName,
vmScaleSetName,
parameters
);
console .log(result);
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Compute;
using Azure.ResourceManager.Compute.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Resources.Models;
TokenCredential cred = new DefaultAzureCredential();
ArmClient client = new ArmClient(cred);
string subscriptionId = "{subscription-id}" ;
string resourceGroupName = "myResourceGroup" ;
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
VirtualMachineScaleSetCollection collection = resourceGroupResource.GetVirtualMachineScaleSets();
string virtualMachineScaleSetName = "{vmss-name}" ;
VirtualMachineScaleSetData data = new VirtualMachineScaleSetData(new AzureLocation("westus" ))
{
Sku = new ComputeSku()
{
Name = "Standard_D1_v2" ,
Tier = "Standard" ,
Capacity = 3 ,
},
UpgradePolicy = new VirtualMachineScaleSetUpgradePolicy()
{
Mode = VirtualMachineScaleSetUpgradeMode.Manual,
},
VirtualMachineProfile = new VirtualMachineScaleSetVmProfile()
{
OSProfile = new VirtualMachineScaleSetOSProfile()
{
ComputerNamePrefix = "{vmss-name}" ,
AdminUsername = "{your-username}" ,
AdminPassword = "{your-password}" ,
},
StorageProfile = new VirtualMachineScaleSetStorageProfile()
{
ImageReference = new ImageReference()
{
Publisher = "MicrosoftWindowsServer" ,
Offer = "WindowsServer" ,
Sku = "2016-Datacenter" ,
Version = "latest" ,
},
OSDisk = new VirtualMachineScaleSetOSDisk(DiskCreateOptionType.FromImage)
{
Caching = CachingType.ReadWrite,
ManagedDisk = new VirtualMachineScaleSetManagedDisk()
{
StorageAccountType = StorageAccountType.StandardLrs,
},
},
},
NetworkProfile = new VirtualMachineScaleSetNetworkProfile()
{
NetworkInterfaceConfigurations =
{
new VirtualMachineScaleSetNetworkConfiguration("{vmss-name}" )
{
Primary = true ,
IPConfigurations =
{
new VirtualMachineScaleSetIPConfiguration("{vmss-name}" )
{
SubnetId = new ResourceIdentifier("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
}
},
EnableIPForwarding = true ,
}
},
},
BootDiagnostics = new BootDiagnostics()
{
Enabled = true ,
StorageUri = new Uri("http://{existing-storage-account-name}.blob.core.windows.net" ),
},
ExtensionProfile = new VirtualMachineScaleSetExtensionProfile()
{
Extensions =
{
new VirtualMachineScaleSetExtensionData()
{
Publisher = "{extension-Publisher}" ,
ExtensionType = "{extension-Type}" ,
TypeHandlerVersion = "{handler-version}" ,
AutoUpgradeMinorVersion = false ,
Settings = BinaryData.FromObjectAsJson(new Dictionary<string , object >()
{
}),
KeyVaultProtectedSettings = new KeyVaultSecretReference(new Uri("https://kvName.vault.azure.net/secrets/secretName/79b88b3a6f5440ffb2e73e44a0db712e" ),new WritableSubResource()
{
Id = new ResourceIdentifier("/subscriptions/a53f7094-a16c-47af-abe4-b05c05d0d79a/resourceGroups/myResourceGroup/providers/Microsoft.KeyVault/vaults/kvName" ),
}),
}
},
},
},
Overprovision = true ,
};
ArmOperation<VirtualMachineScaleSetResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, virtualMachineScaleSetName, data);
VirtualMachineScaleSetResource result = lro.Value;
VirtualMachineScaleSetData resourceData = result.Data;
Console.WriteLine($"Succeeded on id: {resourceData.Id} " );
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
範例回覆
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_D1_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "d053ec5a-8da6-495f-ab13-38216503c6d7" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter" ,
"publisher" : "MicrosoftWindowsServer" ,
"version" : "latest" ,
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"diagnosticsProfile" : {
"bootDiagnostics" : {
"storageUri" : "http://nsgdiagnostic.blob.core.windows.net" ,
"enabled" : true
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"extensionProfile" : {
"extensions" : [
{
"name" : "{extension-name}" ,
"properties" : {
"autoUpgradeMinorVersion" : false ,
"publisher" : "{extension-Publisher}" ,
"type" : "{extension-Type}" ,
"typeHandlerVersion" : "{handler-version}" ,
"settings" : {},
"protectedSettingsFromKeyVault" : {
"sourceVault" : {
"id" : "/subscriptions/a53f7094-a16c-47af-abe4-b05c05d0d79a/resourceGroups/myResourceGroup/providers/Microsoft.KeyVault/vaults/kvName"
},
"secretUrl" : "https://kvName.vault.azure.net/secrets/secretName/79b88b3a6f5440ffb2e73e44a0db712e"
}
}
}
]
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_D1_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "d053ec5a-8da6-495f-ab13-38216503c6d7" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter" ,
"publisher" : "MicrosoftWindowsServer" ,
"version" : "latest" ,
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"diagnosticsProfile" : {
"bootDiagnostics" : {
"storageUri" : "http://nsgdiagnostic.blob.core.windows.net" ,
"enabled" : true
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"extensionProfile" : {
"extensions" : [
{
"name" : "{extension-name}" ,
"properties" : {
"autoUpgradeMinorVersion" : false ,
"publisher" : "{extension-Publisher}" ,
"type" : "{extension-Type}" ,
"typeHandlerVersion" : "{handler-version}" ,
"settings" : {},
"protectedSettingsFromKeyVault" : {
"sourceVault" : {
"id" : "/subscriptions/a53f7094-a16c-47af-abe4-b05c05d0d79a/resourceGroups/myResourceGroup/providers/Microsoft.KeyVault/vaults/kvName"
},
"secretUrl" : "https://kvName.vault.azure.net/secrets/secretName/79b88b3a6f5440ffb2e73e44a0db712e"
}
}
}
]
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
Create or update a scale set with capacity reservation.
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}?api-version=2022-11-01
{
"sku" : {
"tier" : "Standard",
"capacity" : 3,
"name" : "Standard_DS1_v2"
},
"location" : "westus",
"properties" : {
"overprovision" : true,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter",
"publisher" : "MicrosoftWindowsServer",
"version" : "latest",
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite",
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}",
"adminUsername" : "{your-username}",
"adminPassword" : "{your-password}"
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"primary" : true,
"enableIPForwarding" : true,
"ipConfigurations" : [
{
"name" : "{vmss-name}",
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
}
}
]
}
}
]
},
"capacityReservation" : {
"capacityReservationGroup" : {
"id" : "subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/CapacityReservationGroups/{crgName}"
}
}
},
"upgradePolicy" : {
"mode" : "Manual"
}
}
}
import com.azure.core.management.SubResource;
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineScaleSetInner;
import com.azure.resourcemanager.compute.models.ApiEntityReference;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.CapacityReservationProfile;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.Sku;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.UpgradeMode;
import com.azure.resourcemanager.compute.models.UpgradePolicy;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetIpConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetManagedDiskParameters;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetNetworkProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSDisk;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetOSProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetStorageProfile;
import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetVMProfile;
import java.util.Arrays;
public final class Main {
public static void createOrUpdateAScaleSetWithCapacityReservation (
com.azure.resourcemanager.AzureResourceManager azure) {
azure
.virtualMachines()
.manager()
.serviceClient()
.getVirtualMachineScaleSets()
.createOrUpdate(
"myResourceGroup" ,
"{vmss-name}" ,
new VirtualMachineScaleSetInner()
.withLocation("westus" )
.withSku(new Sku().withName("Standard_DS1_v2" ).withTier("Standard" ).withCapacity(3L ))
.withUpgradePolicy(new UpgradePolicy().withMode(UpgradeMode.MANUAL))
.withVirtualMachineProfile(
new VirtualMachineScaleSetVMProfile()
.withOsProfile(
new VirtualMachineScaleSetOSProfile()
.withComputerNamePrefix("{vmss-name}" )
.withAdminUsername("{your-username}" )
.withAdminPassword("fakeTokenPlaceholder" ))
.withStorageProfile(
new VirtualMachineScaleSetStorageProfile()
.withImageReference(
new ImageReference()
.withPublisher("MicrosoftWindowsServer" )
.withOffer("WindowsServer" )
.withSku("2016-Datacenter" )
.withVersion("latest" ))
.withOsDisk(
new VirtualMachineScaleSetOSDisk()
.withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)
.withManagedDisk(
new VirtualMachineScaleSetManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withNetworkProfile(
new VirtualMachineScaleSetNetworkProfile()
.withNetworkInterfaceConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetNetworkConfiguration()
.withName("{vmss-name}" )
.withPrimary(true )
.withIpConfigurations(
Arrays
.asList(
new VirtualMachineScaleSetIpConfiguration()
.withName("{vmss-name}" )
.withSubnet(
new ApiEntityReference()
.withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ))))
.withEnableIpForwarding(true ))))
.withCapacityReservation(
new CapacityReservationProfile()
.withCapacityReservationGroup(
new SubResource()
.withId(
"subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/CapacityReservationGroups/{crgName}" ))))
.withOverprovision(true ),
com.azure.core.util.Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python virtual_machine_scale_set_create_with_capacity_reservation.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main () :
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="{subscription-id}" ,
)
response = client.virtual_machine_scale_sets.begin_create_or_update(
resource_group_name="myResourceGroup" ,
vm_scale_set_name="{vmss-name}" ,
parameters={
"location" : "westus" ,
"properties" : {
"overprovision" : True ,
"upgradePolicy" : {"mode" : "Manual" },
"virtualMachineProfile" : {
"capacityReservation" : {
"capacityReservationGroup" : {
"id" : "subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/CapacityReservationGroups/{crgName}"
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"enableIPForwarding" : True ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}"
}
},
}
],
"primary" : True ,
},
}
]
},
"osProfile" : {
"adminPassword" : "{your-password}" ,
"adminUsername" : "{your-username}" ,
"computerNamePrefix" : "{vmss-name}" ,
},
"storageProfile" : {
"imageReference" : {
"offer" : "WindowsServer" ,
"publisher" : "MicrosoftWindowsServer" ,
"sku" : "2016-Datacenter" ,
"version" : "latest" ,
},
"osDisk" : {
"caching" : "ReadWrite" ,
"createOption" : "FromImage" ,
"managedDisk" : {"storageAccountType" : "Standard_LRS" },
},
},
},
},
"sku" : {"capacity" : 3 , "name" : "Standard_DS1_v2" , "tier" : "Standard" },
},
).result()
print(response)
if __name__ == "__main__" :
main()
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4"
)
func ExampleVirtualMachineScaleSetsClient_BeginCreateOrUpdate_createOrUpdateAScaleSetWithCapacityReservation () {
cred, err := azidentity.NewDefaultAzureCredential(nil )
if err != nil {
log.Fatalf("failed to obtain a credential: %v" , err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("<subscription-id>" , cred, nil )
if err != nil {
log.Fatalf("failed to create client: %v" , err)
}
poller, err := clientFactory.NewVirtualMachineScaleSetsClient().BeginCreateOrUpdate(ctx, "myResourceGroup" , "{vmss-name}" , armcompute.VirtualMachineScaleSet{
Location: to.Ptr("westus" ),
Properties: &armcompute.VirtualMachineScaleSetProperties{
Overprovision: to.Ptr(true ),
UpgradePolicy: &armcompute.UpgradePolicy{
Mode: to.Ptr(armcompute.UpgradeModeManual),
},
VirtualMachineProfile: &armcompute.VirtualMachineScaleSetVMProfile{
CapacityReservation: &armcompute.CapacityReservationProfile{
CapacityReservationGroup: &armcompute.SubResource{
ID: to.Ptr("subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/CapacityReservationGroups/{crgName}" ),
},
},
NetworkProfile: &armcompute.VirtualMachineScaleSetNetworkProfile{
NetworkInterfaceConfigurations: []*armcompute.VirtualMachineScaleSetNetworkConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetNetworkConfigurationProperties{
EnableIPForwarding: to.Ptr(true ),
IPConfigurations: []*armcompute.VirtualMachineScaleSetIPConfiguration{
{
Name: to.Ptr("{vmss-name}" ),
Properties: &armcompute.VirtualMachineScaleSetIPConfigurationProperties{
Subnet: &armcompute.APIEntityReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
},
},
}},
Primary: to.Ptr(true ),
},
}},
},
OSProfile: &armcompute.VirtualMachineScaleSetOSProfile{
AdminPassword: to.Ptr("{your-password}" ),
AdminUsername: to.Ptr("{your-username}" ),
ComputerNamePrefix: to.Ptr("{vmss-name}" ),
},
StorageProfile: &armcompute.VirtualMachineScaleSetStorageProfile{
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("WindowsServer" ),
Publisher: to.Ptr("MicrosoftWindowsServer" ),
SKU: to.Ptr("2016-Datacenter" ),
Version: to.Ptr("latest" ),
},
OSDisk: &armcompute.VirtualMachineScaleSetOSDisk{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.VirtualMachineScaleSetManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
},
},
SKU: &armcompute.SKU{
Name: to.Ptr("Standard_DS1_v2" ),
Capacity: to.Ptr[int64 ](3 ),
Tier: to.Ptr("Standard" ),
},
}, nil )
if err != nil {
log.Fatalf("failed to finish the request: %v" , err)
}
res, err := poller.PollUntilDone(ctx, nil )
if err != nil {
log.Fatalf("failed to pull the result: %v" , err)
}
_ = res
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require ("@azure/arm-compute" );
const { DefaultAzureCredential } = require ("@azure/identity" );
async function createOrUpdateAScaleSetWithCapacityReservation ( ) {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID" ] || "{subscription-id}" ;
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP" ] || "myResourceGroup" ;
const vmScaleSetName = "{vmss-name}" ;
const parameters = {
location : "westus" ,
overprovision : true ,
sku : { name : "Standard_DS1_v2" , capacity : 3 , tier : "Standard" },
upgradePolicy : { mode : "Manual" },
virtualMachineProfile : {
capacityReservation : {
capacityReservationGroup : {
id : "subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/CapacityReservationGroups/{crgName}" ,
},
},
networkProfile : {
networkInterfaceConfigurations : [
{
name : "{vmss-name}" ,
enableIPForwarding : true ,
ipConfigurations : [
{
name : "{vmss-name}" ,
subnet : {
id : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ,
},
},
],
primary : true ,
},
],
},
osProfile : {
adminPassword : "{your-password}" ,
adminUsername : "{your-username}" ,
computerNamePrefix : "{vmss-name}" ,
},
storageProfile : {
imageReference : {
offer : "WindowsServer" ,
publisher : "MicrosoftWindowsServer" ,
sku : "2016-Datacenter" ,
version : "latest" ,
},
osDisk : {
caching : "ReadWrite" ,
createOption : "FromImage" ,
managedDisk : { storageAccountType : "Standard_LRS" },
},
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachineScaleSets.beginCreateOrUpdateAndWait(
resourceGroupName,
vmScaleSetName,
parameters
);
console .log(result);
}
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Compute;
using Azure.ResourceManager.Compute.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Resources.Models;
TokenCredential cred = new DefaultAzureCredential();
ArmClient client = new ArmClient(cred);
string subscriptionId = "{subscription-id}" ;
string resourceGroupName = "myResourceGroup" ;
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
VirtualMachineScaleSetCollection collection = resourceGroupResource.GetVirtualMachineScaleSets();
string virtualMachineScaleSetName = "{vmss-name}" ;
VirtualMachineScaleSetData data = new VirtualMachineScaleSetData(new AzureLocation("westus" ))
{
Sku = new ComputeSku()
{
Name = "Standard_DS1_v2" ,
Tier = "Standard" ,
Capacity = 3 ,
},
UpgradePolicy = new VirtualMachineScaleSetUpgradePolicy()
{
Mode = VirtualMachineScaleSetUpgradeMode.Manual,
},
VirtualMachineProfile = new VirtualMachineScaleSetVmProfile()
{
OSProfile = new VirtualMachineScaleSetOSProfile()
{
ComputerNamePrefix = "{vmss-name}" ,
AdminUsername = "{your-username}" ,
AdminPassword = "{your-password}" ,
},
StorageProfile = new VirtualMachineScaleSetStorageProfile()
{
ImageReference = new ImageReference()
{
Publisher = "MicrosoftWindowsServer" ,
Offer = "WindowsServer" ,
Sku = "2016-Datacenter" ,
Version = "latest" ,
},
OSDisk = new VirtualMachineScaleSetOSDisk(DiskCreateOptionType.FromImage)
{
Caching = CachingType.ReadWrite,
ManagedDisk = new VirtualMachineScaleSetManagedDisk()
{
StorageAccountType = StorageAccountType.StandardLrs,
},
},
},
NetworkProfile = new VirtualMachineScaleSetNetworkProfile()
{
NetworkInterfaceConfigurations =
{
new VirtualMachineScaleSetNetworkConfiguration("{vmss-name}" )
{
Primary = true ,
IPConfigurations =
{
new VirtualMachineScaleSetIPConfiguration("{vmss-name}" )
{
SubnetId = new ResourceIdentifier("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/{existing-virtual-network-name}/subnets/{existing-subnet-name}" ),
}
},
EnableIPForwarding = true ,
}
},
},
CapacityReservationGroupId = new ResourceIdentifier("subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/CapacityReservationGroups/{crgName}" ),
},
Overprovision = true ,
};
ArmOperation<VirtualMachineScaleSetResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, virtualMachineScaleSetName, data);
VirtualMachineScaleSetResource result = lro.Value;
VirtualMachineScaleSetData resourceData = result.Data;
Console.WriteLine($"Succeeded on id: {resourceData.Id} " );
To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue
範例回覆
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_DS1_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "d053ec5a-8da6-495f-ab13-38216503c6d7" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter" ,
"publisher" : "MicrosoftWindowsServer" ,
"version" : "latest" ,
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
},
"capacityReservation" : {
"capacityReservationGroup" : {
"id" : "subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/CapacityReservationGroups/{crgName}"
}
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
{
"sku" : {
"tier" : "Standard" ,
"capacity" : 3 ,
"name" : "Standard_DS1_v2"
},
"name" : "{vmss-name}" ,
"properties" : {
"singlePlacementGroup" : true ,
"overprovision" : true ,
"uniqueId" : "d053ec5a-8da6-495f-ab13-38216503c6d7" ,
"virtualMachineProfile" : {
"storageProfile" : {
"imageReference" : {
"sku" : "2016-Datacenter" ,
"publisher" : "MicrosoftWindowsServer" ,
"version" : "latest" ,
"offer" : "WindowsServer"
},
"osDisk" : {
"caching" : "ReadWrite" ,
"managedDisk" : {
"storageAccountType" : "Standard_LRS"
},
"createOption" : "FromImage"
}
},
"osProfile" : {
"computerNamePrefix" : "{vmss-name}" ,
"adminUsername" : "{your-username}" ,
"secrets" : [],
"windowsConfiguration" : {
"provisionVMAgent" : true ,
"enableAutomaticUpdates" : true
}
},
"networkProfile" : {
"networkInterfaceConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"dnsSettings" : {
"dnsServers" : []
},
"primary" : true ,
"enableIPForwarding" : true ,
"ipConfigurations" : [
{
"name" : "{vmss-name}" ,
"properties" : {
"subnet" : {
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/nsgExistingVnet/subnets/nsgExistingSubnet"
},
"privateIPAddressVersion" : "IPv4"
}
}
],
"enableAcceleratedNetworking" : false
}
}
]
},
"capacityReservation" : {
"capacityReservationGroup" : {
"id" : "subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/CapacityReservationGroups/{crgName}"
}
}
},
"upgradePolicy" : {
"mode" : "Manual"
},
"provisioningState" : "Creating"
},
"location" : "westus" ,
"type" : "Microsoft.Compute/virtualMachineScaleSets" ,
"id" : "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{vmss-name}"
}
展開資料表
啟用或停用虛擬機或虛擬機擴展集上的功能。
展開資料表
名稱
類型
Description
hibernationEnabled
boolean
啟用或停用 VM 上休眠功能的旗標。
ultraSSDEnabled
boolean
旗標,可啟用或停用在 VM 或 VMSS 上具有一或多個具有 UltraSSD_LRS記憶體帳戶類型的受控數據磁碟。 只有啟用此屬性時,才能將具有記憶體帳戶類型的受控磁碟UltraSSD_LRS新增至虛擬機或虛擬機擴展集。
AdditionalUnattendContent
指定其他 XML 格式資訊,這些資訊可以包含在 Windows 安裝程式所使用的 Unattend.xml 檔案中。 內容是藉由設定名稱、元件名稱和套用內容的傳遞來定義。
展開資料表
名稱
類型
Description
componentName
ComponentNames
元件名稱。 目前唯一允許的值是 Microsoft-Windows-Shell-Setup。
content
string
針對指定的路徑和元件,指定新增至 unattend.xml 檔案的 XML 格式內容。 XML 必須小於 4KB,而且必須包含要插入之設定或功能的根元素。
passName
PassNames
傳遞名稱。 目前唯一允許的值是 OobeSystem。
settingName
SettingNames
指定要套用內容之設定的名稱。 可能的值為:FirstLogonCommands 和 AutoLogon。
API 實體參考。
展開資料表
名稱
類型
Description
id
string
/subscriptions/{SubscriptionId}/resourceGroups/{ResourceGroupName}/... 形式的 ARM 資源標識符
API 錯誤。
展開資料表
名稱
類型
Description
code
string
錯誤碼。
details
ApiErrorBase []
API 錯誤詳細數據
innererror
InnerError
Api 內部錯誤
message
string
錯誤訊息。
target
string
特定錯誤的目標。
API 錯誤基底。
展開資料表
名稱
類型
Description
code
string
錯誤碼。
message
string
錯誤訊息。
target
string
特定錯誤的目標。
包含應該提供給 VM/VMSS 的資源庫應用程式清單
展開資料表
用於執行自動OS升級的組態參數。
展開資料表
名稱
類型
Description
disableAutomaticRollback
boolean
是否應該停用OS映像復原功能。 預設值為 False。
enableAutomaticOSUpgrade
boolean
指出當較新版本的OS映像可用時,是否應該以滾動方式自動套用OS升級至擴展集實例。 預設值為 False。 如果 Windows 擴展集將此設定為 true,enableAutomaticUpdates 會自動設定為 false,且無法設定為 true。
useRollingUpgradePolicy
boolean
指出是否應在自動OS升級期間使用滾動升級原則。 預設值為 False。 如果未在 VMSS 上定義任何原則,自動 OS 升級將會回復為默認原則。
指定虛擬機擴展集上自動修復的組態參數。
展開資料表
名稱
類型
Description
enabled
boolean
指定是否應在虛擬機擴展集上啟用自動修復。 預設值為 false。
gracePeriod
string
因為 VM 上的狀態變更而暫停自動修復的時間量。 寬限時間會在狀態變更完成之後開始。 這有助於避免提前或意外修復。 時間持續時間應以 ISO 8601 格式指定。 允許的寬限期下限為 10 分鐘 (PT10M) ,這也是預設值。 允許的寬限期上限為 90 分鐘, (PT90M) 。
repairAction
RepairAction
修復動作的類型 (取代、重新啟動、重新映像) ,用於修復擴展集中狀況不良的虛擬機。 預設值為 replace。
指定 Azure Spot VM 或 VMSS 的計費相關詳細數據。 API 版本下限:2019-03-01。
展開資料表
名稱
類型
Description
maxPrice
number
指定您願意支付 Azure Spot VM/VMSS 的最大價格。 此價格以美元為單位。 此價格將會與 VM 大小的目前 Azure Spot 價格進行比較。 此外,價格會在建立/更新 Azure Spot VM/VMSS 時進行比較,而且只有在 maxPrice 大於目前的 Azure Spot 價格時,作業才會成功。 如果目前的 Azure Spot 價格超出建立 VM/VMSS 之後的 maxPrice,maxPrice 也會用於收回 Azure Spot VM/VMSS。 可能的值包括: - 任何大於零的十進位值。 範例:0.01538 -1 – 表示預設價格為隨選。 您可以將 maxPrice 設定為 -1,以指出基於價格考慮,不應收回 Azure Spot VM/VMSS。 此外,如果默認價格不是由您提供,則為 -1。 API 版本下限:2019-03-01。
開機診斷是一項偵錯功能,可讓您檢視控制台輸出和螢幕快照以診斷 VM 狀態。 您可以輕鬆地檢視主控台記錄檔的輸出。 Azure 也可讓您從 Hypervisor 查看 VM 的螢幕快照。
展開資料表
名稱
類型
Description
enabled
boolean
是否應在虛擬機上啟用開機診斷。
storageUri
string
用來放置主控台輸出和螢幕快照的記憶體帳戶 URI。 如果未在啟用開機診斷時指定 storageUri,則會使用受控記憶體。
指定快取需求。 可能的值包括:
無
ReadOnly
讀寫 預設值: 標準記憶體無。進階記憶體的 ReadOnly
展開資料表
名稱
類型
Description
None
string
ReadOnly
string
ReadWrite
string
CapacityReservationProfile
容量保留配置文件的參數。
展開資料表
計算服務的錯誤回應。
展開資料表
名稱
類型
Description
error
ApiError
Api 錯誤。
元件名稱。 目前唯一允許的值是 Microsoft-Windows-Shell-Setup。
展開資料表
名稱
類型
Description
Microsoft-Windows-Shell-Setup
string
指定刪除 VM 時公用 IP 會發生什麼事
展開資料表
名稱
類型
Description
Delete
string
Detach
string
指定開機診斷設定狀態。 API 版本下限:2015-06-15。
展開資料表
名稱
類型
Description
bootDiagnostics
BootDiagnostics
開機診斷是一項偵錯功能,可讓您檢視控制台輸出和螢幕快照來診斷 VM 狀態。
注意 :如果指定 storageUri,請確定記憶體帳戶位於與 VM 相同的區域和訂用帳戶中。 您可以輕鬆地檢視主控台記錄的輸出。 Azure 也可讓您從 Hypervisor 查看 VM 的螢幕快照。
指定作業系統磁碟的暫時磁碟設定。
展開資料表
名稱
類型
Description
Local
string
指定作業系統磁碟的暫時磁碟位置。 用戶可以在要求中使用此屬性來選擇位置,也就是快取磁碟或暫時OS磁碟布建的資源磁碟空間。 如需暫時 OS 磁碟大小需求的詳細資訊,請參閱 Windows VM 的暫時 OS 磁碟大小需求, https://docs.microsoft.com/azure/virtual-machines/windows/ephemeral-os-disks#size-requirements 以及 Linux VM 的 https://docs.microsoft.com/azure/virtual-machines/linux/ephemeral-os-disks#size-requirements
展開資料表
名稱
類型
Description
CacheDisk
string
ResourceDisk
string
描述可針對操作系統磁碟指定之暫時磁碟設定的參數。 注意:暫時磁碟設定只能針對受控磁碟指定。
展開資料表
展開資料表
名稱
類型
Description
NVMe
string
SCSI
string
指定應該如何建立擴展集中的虛擬機。 唯一允許的值是: FromImage \u2013 當您使用映像來建立虛擬機時,會使用此值。 如果您使用平臺映像,則也會使用上述的 imageReference 元素。 如果您使用市集映射,您也會使用先前所述的 plan 元素。
展開資料表
名稱
類型
Description
Attach
string
Empty
string
FromImage
string
指定是否應在 VMSS Flex 刪除時刪除或卸離 OS 磁碟 (此功能僅適用於只有彈性協調流程模式的 VMSS) 。 可能的值:
刪除 如果使用此值,則會在刪除 VMSS Flex VM 時刪除 OS 磁碟。
分離 如果使用此值,則會在刪除 VMSS Flex VM 之後保留 OS 磁碟。 預設值設定為 Delete 。 針對暫時OS磁碟,預設值會設定為 Delete 。 使用者無法變更暫時 OS 磁碟的刪除選項。
展開資料表
名稱
類型
Description
Delete
string
Detach
string
DiskEncryptionSetParameters
描述可針對磁碟指定的客戶受控磁碟加密集資源標識符參數。 注意:磁碟加密集資源標識碼只能指定給受控磁碟。 如需詳細資訊,請參閱 https://aka.ms/mdssewithcmkoverview 。
展開資料表
名稱
類型
Description
id
string
資源標識碼
擴充位置的複雜類型。
展開資料表
擴充位置的類型。
展開資料表
名稱
類型
Description
EdgeZone
string
指定要使用之映像的相關信息。 您可以指定平臺映像、Marketplace 映像或虛擬機映射的相關信息。 當您想要使用平臺映像、市集映像或虛擬機映像,但不會用於其他建立作業時,需要此元素。 注意:映像參考發行者和供應專案只能在您建立擴展集時設定。
展開資料表
名稱
類型
Description
communityGalleryImageId
string
指定 VM 部署的社群資源庫映像唯一標識碼。 這可以從社群資源庫映像 GET 呼叫擷取。
exactVersion
string
以十進位數指定,也就是用來建立虛擬機的平臺映像或市集映射版本。 這個只讀欄位與 'version' 不同,只有在 'version' 字段中指定的值為 'latest' 時。
id
string
資源標識碼
offer
string
指定用來建立虛擬機的平臺映像或市集映像供應專案。
publisher
string
映像發行者。
sharedGalleryImageId
string
指定 VM 部署的共享資源庫映像唯一識別碼。 這可以從共用資源庫映像 GET 呼叫擷取。
sku
string
映像 SKU。
version
string
指定用來建立虛擬機的平臺映像或 Marketplace 映像版本。 允許的格式為 Major.Minor.Build 或 'latest'。 主要、次要和組建都是十進位數。 指定「最新」以使用部署階段可用的最新映像版本。 即使您使用「最新」,即使有新版本可供使用,VM 映像也不會在部署時間之後自動更新。 請勿針對資源庫映射部署使用字段 'version',資源庫映射應該一律使用 'id' 字段進行部署,若要使用資源庫映射的 'latest' 版本,只要設定 '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/gallerys/{galleryName}/images/{imageName}',就不需要輸入版本。
內部錯誤詳細數據。
展開資料表
名稱
類型
Description
errordetail
string
內部錯誤訊息或例外狀況傾印。
exceptiontype
string
例外狀況型別。
從 Api-Version 2019-07-01 開始提供,它代表特定 ipconfiguration 是 IPv4 或 IPv6。 預設值會採用為 IPv4。 可能的值為:'IPv4' 和 'IPv6'。
展開資料表
名稱
類型
Description
IPv4
string
IPv6
string
描述 金鑰保存庫 秘密的參考
展開資料表
名稱
類型
Description
secretUrl
string
參考 金鑰保存庫 中秘密的URL。
sourceVault
SubResource
包含秘密之 金鑰保存庫的相對 URL。
指定虛擬機上的Linux作業系統設定。 如需支援的Linux發行版清單,請參閱 Azure-Endorsed 發行版上的Linux 。
展開資料表
名稱
類型
Description
disablePasswordAuthentication
boolean
指定是否應該停用密碼驗證。
enableVMAgentPlatformUpdates
boolean
指出是否已針對Linux虛擬機啟用VMAgent Platform 匯報。 預設值為 False。
patchSettings
LinuxPatchSettings
[預覽功能]指定與Linux上的VM客體修補相關的設定。
provisionVMAgent
boolean
指出是否應該在虛擬機器上佈建虛擬機器代理程式。 當要求本文中未指定這個屬性時,預設行為是將它設定為 true。 這可確保 VM 代理程式已安裝在 VM 上,以便稍後將擴充功能新增至 VM。
ssh
SshConfiguration
指定 Linux OS 的 SSH 金鑰組態。
指定 IaaS 虛擬機的 VM 客體修補評估模式。 可能的值包括:
ImageDefault - 您可以在虛擬機上控制修補程式評估的時間。
AutomaticByPlatform - 平臺會觸發定期修補程序評估。 屬性 provisionVMAgent 必須為 true。
展開資料表
名稱
類型
Description
AutomaticByPlatform
string
ImageDefault
string
指定與Linux上的VM客體修補相關的設定。
展開資料表
名稱
類型
Description
assessmentMode
LinuxPatchAssessmentMode
指定 IaaS 虛擬機的 VM 客體修補評估模式。 可能的值包括:
ImageDefault - 您可以在虛擬機上控制修補程式評估的時間。
AutomaticByPlatform - 平臺會觸發定期修補評估。 屬性 provisionVMAgent 必須是 true。
automaticByPlatformSettings
LinuxVMGuestPatchAutomaticByPlatformSettings
在 Linux 上的 VM 客體修補中指定 Patch 模式 AutomaticByPlatform 的其他設定。
patchMode
LinuxVMGuestPatchMode
指定 VM 客體修補至 IaaS 虛擬機的模式,或與 OrchestraMode 為彈性的虛擬機擴展集相關聯的虛擬機。 可能的值包括:
ImageDefault - 會使用虛擬機的默認修補組態。
AutomaticByPlatform - 虛擬機將會由平台自動更新。 provisionVMAgent 屬性必須是 true
指定所有 AutomaticByPlatform 修補程式安裝作業的重新啟動設定。
展開資料表
名稱
類型
Description
Always
string
IfRequired
string
Never
string
Unknown
string
指定在Linux修補程式設定中選取修補程式模式 AutomaticByPlatform 時要套用的其他設定。
展開資料表
指定 VM 客體修補至 IaaS 虛擬機的模式,或與具有 OrchestrationMode 的虛擬機擴展集相關聯的虛擬機作為彈性。 可能的值包括:
ImageDefault - 會使用虛擬機的默認修補組態。
AutomaticByPlatform - 虛擬機將會由平台自動更新。 屬性 provisionVMAgent 必須為 true
展開資料表
名稱
類型
Description
AutomaticByPlatform
string
ImageDefault
string
會指定在具有協調流程模式 「彈性」的虛擬機擴展集網路介面設定中建立網路資源時所使用的 Microsoft.Network API 版本
展開資料表
名稱
類型
Description
2020-11-01
string
此屬性可讓您指定從使用者映像或特製化 VHD 建立 VM 時,磁碟包含的 OS 類型。 可能的值包括:
Windows
Linux
展開資料表
名稱
類型
Description
Linux
string
Windows
string
指定虛擬機擴展集的協調流程模式。
展開資料表
名稱
類型
Description
Flexible
string
Uniform
string
OSImageNotificationProfile
展開資料表
名稱
類型
Description
enable
boolean
指定是否啟用或停用OS映像排程事件。
notBeforeTimeout
string
虛擬機重新映像或其操作系統升級的時間長度,在事件自動核准之前,必須先核准 OS 映射排程事件, (逾時) 。 設定是以 ISO 8601 格式指定,而且此值必須是 15 分鐘, (PT15M)
傳遞名稱。 目前唯一允許的值是 OobeSystem。
展開資料表
名稱
類型
Description
OobeSystem
string
指定與 Windows 上的 VM 客體修補相關的設定。
展開資料表
名稱
類型
Description
assessmentMode
WindowsPatchAssessmentMode
指定 IaaS 虛擬機的 VM 客體修補評估模式。 可能的值包括:
ImageDefault - 您可以在虛擬機上控制修補程式評估的時間。
AutomaticByPlatform - 平臺會觸發定期修補評估。 屬性 provisionVMAgent 必須是 true。
automaticByPlatformSettings
WindowsVMGuestPatchAutomaticByPlatformSettings
指定 Windows 上 VM 客體修補中的 Patch 模式 AutomaticByPlatform 的其他設定。
enableHotpatching
boolean
可讓客戶修補其 Azure VM,而不需要重新啟動。 針對 enableHotpatching,'provisionVMAgent' 必須設定為 true,而且 'patchMode' 必須設定為 'AutomaticByPlatform'。
patchMode
WindowsVMGuestPatchMode
指定 VM 客體修補至 IaaS 虛擬機的模式,或與 OrchestraMode 為彈性的虛擬機擴展集相關聯的虛擬機。 可能的值包括:
手動 - 您可以控制將修補程式應用程式套用至虛擬機。 您可以在 VM 內手動套用修補程式來執行此動作。 在此模式中,自動更新會停用;屬性 WindowsConfiguration.enableAutomaticUpdates 必須為 false
AutomaticByOS - 作業系統會自動更新虛擬機。 WindowsConfiguration.enableAutomaticUpdates 屬性必須是 true。
AutomaticByPlatform - 虛擬機將會由平台自動更新。 provisionVMAgent 和 WindowsConfiguration.enableAutomaticUpdates 屬性必須是 true
指定用來建立虛擬機之 Marketplace 映像的相關信息。 此元素僅用於市集映像。 您必須先啟用映像以程序設計方式使用,才能從 API 使用市集映射。 在 Azure 入口網站 中,尋找您想要使用的市集映像,然後按兩下 [想要以程序設計方式部署][開始使用] -> 。 輸入任何必要資訊,然後按兩下 [ 儲存 ]。
展開資料表
名稱
類型
Description
name
string
方案標識碼。
product
string
指定市集中映像的產品。 這個值與 imageReference 元素下的 Offer 相同。
promotionCode
string
促銷碼。
publisher
string
發行者標識碼。
指定擴展集中具有彈性協調流程模式之 Spot 和一般優先順序 VM 的目標分割。 有了這個屬性,客戶就可以指定建立為 VMSS flex 實例的一般優先順序 VM 基底數目,並在達到此基底目標之後,在現成和一般優先順序 VM 之間分割。
展開資料表
名稱
類型
Description
baseRegularPriorityCount
integer
在相應放大時,將會在此擴展集中建立的一般優先順序 VM 基底數目。
regularPriorityPercentageAboveBase
integer
達到基底一般優先順序計數之後的 VM 實例百分比,預期會使用一般優先順序。
指定 WinRM 接聽程式的通訊協定。 可能的值包括:
http
https
展開資料表
名稱
類型
Description
Http
string
Https
string
描述公用IP Sku。 它只能以 OrchestrationMode 設定為彈性。
展開資料表
指定公用IP SKU 名稱
展開資料表
名稱
類型
Description
Basic
string
Standard
string
指定公用IP SKU層
展開資料表
名稱
類型
Description
Global
string
Regional
string
修復動作的類型 (取代、重新啟動、重新映像) ,用於修復擴展集中狀況不良的虛擬機。 預設值為 replace。
展開資料表
名稱
類型
Description
Reimage
string
Replace
string
Restart
string
用於虛擬機擴展集的身分識別類型。 「SystemAssigned、UserAssigned」類型同時包含隱含建立的身分識別,和一組使用者指派的身分識別。 類型 『None』 會從虛擬機擴展集移除任何身分識別。
展開資料表
名稱
類型
Description
None
string
SystemAssigned
string
SystemAssigned, UserAssigned
string
UserAssigned
string
執行滾動升級時所使用的組態參數。
展開資料表
名稱
類型
Description
enableCrossZoneUpgrade
boolean
允許 VMSS 在建構升級批次時忽略 AZ 界限。 將 Update 網域和 maxBatchInstancePercent 納入考慮,以判斷批次大小。
maxBatchInstancePercent
integer
一個批次中滾動升級同時升級的虛擬機實例總數百分比上限。 由於這是最大,先前或未來批次中狀況不良的實例可能會導致批次中的實例百分比降低,以確保更高的可靠性。 此參數的預設值為 20%。
maxSurge
boolean
建立新的虛擬機以升級擴展集,而不是更新現有的虛擬機。 建立每個批次的新虛擬機之後,將會刪除現有的虛擬機。
maxUnhealthyInstancePercent
integer
擴展集中可同時狀況不良之虛擬機實例總數的百分比上限,可能是因為升級而發生,或是在輪流升級中止之前,在虛擬機健康情況檢查處於狀況不良狀態時找到。 啟動任何批次之前,將會先檢查此條件約束。 此參數的預設值為 20%。
maxUnhealthyUpgradedInstancePercent
integer
可發現處於狀況不良狀態的升級虛擬機實例百分比上限。 升級每個批次之後,就會進行這項檢查。 如果超過此百分比,滾動更新就會中止。 此參數的預設值為 20%。
pauseTimeBetweenBatches
string
完成一個批次中所有虛擬機的更新和啟動下一個批次之間的等候時間。 時間持續時間應以 ISO 8601 格式指定。 默認值為 0 秒, (PT0S) 。
prioritizeUnhealthyInstances
boolean
在任何狀況良好的實例之前,升級擴展集中的所有狀況不良實例。
rollbackFailedInstancesOnPolicyBreach
boolean
如果違反滾動升級原則,復原失敗實例至先前的模型。
描述虛擬機擴展集的相應縮小原則。
展開資料表
名稱
類型
Description
forceDeletion
boolean
此屬性可讓您指定在預覽版中調整虛擬機擴展集時,是否必須強制刪除移除的虛擬機。 (Preview 中的功能)
rules
VirtualMachineScaleSetScaleInRules []
調整虛擬機擴展集時所要遵循的規則。 可能的值包括:
預設 當虛擬機擴展集相應縮小時,如果擴展集是區域性擴展集,則擴展集會先跨區域平衡。 然後,它會盡可能跨容錯網域進行平衡。 在每個容錯網域內,選擇移除的虛擬機將是未受到相應縮小保護的最新虛擬機。
OldestVM 當虛擬機擴展集正在相應縮小時,將會選擇未受相應縮小保護的最舊虛擬機進行移除。 針對區域性虛擬機擴展集,擴展集會先跨區域進行平衡。 在每個區域中,將會選擇未受保護的最舊虛擬機來移除。
NewestVM 當虛擬機擴展集正在相應縮小時,將會選擇未受相應縮小保護的最新虛擬機進行移除。 針對區域性虛擬機擴展集,擴展集會先跨區域進行平衡。 在每個區域中,將會選擇未受保護的最新虛擬機來移除。
展開資料表
指定受控磁碟的 EncryptionType。 它設定為 DiskWithVMGuestState 以加密受控磁碟以及 VMGuestState Blob,以及只加密 VMGuestState Blob 的 VMGuestStateOnly。 注意:它只能設定為機密 VM。
展開資料表
名稱
類型
Description
DiskWithVMGuestState
string
VMGuestStateOnly
string
指定虛擬機或虛擬機擴展集的安全性配置檔設定。
展開資料表
名稱
類型
Description
encryptionAtHost
boolean
這個屬性可由要求中的使用者用來啟用或停用虛擬機或虛擬機擴展集的主機加密。 這會啟用所有磁碟的加密,包括主機本身的資源/暫存磁碟。 默認值:除非資源的此屬性設定為 true,否則將會停用主機上的加密。
securityType
SecurityTypes
指定虛擬機的 SecurityType。 它必須設定為任何指定的值,才能啟用 UefiSettings。 默認值:除非設定此屬性,否則不會啟用 UefiSettings。
uefiSettings
UefiSettings
指定建立虛擬機時所使用的安全開機和 vTPM 等安全性設定。 API 版本下限:2020-12-01
指定虛擬機的 SecurityType。 它必須設定為任何指定的值,才能啟用 UefiSettings。 默認值:除非已設定此屬性,否則不會啟用 UefiSettings。
展開資料表
名稱
類型
Description
ConfidentialVM
string
TrustedLaunch
string
指定使用「最新」映像版本時,用來為擴展集中的所有虛擬機設定相同映射版本的服務成品參考標識符。 最低 API 版本:2022-11-01
展開資料表
名稱
類型
Description
id
string
服務成品參考標識符的格式為 /subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Compute/gallerys/{galleryName}/serviceArtifacts/{serviceArtifactName}/vmArtifactsProfiles/{vmArtifactsProfilesName}
指定要套用內容之設定的名稱。 可能的值為:FirstLogonCommands 和 AutoLogon。
展開資料表
名稱
類型
Description
AutoLogon
string
FirstLogonCommands
string
描述虛擬機擴展集 SKU。 注意:如果擴展集目前所在的硬體不支援新的 VM SKU,您必須先解除分配擴展集中的 VM,才能修改 SKU 名稱。
展開資料表
名稱
類型
Description
capacity
integer
指定擴展集中的虛擬機數目。
name
string
SKU 名稱。
tier
string
指定擴展集中的虛擬機層。 可能的值如下:
標準
基本
指定虛擬機擴展集的 Spot-Try-Restore 屬性。 透過此屬性,客戶可以根據容量可用性和定價條件約束,啟用或停用收回的現成 VMSS VM 實例自動還原。
展開資料表
名稱
類型
Description
enabled
boolean
啟用 Spot-Try-Restore 功能,其中收回的 VMSS SPOT 實例會嘗試根據容量可用性和定價條件約束,以機率方式還原
restoreTimeout
string
以 ISO 8601 時間持續時間表示的逾時值,之後平臺將不會嘗試還原 VMSS SPOT 實例
在 Azure 上執行的 Linux 型 VM SSH 設定
展開資料表
名稱
類型
Description
publicKeys
SshPublicKey []
用來向Linux型VM進行驗證的SSH公鑰清單。
包含 SSH 憑證公鑰的相關信息,以及放置公鑰之 Linux VM 上的路徑。
展開資料表
名稱
類型
Description
keyData
string
用來透過 ssh 向 VM 進行驗證的 SSH 公鑰憑證。 密鑰至少必須是 2048 位,且格式為 ssh-rsa。 如需建立 SSH 金鑰,請參閱 [在 Linux 和 Mac 上為 Azure 中的 Linux VM 建立 SSH 金鑰]https://docs.microsoft.com/azure/virtual-machines/linux/create-ssh-keys-detailed).
path
string
指定儲存 ssh 公鑰的已建立 VM 上的完整路徑。 如果檔案已經存在,指定的金鑰就會附加至該檔案。 範例:/home/user/.ssh/authorized_keys
指定受控磁碟的記憶體帳戶類型。 注意:UltraSSD_LRS只能與數據磁碟搭配使用,因此無法與OS磁碟搭配使用。
展開資料表
名稱
類型
Description
PremiumV2_LRS
string
Premium_LRS
string
Premium_ZRS
string
StandardSSD_LRS
string
StandardSSD_ZRS
string
Standard_LRS
string
UltraSSD_LRS
string
展開資料表
名稱
類型
Description
id
string
資源標識碼
TerminateNotificationProfile
展開資料表
名稱
類型
Description
enable
boolean
指定是否啟用或停用 Terminate Scheduled 事件。
notBeforeTimeout
string
刪除虛擬機的可設定時間長度,在自動核准事件之前,虛擬機必須核准終止排程事件, (逾時) 。 設定必須以 ISO 8601 格式指定,預設值為 5 分鐘, (PT5M)
指定安全性設定,例如建立虛擬機時所使用的安全開機和 vTPM。 最低 API 版本:2020-12-01
展開資料表
名稱
類型
Description
secureBootEnabled
boolean
指定是否應在虛擬機上啟用安全開機。 最低 API 版本:2020-12-01
vTpmEnabled
boolean
指定是否應在虛擬機上啟用 vTPM。 最低 API 版本:2020-12-01
指定升級至擴展集中虛擬機的模式。 可能的值包括:
手動 - 您可以控制擴充集中虛擬機更新的應用程式。 您可以使用 manualUpgrade 動作來執行此動作。
自動 -擴展集中的所有虛擬機都會同時自動更新。
展開資料表
名稱
類型
Description
Automatic
string
Manual
string
Rolling
string
描述升級原則 - 自動、手動或滾動。
展開資料表
與虛擬機相關聯的使用者身分識別清單。 使用者身分識別字典索引鍵參考的格式為 ARM 資源標識符:'/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}'。
展開資料表
描述 金鑰保存庫 中的單一憑證參考,以及憑證應該位於 VM 上的位置。
展開資料表
名稱
類型
Description
certificateStore
string
針對 Windows VM,指定應該新增憑證之虛擬機上的證書存儲。 指定的證書存儲隱含地位於LocalMachine帳戶中。 針對Linux VM,憑證檔案會放在 /var/lib/waagent 目錄底下,而 X509 憑證檔案的檔名<為 UppercaseThumbprint.crt,而<私鑰則為 UppercaseThumbprint.prv>>。 這兩個檔案都是 .pem 格式。
certificateUrl
string
這是已上傳至 金鑰保存庫 做為秘密之憑證的 URL。 如需將秘密新增至 金鑰保存庫,請參閱將密鑰或秘密新增至密鑰保存庫 。 在此情況下,您的憑證必須是下列 JSON 物件的 Base64 編碼,其編碼方式為 UTF-8: { “data”:“”, “dataType”:“pfx”, “password”:“” } 若要在虛擬機上安裝憑證,建議您使用適用於Linux的 Azure 金鑰保存庫 虛擬機擴充功能 或適用於 Windows 的 Azure 金鑰保存庫 虛擬機擴充功能 。
描述一組憑證,這些憑證全都在相同的 金鑰保存庫 中。
展開資料表
名稱
類型
Description
sourceVault
SubResource
包含 VaultCertificates 中所有憑證之 金鑰保存庫 的相對 URL。
vaultCertificates
VaultCertificate []
SourceVault 中包含憑證的金鑰保存庫參考清單。
描述磁碟的 URI。
展開資料表
名稱
類型
Description
uri
string
指定虛擬硬碟的 URI。
VirtualMachineEvictionPolicyTypes
指定 Azure Spot 虛擬機和 Azure Spot 擴展集的收回原則。 針對 Azure Spot 虛擬機,同時支援「解除分配」和「刪除」,且最低 API 版本為 2019-03-01。 針對 Azure Spot 擴展集,同時支援 'Deallocate' 和 'Delete',且最低 api 版本為 2017-10-30-preview。
展開資料表
名稱
類型
Description
Deallocate
string
Delete
string
VirtualMachinePriorityTypes
指定擴展集中虛擬機的優先順序。 最低 API 版本:2017-10-30-preview
展開資料表
名稱
類型
Description
Low
string
Regular
string
Spot
string
描述虛擬機擴展集。
展開資料表
名稱
類型
Description
extendedLocation
ExtendedLocation
虛擬機擴展集的擴充位置。
id
string
資源標識碼
identity
VirtualMachineScaleSetIdentity
如果已設定,則為虛擬機擴展集的身分識別。
location
string
資源位置
name
string
資源名稱
plan
Plan
指定用來建立虛擬機之 Marketplace 映像的相關信息。 此元素僅用於市集映像。 您必須先啟用映像以程序設計方式使用,才能從 API 使用市集映射。 在 Azure 入口網站 中,尋找您想要使用的市集映射,然後按兩下 [想要以程序設計方式部署],[開始使用] -> 。 輸入任何必要資訊,然後按兩下 [ 儲存 ]。
properties.additionalCapabilities
AdditionalCapabilities
指定虛擬機擴展集中 虛擬機器 上啟用或停用的其他功能。 例如:虛擬機器 是否能夠支援使用UltraSSD_LRS記憶體帳戶類型鏈接受控數據磁碟。
properties.automaticRepairsPolicy
AutomaticRepairsPolicy
自動修復的原則。
properties.constrainedMaximumCapacity
boolean
必須設定為 True 或省略的選擇性屬性。
properties.doNotRunExtensionsOnOverprovisionedVMs
boolean
啟用 Overprovision 時,擴充功能只會在最後保留的要求 VM 數目上啟動。 因此,此屬性可確保擴充功能不會在額外的過度布建 VM 上執行。
properties.hostGroup
SubResource
指定虛擬機擴展集所在專用主機群組的相關信息。 API 版本下限:2020-06-01。
properties.orchestrationMode
OrchestrationMode
指定虛擬機擴展集的協調流程模式。
properties.overprovision
boolean
指定是否應該過度布建虛擬機擴展集。
properties.platformFaultDomainCount
integer
每個放置群組的容錯網域計數。
properties.priorityMixPolicy
PriorityMixPolicy
指定在相同 VMSS Flex 實例內混合 Spot 和一般優先順序 VM 所需的目標。
properties.provisioningState
string
布建狀態,只會出現在回應中。
properties.proximityPlacementGroup
SubResource
指定虛擬機擴展集應指派的鄰近放置群組相關信息。 API 版本下限:2018-04-01。
properties.scaleInPolicy
ScaleInPolicy
指定在虛擬機擴展集中調整 虛擬機器 時所套用的原則。
properties.singlePlacementGroup
boolean
若為 true,則會將擴展集限制為單一放置群組,大小上限為 100 部虛擬機。 注意:如果 singlePlacementGroup 為 true,它可能會修改為 false。 不過,如果 singlePlacementGroup 為 false,則無法修改成 true。
properties.spotRestorePolicy
SpotRestorePolicy
指定虛擬機擴展集的Spot Restore 屬性。
properties.timeCreated
string
指定虛擬機擴展集資源建立的時間。 API 版本下限:2021-11-01。
properties.uniqueId
string
指定可唯一識別虛擬機擴展集的標識碼。
properties.upgradePolicy
UpgradePolicy
升級原則。
properties.virtualMachineProfile
VirtualMachineScaleSetVMProfile
虛擬機器配置檔。
properties.zoneBalance
boolean
如果發生區域中斷,是否要強制甚至跨 x 區域的虛擬機散發。 只有在擴展集的區域屬性包含多個區域時,才能設定 zoneBalance 屬性。 如果沒有指定區域或只指定一個區域,不應設定 zoneBalance 屬性。
sku
Sku
虛擬機擴展集 SKU。
tags
object
資源標籤
type
string
資源類型
zones
string[]
虛擬機擴展集區域。 注意:只有在建立擴展集時,才能設定可用性區域
VirtualMachineScaleSetDataDisk
描述虛擬機擴展集數據磁碟。
展開資料表
名稱
類型
Description
caching
CachingTypes
指定快取需求。 可能的值包括:
無
ReadOnly
讀寫 預設值: 標準記憶體無。進階記憶體的 ReadOnly
createOption
DiskCreateOptionTypes
create 選項。
deleteOption
DiskDeleteOptionTypes
指定在 VMSS Flex 刪除時應該刪除或中斷連結數據磁碟 (此功能僅適用於具有彈性協調流程模式的 VMSS) 。 可能的值:
刪除 如果使用此值,則會在刪除 VMSS Flex VM 時刪除資料磁碟。
分離 如果使用此值,則會在刪除 VMSS Flex VM 之後保留數據磁碟。 預設值設定為 Delete 。
diskIOPSReadWrite
integer
指定受控磁碟的 Read-Write IOPS。 只有當 StorageAccountType 是UltraSSD_LRS時,才應該使用。 如果未指定,則會根據diskSizeGB指派預設值。
diskMBpsReadWrite
integer
指定受控磁碟的每秒 MB 頻寬。 只有當 StorageAccountType 是UltraSSD_LRS時,才應該使用。 如果未指定,則會根據diskSizeGB指派預設值。
diskSizeGB
integer
指定以 GB 為單位的空白資料磁碟大小。 此元素可用來覆寫虛擬機映像中的磁碟大小。 diskSizeGB 是磁碟的位元組 x 1024^3 數目,且值不能大於 1023
lun
integer
指定數據磁碟的邏輯單元編號。 這個值是用來識別 VM 內的數據磁碟,因此對於連結至 VM 的每個數據磁碟都必須是唯一的。
managedDisk
VirtualMachineScaleSetManagedDiskParameters
受控磁碟參數。
name
string
磁碟名稱。
writeAcceleratorEnabled
boolean
指定是否應該在磁碟上啟用或停用 writeAccelerator。
VirtualMachineScaleSetExtension
描述虛擬機擴展集擴充功能。
展開資料表
名稱
類型
Description
id
string
資源標識碼
name
string
延伸模組的名稱。
properties.autoUpgradeMinorVersion
boolean
指出擴充功能是否應該在部署期間使用較新的次要版本。 不過,部署之後,除非重新部署延伸模組,否則延伸模組將不會升級次要版本,即使此屬性設定為 true 亦然。
properties.enableAutomaticUpgrade
boolean
指出如果有較新版本的擴充功能可用,平臺是否應該自動升級延伸模組。
properties.forceUpdateTag
string
如果提供值且與先前的值不同,即使延伸模組組態尚未變更,擴充處理程式仍會強制更新。
properties.protectedSettings
object
延伸模組可以包含 protectedSettings 或 protectedSettingsFromKeyVault,或完全不包含受保護的設定。
properties.protectedSettingsFromKeyVault
KeyVaultSecretReference
以傳址方式傳遞並從金鑰保存庫取用的延伸模組受保護設定
properties.provisionAfterExtensions
string[]
延伸模組名稱的集合,之後必須布建此延伸模組。
properties.provisioningState
string
布建狀態,只會出現在回應中。
properties.publisher
string
擴充處理程序發行者的名稱。
properties.settings
object
延伸模組的 Json 格式化公用設定。
properties.suppressFailures
boolean
指出從擴充功能產生的失敗是否會隱藏 (作業失敗,例如不會連線到 VM,而不論此值為何) 。 預設值為 false。
properties.type
string
指定延伸模組的類型;例如“CustomScriptExtension”。
properties.typeHandlerVersion
string
指定文稿處理程式的版本。
type
string
資源類型
VirtualMachineScaleSetExtensionProfile
描述虛擬機擴展集擴充功能配置檔。
展開資料表
名稱
類型
Description
extensions
VirtualMachineScaleSetExtension []
虛擬機擴展集子擴充功能資源。
extensionsTimeBudget
string
指定要啟動之所有延伸模組的加註時間。 持續時間應介於 15 分鐘到 120 分鐘之間, (內含) ,且應以 ISO 8601 格式指定。 預設值為90分鐘 (PT1H30M) 。 API 版本下限:2020-06-01
VirtualMachineScaleSetHardwareProfile
指定虛擬機擴展集的硬體設定。
展開資料表
名稱
類型
Description
vmSizeProperties
VMSizeProperties
指定自定義虛擬機大小的屬性。 API 版本下限:2021-11-01。 如需詳細資訊,請遵循 VM 自定義 中的指示。
VirtualMachineScaleSetIdentity
虛擬機擴展集的身分識別。
展開資料表
名稱
類型
Description
principalId
string
虛擬機擴展集身分識別的主體標識碼。 此屬性只會針對系統指派的身分識別提供。
tenantId
string
與虛擬機擴展集相關聯的租用戶標識碼。 此屬性只會針對系統指派的身分識別提供。
type
ResourceIdentityType
用於虛擬機擴展集的身分識別類型。 「SystemAssigned、UserAssigned」類型同時包含隱含建立的身分識別,和一組使用者指派的身分識別。 類型 『None』 會從虛擬機擴展集移除任何身分識別。
userAssignedIdentities
UserAssignedIdentities
與虛擬機擴展集相關聯的使用者身分識別清單。 使用者身分識別字典索引鍵參考的格式為 ARM 資源標識符:'/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}'。
VirtualMachineScaleSetIPConfiguration
描述虛擬機擴展集網路配置檔的IP組態。
展開資料表
名稱
類型
Description
name
string
IP 組態名稱。
properties.applicationGatewayBackendAddressPools
SubResource []
指定應用程式閘道後端位址池的參考數位。 擴展集可以參考多個應用程式閘道的後端位址池。 多個擴展集無法使用相同的應用程式閘道。
properties.applicationSecurityGroups
SubResource []
指定應用程式安全組的參考陣列。
properties.loadBalancerBackendAddressPools
SubResource []
指定負載平衡器後端位址池的參考陣列。 擴展集可以參考一個公用和一個內部負載平衡器的後端位址池。 多個擴展集無法使用相同的基本 SKU 負載平衡器。
properties.loadBalancerInboundNatPools
SubResource []
指定負載平衡器輸入 Nat 集區的參考陣列。 擴展集可以參考一個公用和一個內部負載平衡器的輸入 nat 集區。 多個擴展集無法使用相同的基本 SKU 負載平衡器。
properties.primary
boolean
指定虛擬機有1個以上的網路介面時的主要網路介面。
properties.privateIPAddressVersion
IPVersion
從 Api-Version 2017-03-30 起提供,它代表特定 ipconfiguration 是 IPv4 或 IPv6。 預設值會採用為 IPv4。 可能的值為:'IPv4' 和 'IPv6'。
properties.publicIPAddressConfiguration
VirtualMachineScaleSetPublicIPAddressConfiguration
publicIPAddressConfiguration。
properties.subnet
ApiEntityReference
指定子網的識別碼。
VirtualMachineScaleSetIpTag
包含與公用IP位址相關聯的IP標籤。
展開資料表
名稱
類型
Description
ipTagType
string
IP 標籤類型。 範例:FirstPartyUsage。
tag
string
與公用IP相關聯的IP標籤。 範例:SQL、記憶體等。
VirtualMachineScaleSetManagedDiskParameters
描述 ScaleSet 受控磁碟的參數。
展開資料表
VirtualMachineScaleSetNetworkConfiguration
描述虛擬機擴展集網路配置檔的網路組態。
展開資料表
名稱
類型
Description
name
string
網路組態名稱。
properties.deleteOption
DeleteOptions
指定刪除 VM 時網路介面會發生什麼情況
properties.disableTcpStateTracking
boolean
指定是否停用網路介面以進行 tcp 狀態追蹤。
properties.dnsSettings
VirtualMachineScaleSetNetworkConfigurationDnsSettings
要套用在網路介面上的 DNS 設定。
properties.enableAcceleratedNetworking
boolean
指定網路介面是否已啟用加速網路。
properties.enableFpga
boolean
指定網路介面是否已啟用 FPGA 網路功能。
properties.enableIPForwarding
boolean
是否在此 NIC 上啟用 IP 轉送。
properties.ipConfigurations
VirtualMachineScaleSetIPConfiguration []
指定網路介面的IP組態。
properties.networkSecurityGroup
SubResource
網路安全組。
properties.primary
boolean
指定虛擬機有1個以上的網路介面時的主要網路介面。
VirtualMachineScaleSetNetworkConfigurationDnsSettings
描述虛擬機擴展集網路設定的 DNS 設定。
展開資料表
名稱
類型
Description
dnsServers
string[]
DNS 伺服器 IP 位址清單
VirtualMachineScaleSetNetworkProfile
描述虛擬機擴展集網路配置檔。
展開資料表
名稱
類型
Description
healthProbe
ApiEntityReference
負載平衡器探查的參考,用來判斷虛擬機擴展集中實例的健康情況。 參考的格式為:'/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/loadBalancers/{loadBalancerName}/probes/{probeName}'。
networkApiVersion
NetworkApiVersion
指定在具有協調流程模式 「彈性」的虛擬機擴展集網路介面設定中建立網路資源時所使用的 Microsoft.Network API 版本
networkInterfaceConfigurations
VirtualMachineScaleSetNetworkConfiguration []
網路組態的清單。
VirtualMachineScaleSetOSDisk
描述虛擬機擴展集作業系統磁碟。
展開資料表
名稱
類型
Description
caching
CachingTypes
指定快取需求。 可能的值包括:
無
ReadOnly
讀寫 預設值: 標準記憶體無。進階記憶體的 ReadOnly
createOption
DiskCreateOptionTypes
指定應如何建立擴展集中的虛擬機。 唯一允許的值是: FromImage \u2013 當您使用映像來建立虛擬機時,會使用此值。 如果您使用平臺映像,則也會使用上述的 imageReference 元素。 如果您使用 Marketplace 映射,則也會使用先前所述的 plan 元素。
deleteOption
DiskDeleteOptionTypes
指定在 VMSS Flex 刪除時應該刪除或中斷連結 OS 磁碟 (此功能僅適用於具有彈性 OrchestrationMode 的 VMSS) 。 可能的值:
刪除 如果使用此值,則會在刪除 VMSS Flex VM 時刪除 OS 磁碟。
分離 如果使用此值,則會在刪除 VMSS Flex VM 之後保留 OS 磁碟。 預設值設定為 Delete 。 若為暫時OS磁碟,預設值會設定為 Delete 。 使用者無法變更暫時 OS 磁碟的刪除選項。
diffDiskSettings
DiffDiskSettings
指定虛擬機擴展集所使用作業系統磁碟的暫時磁碟設定。
diskSizeGB
integer
指定以 GB 為單位的空白資料磁碟大小。 此元素可用來覆寫虛擬機映像中的磁碟大小。 diskSizeGB 是磁碟的位元組 x 1024^3 數目,且值不能大於 1023
image
VirtualHardDisk
指定要根據擴展集之非受控使用者映像的資訊。
managedDisk
VirtualMachineScaleSetManagedDiskParameters
受控磁碟參數。
name
string
磁碟名稱。
osType
OperatingSystemTypes
此屬性可讓您指定從使用者映像或特製化 VHD 建立 VM 時,磁碟包含的 OS 類型。 可能的值包括:
Windows
Linux
vhdContainers
string[]
指定用來儲存擴展集作業系統磁碟的容器 URL。
writeAcceleratorEnabled
boolean
指定是否應該在磁碟上啟用或停用 writeAccelerator。
VirtualMachineScaleSetOSProfile
描述虛擬機擴展集 OS 配置檔。
展開資料表
名稱
類型
Description
adminPassword
string
指定系統管理員帳戶的密碼。
Windows) 長度下限 (: 8 個字元
Linux) 長度下限 (: 6 個字元
Windows) 長度上限 (: 123 個字元
Linux) 長度上限 (: 72 個字元
複雜度需求: 需要滿足下列 4 個條件中的 3 個 字元較低 具有大字元 具有數位 具有特殊字元 (Regex 比對 [\W_])
不允許的值: “abc@123”、“P@$$w 0rd”、“P@ssw0rd”、“P@ssword123”、“Pa$$word”、“pass@word1”、“Password!”、“Password1”、“Password22”、“iveyou!” 如需重設密碼,請參閱 如何在 Windows VM 中重設遠端桌面服務或其登入密碼 如需重設根密碼,請參閱 使用 VMAccess 擴充功能管理使用者、SSH 及檢查或修復 Azure Linux VM 上的磁碟
adminUsername
string
指定系統管理員帳戶的名稱。
僅限 Windows 的限制: 不能以 “.
不允許的值: “administrator”、“admin”、“user”、“user1”、“test”、“user2”、“test1”、“user3”、“admin1”、“1”、 “123”、“a”、“actuser”、“adm”、“admin2”、“aspnet”、“backup”、“console”、“david”、“guest”、“john”、“owner”、“root”、“server”、“sql”、“support”、“support_388945a0”、“sys”、“test2”、“test3”、“user4”、“user5”。
Linux () 長度下限: 1 個字元
Linux) 長度上限 (: 64 個字元
Windows) 最大長度 (: 20 個字元
allowExtensionOperations
boolean
指定是否應該在虛擬機擴展集上允許擴充功能作業。 只有在虛擬機擴展集上沒有擴充功能時,才能將此設定為 False。
computerNamePrefix
string
指定擴展集中所有虛擬機的計算機名稱前置詞。 計算機名稱前置詞長度必須為1到15個字元。
customData
string
指定自訂資料的 Base-64 編碼字串。 Base-64 編碼字串會解碼成二進位陣列而儲存為虛擬機器上的檔案。 二進位陣列的長度上限是 65535 個位元組。 如需針對 VM 使用 cloud-init,請參閱在建立期間使用 cloud-init 自定義 Linux VM
linuxConfiguration
LinuxConfiguration
指定虛擬機上的Linux作業系統設定。 如需支援的Linux發行版清單,請參閱 Azure-Endorsed 發行版上的Linux 。
requireGuestProvisionSignal
boolean
必須設定為 True 或省略的選擇性屬性。
secrets
VaultSecretGroup []
指定應該安裝在擴展集中虛擬機上的憑證集。 若要在虛擬機上安裝憑證,建議您使用適用於Linux的 Azure 金鑰保存庫 虛擬機擴充功能 或適用於 Windows 的 Azure 金鑰保存庫 虛擬機擴充功能 。
windowsConfiguration
WindowsConfiguration
指定虛擬機器上的 Windows 作業系統設定。
VirtualMachineScaleSetPublicIPAddressConfiguration
描述虛擬機擴展集IP組態的PublicIPAddress設定
展開資料表
VirtualMachineScaleSetPublicIPAddressConfigurationDnsSettings
描述虛擬機擴展集網路組態的 DNS 設定。
展開資料表
名稱
類型
Description
domainNameLabel
string
功能變數名稱標籤。功能變數名稱標籤和 VM 索引的串連將會是將建立之 PublicIPAddress 資源的功能變數名稱標籤
VirtualMachineScaleSetScaleInRules
調整虛擬機擴展集時要遵循的規則。 可能的值包括:
預設 當虛擬機擴展集相應縮小時,如果擴展集是區域性擴展集,則擴展集會先跨區域平衡。 然後,它將會盡可能跨容錯網域進行平衡。 在每個容錯網域內,選擇移除的虛擬機將會是不受相應縮小保護的最新虛擬機。
OldestVM 當虛擬機擴展集進行相應縮小時,將會選擇未受相應縮小保護的最舊虛擬機進行移除。 針對區域性虛擬機擴展集,擴展集會先跨區域平衡。 在每個區域內,將會選擇未受保護的最舊虛擬機來移除。
NewestVM 當虛擬機擴展集正在相應縮小時,系統會選擇未受相應縮小保護的最新虛擬機,以移除。 針對區域性虛擬機擴展集,擴展集會先跨區域平衡。 在每個區域中,將會選擇未受保護的最新虛擬機來移除。
展開資料表
名稱
類型
Description
Default
string
NewestVM
string
OldestVM
string
VirtualMachineScaleSetStorageProfile
描述虛擬機擴展集記憶體配置檔。
展開資料表
VirtualMachineScaleSetVMProfile
描述虛擬機擴展集虛擬機配置檔。
展開資料表
指定受控磁碟的安全性配置檔設定。 注意:它只能針對機密 VM 進行設定
展開資料表
名稱
類型
Description
diskEncryptionSet
DiskEncryptionSetParameters
針對客戶受控密鑰加密的機密VM OS 磁碟和 VMGuest Blob 所使用的受控磁碟,指定客戶受控磁碟加密集資源識別碼。
securityEncryptionType
securityEncryptionTypes
指定受控磁碟的 EncryptionType。 它設定為 DiskWithVMGuestState 以加密受控磁碟以及 VMGuestState Blob,以及只加密 VMGuestState Blob 的 VMGuestStateOnly。 注意:它只能設定為機密 VM。
指定參考計算資源庫應用程式版本的必要資訊
展開資料表
名稱
類型
Description
configurationReference
string
選擇性,指定 Azure Blob 的 URI,以在提供時取代套件的預設組態
enableAutomaticUpgrade
boolean
如果設定為 true,當 PIR/SIG 中有新的資源庫應用程式版本可用時,VM/VMSS 會自動更新
order
integer
選擇性,指定必須安裝套件的順序
packageReferenceId
string
指定 /subscriptions/{SubscriptionId}/resourceGroups/{ResourceGroupName}/providers/Microsoft.Compute/gallerys/{galleryName}/applications/{application}/versions/{version} 形式的 GalleryApplicationVersion 資源標識符
tags
string
選擇性,指定更多泛型內容的傳遞值。
treatFailureAsDeploymentFailure
boolean
選擇性,如果為 true,VmApplication 中任何作業的任何失敗都會使部署失敗
指定虛擬機上的 VM 大小屬性設定。
展開資料表
名稱
類型
Description
vCPUsAvailable
integer
指定 VM 可用的 vCPU 數目。 當要求本文中未指定此屬性時,預設行為是將它設定為針對該 VM 大小所公開的 vCPU 值,以 列出區域中所有可用的虛擬機大小 。
vCPUsPerCore
integer
指定 vCPU 與實體核心比率。 當要求本文中未指定此屬性時,預設行為會針對API回應中公開的 VM 大小設定為 vCPUPerCore 的值,以 列出區域中所有可用的虛擬機大小 將此屬性設定為 1 也表示已停用超線程處理。
指定虛擬機器上的 Windows 作業系統設定。
展開資料表
名稱
類型
Description
additionalUnattendContent
AdditionalUnattendContent []
指定可併入 Unattend.xml 檔案 (由 Windows 安裝程式使用) 的額外 Base-64 編碼 XML 格式資訊。
enableAutomaticUpdates
boolean
指出是否為 Windows 虛擬機啟用自動 匯報。 預設值為 true。 對於虛擬機擴展集,此屬性可以更新,更新將會在OS重新佈建上生效。
enableVMAgentPlatformUpdates
boolean
指出是否為 Windows 虛擬機啟用 VMAgent Platform 匯報。 預設值為 False。
patchSettings
PatchSettings
[預覽功能]指定與 Windows 上的 VM 客體修補相關的設定。
provisionVMAgent
boolean
指出是否應該在虛擬機器上佈建虛擬機器代理程式。 當要求本文中未指定這個屬性時,預設行為是將它設定為 true。 這可確保 VM 代理程式已安裝在 VM 上,以便稍後將擴充功能新增至 VM。
timeZone
string
指定虛擬機的時區。 例如“Pacific Standard Time”。 可能的值可以從 TimeZoneInfo.GetSystemTimeZones 傳回的時區 TimeZoneInfo.Id 值。
winRM
WinRMConfiguration
指定 Windows 遠端管理接聽程式。 藉此將啟用遠端 Windows PowerShell。
WindowsPatchAssessmentMode
指定 IaaS 虛擬機的 VM 客體修補評估模式。 可能的值包括:
ImageDefault - 您可以在虛擬機上控制修補程式評估的時間。
AutomaticByPlatform - 平臺會觸發定期修補程序評估。 屬性 provisionVMAgent 必須為 true。
展開資料表
名稱
類型
Description
AutomaticByPlatform
string
ImageDefault
string
指定所有 AutomaticByPlatform 修補程式安裝作業的重新啟動設定。
展開資料表
名稱
類型
Description
Always
string
IfRequired
string
Never
string
Unknown
string
指定在 Windows 修補程式設定中選取修補程式模式 AutomaticByPlatform 時要套用的其他設定。
展開資料表
指定 VM 客體修補至 IaaS 虛擬機的模式,或與具有 OrchestrationMode 的虛擬機擴展集相關聯的虛擬機作為彈性。 可能的值包括:
手動 - 您可以控制將修補程式應用程式套用至虛擬機。 您可以在 VM 內手動套用修補程式來執行此動作。 在此模式中,會停用自動更新;屬性 WindowsConfiguration.enableAutomaticUpdates 必須為 false
AutomaticByOS - 作業系統會自動更新虛擬機。 屬性 WindowsConfiguration.enableAutomaticUpdates 必須為 true。
AutomaticByPlatform - 虛擬機將會由平台自動更新。 provisionVMAgent 和 WindowsConfiguration.enableAutomaticUpdates 屬性必須為 true
展開資料表
名稱
類型
Description
AutomaticByOS
string
AutomaticByPlatform
string
Manual
string
描述 VM 的 Windows 遠端管理設定
展開資料表
描述 Windows 遠端管理接聽程式的通訊協議和指紋
展開資料表