建立或更新虛擬機的作業。 請注意,某些屬性只能在虛擬機建立期間設定。
PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}?api-version=2024-03-01
URI 參數
名稱 |
位於 |
必要 |
類型 |
Description |
resourceGroupName
|
path |
True
|
string
|
資源群組的名稱。
|
subscriptionId
|
path |
True
|
string
|
可唯一識別 Microsoft Azure 訂用帳戶的訂用帳戶認證。 訂用帳戶識別碼會構成每個服務呼叫 URI 的一部分。
|
vmName
|
path |
True
|
string
|
虛擬機器的名稱。
|
api-version
|
query |
True
|
string
|
用戶端 API 版本。
|
名稱 |
必要 |
類型 |
Description |
If-Match
|
|
string
|
轉換的ETag。 省略此值以一律覆寫目前的資源。 指定最後一個出現的 ETag 值,以防止意外覆寫並行變更。
|
If-None-Match
|
|
string
|
設定為 『*』 以允許建立新的記錄集,但為了避免更新現有的記錄集。 其他值會導致伺服器發生錯誤,因為它們不受支援。
|
要求本文
回應
安全性
azure_auth
Azure Active Directory OAuth2 Flow
類型:
oauth2
Flow:
implicit
授權 URL:
https://login.microsoftonline.com/common/oauth2/authorize
範圍
名稱 |
Description |
user_impersonation
|
模擬您的用戶帳戶
|
範例
Create a custom-image vm from an unmanaged generalized os image.
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/{vm-name}?api-version=2024-03-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"storageProfile": {
"osDisk": {
"name": "myVMosdisk",
"image": {
"uri": "http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/{existing-generalized-os-image-blob-name}.vhd"
},
"osType": "Windows",
"createOption": "FromImage",
"caching": "ReadWrite",
"vhd": {
"uri": "http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk.vhd"
}
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
from typing import Any, IO, Union
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_create_custom_image_vm_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_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="{vm-name}",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_D1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"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": "myVMosdisk",
"osType": "Windows",
"vhd": {
"uri": "http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk.vhd"
},
}
},
},
},
).result()
print(response)
# x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_CustomImageVmFromAnUnmanagedGeneralizedOsImage.json
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/v5"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/92de53a5f1e0e03c94b40475d2135d97148ed014/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_CustomImageVmFromAnUnmanagedGeneralizedOsImage.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createACustomImageVmFromAnUnmanagedGeneralizedOsImage() {
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.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "{vm-name}", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
}},
},
OSProfile: &armcompute.OSProfile{
AdminPassword: to.Ptr("{your-password}"),
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
},
StorageProfile: &armcompute.StorageProfile{
OSDisk: &armcompute.OSDisk{
Name: to.Ptr("myVMosdisk"),
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"),
},
OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
Vhd: &armcompute.VirtualHardDisk{
URI: to.Ptr("http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk.vhd"),
},
},
},
},
}, &armcompute.VirtualMachinesClientBeginCreateOrUpdateOptions{IfMatch: nil,
IfNoneMatch: 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)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.VirtualMachine = armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// Properties: &armcompute.VirtualMachineProperties{
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// }},
// },
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// ComputerName: to.Ptr("myVM"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// EnableAutomaticUpdates: to.Ptr(true),
// ProvisionVMAgent: to.Ptr(true),
// },
// },
// ProvisioningState: to.Ptr("Succeeded"),
// StorageProfile: &armcompute.StorageProfile{
// DataDisks: []*armcompute.DataDisk{
// },
// OSDisk: &armcompute.OSDisk{
// Name: to.Ptr("myVMosdisk"),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// Image: &armcompute.VirtualHardDisk{
// URI: to.Ptr("https://{existing-storage-account-name}.blob.core.windows.net/system/Microsoft.Compute/Images/vhds/{existing-generalized-os-image-blob-name}.vhd"),
// },
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// Vhd: &armcompute.VirtualHardDisk{
// URI: to.Ptr("http://{existing-storage-account-name}.blob.core.windows.net/vhds/myDisk.vhd"),
// },
// },
// },
// VMID: to.Ptr("926cd555-a07c-4ff5-b214-4aa4dd09d79b"),
// },
// }
}
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");
/**
* This sample demonstrates how to The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_CustomImageVmFromAnUnmanagedGeneralizedOsImage.json
*/
async function createACustomImageVMFromAnUnmanagedGeneralizedOSImage() {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP"] || "myResourceGroup";
const vmName = "{vm-name}";
const parameters = {
hardwareProfile: { vmSize: "Standard_D1_v2" },
location: "westus",
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
osProfile: {
adminPassword: "{your-password}",
adminUsername: "{your-username}",
computerName: "myVM",
},
storageProfile: {
osDisk: {
name: "myVMosdisk",
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",
},
osType: "Windows",
vhd: {
uri: "http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk.vhd",
},
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.beginCreateOrUpdateAndWait(
resourceGroupName,
vmName,
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
範例回覆
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"osDisk": {
"name": "myVMosdisk",
"image": {
"uri": "https://{existing-storage-account-name}.blob.core.windows.net/system/Microsoft.Compute/Images/vhds/{existing-generalized-os-image-blob-name}.vhd"
},
"caching": "ReadWrite",
"createOption": "FromImage",
"osType": "Windows",
"vhd": {
"uri": "http://{existing-storage-account-name}.blob.core.windows.net/vhds/myDisk.vhd"
}
},
"dataDisks": []
},
"vmId": "926cd555-a07c-4ff5-b214-4aa4dd09d79b",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"osDisk": {
"name": "myVMosdisk",
"image": {
"uri": "https://{existing-storage-account-name}.blob.core.windows.net/system/Microsoft.Compute/Images/vhds/{existing-generalized-os-image-blob-name}.vhd"
},
"caching": "ReadWrite",
"createOption": "FromImage",
"osType": "Windows",
"vhd": {
"uri": "http://{existing-storage-account-name}.blob.core.windows.net/vhds/myDisk.vhd"
}
},
"dataDisks": []
},
"vmId": "926cd555-a07c-4ff5-b214-4aa4dd09d79b",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Create a Linux vm with a patch setting assessmentMode of ImageDefault.
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2024-03-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D2s_v3"
},
"storageProfile": {
"imageReference": {
"sku": "16.04-LTS",
"publisher": "Canonical",
"version": "latest",
"offer": "UbuntuServer"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Premium_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}",
"linuxConfiguration": {
"provisionVMAgent": true,
"patchSettings": {
"assessmentMode": "ImageDefault"
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
from typing import Any, IO, Union
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_create_linux_vm_with_patch_setting_assessment_mode_of_image_default.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_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_D2s_v3"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
"linuxConfiguration": {
"patchSettings": {"assessmentMode": "ImageDefault"},
"provisionVMAgent": True,
},
},
"storageProfile": {
"imageReference": {
"offer": "UbuntuServer",
"publisher": "Canonical",
"sku": "16.04-LTS",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Premium_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_LinuxVmWithPatchSettingAssessmentModeOfImageDefault.json
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/v5"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/92de53a5f1e0e03c94b40475d2135d97148ed014/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_LinuxVmWithPatchSettingAssessmentModeOfImageDefault.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createALinuxVmWithAPatchSettingAssessmentModeOfImageDefault() {
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.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD2SV3),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
}},
},
OSProfile: &armcompute.OSProfile{
AdminPassword: to.Ptr("{your-password}"),
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
LinuxConfiguration: &armcompute.LinuxConfiguration{
PatchSettings: &armcompute.LinuxPatchSettings{
AssessmentMode: to.Ptr(armcompute.LinuxPatchAssessmentModeImageDefault),
},
ProvisionVMAgent: to.Ptr(true),
},
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("UbuntuServer"),
Publisher: to.Ptr("Canonical"),
SKU: to.Ptr("16.04-LTS"),
Version: to.Ptr("latest"),
},
OSDisk: &armcompute.OSDisk{
Name: to.Ptr("myVMosdisk"),
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesPremiumLRS),
},
},
},
},
}, &armcompute.VirtualMachinesClientBeginCreateOrUpdateOptions{IfMatch: nil,
IfNoneMatch: 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)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.VirtualMachine = armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// Properties: &armcompute.VirtualMachineProperties{
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD2SV3),
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// }},
// },
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// ComputerName: to.Ptr("myVM"),
// LinuxConfiguration: &armcompute.LinuxConfiguration{
// PatchSettings: &armcompute.LinuxPatchSettings{
// AssessmentMode: to.Ptr(armcompute.LinuxPatchAssessmentModeImageDefault),
// },
// ProvisionVMAgent: to.Ptr(true),
// },
// Secrets: []*armcompute.VaultSecretGroup{
// },
// },
// ProvisioningState: to.Ptr("Succeeded"),
// StorageProfile: &armcompute.StorageProfile{
// DataDisks: []*armcompute.DataDisk{
// },
// ImageReference: &armcompute.ImageReference{
// Offer: to.Ptr("UbuntuServer"),
// Publisher: to.Ptr("Canonical"),
// SKU: to.Ptr("16.04-LTS"),
// Version: to.Ptr("latest"),
// },
// OSDisk: &armcompute.OSDisk{
// Name: to.Ptr("myVMosdisk"),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesPremiumLRS),
// },
// OSType: to.Ptr(armcompute.OperatingSystemTypesLinux),
// },
// },
// VMID: to.Ptr("a149cd25-409f-41af-8088-275f5486bc93"),
// },
// }
}
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");
/**
* This sample demonstrates how to The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_LinuxVmWithPatchSettingAssessmentModeOfImageDefault.json
*/
async function createALinuxVMWithAPatchSettingAssessmentModeOfImageDefault() {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP"] || "myResourceGroup";
const vmName = "myVM";
const parameters = {
hardwareProfile: { vmSize: "Standard_D2s_v3" },
location: "westus",
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
osProfile: {
adminPassword: "{your-password}",
adminUsername: "{your-username}",
computerName: "myVM",
linuxConfiguration: {
patchSettings: { assessmentMode: "ImageDefault" },
provisionVMAgent: true,
},
},
storageProfile: {
imageReference: {
offer: "UbuntuServer",
publisher: "Canonical",
sku: "16.04-LTS",
version: "latest",
},
osDisk: {
name: "myVMosdisk",
caching: "ReadWrite",
createOption: "FromImage",
managedDisk: { storageAccountType: "Premium_LRS" },
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.beginCreateOrUpdateAndWait(
resourceGroupName,
vmName,
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
import com.azure.core.management.SubResource;
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.AdditionalCapabilities;
import com.azure.resourcemanager.compute.models.ApiEntityReference;
import com.azure.resourcemanager.compute.models.ApplicationProfile;
import com.azure.resourcemanager.compute.models.BootDiagnostics;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DataDisk;
import com.azure.resourcemanager.compute.models.DeleteOptions;
import com.azure.resourcemanager.compute.models.DiagnosticsProfile;
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.DiskControllerTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.DiskEncryptionSetParameters;
import com.azure.resourcemanager.compute.models.DomainNameLabelScopeTypes;
import com.azure.resourcemanager.compute.models.EventGridAndResourceGraph;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.LinuxConfiguration;
import com.azure.resourcemanager.compute.models.LinuxPatchAssessmentMode;
import com.azure.resourcemanager.compute.models.LinuxPatchSettings;
import com.azure.resourcemanager.compute.models.LinuxVMGuestPatchAutomaticByPlatformRebootSetting;
import com.azure.resourcemanager.compute.models.LinuxVMGuestPatchAutomaticByPlatformSettings;
import com.azure.resourcemanager.compute.models.LinuxVMGuestPatchMode;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.Mode;
import com.azure.resourcemanager.compute.models.NetworkApiVersion;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSImageNotificationProfile;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.OperatingSystemTypes;
import com.azure.resourcemanager.compute.models.PatchSettings;
import com.azure.resourcemanager.compute.models.Plan;
import com.azure.resourcemanager.compute.models.ProxyAgentSettings;
import com.azure.resourcemanager.compute.models.PublicIpAddressSku;
import com.azure.resourcemanager.compute.models.PublicIpAddressSkuName;
import com.azure.resourcemanager.compute.models.PublicIpAddressSkuTier;
import com.azure.resourcemanager.compute.models.PublicIpAllocationMethod;
import com.azure.resourcemanager.compute.models.ScheduledEventsAdditionalPublishingTargets;
import com.azure.resourcemanager.compute.models.ScheduledEventsPolicy;
import com.azure.resourcemanager.compute.models.ScheduledEventsProfile;
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.SshConfiguration;
import com.azure.resourcemanager.compute.models.SshPublicKey;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.TerminateNotificationProfile;
import com.azure.resourcemanager.compute.models.UefiSettings;
import com.azure.resourcemanager.compute.models.UserInitiatedReboot;
import com.azure.resourcemanager.compute.models.UserInitiatedRedeploy;
import com.azure.resourcemanager.compute.models.VMDiskSecurityProfile;
import com.azure.resourcemanager.compute.models.VMGalleryApplication;
import com.azure.resourcemanager.compute.models.VMSizeProperties;
import com.azure.resourcemanager.compute.models.VirtualHardDisk;
import com.azure.resourcemanager.compute.models.VirtualMachineNetworkInterfaceConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineNetworkInterfaceIpConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachinePublicIpAddressConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachinePublicIpAddressDnsSettingsConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import com.azure.resourcemanager.compute.models.WindowsConfiguration;
import com.azure.resourcemanager.compute.models.WindowsPatchAssessmentMode;
import com.azure.resourcemanager.compute.models.WindowsVMGuestPatchAutomaticByPlatformRebootSetting;
import com.azure.resourcemanager.compute.models.WindowsVMGuestPatchAutomaticByPlatformSettings;
import com.azure.resourcemanager.compute.models.WindowsVMGuestPatchMode;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_LinuxVmWithPatchSettingAssessmentModeOfImageDefault.json
*/
/**
* Sample code: Create a Linux vm with a patch setting assessmentMode of ImageDefault.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createALinuxVmWithAPatchSettingAssessmentModeOfImageDefault(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2S_V3))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("Canonical").withOffer("UbuntuServer")
.withSku("16.04-LTS").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder")
.withLinuxConfiguration(new LinuxConfiguration().withProvisionVMAgent(true).withPatchSettings(
new LinuxPatchSettings().withAssessmentMode(LinuxPatchAssessmentMode.IMAGE_DEFAULT))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_CustomImageVmFromAnUnmanagedGeneralizedOsImage.json
*/
/**
* Sample code: Create a custom-image vm from an unmanaged generalized os image.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createACustomImageVmFromAnUnmanagedGeneralizedOsImage(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines()
.createOrUpdate("myResourceGroup", "{vm-name}", new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile().withOsDisk(new OSDisk()
.withOsType(OperatingSystemTypes.WINDOWS).withName("myVMosdisk")
.withVhd(new VirtualHardDisk().withUri(
"http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk.vhd"))
.withImage(new VirtualHardDisk().withUri(
"http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/{existing-generalized-os-image-blob-name}.vhd"))
.withCaching(CachingTypes.READ_WRITE).withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithEncryptionAtHost.json
*/
/**
* Sample code: Create a vm with Host Encryption using encryptionAtHost property.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createAVmWithHostEncryptionUsingEncryptionAtHostProperty(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withPlan(new Plan().withName("windows2016").withPublisher("microsoft-ads")
.withProduct("windows-data-science-vm"))
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_DS1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("microsoft-ads")
.withOffer("windows-data-science-vm").withSku("windows2016").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withSecurityProfile(new SecurityProfile().withEncryptionAtHost(true)),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_InAnAvailabilitySet.json
*/
/**
* Sample code: Create a vm in an availability set.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmInAnAvailabilitySet(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withAvailabilitySet(new SubResource().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/availabilitySets/{existing-availability-set-name}")),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithNetworkInterfaceConfiguration.json
*/
/**
* Sample code: Create a VM with network interface configuration.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createAVMWithNetworkInterfaceConfiguration(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(new NetworkProfile()
.withNetworkApiVersion(NetworkApiVersion.TWO_ZERO_TWO_ZERO_ONE_ONE_ZERO_ONE)
.withNetworkInterfaceConfigurations(
Arrays.asList(new VirtualMachineNetworkInterfaceConfiguration().withName("{nic-config-name}")
.withPrimary(true).withDeleteOption(DeleteOptions.DELETE)
.withIpConfigurations(Arrays.asList(new VirtualMachineNetworkInterfaceIpConfiguration()
.withName("{ip-config-name}").withPrimary(true)
.withPublicIpAddressConfiguration(new VirtualMachinePublicIpAddressConfiguration()
.withName("{publicIP-config-name}")
.withSku(new PublicIpAddressSku().withName(PublicIpAddressSkuName.BASIC)
.withTier(PublicIpAddressSkuTier.GLOBAL))
.withDeleteOption(DeleteOptions.DETACH)
.withPublicIpAllocationMethod(PublicIpAllocationMethod.STATIC))))))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithADiffOsDiskUsingDiffDiskPlacementAsNvmeDisk.json
*/
/**
* Sample code: Create a vm with ephemeral os disk provisioning in Nvme disk using placement property.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithEphemeralOsDiskProvisioningInNvmeDiskUsingPlacementProperty(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withPlan(new Plan().withName("windows2016").withPublisher("microsoft-ads")
.withProduct("windows-data-science-vm"))
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_DS1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("microsoft-ads")
.withOffer("windows-data-science-vm").withSku("windows2016").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withDiffDiskSettings(new DiffDiskSettings().withOption(DiffDiskOptions.LOCAL)
.withPlacement(DiffDiskPlacement.NVME_DISK))
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_FromASpecializedSharedImage.json
*/
/**
* Sample code: Create a vm from a specialized shared image.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmFromASpecializedSharedImage(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile().withImageReference(new ImageReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/mySharedGallery/images/mySharedImage"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithPasswordAuthentication.json
*/
/**
* Sample code: Create a vm with password authentication.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithPasswordAuthentication(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithScheduledEventsProfile.json
*/
/**
* Sample code: Create a vm with Scheduled Events Profile.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithScheduledEventsProfile(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withScheduledEventsPolicy(new ScheduledEventsPolicy()
.withUserInitiatedRedeploy(new UserInitiatedRedeploy().withAutomaticallyApprove(true))
.withUserInitiatedReboot(new UserInitiatedReboot().withAutomaticallyApprove(true))
.withScheduledEventsAdditionalPublishingTargets(new ScheduledEventsAdditionalPublishingTargets()
.withEventGridAndResourceGraph(new EventGridAndResourceGraph().withEnable(true))))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics()
.withEnabled(true).withStorageUri("http://{existing-storage-account-name}.blob.core.windows.net")))
.withScheduledEventsProfile(new ScheduledEventsProfile()
.withTerminateNotificationProfile(
new TerminateNotificationProfile().withNotBeforeTimeout("PT10M").withEnable(true))
.withOsImageNotificationProfile(
new OSImageNotificationProfile().withNotBeforeTimeout("PT15M").withEnable(true))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithADiffOsDiskUsingDiffDiskPlacementAsResourceDisk.json
*/
/**
* Sample code: Create a vm with ephemeral os disk provisioning in Resource disk using placement property.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithEphemeralOsDiskProvisioningInResourceDiskUsingPlacementProperty(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withPlan(new Plan().withName("windows2016").withPublisher("microsoft-ads")
.withProduct("windows-data-science-vm"))
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_DS1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("microsoft-ads")
.withOffer("windows-data-science-vm").withSku("windows2016").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withDiffDiskSettings(new DiffDiskSettings().withOption(DiffDiskOptions.LOCAL)
.withPlacement(DiffDiskPlacement.RESOURCE_DISK))
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithADiffOsDisk.json
*/
/**
* Sample code: Create a vm with ephemeral os disk.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithEphemeralOsDisk(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withPlan(new Plan().withName("windows2016").withPublisher("microsoft-ads")
.withProduct("windows-data-science-vm"))
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_DS1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("microsoft-ads")
.withOffer("windows-data-science-vm").withSku("windows2016").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withDiffDiskSettings(new DiffDiskSettings().withOption(DiffDiskOptions.LOCAL))
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithSecurityTypeConfidentialVMWithCustomerManagedKeys.json
*/
/**
* Sample code: Create a VM with securityType ConfidentialVM with Customer Managed Keys.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMWithSecurityTypeConfidentialVMWithCustomerManagedKeys(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(
new HardwareProfile().withVmSize(VirtualMachineSizeTypes.fromString("Standard_DC2as_v5")))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("2019-datacenter-cvm").withSku("windows-cvm").withVersion("17763.2183.2109130127"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)
.withManagedDisk(new ManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.STANDARD_SSD_LRS)
.withSecurityProfile(new VMDiskSecurityProfile()
.withSecurityEncryptionType(SecurityEncryptionTypes.DISK_WITH_VMGUEST_STATE)
.withDiskEncryptionSet(new DiskEncryptionSetParameters().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"))))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withSecurityProfile(new SecurityProfile()
.withUefiSettings(new UefiSettings().withSecureBootEnabled(true).withVTpmEnabled(true))
.withSecurityType(SecurityTypes.CONFIDENTIAL_VM)),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithDiskEncryptionSetResource.json
*/
/**
* Sample code: Create a vm with DiskEncryptionSet resource id in the os disk and data disk.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithDiskEncryptionSetResourceIdInTheOsDiskAndDataDisk(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile().withImageReference(new ImageReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/{existing-custom-image-name}"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)
.withManagedDisk(new ManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.STANDARD_LRS)
.withDiskEncryptionSet(new DiskEncryptionSetParameters().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"))))
.withDataDisks(Arrays.asList(new DataDisk().withLun(0).withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.EMPTY).withDiskSizeGB(1023)
.withManagedDisk(new ManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.STANDARD_LRS)
.withDiskEncryptionSet(new DiskEncryptionSetParameters().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"))),
new DataDisk().withLun(1).withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.ATTACH).withDiskSizeGB(1023)
.withManagedDisk(new ManagedDiskParameters().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/{existing-managed-disk-name}")
.withStorageAccountType(StorageAccountTypes.STANDARD_LRS)
.withDiskEncryptionSet(new DiskEncryptionSetParameters().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"))))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithDiskControllerType.json
*/
/**
* Sample code: Create a VM with Disk Controller Type.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMWithDiskControllerType(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D4_V3))
.withScheduledEventsPolicy(new ScheduledEventsPolicy()
.withUserInitiatedRedeploy(new UserInitiatedRedeploy().withAutomaticallyApprove(true))
.withUserInitiatedReboot(new UserInitiatedReboot().withAutomaticallyApprove(true))
.withScheduledEventsAdditionalPublishingTargets(new ScheduledEventsAdditionalPublishingTargets()
.withEventGridAndResourceGraph(new EventGridAndResourceGraph().withEnable(true))))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS)))
.withDiskControllerType(DiskControllerTypes.NVME))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics()
.withEnabled(true).withStorageUri("http://{existing-storage-account-name}.blob.core.windows.net")))
.withUserData("U29tZSBDdXN0b20gRGF0YQ=="),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_FromASharedGalleryImage.json
*/
/**
* Sample code: Create a VM from a shared gallery image.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMFromASharedGalleryImage(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withSharedGalleryImageId(
"/SharedGalleries/sharedGalleryName/Images/sharedGalleryImageName/Versions/sharedGalleryImageVersionName"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithVMSizeProperties.json
*/
/**
* Sample code: Create a VM with VM Size Properties.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMWithVMSizeProperties(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D4_V3)
.withVmSizeProperties(new VMSizeProperties().withVCpusAvailable(1).withVCpusPerCore(1)))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics()
.withEnabled(true).withStorageUri("http://{existing-storage-account-name}.blob.core.windows.net")))
.withUserData("U29tZSBDdXN0b20gRGF0YQ=="),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_PlatformImageVmWithUnmanagedOsAndDataDisks.json
*/
/**
* Sample code: Create a platform-image vm with unmanaged os and data disks.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createAPlatformImageVmWithUnmanagedOsAndDataDisks(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines()
.createOrUpdate("myResourceGroup", "{vm-name}", new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withVhd(new VirtualHardDisk().withUri(
"http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk.vhd"))
.withCaching(CachingTypes.READ_WRITE).withCreateOption(DiskCreateOptionTypes.FROM_IMAGE))
.withDataDisks(Arrays.asList(new DataDisk().withLun(0).withVhd(new VirtualHardDisk().withUri(
"http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk0.vhd"))
.withCreateOption(DiskCreateOptionTypes.EMPTY).withDiskSizeGB(1023),
new DataDisk().withLun(1).withVhd(new VirtualHardDisk().withUri(
"http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk1.vhd"))
.withCreateOption(DiskCreateOptionTypes.EMPTY).withDiskSizeGB(1023))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_LinuxVmWithPatchSettingModesOfAutomaticByPlatform.json
*/
/**
* Sample code: Create a Linux vm with a patch settings patchMode and assessmentMode set to AutomaticByPlatform.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createALinuxVmWithAPatchSettingsPatchModeAndAssessmentModeSetToAutomaticByPlatform(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2S_V3))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("Canonical").withOffer("UbuntuServer")
.withSku("16.04-LTS").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder")
.withLinuxConfiguration(new LinuxConfiguration().withProvisionVMAgent(true).withPatchSettings(
new LinuxPatchSettings().withPatchMode(LinuxVMGuestPatchMode.AUTOMATIC_BY_PLATFORM)
.withAssessmentMode(LinuxPatchAssessmentMode.AUTOMATIC_BY_PLATFORM))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithSecurityTypeConfidentialVMWithNonPersistedTPM.json
*/
/**
* Sample code: Create a VM with securityType ConfidentialVM with NonPersistedTPM securityEncryptionType.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMWithSecurityTypeConfidentialVMWithNonPersistedTPMSecurityEncryptionType(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(
new HardwareProfile().withVmSize(VirtualMachineSizeTypes.fromString("Standard_DC2es_v5")))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("UbuntuServer")
.withOffer("2022-datacenter-cvm").withSku("linux-cvm").withVersion("17763.2183.2109130127"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_SSD_LRS)
.withSecurityProfile(new VMDiskSecurityProfile()
.withSecurityEncryptionType(SecurityEncryptionTypes.NON_PERSISTED_TPM)))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withSecurityProfile(new SecurityProfile()
.withUefiSettings(new UefiSettings().withSecureBootEnabled(false).withVTpmEnabled(true))
.withSecurityType(SecurityTypes.CONFIDENTIAL_VM)),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithAMarketplaceImagePlan.json
*/
/**
* Sample code: Create a vm with a marketplace image plan.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithAMarketplaceImagePlan(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withPlan(new Plan().withName("windows2016").withPublisher("microsoft-ads")
.withProduct("windows-data-science-vm"))
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("microsoft-ads")
.withOffer("windows-data-science-vm").withSku("windows2016").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WindowsVmWithPatchSettingAssessmentModeOfImageDefault.json
*/
/**
* Sample code: Create a Windows vm with a patch setting assessmentMode of ImageDefault.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAWindowsVmWithAPatchSettingAssessmentModeOfImageDefault(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder")
.withWindowsConfiguration(new WindowsConfiguration().withProvisionVMAgent(true)
.withEnableAutomaticUpdates(true).withPatchSettings(
new PatchSettings().withAssessmentMode(WindowsPatchAssessmentMode.IMAGE_DEFAULT))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/
* VirtualMachine_Create_WindowsVmWithPatchSettingModeOfAutomaticByPlatformAndEnableHotPatchingTrue.json
*/
/**
* Sample code: Create a Windows vm with a patch setting patchMode of AutomaticByPlatform and enableHotpatching set
* to true.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAWindowsVmWithAPatchSettingPatchModeOfAutomaticByPlatformAndEnableHotpatchingSetToTrue(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder")
.withWindowsConfiguration(new WindowsConfiguration().withProvisionVMAgent(true)
.withEnableAutomaticUpdates(true)
.withPatchSettings(new PatchSettings()
.withPatchMode(WindowsVMGuestPatchMode.AUTOMATIC_BY_PLATFORM).withEnableHotpatching(true))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithExtensionsTimeBudget.json
*/
/**
* Sample code: Create a vm with an extensions time budget.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithAnExtensionsTimeBudget(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics()
.withEnabled(true).withStorageUri("http://{existing-storage-account-name}.blob.core.windows.net")))
.withExtensionsTimeBudget("PT30M"),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithEmptyDataDisks.json
*/
/**
* Sample code: Create a vm with empty data disks.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithEmptyDataDisks(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS)))
.withDataDisks(Arrays.asList(
new DataDisk().withLun(0).withCreateOption(DiskCreateOptionTypes.EMPTY).withDiskSizeGB(1023),
new DataDisk().withLun(1).withCreateOption(DiskCreateOptionTypes.EMPTY).withDiskSizeGB(1023))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithSecurityTypeConfidentialVM.json
*/
/**
* Sample code: Create a VM with securityType ConfidentialVM with Platform Managed Keys.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMWithSecurityTypeConfidentialVMWithPlatformManagedKeys(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(
new HardwareProfile().withVmSize(VirtualMachineSizeTypes.fromString("Standard_DC2as_v5")))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("2019-datacenter-cvm").withSku("windows-cvm").withVersion("17763.2183.2109130127"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_SSD_LRS)
.withSecurityProfile(new VMDiskSecurityProfile()
.withSecurityEncryptionType(SecurityEncryptionTypes.DISK_WITH_VMGUEST_STATE)))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withSecurityProfile(new SecurityProfile()
.withUefiSettings(new UefiSettings().withSecureBootEnabled(true).withVTpmEnabled(true))
.withSecurityType(SecurityTypes.CONFIDENTIAL_VM)),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithDataDisksFromSourceResource.json
*/
/**
* Sample code: Create a vm with data disks using 'Copy' and 'Restore' options.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createAVmWithDataDisksUsingCopyAndRestoreOptions(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS)))
.withDataDisks(Arrays.asList(new DataDisk().withLun(0).withCreateOption(DiskCreateOptionTypes.COPY)
.withDiskSizeGB(1023)
.withSourceResource(new ApiEntityReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/{existing-snapshot-name}")),
new DataDisk().withLun(1).withCreateOption(DiskCreateOptionTypes.COPY).withDiskSizeGB(1023)
.withSourceResource(new ApiEntityReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/{existing-disk-name}")),
new DataDisk().withLun(2).withCreateOption(DiskCreateOptionTypes.RESTORE).withDiskSizeGB(1023)
.withSourceResource(new ApiEntityReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/restorePointCollections/{existing-rpc-name}/restorePoints/{existing-rp-name}/diskRestorePoints/{existing-disk-restore-point-name}")))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_FromACustomImage.json
*/
/**
* Sample code: Create a vm from a custom image.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmFromACustomImage(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile().withImageReference(new ImageReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/{existing-custom-image-name}"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithHibernationEnabled.json
*/
/**
* Sample code: Create a VM with HibernationEnabled.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMWithHibernationEnabled(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup",
"{vm-name}",
new VirtualMachineInner().withLocation("eastus2euap")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2S_V3))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2019-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("vmOSdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withAdditionalCapabilities(new AdditionalCapabilities().withHibernationEnabled(true))
.withOsProfile(new OSProfile().withComputerName("{vm-name}").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics()
.withEnabled(true).withStorageUri("http://{existing-storage-account-name}.blob.core.windows.net"))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithUefiSettings.json
*/
/**
* Sample code: Create a VM with Uefi Settings of secureBoot and vTPM.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createAVMWithUefiSettingsOfSecureBootAndVTPM(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2S_V3))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference()
.withPublisher("MicrosoftWindowsServer").withOffer("windowsserver-gen2preview-preview")
.withSku("windows10-tvm").withVersion("18363.592.2001092016"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_SSD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withSecurityProfile(new SecurityProfile()
.withUefiSettings(new UefiSettings().withSecureBootEnabled(true).withVTpmEnabled(true))
.withSecurityType(SecurityTypes.TRUSTED_LAUNCH)),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithApplicationProfile.json
*/
/**
* Sample code: Create a vm with Application Profile.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithApplicationProfile(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("{image_publisher}")
.withOffer("{image_offer}").withSku("{image_sku}").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(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(false).withEnableAutomaticUpgrade(false),
new VMGalleryApplication().withPackageReferenceId(
"/subscriptions/32c17a9e-aa7b-4ba5-a45b-e324116b6fdg/resourceGroups/myresourceGroupName3/providers/Microsoft.Compute/galleries/myGallery2/applications/MyApplication2/versions/1.1")))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithNetworkInterfaceConfigurationDnsSettings.json
*/
/**
* Sample code: Create a VM with network interface configuration with public ip address dns settings.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMWithNetworkInterfaceConfigurationWithPublicIpAddressDnsSettings(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkApiVersion(NetworkApiVersion.TWO_ZERO_TWO_ZERO_ONE_ONE_ZERO_ONE)
.withNetworkInterfaceConfigurations(
Arrays.asList(new VirtualMachineNetworkInterfaceConfiguration()
.withName("{nic-config-name}").withPrimary(true).withDeleteOption(DeleteOptions.DELETE)
.withIpConfigurations(Arrays.asList(new VirtualMachineNetworkInterfaceIpConfiguration()
.withName("{ip-config-name}").withPrimary(true)
.withPublicIpAddressConfiguration(new VirtualMachinePublicIpAddressConfiguration()
.withName("{publicIP-config-name}")
.withSku(new PublicIpAddressSku().withName(PublicIpAddressSkuName.BASIC)
.withTier(PublicIpAddressSkuTier.GLOBAL))
.withDeleteOption(DeleteOptions.DETACH)
.withDnsSettings(new VirtualMachinePublicIpAddressDnsSettingsConfiguration()
.withDomainNameLabel("aaaaa")
.withDomainNameLabelScope(DomainNameLabelScopeTypes.TENANT_REUSE))
.withPublicIpAllocationMethod(PublicIpAllocationMethod.STATIC))))))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_InAVmssWithCustomerAssignedPlatformFaultDomain.json
*/
/**
* Sample code: Create a vm in a Virtual Machine Scale Set with customer assigned platformFaultDomain.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmInAVirtualMachineScaleSetWithCustomerAssignedPlatformFaultDomain(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withVirtualMachineScaleSet(new SubResource().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{existing-flex-vmss-name-with-platformFaultDomainCount-greater-than-1}"))
.withPlatformFaultDomain(1),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithBootDiagnostics.json
*/
/**
* Sample code: Create a vm with boot diagnostics.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithBootDiagnostics(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics()
.withEnabled(true).withStorageUri("http://{existing-storage-account-name}.blob.core.windows.net"))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithSshAuthentication.json
*/
/**
* Sample code: Create a vm with ssh authentication.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithSshAuthentication(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("{image_publisher}")
.withOffer("{image_offer}").withSku("{image_sku}").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").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"))))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_FromACommunityGalleryImage.json
*/
/**
* Sample code: Create a VM from a community gallery image.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMFromACommunityGalleryImage(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withCommunityGalleryImageId(
"/CommunityGalleries/galleryPublicName/Images/communityGalleryImageName/Versions/communityGalleryImageVersionName"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithUserData.json
*/
/**
* Sample code: Create a VM with UserData.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMWithUserData(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup",
"{vm-name}",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("vmOSdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("{vm-name}").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics()
.withEnabled(true).withStorageUri("http://{existing-storage-account-name}.blob.core.windows.net")))
.withUserData("RXhhbXBsZSBVc2VyRGF0YQ=="),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_FromAGeneralizedSharedImage.json
*/
/**
* Sample code: Create a vm from a generalized shared image.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmFromAGeneralizedSharedImage(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile().withImageReference(new ImageReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/mySharedGallery/images/mySharedImage"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_LinuxVmWithAutomaticByPlatformSettings.json
*/
/**
* Sample code: Create a Linux vm with a patch setting patchMode of AutomaticByPlatform and
* AutomaticByPlatformSettings.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createALinuxVmWithAPatchSettingPatchModeOfAutomaticByPlatformAndAutomaticByPlatformSettings(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2S_V3))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("Canonical").withOffer("UbuntuServer")
.withSku("16.04-LTS").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder")
.withLinuxConfiguration(new LinuxConfiguration().withProvisionVMAgent(true).withPatchSettings(
new LinuxPatchSettings().withPatchMode(LinuxVMGuestPatchMode.AUTOMATIC_BY_PLATFORM)
.withAssessmentMode(LinuxPatchAssessmentMode.AUTOMATIC_BY_PLATFORM)
.withAutomaticByPlatformSettings(new LinuxVMGuestPatchAutomaticByPlatformSettings()
.withRebootSetting(LinuxVMGuestPatchAutomaticByPlatformRebootSetting.NEVER)
.withBypassPlatformSafetyChecksOnUserSchedule(true)))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WindowsVmWithPatchSettingModeOfManual.json
*/
/**
* Sample code: Create a Windows vm with a patch setting patchMode of Manual.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createAWindowsVmWithAPatchSettingPatchModeOfManual(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder").withWindowsConfiguration(
new WindowsConfiguration().withProvisionVMAgent(true).withEnableAutomaticUpdates(true)
.withPatchSettings(new PatchSettings().withPatchMode(WindowsVMGuestPatchMode.MANUAL))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithProxyAgentSettings.json
*/
/**
* Sample code: Create a VM with ProxyAgent Settings of enabled and mode.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createAVMWithProxyAgentSettingsOfEnabledAndMode(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2S_V3))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2019-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_SSD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withSecurityProfile(new SecurityProfile()
.withProxyAgentSettings(new ProxyAgentSettings().withEnabled(true).withMode(Mode.ENFORCE))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_LinuxVmWithPatchSettingModeOfImageDefault.json
*/
/**
* Sample code: Create a Linux vm with a patch setting patchMode of ImageDefault.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createALinuxVmWithAPatchSettingPatchModeOfImageDefault(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2S_V3))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("Canonical").withOffer("UbuntuServer")
.withSku("16.04-LTS").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder")
.withLinuxConfiguration(new LinuxConfiguration().withProvisionVMAgent(true).withPatchSettings(
new LinuxPatchSettings().withPatchMode(LinuxVMGuestPatchMode.IMAGE_DEFAULT))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithManagedBootDiagnostics.json
*/
/**
* Sample code: Create a vm with managed boot diagnostics.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithManagedBootDiagnostics(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(
new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics().withEnabled(true))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WindowsVmWithAutomaticByPlatformSettings.json
*/
/**
* Sample code: Create a Windows vm with a patch setting patchMode of AutomaticByPlatform and
* AutomaticByPlatformSettings.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAWindowsVmWithAPatchSettingPatchModeOfAutomaticByPlatformAndAutomaticByPlatformSettings(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder").withWindowsConfiguration(
new WindowsConfiguration().withProvisionVMAgent(true).withEnableAutomaticUpdates(true)
.withPatchSettings(new PatchSettings()
.withPatchMode(WindowsVMGuestPatchMode.AUTOMATIC_BY_PLATFORM)
.withAssessmentMode(WindowsPatchAssessmentMode.AUTOMATIC_BY_PLATFORM)
.withAutomaticByPlatformSettings(new WindowsVMGuestPatchAutomaticByPlatformSettings()
.withRebootSetting(WindowsVMGuestPatchAutomaticByPlatformRebootSetting.NEVER)
.withBypassPlatformSafetyChecksOnUserSchedule(false)))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
範例回覆
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"linuxConfiguration": {
"provisionVMAgent": true,
"patchSettings": {
"assessmentMode": "ImageDefault"
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "16.04-LTS",
"publisher": "Canonical",
"version": "latest",
"offer": "UbuntuServer"
},
"osDisk": {
"osType": "Linux",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Premium_LRS"
}
},
"dataDisks": []
},
"vmId": "a149cd25-409f-41af-8088-275f5486bc93",
"hardwareProfile": {
"vmSize": "Standard_D2s_v3"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"linuxConfiguration": {
"provisionVMAgent": true,
"patchSettings": {
"assessmentMode": "ImageDefault"
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "16.04-LTS",
"publisher": "Canonical",
"version": "latest",
"offer": "UbuntuServer"
},
"osDisk": {
"osType": "Linux",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Premium_LRS"
}
},
"dataDisks": []
},
"vmId": "a149cd25-409f-41af-8088-275f5486bc93",
"hardwareProfile": {
"vmSize": "Standard_D2s_v3"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2024-03-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D2s_v3"
},
"storageProfile": {
"imageReference": {
"sku": "16.04-LTS",
"publisher": "Canonical",
"version": "latest",
"offer": "UbuntuServer"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Premium_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}",
"linuxConfiguration": {
"provisionVMAgent": true,
"patchSettings": {
"patchMode": "AutomaticByPlatform",
"assessmentMode": "AutomaticByPlatform",
"automaticByPlatformSettings": {
"rebootSetting": "Never",
"bypassPlatformSafetyChecksOnUserSchedule": true
}
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
from typing import Any, IO, Union
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_create_linux_vm_with_automatic_by_platform_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_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_D2s_v3"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
"linuxConfiguration": {
"patchSettings": {
"assessmentMode": "AutomaticByPlatform",
"automaticByPlatformSettings": {
"bypassPlatformSafetyChecksOnUserSchedule": True,
"rebootSetting": "Never",
},
"patchMode": "AutomaticByPlatform",
},
"provisionVMAgent": True,
},
},
"storageProfile": {
"imageReference": {
"offer": "UbuntuServer",
"publisher": "Canonical",
"sku": "16.04-LTS",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Premium_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_LinuxVmWithAutomaticByPlatformSettings.json
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/v5"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/92de53a5f1e0e03c94b40475d2135d97148ed014/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_LinuxVmWithAutomaticByPlatformSettings.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createALinuxVmWithAPatchSettingPatchModeOfAutomaticByPlatformAndAutomaticByPlatformSettings() {
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.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD2SV3),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
}},
},
OSProfile: &armcompute.OSProfile{
AdminPassword: to.Ptr("{your-password}"),
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
LinuxConfiguration: &armcompute.LinuxConfiguration{
PatchSettings: &armcompute.LinuxPatchSettings{
AssessmentMode: to.Ptr(armcompute.LinuxPatchAssessmentModeAutomaticByPlatform),
AutomaticByPlatformSettings: &armcompute.LinuxVMGuestPatchAutomaticByPlatformSettings{
BypassPlatformSafetyChecksOnUserSchedule: to.Ptr(true),
RebootSetting: to.Ptr(armcompute.LinuxVMGuestPatchAutomaticByPlatformRebootSettingNever),
},
PatchMode: to.Ptr(armcompute.LinuxVMGuestPatchModeAutomaticByPlatform),
},
ProvisionVMAgent: to.Ptr(true),
},
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("UbuntuServer"),
Publisher: to.Ptr("Canonical"),
SKU: to.Ptr("16.04-LTS"),
Version: to.Ptr("latest"),
},
OSDisk: &armcompute.OSDisk{
Name: to.Ptr("myVMosdisk"),
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesPremiumLRS),
},
},
},
},
}, &armcompute.VirtualMachinesClientBeginCreateOrUpdateOptions{IfMatch: nil,
IfNoneMatch: 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)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.VirtualMachine = armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// Properties: &armcompute.VirtualMachineProperties{
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD2SV3),
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// }},
// },
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// ComputerName: to.Ptr("myVM"),
// LinuxConfiguration: &armcompute.LinuxConfiguration{
// PatchSettings: &armcompute.LinuxPatchSettings{
// AssessmentMode: to.Ptr(armcompute.LinuxPatchAssessmentModeAutomaticByPlatform),
// AutomaticByPlatformSettings: &armcompute.LinuxVMGuestPatchAutomaticByPlatformSettings{
// BypassPlatformSafetyChecksOnUserSchedule: to.Ptr(true),
// RebootSetting: to.Ptr(armcompute.LinuxVMGuestPatchAutomaticByPlatformRebootSettingNever),
// },
// PatchMode: to.Ptr(armcompute.LinuxVMGuestPatchModeAutomaticByPlatform),
// },
// ProvisionVMAgent: to.Ptr(true),
// },
// Secrets: []*armcompute.VaultSecretGroup{
// },
// },
// ProvisioningState: to.Ptr("Succeeded"),
// StorageProfile: &armcompute.StorageProfile{
// DataDisks: []*armcompute.DataDisk{
// },
// ImageReference: &armcompute.ImageReference{
// Offer: to.Ptr("UbuntuServer"),
// Publisher: to.Ptr("Canonical"),
// SKU: to.Ptr("16.04-LTS"),
// Version: to.Ptr("latest"),
// },
// OSDisk: &armcompute.OSDisk{
// Name: to.Ptr("myVMosdisk"),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesPremiumLRS),
// },
// OSType: to.Ptr(armcompute.OperatingSystemTypesLinux),
// },
// },
// VMID: to.Ptr("a149cd25-409f-41af-8088-275f5486bc93"),
// },
// }
}
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");
/**
* This sample demonstrates how to The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_LinuxVmWithAutomaticByPlatformSettings.json
*/
async function createALinuxVMWithAPatchSettingPatchModeOfAutomaticByPlatformAndAutomaticByPlatformSettings() {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP"] || "myResourceGroup";
const vmName = "myVM";
const parameters = {
hardwareProfile: { vmSize: "Standard_D2s_v3" },
location: "westus",
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
osProfile: {
adminPassword: "{your-password}",
adminUsername: "{your-username}",
computerName: "myVM",
linuxConfiguration: {
patchSettings: {
assessmentMode: "AutomaticByPlatform",
automaticByPlatformSettings: {
bypassPlatformSafetyChecksOnUserSchedule: true,
rebootSetting: "Never",
},
patchMode: "AutomaticByPlatform",
},
provisionVMAgent: true,
},
},
storageProfile: {
imageReference: {
offer: "UbuntuServer",
publisher: "Canonical",
sku: "16.04-LTS",
version: "latest",
},
osDisk: {
name: "myVMosdisk",
caching: "ReadWrite",
createOption: "FromImage",
managedDisk: { storageAccountType: "Premium_LRS" },
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.beginCreateOrUpdateAndWait(
resourceGroupName,
vmName,
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
範例回覆
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"linuxConfiguration": {
"provisionVMAgent": true,
"patchSettings": {
"patchMode": "AutomaticByPlatform",
"assessmentMode": "AutomaticByPlatform",
"automaticByPlatformSettings": {
"rebootSetting": "Never",
"bypassPlatformSafetyChecksOnUserSchedule": true
}
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "16.04-LTS",
"publisher": "Canonical",
"version": "latest",
"offer": "UbuntuServer"
},
"osDisk": {
"osType": "Linux",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Premium_LRS"
}
},
"dataDisks": []
},
"vmId": "a149cd25-409f-41af-8088-275f5486bc93",
"hardwareProfile": {
"vmSize": "Standard_D2s_v3"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"linuxConfiguration": {
"provisionVMAgent": true,
"patchSettings": {
"patchMode": "AutomaticByPlatform",
"assessmentMode": "AutomaticByPlatform",
"automaticByPlatformSettings": {
"rebootSetting": "Never",
"bypassPlatformSafetyChecksOnUserSchedule": true
}
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "16.04-LTS",
"publisher": "Canonical",
"version": "latest",
"offer": "UbuntuServer"
},
"osDisk": {
"osType": "Linux",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Premium_LRS"
}
},
"dataDisks": []
},
"vmId": "a149cd25-409f-41af-8088-275f5486bc93",
"hardwareProfile": {
"vmSize": "Standard_D2s_v3"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Create a Linux vm with a patch setting patchMode of ImageDefault.
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2024-03-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D2s_v3"
},
"storageProfile": {
"imageReference": {
"sku": "16.04-LTS",
"publisher": "Canonical",
"version": "latest",
"offer": "UbuntuServer"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Premium_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}",
"linuxConfiguration": {
"provisionVMAgent": true,
"patchSettings": {
"patchMode": "ImageDefault"
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
from typing import Any, IO, Union
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_create_linux_vm_with_patch_setting_mode_of_image_default.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_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_D2s_v3"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
"linuxConfiguration": {"patchSettings": {"patchMode": "ImageDefault"}, "provisionVMAgent": True},
},
"storageProfile": {
"imageReference": {
"offer": "UbuntuServer",
"publisher": "Canonical",
"sku": "16.04-LTS",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Premium_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_LinuxVmWithPatchSettingModeOfImageDefault.json
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/v5"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/92de53a5f1e0e03c94b40475d2135d97148ed014/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_LinuxVmWithPatchSettingModeOfImageDefault.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createALinuxVmWithAPatchSettingPatchModeOfImageDefault() {
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.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD2SV3),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
}},
},
OSProfile: &armcompute.OSProfile{
AdminPassword: to.Ptr("{your-password}"),
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
LinuxConfiguration: &armcompute.LinuxConfiguration{
PatchSettings: &armcompute.LinuxPatchSettings{
PatchMode: to.Ptr(armcompute.LinuxVMGuestPatchModeImageDefault),
},
ProvisionVMAgent: to.Ptr(true),
},
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("UbuntuServer"),
Publisher: to.Ptr("Canonical"),
SKU: to.Ptr("16.04-LTS"),
Version: to.Ptr("latest"),
},
OSDisk: &armcompute.OSDisk{
Name: to.Ptr("myVMosdisk"),
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesPremiumLRS),
},
},
},
},
}, &armcompute.VirtualMachinesClientBeginCreateOrUpdateOptions{IfMatch: nil,
IfNoneMatch: 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)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.VirtualMachine = armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// Properties: &armcompute.VirtualMachineProperties{
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD2SV3),
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// }},
// },
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// ComputerName: to.Ptr("myVM"),
// LinuxConfiguration: &armcompute.LinuxConfiguration{
// PatchSettings: &armcompute.LinuxPatchSettings{
// PatchMode: to.Ptr(armcompute.LinuxVMGuestPatchModeImageDefault),
// },
// ProvisionVMAgent: to.Ptr(true),
// },
// Secrets: []*armcompute.VaultSecretGroup{
// },
// },
// ProvisioningState: to.Ptr("Succeeded"),
// StorageProfile: &armcompute.StorageProfile{
// DataDisks: []*armcompute.DataDisk{
// },
// ImageReference: &armcompute.ImageReference{
// Offer: to.Ptr("UbuntuServer"),
// Publisher: to.Ptr("Canonical"),
// SKU: to.Ptr("16.04-LTS"),
// Version: to.Ptr("latest"),
// },
// OSDisk: &armcompute.OSDisk{
// Name: to.Ptr("myVMosdisk"),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesPremiumLRS),
// },
// OSType: to.Ptr(armcompute.OperatingSystemTypesLinux),
// },
// },
// VMID: to.Ptr("a149cd25-409f-41af-8088-275f5486bc93"),
// },
// }
}
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");
/**
* This sample demonstrates how to The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_LinuxVmWithPatchSettingModeOfImageDefault.json
*/
async function createALinuxVMWithAPatchSettingPatchModeOfImageDefault() {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP"] || "myResourceGroup";
const vmName = "myVM";
const parameters = {
hardwareProfile: { vmSize: "Standard_D2s_v3" },
location: "westus",
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
osProfile: {
adminPassword: "{your-password}",
adminUsername: "{your-username}",
computerName: "myVM",
linuxConfiguration: {
patchSettings: { patchMode: "ImageDefault" },
provisionVMAgent: true,
},
},
storageProfile: {
imageReference: {
offer: "UbuntuServer",
publisher: "Canonical",
sku: "16.04-LTS",
version: "latest",
},
osDisk: {
name: "myVMosdisk",
caching: "ReadWrite",
createOption: "FromImage",
managedDisk: { storageAccountType: "Premium_LRS" },
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.beginCreateOrUpdateAndWait(
resourceGroupName,
vmName,
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
範例回覆
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"linuxConfiguration": {
"provisionVMAgent": true,
"patchSettings": {
"patchMode": "ImageDefault"
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "16.04-LTS",
"publisher": "Canonical",
"version": "latest",
"offer": "UbuntuServer"
},
"osDisk": {
"osType": "Linux",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Premium_LRS"
}
},
"dataDisks": []
},
"vmId": "a149cd25-409f-41af-8088-275f5486bc93",
"hardwareProfile": {
"vmSize": "Standard_D2s_v3"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"linuxConfiguration": {
"provisionVMAgent": true,
"patchSettings": {
"patchMode": "ImageDefault"
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "16.04-LTS",
"publisher": "Canonical",
"version": "latest",
"offer": "UbuntuServer"
},
"osDisk": {
"osType": "Linux",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Premium_LRS"
}
},
"dataDisks": []
},
"vmId": "a149cd25-409f-41af-8088-275f5486bc93",
"hardwareProfile": {
"vmSize": "Standard_D2s_v3"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2024-03-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D2s_v3"
},
"storageProfile": {
"imageReference": {
"sku": "16.04-LTS",
"publisher": "Canonical",
"version": "latest",
"offer": "UbuntuServer"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Premium_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}",
"linuxConfiguration": {
"provisionVMAgent": true,
"patchSettings": {
"patchMode": "AutomaticByPlatform",
"assessmentMode": "AutomaticByPlatform"
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
from typing import Any, IO, Union
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_create_linux_vm_with_patch_setting_modes_of_automatic_by_platform.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_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_D2s_v3"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
"linuxConfiguration": {
"patchSettings": {"assessmentMode": "AutomaticByPlatform", "patchMode": "AutomaticByPlatform"},
"provisionVMAgent": True,
},
},
"storageProfile": {
"imageReference": {
"offer": "UbuntuServer",
"publisher": "Canonical",
"sku": "16.04-LTS",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Premium_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_LinuxVmWithPatchSettingModesOfAutomaticByPlatform.json
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/v5"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/92de53a5f1e0e03c94b40475d2135d97148ed014/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_LinuxVmWithPatchSettingModesOfAutomaticByPlatform.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createALinuxVmWithAPatchSettingsPatchModeAndAssessmentModeSetToAutomaticByPlatform() {
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.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD2SV3),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
}},
},
OSProfile: &armcompute.OSProfile{
AdminPassword: to.Ptr("{your-password}"),
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
LinuxConfiguration: &armcompute.LinuxConfiguration{
PatchSettings: &armcompute.LinuxPatchSettings{
AssessmentMode: to.Ptr(armcompute.LinuxPatchAssessmentModeAutomaticByPlatform),
PatchMode: to.Ptr(armcompute.LinuxVMGuestPatchModeAutomaticByPlatform),
},
ProvisionVMAgent: to.Ptr(true),
},
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("UbuntuServer"),
Publisher: to.Ptr("Canonical"),
SKU: to.Ptr("16.04-LTS"),
Version: to.Ptr("latest"),
},
OSDisk: &armcompute.OSDisk{
Name: to.Ptr("myVMosdisk"),
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesPremiumLRS),
},
},
},
},
}, &armcompute.VirtualMachinesClientBeginCreateOrUpdateOptions{IfMatch: nil,
IfNoneMatch: 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)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.VirtualMachine = armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// Properties: &armcompute.VirtualMachineProperties{
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD2SV3),
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// }},
// },
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// ComputerName: to.Ptr("myVM"),
// LinuxConfiguration: &armcompute.LinuxConfiguration{
// PatchSettings: &armcompute.LinuxPatchSettings{
// AssessmentMode: to.Ptr(armcompute.LinuxPatchAssessmentModeAutomaticByPlatform),
// PatchMode: to.Ptr(armcompute.LinuxVMGuestPatchModeAutomaticByPlatform),
// },
// ProvisionVMAgent: to.Ptr(true),
// },
// Secrets: []*armcompute.VaultSecretGroup{
// },
// },
// ProvisioningState: to.Ptr("Succeeded"),
// StorageProfile: &armcompute.StorageProfile{
// DataDisks: []*armcompute.DataDisk{
// },
// ImageReference: &armcompute.ImageReference{
// Offer: to.Ptr("UbuntuServer"),
// Publisher: to.Ptr("Canonical"),
// SKU: to.Ptr("16.04-LTS"),
// Version: to.Ptr("latest"),
// },
// OSDisk: &armcompute.OSDisk{
// Name: to.Ptr("myVMosdisk"),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesPremiumLRS),
// },
// OSType: to.Ptr(armcompute.OperatingSystemTypesLinux),
// },
// },
// VMID: to.Ptr("a149cd25-409f-41af-8088-275f5486bc93"),
// },
// }
}
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");
/**
* This sample demonstrates how to The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_LinuxVmWithPatchSettingModesOfAutomaticByPlatform.json
*/
async function createALinuxVMWithAPatchSettingsPatchModeAndAssessmentModeSetToAutomaticByPlatform() {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP"] || "myResourceGroup";
const vmName = "myVM";
const parameters = {
hardwareProfile: { vmSize: "Standard_D2s_v3" },
location: "westus",
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
osProfile: {
adminPassword: "{your-password}",
adminUsername: "{your-username}",
computerName: "myVM",
linuxConfiguration: {
patchSettings: {
assessmentMode: "AutomaticByPlatform",
patchMode: "AutomaticByPlatform",
},
provisionVMAgent: true,
},
},
storageProfile: {
imageReference: {
offer: "UbuntuServer",
publisher: "Canonical",
sku: "16.04-LTS",
version: "latest",
},
osDisk: {
name: "myVMosdisk",
caching: "ReadWrite",
createOption: "FromImage",
managedDisk: { storageAccountType: "Premium_LRS" },
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.beginCreateOrUpdateAndWait(
resourceGroupName,
vmName,
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
範例回覆
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"linuxConfiguration": {
"provisionVMAgent": true,
"patchSettings": {
"patchMode": "AutomaticByPlatform",
"assessmentMode": "AutomaticByPlatform"
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "16.04-LTS",
"publisher": "Canonical",
"version": "latest",
"offer": "UbuntuServer"
},
"osDisk": {
"osType": "Linux",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Premium_LRS"
}
},
"dataDisks": []
},
"vmId": "a149cd25-409f-41af-8088-275f5486bc93",
"hardwareProfile": {
"vmSize": "Standard_D2s_v3"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"linuxConfiguration": {
"provisionVMAgent": true,
"patchSettings": {
"patchMode": "AutomaticByPlatform",
"assessmentMode": "AutomaticByPlatform"
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "16.04-LTS",
"publisher": "Canonical",
"version": "latest",
"offer": "UbuntuServer"
},
"osDisk": {
"osType": "Linux",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Premium_LRS"
}
},
"dataDisks": []
},
"vmId": "a149cd25-409f-41af-8088-275f5486bc93",
"hardwareProfile": {
"vmSize": "Standard_D2s_v3"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/{vm-name}?api-version=2024-03-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D2_v2"
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"caching": "ReadWrite",
"vhd": {
"uri": "http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk.vhd"
},
"createOption": "FromImage",
"name": "myVMosdisk"
},
"dataDisks": [
{
"diskSizeGB": 1023,
"createOption": "Empty",
"lun": 0,
"vhd": {
"uri": "http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk0.vhd"
}
},
{
"diskSizeGB": 1023,
"createOption": "Empty",
"lun": 1,
"vhd": {
"uri": "http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk1.vhd"
}
}
]
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
from typing import Any, IO, Union
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_create_platform_image_vm_with_unmanaged_os_and_data_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_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="{vm-name}",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_D2_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"storageProfile": {
"dataDisks": [
{
"createOption": "Empty",
"diskSizeGB": 1023,
"lun": 0,
"vhd": {
"uri": "http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk0.vhd"
},
},
{
"createOption": "Empty",
"diskSizeGB": 1023,
"lun": 1,
"vhd": {
"uri": "http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk1.vhd"
},
},
],
"imageReference": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2016-Datacenter",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"vhd": {
"uri": "http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk.vhd"
},
},
},
},
},
).result()
print(response)
# x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_PlatformImageVmWithUnmanagedOsAndDataDisks.json
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/v5"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/92de53a5f1e0e03c94b40475d2135d97148ed014/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_PlatformImageVmWithUnmanagedOsAndDataDisks.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAPlatformImageVmWithUnmanagedOsAndDataDisks() {
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.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "{vm-name}", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD2V2),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
}},
},
OSProfile: &armcompute.OSProfile{
AdminPassword: to.Ptr("{your-password}"),
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
},
StorageProfile: &armcompute.StorageProfile{
DataDisks: []*armcompute.DataDisk{
{
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesEmpty),
DiskSizeGB: to.Ptr[int32](1023),
Lun: to.Ptr[int32](0),
Vhd: &armcompute.VirtualHardDisk{
URI: to.Ptr("http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk0.vhd"),
},
},
{
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesEmpty),
DiskSizeGB: to.Ptr[int32](1023),
Lun: to.Ptr[int32](1),
Vhd: &armcompute.VirtualHardDisk{
URI: to.Ptr("http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk1.vhd"),
},
}},
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("WindowsServer"),
Publisher: to.Ptr("MicrosoftWindowsServer"),
SKU: to.Ptr("2016-Datacenter"),
Version: to.Ptr("latest"),
},
OSDisk: &armcompute.OSDisk{
Name: to.Ptr("myVMosdisk"),
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
Vhd: &armcompute.VirtualHardDisk{
URI: to.Ptr("http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk.vhd"),
},
},
},
},
}, &armcompute.VirtualMachinesClientBeginCreateOrUpdateOptions{IfMatch: nil,
IfNoneMatch: 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)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.VirtualMachine = armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// Properties: &armcompute.VirtualMachineProperties{
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD2V2),
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// }},
// },
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// ComputerName: to.Ptr("myVM"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// EnableAutomaticUpdates: to.Ptr(true),
// ProvisionVMAgent: to.Ptr(true),
// },
// },
// ProvisioningState: to.Ptr("Succeeded"),
// StorageProfile: &armcompute.StorageProfile{
// DataDisks: []*armcompute.DataDisk{
// {
// Name: to.Ptr("dataDisk0"),
// Caching: to.Ptr(armcompute.CachingTypesNone),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesEmpty),
// DiskSizeGB: to.Ptr[int32](1023),
// Lun: to.Ptr[int32](0),
// Vhd: &armcompute.VirtualHardDisk{
// URI: to.Ptr("http://{existing-storage-account-name}.blob.core.windows.net/vhds/myDisk0.vhd"),
// },
// },
// {
// Name: to.Ptr("dataDisk1"),
// Caching: to.Ptr(armcompute.CachingTypesNone),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesEmpty),
// DiskSizeGB: to.Ptr[int32](1023),
// Lun: to.Ptr[int32](1),
// Vhd: &armcompute.VirtualHardDisk{
// URI: to.Ptr("http://{existing-storage-account-name}.blob.core.windows.net/vhds/myDisk1.vhd"),
// },
// }},
// ImageReference: &armcompute.ImageReference{
// Offer: to.Ptr("WindowsServer"),
// Publisher: to.Ptr("MicrosoftWindowsServer"),
// SKU: to.Ptr("2016-Datacenter"),
// Version: to.Ptr("latest"),
// },
// OSDisk: &armcompute.OSDisk{
// Name: to.Ptr("myVMosdisk"),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// Vhd: &armcompute.VirtualHardDisk{
// URI: to.Ptr("http://{existing-storage-account-name}.blob.core.windows.net/vhds/myDisk.vhd"),
// },
// },
// },
// VMID: to.Ptr("5230a749-2f68-4830-900b-702182d32e63"),
// },
// }
}
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");
/**
* This sample demonstrates how to The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_PlatformImageVmWithUnmanagedOsAndDataDisks.json
*/
async function createAPlatformImageVMWithUnmanagedOSAndDataDisks() {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP"] || "myResourceGroup";
const vmName = "{vm-name}";
const parameters = {
hardwareProfile: { vmSize: "Standard_D2_v2" },
location: "westus",
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
osProfile: {
adminPassword: "{your-password}",
adminUsername: "{your-username}",
computerName: "myVM",
},
storageProfile: {
dataDisks: [
{
createOption: "Empty",
diskSizeGB: 1023,
lun: 0,
vhd: {
uri: "http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk0.vhd",
},
},
{
createOption: "Empty",
diskSizeGB: 1023,
lun: 1,
vhd: {
uri: "http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk1.vhd",
},
},
],
imageReference: {
offer: "WindowsServer",
publisher: "MicrosoftWindowsServer",
sku: "2016-Datacenter",
version: "latest",
},
osDisk: {
name: "myVMosdisk",
caching: "ReadWrite",
createOption: "FromImage",
vhd: {
uri: "http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk.vhd",
},
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.beginCreateOrUpdateAndWait(
resourceGroupName,
vmName,
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
範例回覆
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"vhd": {
"uri": "http://{existing-storage-account-name}.blob.core.windows.net/vhds/myDisk.vhd"
},
"createOption": "FromImage",
"name": "myVMosdisk",
"caching": "ReadWrite"
},
"dataDisks": [
{
"name": "dataDisk0",
"diskSizeGB": 1023,
"createOption": "Empty",
"caching": "None",
"vhd": {
"uri": "http://{existing-storage-account-name}.blob.core.windows.net/vhds/myDisk0.vhd"
},
"lun": 0
},
{
"name": "dataDisk1",
"diskSizeGB": 1023,
"createOption": "Empty",
"caching": "None",
"vhd": {
"uri": "http://{existing-storage-account-name}.blob.core.windows.net/vhds/myDisk1.vhd"
},
"lun": 1
}
]
},
"vmId": "5230a749-2f68-4830-900b-702182d32e63",
"hardwareProfile": {
"vmSize": "Standard_D2_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"vhd": {
"uri": "http://{existing-storage-account-name}.blob.core.windows.net/vhds/myDisk.vhd"
},
"createOption": "FromImage",
"name": "myVMosdisk",
"caching": "ReadWrite"
},
"dataDisks": [
{
"name": "dataDisk0",
"diskSizeGB": 1023,
"createOption": "Empty",
"caching": "None",
"vhd": {
"uri": "http://{existing-storage-account-name}.blob.core.windows.net/vhds/myDisk0.vhd"
},
"lun": 0
},
{
"name": "dataDisk1",
"diskSizeGB": 1023,
"createOption": "Empty",
"caching": "None",
"vhd": {
"uri": "http://{existing-storage-account-name}.blob.core.windows.net/vhds/myDisk1.vhd"
},
"lun": 1
}
]
},
"vmId": "5230a749-2f68-4830-900b-702182d32e63",
"hardwareProfile": {
"vmSize": "Standard_D2_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2024-03-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"storageProfile": {
"imageReference": {
"communityGalleryImageId": "/CommunityGalleries/galleryPublicName/Images/communityGalleryImageName/Versions/communityGalleryImageVersionName"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
from typing import Any, IO, Union
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_create_from_acommunity_gallery_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_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_D1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"storageProfile": {
"imageReference": {
"communityGalleryImageId": "/CommunityGalleries/galleryPublicName/Images/communityGalleryImageName/Versions/communityGalleryImageVersionName"
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Standard_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_FromACommunityGalleryImage.json
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/v5"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/92de53a5f1e0e03c94b40475d2135d97148ed014/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_FromACommunityGalleryImage.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVmFromACommunityGalleryImage() {
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.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
}},
},
OSProfile: &armcompute.OSProfile{
AdminPassword: to.Ptr("{your-password}"),
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
CommunityGalleryImageID: to.Ptr("/CommunityGalleries/galleryPublicName/Images/communityGalleryImageName/Versions/communityGalleryImageVersionName"),
},
OSDisk: &armcompute.OSDisk{
Name: to.Ptr("myVMosdisk"),
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
},
}, &armcompute.VirtualMachinesClientBeginCreateOrUpdateOptions{IfMatch: nil,
IfNoneMatch: 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)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.VirtualMachine = armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// Properties: &armcompute.VirtualMachineProperties{
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// }},
// },
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// ComputerName: to.Ptr("myVM"),
// LinuxConfiguration: &armcompute.LinuxConfiguration{
// DisablePasswordAuthentication: to.Ptr(false),
// },
// Secrets: []*armcompute.VaultSecretGroup{
// },
// },
// ProvisioningState: to.Ptr("Succeeded"),
// StorageProfile: &armcompute.StorageProfile{
// DataDisks: []*armcompute.DataDisk{
// },
// ImageReference: &armcompute.ImageReference{
// CommunityGalleryImageID: to.Ptr("/CommunityGalleries/galleryPublicName/Images/communityGalleryImageName/Versions/communityGalleryImageVersionName"),
// },
// OSDisk: &armcompute.OSDisk{
// Name: to.Ptr("myVMosdisk"),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// DiskSizeGB: to.Ptr[int32](30),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// OSType: to.Ptr(armcompute.OperatingSystemTypesLinux),
// },
// },
// VMID: to.Ptr("71aa3d5a-d73d-4970-9182-8580433b2865"),
// },
// }
}
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");
/**
* This sample demonstrates how to The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_FromACommunityGalleryImage.json
*/
async function createAVMFromACommunityGalleryImage() {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP"] || "myResourceGroup";
const vmName = "myVM";
const parameters = {
hardwareProfile: { vmSize: "Standard_D1_v2" },
location: "westus",
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
osProfile: {
adminPassword: "{your-password}",
adminUsername: "{your-username}",
computerName: "myVM",
},
storageProfile: {
imageReference: {
communityGalleryImageId:
"/CommunityGalleries/galleryPublicName/Images/communityGalleryImageName/Versions/communityGalleryImageVersionName",
},
osDisk: {
name: "myVMosdisk",
caching: "ReadWrite",
createOption: "FromImage",
managedDisk: { storageAccountType: "Standard_LRS" },
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.beginCreateOrUpdateAndWait(
resourceGroupName,
vmName,
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
範例回覆
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"linuxConfiguration": {
"disablePasswordAuthentication": false
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"communityGalleryImageId": "/CommunityGalleries/galleryPublicName/Images/communityGalleryImageName/Versions/communityGalleryImageVersionName"
},
"osDisk": {
"name": "myVMosdisk",
"diskSizeGB": 30,
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"caching": "ReadWrite",
"createOption": "FromImage",
"osType": "Linux"
},
"dataDisks": []
},
"vmId": "71aa3d5a-d73d-4970-9182-8580433b2865",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"linuxConfiguration": {
"disablePasswordAuthentication": false
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"communityGalleryImageId": "/CommunityGalleries/galleryPublicName/Images/communityGalleryImageName/Versions/communityGalleryImageVersionName"
},
"osDisk": {
"name": "myVMosdisk",
"diskSizeGB": 30,
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"caching": "ReadWrite",
"createOption": "FromImage",
"osType": "Linux"
},
"dataDisks": []
},
"vmId": "71aa3d5a-d73d-4970-9182-8580433b2865",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Create a vm from a custom image.
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2024-03-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"storageProfile": {
"imageReference": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/{existing-custom-image-name}"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
from typing import Any, IO, Union
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_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_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_D1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"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"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_FromACustomImage.json
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/v5"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/92de53a5f1e0e03c94b40475d2135d97148ed014/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_FromACustomImage.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVmFromACustomImage() {
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.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
}},
},
OSProfile: &armcompute.OSProfile{
AdminPassword: to.Ptr("{your-password}"),
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/{existing-custom-image-name}"),
},
OSDisk: &armcompute.OSDisk{
Name: to.Ptr("myVMosdisk"),
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
},
}, &armcompute.VirtualMachinesClientBeginCreateOrUpdateOptions{IfMatch: nil,
IfNoneMatch: 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)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.VirtualMachine = armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// Properties: &armcompute.VirtualMachineProperties{
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// }},
// },
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// ComputerName: to.Ptr("myVM"),
// LinuxConfiguration: &armcompute.LinuxConfiguration{
// DisablePasswordAuthentication: to.Ptr(false),
// },
// Secrets: []*armcompute.VaultSecretGroup{
// },
// },
// ProvisioningState: to.Ptr("Succeeded"),
// StorageProfile: &armcompute.StorageProfile{
// DataDisks: []*armcompute.DataDisk{
// },
// ImageReference: &armcompute.ImageReference{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/nsgcustom"),
// },
// OSDisk: &armcompute.OSDisk{
// Name: to.Ptr("myVMosdisk"),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// DiskSizeGB: to.Ptr[int32](30),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// OSType: to.Ptr(armcompute.OperatingSystemTypesLinux),
// },
// },
// VMID: to.Ptr("71aa3d5a-d73d-4970-9182-8580433b2865"),
// },
// }
}
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");
/**
* This sample demonstrates how to The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_FromACustomImage.json
*/
async function createAVMFromACustomImage() {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP"] || "myResourceGroup";
const vmName = "myVM";
const parameters = {
hardwareProfile: { vmSize: "Standard_D1_v2" },
location: "westus",
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
osProfile: {
adminPassword: "{your-password}",
adminUsername: "{your-username}",
computerName: "myVM",
},
storageProfile: {
imageReference: {
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/{existing-custom-image-name}",
},
osDisk: {
name: "myVMosdisk",
caching: "ReadWrite",
createOption: "FromImage",
managedDisk: { storageAccountType: "Standard_LRS" },
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.beginCreateOrUpdateAndWait(
resourceGroupName,
vmName,
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
範例回覆
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"linuxConfiguration": {
"disablePasswordAuthentication": false
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/nsgcustom"
},
"osDisk": {
"name": "myVMosdisk",
"diskSizeGB": 30,
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"caching": "ReadWrite",
"createOption": "FromImage",
"osType": "Linux"
},
"dataDisks": []
},
"vmId": "71aa3d5a-d73d-4970-9182-8580433b2865",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"linuxConfiguration": {
"disablePasswordAuthentication": false
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/nsgcustom"
},
"osDisk": {
"name": "myVMosdisk",
"diskSizeGB": 30,
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"caching": "ReadWrite",
"createOption": "FromImage",
"osType": "Linux"
},
"dataDisks": []
},
"vmId": "71aa3d5a-d73d-4970-9182-8580433b2865",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Create a vm from a generalized shared image.
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2024-03-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"storageProfile": {
"imageReference": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/mySharedGallery/images/mySharedImage"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
from typing import Any, IO, Union
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_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_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_D1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"storageProfile": {
"imageReference": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/mySharedGallery/images/mySharedImage"
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Standard_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_FromAGeneralizedSharedImage.json
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/v5"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/92de53a5f1e0e03c94b40475d2135d97148ed014/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_FromAGeneralizedSharedImage.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVmFromAGeneralizedSharedImage() {
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.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
}},
},
OSProfile: &armcompute.OSProfile{
AdminPassword: to.Ptr("{your-password}"),
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/mySharedGallery/images/mySharedImage"),
},
OSDisk: &armcompute.OSDisk{
Name: to.Ptr("myVMosdisk"),
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
},
}, &armcompute.VirtualMachinesClientBeginCreateOrUpdateOptions{IfMatch: nil,
IfNoneMatch: 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)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.VirtualMachine = armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// Properties: &armcompute.VirtualMachineProperties{
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// }},
// },
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// ComputerName: to.Ptr("myVM"),
// LinuxConfiguration: &armcompute.LinuxConfiguration{
// DisablePasswordAuthentication: to.Ptr(false),
// },
// Secrets: []*armcompute.VaultSecretGroup{
// },
// },
// ProvisioningState: to.Ptr("Succeeded"),
// StorageProfile: &armcompute.StorageProfile{
// DataDisks: []*armcompute.DataDisk{
// },
// ImageReference: &armcompute.ImageReference{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/mySharedGallery/images/mySharedImage"),
// },
// OSDisk: &armcompute.OSDisk{
// Name: to.Ptr("myVMosdisk"),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// DiskSizeGB: to.Ptr[int32](30),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// OSType: to.Ptr(armcompute.OperatingSystemTypesLinux),
// },
// },
// VMID: to.Ptr("71aa3d5a-d73d-4970-9182-8580433b2865"),
// },
// }
}
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");
/**
* This sample demonstrates how to The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_FromAGeneralizedSharedImage.json
*/
async function createAVMFromAGeneralizedSharedImage() {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP"] || "myResourceGroup";
const vmName = "myVM";
const parameters = {
hardwareProfile: { vmSize: "Standard_D1_v2" },
location: "westus",
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
osProfile: {
adminPassword: "{your-password}",
adminUsername: "{your-username}",
computerName: "myVM",
},
storageProfile: {
imageReference: {
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/mySharedGallery/images/mySharedImage",
},
osDisk: {
name: "myVMosdisk",
caching: "ReadWrite",
createOption: "FromImage",
managedDisk: { storageAccountType: "Standard_LRS" },
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.beginCreateOrUpdateAndWait(
resourceGroupName,
vmName,
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
範例回覆
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"linuxConfiguration": {
"disablePasswordAuthentication": false
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/mySharedGallery/images/mySharedImage"
},
"osDisk": {
"name": "myVMosdisk",
"diskSizeGB": 30,
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"caching": "ReadWrite",
"createOption": "FromImage",
"osType": "Linux"
},
"dataDisks": []
},
"vmId": "71aa3d5a-d73d-4970-9182-8580433b2865",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"linuxConfiguration": {
"disablePasswordAuthentication": false
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/mySharedGallery/images/mySharedImage"
},
"osDisk": {
"name": "myVMosdisk",
"diskSizeGB": 30,
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"caching": "ReadWrite",
"createOption": "FromImage",
"osType": "Linux"
},
"dataDisks": []
},
"vmId": "71aa3d5a-d73d-4970-9182-8580433b2865",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Create a VM from a shared gallery image
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2024-03-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"storageProfile": {
"imageReference": {
"sharedGalleryImageId": "/SharedGalleries/sharedGalleryName/Images/sharedGalleryImageName/Versions/sharedGalleryImageVersionName"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
from typing import Any, IO, Union
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_create_from_ashared_gallery_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_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_D1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"storageProfile": {
"imageReference": {
"sharedGalleryImageId": "/SharedGalleries/sharedGalleryName/Images/sharedGalleryImageName/Versions/sharedGalleryImageVersionName"
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Standard_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_FromASharedGalleryImage.json
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/v5"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/92de53a5f1e0e03c94b40475d2135d97148ed014/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_FromASharedGalleryImage.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVmFromASharedGalleryImage() {
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.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
}},
},
OSProfile: &armcompute.OSProfile{
AdminPassword: to.Ptr("{your-password}"),
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
SharedGalleryImageID: to.Ptr("/SharedGalleries/sharedGalleryName/Images/sharedGalleryImageName/Versions/sharedGalleryImageVersionName"),
},
OSDisk: &armcompute.OSDisk{
Name: to.Ptr("myVMosdisk"),
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
},
}, &armcompute.VirtualMachinesClientBeginCreateOrUpdateOptions{IfMatch: nil,
IfNoneMatch: 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)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.VirtualMachine = armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// Properties: &armcompute.VirtualMachineProperties{
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// }},
// },
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// ComputerName: to.Ptr("myVM"),
// LinuxConfiguration: &armcompute.LinuxConfiguration{
// DisablePasswordAuthentication: to.Ptr(false),
// },
// Secrets: []*armcompute.VaultSecretGroup{
// },
// },
// ProvisioningState: to.Ptr("Succeeded"),
// StorageProfile: &armcompute.StorageProfile{
// DataDisks: []*armcompute.DataDisk{
// },
// ImageReference: &armcompute.ImageReference{
// SharedGalleryImageID: to.Ptr("/SharedGalleries/sharedGalleryName/Images/sharedGalleryImageName/Versions/sharedGalleryImageVersionName"),
// },
// OSDisk: &armcompute.OSDisk{
// Name: to.Ptr("myVMosdisk"),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// DiskSizeGB: to.Ptr[int32](30),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// OSType: to.Ptr(armcompute.OperatingSystemTypesLinux),
// },
// },
// VMID: to.Ptr("71aa3d5a-d73d-4970-9182-8580433b2865"),
// },
// }
}
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");
/**
* This sample demonstrates how to The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_FromASharedGalleryImage.json
*/
async function createAVMFromASharedGalleryImage() {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP"] || "myResourceGroup";
const vmName = "myVM";
const parameters = {
hardwareProfile: { vmSize: "Standard_D1_v2" },
location: "westus",
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
osProfile: {
adminPassword: "{your-password}",
adminUsername: "{your-username}",
computerName: "myVM",
},
storageProfile: {
imageReference: {
sharedGalleryImageId:
"/SharedGalleries/sharedGalleryName/Images/sharedGalleryImageName/Versions/sharedGalleryImageVersionName",
},
osDisk: {
name: "myVMosdisk",
caching: "ReadWrite",
createOption: "FromImage",
managedDisk: { storageAccountType: "Standard_LRS" },
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.beginCreateOrUpdateAndWait(
resourceGroupName,
vmName,
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
範例回覆
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"linuxConfiguration": {
"disablePasswordAuthentication": false
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sharedGalleryImageId": "/SharedGalleries/sharedGalleryName/Images/sharedGalleryImageName/Versions/sharedGalleryImageVersionName"
},
"osDisk": {
"name": "myVMosdisk",
"diskSizeGB": 30,
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"caching": "ReadWrite",
"createOption": "FromImage",
"osType": "Linux"
},
"dataDisks": []
},
"vmId": "71aa3d5a-d73d-4970-9182-8580433b2865",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"linuxConfiguration": {
"disablePasswordAuthentication": false
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sharedGalleryImageId": "/SharedGalleries/sharedGalleryName/Images/sharedGalleryImageName/Versions/sharedGalleryImageVersionName"
},
"osDisk": {
"name": "myVMosdisk",
"diskSizeGB": 30,
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"caching": "ReadWrite",
"createOption": "FromImage",
"osType": "Linux"
},
"dataDisks": []
},
"vmId": "71aa3d5a-d73d-4970-9182-8580433b2865",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Create a vm from a specialized shared image.
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2024-03-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"storageProfile": {
"imageReference": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/mySharedGallery/images/mySharedImage"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
from typing import Any, IO, Union
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_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_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_D1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"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"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_FromASpecializedSharedImage.json
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/v5"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/92de53a5f1e0e03c94b40475d2135d97148ed014/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_FromASpecializedSharedImage.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVmFromASpecializedSharedImage() {
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.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
}},
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/mySharedGallery/images/mySharedImage"),
},
OSDisk: &armcompute.OSDisk{
Name: to.Ptr("myVMosdisk"),
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
},
}, &armcompute.VirtualMachinesClientBeginCreateOrUpdateOptions{IfMatch: nil,
IfNoneMatch: 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)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.VirtualMachine = armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// Properties: &armcompute.VirtualMachineProperties{
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// }},
// },
// ProvisioningState: to.Ptr("Succeeded"),
// StorageProfile: &armcompute.StorageProfile{
// DataDisks: []*armcompute.DataDisk{
// },
// ImageReference: &armcompute.ImageReference{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/mySharedGallery/images/mySharedImage"),
// },
// OSDisk: &armcompute.OSDisk{
// Name: to.Ptr("myVMosdisk"),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// DiskSizeGB: to.Ptr[int32](30),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// OSType: to.Ptr(armcompute.OperatingSystemTypesLinux),
// },
// },
// VMID: to.Ptr("71aa3d5a-d73d-4970-9182-8580433b2865"),
// },
// }
}
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");
/**
* This sample demonstrates how to The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_FromASpecializedSharedImage.json
*/
async function createAVMFromASpecializedSharedImage() {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP"] || "myResourceGroup";
const vmName = "myVM";
const parameters = {
hardwareProfile: { vmSize: "Standard_D1_v2" },
location: "westus",
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
storageProfile: {
imageReference: {
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/mySharedGallery/images/mySharedImage",
},
osDisk: {
name: "myVMosdisk",
caching: "ReadWrite",
createOption: "FromImage",
managedDisk: { storageAccountType: "Standard_LRS" },
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.beginCreateOrUpdateAndWait(
resourceGroupName,
vmName,
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
範例回覆
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/mySharedGallery/images/mySharedImage"
},
"osDisk": {
"name": "myVMosdisk",
"diskSizeGB": 30,
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"caching": "ReadWrite",
"createOption": "FromImage",
"osType": "Linux"
},
"dataDisks": []
},
"vmId": "71aa3d5a-d73d-4970-9182-8580433b2865",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/mySharedGallery/images/mySharedImage"
},
"osDisk": {
"name": "myVMosdisk",
"diskSizeGB": 30,
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"caching": "ReadWrite",
"createOption": "FromImage",
"osType": "Linux"
},
"dataDisks": []
},
"vmId": "71aa3d5a-d73d-4970-9182-8580433b2865",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Create a vm in a Virtual Machine Scale Set with customer assigned platformFaultDomain.
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2024-03-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"virtualMachineScaleSet": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{existing-flex-vmss-name-with-platformFaultDomainCount-greater-than-1}"
},
"platformFaultDomain": 1
}
}
from typing import Any, IO, Union
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_create_in_avmss_with_customer_assigned_platform_fault_domain.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_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_D1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"platformFaultDomain": 1,
"storageProfile": {
"imageReference": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2016-Datacenter",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Standard_LRS"},
"name": "myVMosdisk",
},
},
"virtualMachineScaleSet": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{existing-flex-vmss-name-with-platformFaultDomainCount-greater-than-1}"
},
},
},
).result()
print(response)
# x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_InAVmssWithCustomerAssignedPlatformFaultDomain.json
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/v5"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/92de53a5f1e0e03c94b40475d2135d97148ed014/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_InAVmssWithCustomerAssignedPlatformFaultDomain.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVmInAVirtualMachineScaleSetWithCustomerAssignedPlatformFaultDomain() {
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.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
}},
},
OSProfile: &armcompute.OSProfile{
AdminPassword: to.Ptr("{your-password}"),
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
},
PlatformFaultDomain: to.Ptr[int32](1),
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("WindowsServer"),
Publisher: to.Ptr("MicrosoftWindowsServer"),
SKU: to.Ptr("2016-Datacenter"),
Version: to.Ptr("latest"),
},
OSDisk: &armcompute.OSDisk{
Name: to.Ptr("myVMosdisk"),
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
VirtualMachineScaleSet: &armcompute.SubResource{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{existing-flex-vmss-name-with-platformFaultDomainCount-greater-than-1}"),
},
},
}, &armcompute.VirtualMachinesClientBeginCreateOrUpdateOptions{IfMatch: nil,
IfNoneMatch: 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)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.VirtualMachine = armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// Properties: &armcompute.VirtualMachineProperties{
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// }},
// },
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// ComputerName: to.Ptr("myVM"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// EnableAutomaticUpdates: to.Ptr(true),
// ProvisionVMAgent: to.Ptr(true),
// },
// },
// PlatformFaultDomain: to.Ptr[int32](1),
// ProvisioningState: to.Ptr("Succeeded"),
// StorageProfile: &armcompute.StorageProfile{
// DataDisks: []*armcompute.DataDisk{
// },
// ImageReference: &armcompute.ImageReference{
// Offer: to.Ptr("WindowsServer"),
// Publisher: to.Ptr("MicrosoftWindowsServer"),
// SKU: to.Ptr("2016-Datacenter"),
// Version: to.Ptr("latest"),
// },
// OSDisk: &armcompute.OSDisk{
// Name: to.Ptr("myVMosdisk"),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// },
// },
// VirtualMachineScaleSet: &armcompute.SubResource{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/myExistingFlexVmss"),
// },
// VMID: to.Ptr("7cce54f2-ecd3-4ddd-a8d9-50984faa3918"),
// },
// }
}
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");
/**
* This sample demonstrates how to The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_InAVmssWithCustomerAssignedPlatformFaultDomain.json
*/
async function createAVMInAVirtualMachineScaleSetWithCustomerAssignedPlatformFaultDomain() {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP"] || "myResourceGroup";
const vmName = "myVM";
const parameters = {
hardwareProfile: { vmSize: "Standard_D1_v2" },
location: "westus",
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
osProfile: {
adminPassword: "{your-password}",
adminUsername: "{your-username}",
computerName: "myVM",
},
platformFaultDomain: 1,
storageProfile: {
imageReference: {
offer: "WindowsServer",
publisher: "MicrosoftWindowsServer",
sku: "2016-Datacenter",
version: "latest",
},
osDisk: {
name: "myVMosdisk",
caching: "ReadWrite",
createOption: "FromImage",
managedDisk: { storageAccountType: "Standard_LRS" },
},
},
virtualMachineScaleSet: {
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{existing-flex-vmss-name-with-platformFaultDomainCount-greater-than-1}",
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.beginCreateOrUpdateAndWait(
resourceGroupName,
vmName,
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
範例回覆
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"vmId": "7cce54f2-ecd3-4ddd-a8d9-50984faa3918",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"virtualMachineScaleSet": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/myExistingFlexVmss"
},
"platformFaultDomain": 1,
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"vmId": "7cce54f2-ecd3-4ddd-a8d9-50984faa3918",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"virtualMachineScaleSet": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/myExistingFlexVmss"
},
"platformFaultDomain": 1,
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Create a vm in an availability set.
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2024-03-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"availabilitySet": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/availabilitySets/{existing-availability-set-name}"
}
}
}
from typing import Any, IO, Union
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_create_in_an_availability_set.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_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"availabilitySet": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/availabilitySets/{existing-availability-set-name}"
},
"hardwareProfile": {"vmSize": "Standard_D1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"storageProfile": {
"imageReference": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2016-Datacenter",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Standard_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_InAnAvailabilitySet.json
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/v5"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/92de53a5f1e0e03c94b40475d2135d97148ed014/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_InAnAvailabilitySet.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVmInAnAvailabilitySet() {
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.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
AvailabilitySet: &armcompute.SubResource{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/availabilitySets/{existing-availability-set-name}"),
},
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
}},
},
OSProfile: &armcompute.OSProfile{
AdminPassword: to.Ptr("{your-password}"),
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("WindowsServer"),
Publisher: to.Ptr("MicrosoftWindowsServer"),
SKU: to.Ptr("2016-Datacenter"),
Version: to.Ptr("latest"),
},
OSDisk: &armcompute.OSDisk{
Name: to.Ptr("myVMosdisk"),
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
},
}, &armcompute.VirtualMachinesClientBeginCreateOrUpdateOptions{IfMatch: nil,
IfNoneMatch: 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)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.VirtualMachine = armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// Properties: &armcompute.VirtualMachineProperties{
// AvailabilitySet: &armcompute.SubResource{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/availabilitySets/NSGEXISTINGAS"),
// },
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// }},
// },
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// ComputerName: to.Ptr("myVM"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// EnableAutomaticUpdates: to.Ptr(true),
// ProvisionVMAgent: to.Ptr(true),
// },
// },
// ProvisioningState: to.Ptr("Succeeded"),
// StorageProfile: &armcompute.StorageProfile{
// DataDisks: []*armcompute.DataDisk{
// },
// ImageReference: &armcompute.ImageReference{
// Offer: to.Ptr("WindowsServer"),
// Publisher: to.Ptr("MicrosoftWindowsServer"),
// SKU: to.Ptr("2016-Datacenter"),
// Version: to.Ptr("latest"),
// },
// OSDisk: &armcompute.OSDisk{
// Name: to.Ptr("myVMosdisk"),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// },
// },
// VMID: to.Ptr("b7a098cc-b0b8-46e8-a205-62f301a62a8f"),
// },
// }
}
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");
/**
* This sample demonstrates how to The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_InAnAvailabilitySet.json
*/
async function createAVMInAnAvailabilitySet() {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP"] || "myResourceGroup";
const vmName = "myVM";
const parameters = {
availabilitySet: {
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/availabilitySets/{existing-availability-set-name}",
},
hardwareProfile: { vmSize: "Standard_D1_v2" },
location: "westus",
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
osProfile: {
adminPassword: "{your-password}",
adminUsername: "{your-username}",
computerName: "myVM",
},
storageProfile: {
imageReference: {
offer: "WindowsServer",
publisher: "MicrosoftWindowsServer",
sku: "2016-Datacenter",
version: "latest",
},
osDisk: {
name: "myVMosdisk",
caching: "ReadWrite",
createOption: "FromImage",
managedDisk: { storageAccountType: "Standard_LRS" },
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.beginCreateOrUpdateAndWait(
resourceGroupName,
vmName,
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
範例回覆
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"vmId": "b7a098cc-b0b8-46e8-a205-62f301a62a8f",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"availabilitySet": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/availabilitySets/NSGEXISTINGAS"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"vmId": "b7a098cc-b0b8-46e8-a205-62f301a62a8f",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"availabilitySet": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/availabilitySets/NSGEXISTINGAS"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Create a vm with a marketplace image plan.
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2024-03-01
{
"location": "westus",
"plan": {
"publisher": "microsoft-ads",
"product": "windows-data-science-vm",
"name": "windows2016"
},
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"storageProfile": {
"imageReference": {
"sku": "windows2016",
"publisher": "microsoft-ads",
"version": "latest",
"offer": "windows-data-science-vm"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
from typing import Any, IO, Union
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_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_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"plan": {"name": "windows2016", "product": "windows-data-science-vm", "publisher": "microsoft-ads"},
"properties": {
"hardwareProfile": {"vmSize": "Standard_D1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"storageProfile": {
"imageReference": {
"offer": "windows-data-science-vm",
"publisher": "microsoft-ads",
"sku": "windows2016",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Standard_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithAMarketplaceImagePlan.json
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/v5"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/92de53a5f1e0e03c94b40475d2135d97148ed014/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithAMarketplaceImagePlan.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVmWithAMarketplaceImagePlan() {
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.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
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.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
}},
},
OSProfile: &armcompute.OSProfile{
AdminPassword: to.Ptr("{your-password}"),
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
},
StorageProfile: &armcompute.StorageProfile{
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.OSDisk{
Name: to.Ptr("myVMosdisk"),
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
},
}, &armcompute.VirtualMachinesClientBeginCreateOrUpdateOptions{IfMatch: nil,
IfNoneMatch: 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)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.VirtualMachine = armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// Plan: &armcompute.Plan{
// Name: to.Ptr("standard-data-science-vm"),
// Product: to.Ptr("standard-data-science-vm"),
// Publisher: to.Ptr("microsoft-ads"),
// },
// Properties: &armcompute.VirtualMachineProperties{
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// }},
// },
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// ComputerName: to.Ptr("myVM"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// EnableAutomaticUpdates: to.Ptr(true),
// ProvisionVMAgent: to.Ptr(true),
// },
// },
// ProvisioningState: to.Ptr("Succeeded"),
// StorageProfile: &armcompute.StorageProfile{
// DataDisks: []*armcompute.DataDisk{
// },
// ImageReference: &armcompute.ImageReference{
// Offer: to.Ptr("standard-data-science-vm"),
// Publisher: to.Ptr("microsoft-ads"),
// SKU: to.Ptr("standard-data-science-vm"),
// Version: to.Ptr("latest"),
// },
// OSDisk: &armcompute.OSDisk{
// Name: to.Ptr("myVMosdisk"),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// },
// },
// VMID: to.Ptr("5c0d55a7-c407-4ed6-bf7d-ddb810267c85"),
// },
// }
}
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");
/**
* This sample demonstrates how to The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithAMarketplaceImagePlan.json
*/
async function createAVMWithAMarketplaceImagePlan() {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP"] || "myResourceGroup";
const vmName = "myVM";
const parameters = {
hardwareProfile: { vmSize: "Standard_D1_v2" },
location: "westus",
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
osProfile: {
adminPassword: "{your-password}",
adminUsername: "{your-username}",
computerName: "myVM",
},
plan: {
name: "windows2016",
product: "windows-data-science-vm",
publisher: "microsoft-ads",
},
storageProfile: {
imageReference: {
offer: "windows-data-science-vm",
publisher: "microsoft-ads",
sku: "windows2016",
version: "latest",
},
osDisk: {
name: "myVMosdisk",
caching: "ReadWrite",
createOption: "FromImage",
managedDisk: { storageAccountType: "Standard_LRS" },
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.beginCreateOrUpdateAndWait(
resourceGroupName,
vmName,
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
範例回覆
{
"name": "myVM",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "standard-data-science-vm",
"publisher": "microsoft-ads",
"version": "latest",
"offer": "standard-data-science-vm"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"vmId": "5c0d55a7-c407-4ed6-bf7d-ddb810267c85",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"plan": {
"publisher": "microsoft-ads",
"product": "standard-data-science-vm",
"name": "standard-data-science-vm"
},
"type": "Microsoft.Compute/virtualMachines",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"location": "westus"
}
{
"name": "myVM",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "standard-data-science-vm",
"publisher": "microsoft-ads",
"version": "latest",
"offer": "standard-data-science-vm"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"vmId": "5c0d55a7-c407-4ed6-bf7d-ddb810267c85",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"plan": {
"publisher": "microsoft-ads",
"product": "standard-data-science-vm",
"name": "standard-data-science-vm"
},
"type": "Microsoft.Compute/virtualMachines",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"location": "westus"
}
Create a vm with an extensions time budget.
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2024-03-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"diagnosticsProfile": {
"bootDiagnostics": {
"storageUri": "http://{existing-storage-account-name}.blob.core.windows.net",
"enabled": true
}
},
"extensionsTimeBudget": "PT30M"
}
}
from typing import Any, IO, Union
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_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_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": True,
"storageUri": "http://{existing-storage-account-name}.blob.core.windows.net",
}
},
"extensionsTimeBudget": "PT30M",
"hardwareProfile": {"vmSize": "Standard_D1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"storageProfile": {
"imageReference": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2016-Datacenter",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Standard_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithExtensionsTimeBudget.json
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/v5"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/92de53a5f1e0e03c94b40475d2135d97148ed014/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithExtensionsTimeBudget.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVmWithAnExtensionsTimeBudget() {
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.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
DiagnosticsProfile: &armcompute.DiagnosticsProfile{
BootDiagnostics: &armcompute.BootDiagnostics{
Enabled: to.Ptr(true),
StorageURI: to.Ptr("http://{existing-storage-account-name}.blob.core.windows.net"),
},
},
ExtensionsTimeBudget: to.Ptr("PT30M"),
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
}},
},
OSProfile: &armcompute.OSProfile{
AdminPassword: to.Ptr("{your-password}"),
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("WindowsServer"),
Publisher: to.Ptr("MicrosoftWindowsServer"),
SKU: to.Ptr("2016-Datacenter"),
Version: to.Ptr("latest"),
},
OSDisk: &armcompute.OSDisk{
Name: to.Ptr("myVMosdisk"),
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
},
}, &armcompute.VirtualMachinesClientBeginCreateOrUpdateOptions{IfMatch: nil,
IfNoneMatch: 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)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.VirtualMachine = armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// Properties: &armcompute.VirtualMachineProperties{
// DiagnosticsProfile: &armcompute.DiagnosticsProfile{
// BootDiagnostics: &armcompute.BootDiagnostics{
// Enabled: to.Ptr(true),
// StorageURI: to.Ptr("http://nsgdiagnostic.blob.core.windows.net"),
// },
// },
// ExtensionsTimeBudget: to.Ptr("PT30M"),
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// }},
// },
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// ComputerName: to.Ptr("myVM"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// EnableAutomaticUpdates: to.Ptr(true),
// ProvisionVMAgent: to.Ptr(true),
// },
// },
// ProvisioningState: to.Ptr("Succeeded"),
// StorageProfile: &armcompute.StorageProfile{
// DataDisks: []*armcompute.DataDisk{
// },
// ImageReference: &armcompute.ImageReference{
// Offer: to.Ptr("WindowsServer"),
// Publisher: to.Ptr("MicrosoftWindowsServer"),
// SKU: to.Ptr("2016-Datacenter"),
// Version: to.Ptr("latest"),
// },
// OSDisk: &armcompute.OSDisk{
// Name: to.Ptr("myVMosdisk"),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// },
// },
// VMID: to.Ptr("676420ba-7a24-4bfe-80bd-9c841ee184fa"),
// },
// }
}
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");
/**
* This sample demonstrates how to The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithExtensionsTimeBudget.json
*/
async function createAVMWithAnExtensionsTimeBudget() {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP"] || "myResourceGroup";
const vmName = "myVM";
const parameters = {
diagnosticsProfile: {
bootDiagnostics: {
enabled: true,
storageUri: "http://{existing-storage-account-name}.blob.core.windows.net",
},
},
extensionsTimeBudget: "PT30M",
hardwareProfile: { vmSize: "Standard_D1_v2" },
location: "westus",
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
osProfile: {
adminPassword: "{your-password}",
adminUsername: "{your-username}",
computerName: "myVM",
},
storageProfile: {
imageReference: {
offer: "WindowsServer",
publisher: "MicrosoftWindowsServer",
sku: "2016-Datacenter",
version: "latest",
},
osDisk: {
name: "myVMosdisk",
caching: "ReadWrite",
createOption: "FromImage",
managedDisk: { storageAccountType: "Standard_LRS" },
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.beginCreateOrUpdateAndWait(
resourceGroupName,
vmName,
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
範例回覆
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"diagnosticsProfile": {
"bootDiagnostics": {
"storageUri": "http://nsgdiagnostic.blob.core.windows.net",
"enabled": true
}
},
"vmId": "676420ba-7a24-4bfe-80bd-9c841ee184fa",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"extensionsTimeBudget": "PT30M",
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"diagnosticsProfile": {
"bootDiagnostics": {
"storageUri": "http://nsgdiagnostic.blob.core.windows.net",
"enabled": true
}
},
"vmId": "676420ba-7a24-4bfe-80bd-9c841ee184fa",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"extensionsTimeBudget": "PT30M",
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Create a vm with Application Profile.
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2024-03-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"storageProfile": {
"imageReference": {
"sku": "{image_sku}",
"publisher": "{image_publisher}",
"version": "latest",
"offer": "{image_offer}"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"name": "myVMosdisk",
"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": false,
"enableAutomaticUpgrade": false
},
{
"packageReferenceId": "/subscriptions/32c17a9e-aa7b-4ba5-a45b-e324116b6fdg/resourceGroups/myresourceGroupName3/providers/Microsoft.Compute/galleries/myGallery2/applications/MyApplication2/versions/1.1"
}
]
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
from typing import Any, IO, Union
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_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_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"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": False,
},
{
"packageReferenceId": "/subscriptions/32c17a9e-aa7b-4ba5-a45b-e324116b6fdg/resourceGroups/myresourceGroupName3/providers/Microsoft.Compute/galleries/myGallery2/applications/MyApplication2/versions/1.1"
},
]
},
"hardwareProfile": {"vmSize": "Standard_D1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"storageProfile": {
"imageReference": {
"offer": "{image_offer}",
"publisher": "{image_publisher}",
"sku": "{image_sku}",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Standard_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithApplicationProfile.json
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/v5"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/92de53a5f1e0e03c94b40475d2135d97148ed014/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithApplicationProfile.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVmWithApplicationProfile() {
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.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
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(false),
},
{
PackageReferenceID: to.Ptr("/subscriptions/32c17a9e-aa7b-4ba5-a45b-e324116b6fdg/resourceGroups/myresourceGroupName3/providers/Microsoft.Compute/galleries/myGallery2/applications/MyApplication2/versions/1.1"),
}},
},
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
}},
},
OSProfile: &armcompute.OSProfile{
AdminPassword: to.Ptr("{your-password}"),
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("{image_offer}"),
Publisher: to.Ptr("{image_publisher}"),
SKU: to.Ptr("{image_sku}"),
Version: to.Ptr("latest"),
},
OSDisk: &armcompute.OSDisk{
Name: to.Ptr("myVMosdisk"),
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
},
}, &armcompute.VirtualMachinesClientBeginCreateOrUpdateOptions{IfMatch: nil,
IfNoneMatch: 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)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.VirtualMachine = armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// Properties: &armcompute.VirtualMachineProperties{
// ApplicationProfile: &armcompute.ApplicationProfile{
// GalleryApplications: []*armcompute.VMGalleryApplication{
// {
// ConfigurationReference: to.Ptr("https://mystorageaccount.blob.core.windows.net/configurations/settings.config"),
// 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"),
// },
// {
// PackageReferenceID: to.Ptr("/subscriptions/32c17a9e-aa7b-4ba5-a45b-e324116b6fdg/resourceGroups/myresourceGroupName3/providers/Microsoft.Compute/galleries/myGallery2/applications/MyApplication2/versions/1.1"),
// }},
// },
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// }},
// },
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// ComputerName: to.Ptr("myVM"),
// 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"),
// }},
// },
// },
// Secrets: []*armcompute.VaultSecretGroup{
// },
// },
// ProvisioningState: to.Ptr("Succeeded"),
// StorageProfile: &armcompute.StorageProfile{
// DataDisks: []*armcompute.DataDisk{
// },
// ImageReference: &armcompute.ImageReference{
// Offer: to.Ptr("UbuntuServer"),
// Publisher: to.Ptr("Canonical"),
// SKU: to.Ptr("16.04-LTS"),
// Version: to.Ptr("latest"),
// },
// OSDisk: &armcompute.OSDisk{
// Name: to.Ptr("myVMosdisk"),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// OSType: to.Ptr(armcompute.OperatingSystemTypesLinux),
// },
// },
// VMID: to.Ptr("e0de9b84-a506-4b95-9623-00a425d05c90"),
// },
// }
}
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");
/**
* This sample demonstrates how to The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithApplicationProfile.json
*/
async function createAVMWithApplicationProfile() {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP"] || "myResourceGroup";
const vmName = "myVM";
const parameters = {
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: false,
},
{
packageReferenceId:
"/subscriptions/32c17a9e-aa7b-4ba5-a45b-e324116b6fdg/resourceGroups/myresourceGroupName3/providers/Microsoft.Compute/galleries/myGallery2/applications/MyApplication2/versions/1.1",
},
],
},
hardwareProfile: { vmSize: "Standard_D1_v2" },
location: "westus",
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
osProfile: {
adminPassword: "{your-password}",
adminUsername: "{your-username}",
computerName: "myVM",
},
storageProfile: {
imageReference: {
offer: "{image_offer}",
publisher: "{image_publisher}",
sku: "{image_sku}",
version: "latest",
},
osDisk: {
name: "myVMosdisk",
caching: "ReadWrite",
createOption: "FromImage",
managedDisk: { storageAccountType: "Standard_LRS" },
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.beginCreateOrUpdateAndWait(
resourceGroupName,
vmName,
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
範例回覆
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"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": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "16.04-LTS",
"publisher": "Canonical",
"version": "latest",
"offer": "UbuntuServer"
},
"osDisk": {
"osType": "Linux",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"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"
}
]
},
"vmId": "e0de9b84-a506-4b95-9623-00a425d05c90",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"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": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "16.04-LTS",
"publisher": "Canonical",
"version": "latest",
"offer": "UbuntuServer"
},
"osDisk": {
"osType": "Linux",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"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"
}
]
},
"vmId": "e0de9b84-a506-4b95-9623-00a425d05c90",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Create a vm with boot diagnostics.
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2024-03-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"diagnosticsProfile": {
"bootDiagnostics": {
"storageUri": "http://{existing-storage-account-name}.blob.core.windows.net",
"enabled": true
}
}
}
}
from typing import Any, IO, Union
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_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_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": True,
"storageUri": "http://{existing-storage-account-name}.blob.core.windows.net",
}
},
"hardwareProfile": {"vmSize": "Standard_D1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"storageProfile": {
"imageReference": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2016-Datacenter",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Standard_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithBootDiagnostics.json
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/v5"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/92de53a5f1e0e03c94b40475d2135d97148ed014/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithBootDiagnostics.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVmWithBootDiagnostics() {
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.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
DiagnosticsProfile: &armcompute.DiagnosticsProfile{
BootDiagnostics: &armcompute.BootDiagnostics{
Enabled: to.Ptr(true),
StorageURI: to.Ptr("http://{existing-storage-account-name}.blob.core.windows.net"),
},
},
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
}},
},
OSProfile: &armcompute.OSProfile{
AdminPassword: to.Ptr("{your-password}"),
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("WindowsServer"),
Publisher: to.Ptr("MicrosoftWindowsServer"),
SKU: to.Ptr("2016-Datacenter"),
Version: to.Ptr("latest"),
},
OSDisk: &armcompute.OSDisk{
Name: to.Ptr("myVMosdisk"),
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
},
}, &armcompute.VirtualMachinesClientBeginCreateOrUpdateOptions{IfMatch: nil,
IfNoneMatch: 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)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.VirtualMachine = armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// Properties: &armcompute.VirtualMachineProperties{
// DiagnosticsProfile: &armcompute.DiagnosticsProfile{
// BootDiagnostics: &armcompute.BootDiagnostics{
// Enabled: to.Ptr(true),
// StorageURI: to.Ptr("http://nsgdiagnostic.blob.core.windows.net"),
// },
// },
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// }},
// },
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// ComputerName: to.Ptr("myVM"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// EnableAutomaticUpdates: to.Ptr(true),
// ProvisionVMAgent: to.Ptr(true),
// },
// },
// ProvisioningState: to.Ptr("Succeeded"),
// StorageProfile: &armcompute.StorageProfile{
// DataDisks: []*armcompute.DataDisk{
// },
// ImageReference: &armcompute.ImageReference{
// Offer: to.Ptr("WindowsServer"),
// Publisher: to.Ptr("MicrosoftWindowsServer"),
// SKU: to.Ptr("2016-Datacenter"),
// Version: to.Ptr("latest"),
// },
// OSDisk: &armcompute.OSDisk{
// Name: to.Ptr("myVMosdisk"),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// },
// },
// VMID: to.Ptr("676420ba-7a24-4bfe-80bd-9c841ee184fa"),
// },
// }
}
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");
/**
* This sample demonstrates how to The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithBootDiagnostics.json
*/
async function createAVMWithBootDiagnostics() {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP"] || "myResourceGroup";
const vmName = "myVM";
const parameters = {
diagnosticsProfile: {
bootDiagnostics: {
enabled: true,
storageUri: "http://{existing-storage-account-name}.blob.core.windows.net",
},
},
hardwareProfile: { vmSize: "Standard_D1_v2" },
location: "westus",
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
osProfile: {
adminPassword: "{your-password}",
adminUsername: "{your-username}",
computerName: "myVM",
},
storageProfile: {
imageReference: {
offer: "WindowsServer",
publisher: "MicrosoftWindowsServer",
sku: "2016-Datacenter",
version: "latest",
},
osDisk: {
name: "myVMosdisk",
caching: "ReadWrite",
createOption: "FromImage",
managedDisk: { storageAccountType: "Standard_LRS" },
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.beginCreateOrUpdateAndWait(
resourceGroupName,
vmName,
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
範例回覆
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"diagnosticsProfile": {
"bootDiagnostics": {
"storageUri": "http://nsgdiagnostic.blob.core.windows.net",
"enabled": true
}
},
"vmId": "676420ba-7a24-4bfe-80bd-9c841ee184fa",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"diagnosticsProfile": {
"bootDiagnostics": {
"storageUri": "http://nsgdiagnostic.blob.core.windows.net",
"enabled": true
}
},
"vmId": "676420ba-7a24-4bfe-80bd-9c841ee184fa",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Create a vm with data disks using 'Copy' and 'Restore' options.
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2024-03-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D2_v2"
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
},
"dataDisks": [
{
"diskSizeGB": 1023,
"createOption": "Copy",
"sourceResource": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/{existing-snapshot-name}"
},
"lun": 0
},
{
"diskSizeGB": 1023,
"createOption": "Copy",
"sourceResource": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/{existing-disk-name}"
},
"lun": 1
},
{
"diskSizeGB": 1023,
"createOption": "Restore",
"sourceResource": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/restorePointCollections/{existing-rpc-name}/restorePoints/{existing-rp-name}/diskRestorePoints/{existing-disk-restore-point-name}"
},
"lun": 2
}
]
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
from typing import Any, IO, Union
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_create_with_data_disks_from_source_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_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_D2_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"storageProfile": {
"dataDisks": [
{
"createOption": "Copy",
"diskSizeGB": 1023,
"lun": 0,
"sourceResource": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/{existing-snapshot-name}"
},
},
{
"createOption": "Copy",
"diskSizeGB": 1023,
"lun": 1,
"sourceResource": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/{existing-disk-name}"
},
},
{
"createOption": "Restore",
"diskSizeGB": 1023,
"lun": 2,
"sourceResource": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/restorePointCollections/{existing-rpc-name}/restorePoints/{existing-rp-name}/diskRestorePoints/{existing-disk-restore-point-name}"
},
},
],
"imageReference": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2016-Datacenter",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Standard_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithDataDisksFromSourceResource.json
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/v5"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/92de53a5f1e0e03c94b40475d2135d97148ed014/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithDataDisksFromSourceResource.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVmWithDataDisksUsingCopyAndRestoreOptions() {
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.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD2V2),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
}},
},
OSProfile: &armcompute.OSProfile{
AdminPassword: to.Ptr("{your-password}"),
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
},
StorageProfile: &armcompute.StorageProfile{
DataDisks: []*armcompute.DataDisk{
{
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesCopy),
DiskSizeGB: to.Ptr[int32](1023),
Lun: to.Ptr[int32](0),
SourceResource: &armcompute.APIEntityReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/{existing-snapshot-name}"),
},
},
{
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesCopy),
DiskSizeGB: to.Ptr[int32](1023),
Lun: to.Ptr[int32](1),
SourceResource: &armcompute.APIEntityReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/{existing-disk-name}"),
},
},
{
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesRestore),
DiskSizeGB: to.Ptr[int32](1023),
Lun: to.Ptr[int32](2),
SourceResource: &armcompute.APIEntityReference{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/restorePointCollections/{existing-rpc-name}/restorePoints/{existing-rp-name}/diskRestorePoints/{existing-disk-restore-point-name}"),
},
}},
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("WindowsServer"),
Publisher: to.Ptr("MicrosoftWindowsServer"),
SKU: to.Ptr("2016-Datacenter"),
Version: to.Ptr("latest"),
},
OSDisk: &armcompute.OSDisk{
Name: to.Ptr("myVMosdisk"),
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
},
}, &armcompute.VirtualMachinesClientBeginCreateOrUpdateOptions{IfMatch: nil,
IfNoneMatch: 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)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.VirtualMachine = armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// Properties: &armcompute.VirtualMachineProperties{
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD2V2),
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// }},
// },
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// ComputerName: to.Ptr("myVM"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// EnableAutomaticUpdates: to.Ptr(true),
// ProvisionVMAgent: to.Ptr(true),
// },
// },
// ProvisioningState: to.Ptr("Succeeded"),
// StorageProfile: &armcompute.StorageProfile{
// DataDisks: []*armcompute.DataDisk{
// {
// Caching: to.Ptr(armcompute.CachingTypesNone),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesCopy),
// DiskSizeGB: to.Ptr[int32](1023),
// Lun: to.Ptr[int32](0),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// SourceResource: &armcompute.APIEntityReference{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/{existing-snapshot-name}"),
// },
// },
// {
// Caching: to.Ptr(armcompute.CachingTypesNone),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesCopy),
// DiskSizeGB: to.Ptr[int32](1023),
// Lun: to.Ptr[int32](1),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// SourceResource: &armcompute.APIEntityReference{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/{existing-disk-name}"),
// },
// },
// {
// Caching: to.Ptr(armcompute.CachingTypesNone),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesRestore),
// DiskSizeGB: to.Ptr[int32](1023),
// Lun: to.Ptr[int32](2),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// SourceResource: &armcompute.APIEntityReference{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/restorePointCollections/{existing-rpc-name}/restorePoints/{existing-rp-name}/diskRestorePoints/{existing-disk-restore-point-name}"),
// },
// }},
// ImageReference: &armcompute.ImageReference{
// Offer: to.Ptr("WindowsServer"),
// Publisher: to.Ptr("MicrosoftWindowsServer"),
// SKU: to.Ptr("2016-Datacenter"),
// Version: to.Ptr("latest"),
// },
// OSDisk: &armcompute.OSDisk{
// Name: to.Ptr("myVMosdisk"),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// },
// },
// VMID: to.Ptr("3906fef9-a1e5-4b83-a8a8-540858b41df0"),
// },
// }
}
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");
/**
* This sample demonstrates how to The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithDataDisksFromSourceResource.json
*/
async function createAVMWithDataDisksUsingCopyAndRestoreOptions() {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP"] || "myResourceGroup";
const vmName = "myVM";
const parameters = {
hardwareProfile: { vmSize: "Standard_D2_v2" },
location: "westus",
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
osProfile: {
adminPassword: "{your-password}",
adminUsername: "{your-username}",
computerName: "myVM",
},
storageProfile: {
dataDisks: [
{
createOption: "Copy",
diskSizeGB: 1023,
lun: 0,
sourceResource: {
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/{existing-snapshot-name}",
},
},
{
createOption: "Copy",
diskSizeGB: 1023,
lun: 1,
sourceResource: {
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/{existing-disk-name}",
},
},
{
createOption: "Restore",
diskSizeGB: 1023,
lun: 2,
sourceResource: {
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/restorePointCollections/{existing-rpc-name}/restorePoints/{existing-rp-name}/diskRestorePoints/{existing-disk-restore-point-name}",
},
},
],
imageReference: {
offer: "WindowsServer",
publisher: "MicrosoftWindowsServer",
sku: "2016-Datacenter",
version: "latest",
},
osDisk: {
name: "myVMosdisk",
caching: "ReadWrite",
createOption: "FromImage",
managedDisk: { storageAccountType: "Standard_LRS" },
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.beginCreateOrUpdateAndWait(
resourceGroupName,
vmName,
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
範例回覆
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": [
{
"caching": "None",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"createOption": "Copy",
"sourceResource": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/{existing-snapshot-name}"
},
"lun": 0,
"diskSizeGB": 1023
},
{
"caching": "None",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"createOption": "Copy",
"sourceResource": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/{existing-disk-name}"
},
"lun": 1,
"diskSizeGB": 1023
},
{
"caching": "None",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"createOption": "Restore",
"sourceResource": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/restorePointCollections/{existing-rpc-name}/restorePoints/{existing-rp-name}/diskRestorePoints/{existing-disk-restore-point-name}"
},
"lun": 2,
"diskSizeGB": 1023
}
]
},
"vmId": "3906fef9-a1e5-4b83-a8a8-540858b41df0",
"hardwareProfile": {
"vmSize": "Standard_D2_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": [
{
"caching": "None",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"createOption": "Copy",
"sourceResource": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/{existing-snapshot-name}"
},
"lun": 0,
"diskSizeGB": 1023,
"toBeDetached": false
},
{
"caching": "None",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"createOption": "Copy",
"sourceResource": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/{existing-disk-name}"
},
"lun": 1,
"diskSizeGB": 1023,
"toBeDetached": false
},
{
"caching": "None",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"createOption": "Restore",
"sourceResource": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/restorePointCollections/{existing-rpc-name}/restorePoints/{existing-rp-name}/diskRestorePoints/{existing-disk-restore-point-name}"
},
"lun": 2,
"diskSizeGB": 1023,
"toBeDetached": false
}
]
},
"vmId": "3906fef9-a1e5-4b83-a8a8-540858b41df0",
"hardwareProfile": {
"vmSize": "Standard_D2_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Create a VM with Disk Controller Type
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2024-03-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D4_v3"
},
"scheduledEventsPolicy": {
"scheduledEventsAdditionalPublishingTargets": {
"eventGridAndResourceGraph": {
"enable": true
}
},
"userInitiatedRedeploy": {
"automaticallyApprove": true
},
"userInitiatedReboot": {
"automaticallyApprove": true
}
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
},
"diskControllerType": "NVMe"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"diagnosticsProfile": {
"bootDiagnostics": {
"storageUri": "http://{existing-storage-account-name}.blob.core.windows.net",
"enabled": true
}
},
"userData": "U29tZSBDdXN0b20gRGF0YQ=="
}
}
from typing import Any, IO, Union
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_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_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": True,
"storageUri": "http://{existing-storage-account-name}.blob.core.windows.net",
}
},
"hardwareProfile": {"vmSize": "Standard_D4_v3"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"scheduledEventsPolicy": {
"scheduledEventsAdditionalPublishingTargets": {"eventGridAndResourceGraph": {"enable": True}},
"userInitiatedReboot": {"automaticallyApprove": True},
"userInitiatedRedeploy": {"automaticallyApprove": True},
},
"storageProfile": {
"diskControllerType": "NVMe",
"imageReference": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2016-Datacenter",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Standard_LRS"},
"name": "myVMosdisk",
},
},
"userData": "U29tZSBDdXN0b20gRGF0YQ==",
},
},
).result()
print(response)
# x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithDiskControllerType.json
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/v5"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/92de53a5f1e0e03c94b40475d2135d97148ed014/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithDiskControllerType.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVmWithDiskControllerType() {
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.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
DiagnosticsProfile: &armcompute.DiagnosticsProfile{
BootDiagnostics: &armcompute.BootDiagnostics{
Enabled: to.Ptr(true),
StorageURI: to.Ptr("http://{existing-storage-account-name}.blob.core.windows.net"),
},
},
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD4V3),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
}},
},
OSProfile: &armcompute.OSProfile{
AdminPassword: to.Ptr("{your-password}"),
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
},
ScheduledEventsPolicy: &armcompute.ScheduledEventsPolicy{
ScheduledEventsAdditionalPublishingTargets: &armcompute.ScheduledEventsAdditionalPublishingTargets{
EventGridAndResourceGraph: &armcompute.EventGridAndResourceGraph{
Enable: to.Ptr(true),
},
},
UserInitiatedReboot: &armcompute.UserInitiatedReboot{
AutomaticallyApprove: to.Ptr(true),
},
UserInitiatedRedeploy: &armcompute.UserInitiatedRedeploy{
AutomaticallyApprove: to.Ptr(true),
},
},
StorageProfile: &armcompute.StorageProfile{
DiskControllerType: to.Ptr(armcompute.DiskControllerTypesNVMe),
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("WindowsServer"),
Publisher: to.Ptr("MicrosoftWindowsServer"),
SKU: to.Ptr("2016-Datacenter"),
Version: to.Ptr("latest"),
},
OSDisk: &armcompute.OSDisk{
Name: to.Ptr("myVMosdisk"),
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
UserData: to.Ptr("U29tZSBDdXN0b20gRGF0YQ=="),
},
}, &armcompute.VirtualMachinesClientBeginCreateOrUpdateOptions{IfMatch: nil,
IfNoneMatch: 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)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.VirtualMachine = armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// Properties: &armcompute.VirtualMachineProperties{
// DiagnosticsProfile: &armcompute.DiagnosticsProfile{
// BootDiagnostics: &armcompute.BootDiagnostics{
// Enabled: to.Ptr(true),
// StorageURI: to.Ptr("http://nsgdiagnostic.blob.core.windows.net"),
// },
// },
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD4V3),
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// }},
// },
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// ComputerName: to.Ptr("myVM"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// EnableAutomaticUpdates: to.Ptr(true),
// ProvisionVMAgent: to.Ptr(true),
// },
// },
// ProvisioningState: to.Ptr("Succeeded"),
// ScheduledEventsPolicy: &armcompute.ScheduledEventsPolicy{
// ScheduledEventsAdditionalPublishingTargets: &armcompute.ScheduledEventsAdditionalPublishingTargets{
// EventGridAndResourceGraph: &armcompute.EventGridAndResourceGraph{
// Enable: to.Ptr(true),
// },
// },
// UserInitiatedReboot: &armcompute.UserInitiatedReboot{
// AutomaticallyApprove: to.Ptr(true),
// },
// UserInitiatedRedeploy: &armcompute.UserInitiatedRedeploy{
// AutomaticallyApprove: to.Ptr(true),
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// DataDisks: []*armcompute.DataDisk{
// },
// DiskControllerType: to.Ptr(armcompute.DiskControllerTypesNVMe),
// ImageReference: &armcompute.ImageReference{
// Offer: to.Ptr("WindowsServer"),
// Publisher: to.Ptr("MicrosoftWindowsServer"),
// SKU: to.Ptr("2016-Datacenter"),
// Version: to.Ptr("latest"),
// },
// OSDisk: &armcompute.OSDisk{
// Name: to.Ptr("myVMosdisk"),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// },
// },
// VMID: to.Ptr("676420ba-7a24-4bfe-80bd-9c841ee184fa"),
// },
// }
}
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");
/**
* This sample demonstrates how to The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithDiskControllerType.json
*/
async function createAVMWithDiskControllerType() {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP"] || "myResourceGroup";
const vmName = "myVM";
const parameters = {
diagnosticsProfile: {
bootDiagnostics: {
enabled: true,
storageUri: "http://{existing-storage-account-name}.blob.core.windows.net",
},
},
hardwareProfile: { vmSize: "Standard_D4_v3" },
location: "westus",
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
osProfile: {
adminPassword: "{your-password}",
adminUsername: "{your-username}",
computerName: "myVM",
},
scheduledEventsPolicy: {
scheduledEventsAdditionalPublishingTargets: {
eventGridAndResourceGraph: { enable: true },
},
userInitiatedReboot: { automaticallyApprove: true },
userInitiatedRedeploy: { automaticallyApprove: true },
},
storageProfile: {
diskControllerType: "NVMe",
imageReference: {
offer: "WindowsServer",
publisher: "MicrosoftWindowsServer",
sku: "2016-Datacenter",
version: "latest",
},
osDisk: {
name: "myVMosdisk",
caching: "ReadWrite",
createOption: "FromImage",
managedDisk: { storageAccountType: "Standard_LRS" },
},
},
userData: "U29tZSBDdXN0b20gRGF0YQ==",
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.beginCreateOrUpdateAndWait(
resourceGroupName,
vmName,
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
範例回覆
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": [],
"diskControllerType": "NVMe"
},
"diagnosticsProfile": {
"bootDiagnostics": {
"storageUri": "http://nsgdiagnostic.blob.core.windows.net",
"enabled": true
}
},
"vmId": "676420ba-7a24-4bfe-80bd-9c841ee184fa",
"hardwareProfile": {
"vmSize": "Standard_D4_v3"
},
"scheduledEventsPolicy": {
"scheduledEventsAdditionalPublishingTargets": {
"eventGridAndResourceGraph": {
"enable": true
}
},
"userInitiatedRedeploy": {
"automaticallyApprove": true
},
"userInitiatedReboot": {
"automaticallyApprove": true
}
},
"provisioningState": "Updating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": [],
"diskControllerType": "NVMe"
},
"diagnosticsProfile": {
"bootDiagnostics": {
"storageUri": "http://nsgdiagnostic.blob.core.windows.net",
"enabled": true
}
},
"vmId": "676420ba-7a24-4bfe-80bd-9c841ee184fa",
"hardwareProfile": {
"vmSize": "Standard_D4_v3"
},
"scheduledEventsPolicy": {
"scheduledEventsAdditionalPublishingTargets": {
"eventGridAndResourceGraph": {
"enable": true
}
},
"userInitiatedRedeploy": {
"automaticallyApprove": true
},
"userInitiatedReboot": {
"automaticallyApprove": true
}
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Create a vm with DiskEncryptionSet resource id in the os disk and data disk.
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2024-03-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"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}"
}
},
"name": "myVMosdisk",
"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
},
{
"caching": "ReadWrite",
"managedDisk": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/{existing-managed-disk-name}",
"storageAccountType": "Standard_LRS",
"diskEncryptionSet": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"
}
},
"diskSizeGB": 1023,
"createOption": "Attach",
"lun": 1
}
]
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
from typing import Any, IO, Union
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_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_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_D1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"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",
},
},
{
"caching": "ReadWrite",
"createOption": "Attach",
"diskSizeGB": 1023,
"lun": 1,
"managedDisk": {
"diskEncryptionSet": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"
},
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/{existing-managed-disk-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",
},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithDiskEncryptionSetResource.json
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/v5"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/92de53a5f1e0e03c94b40475d2135d97148ed014/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithDiskEncryptionSetResource.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVmWithDiskEncryptionSetResourceIdInTheOsDiskAndDataDisk() {
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.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
}},
},
OSProfile: &armcompute.OSProfile{
AdminPassword: to.Ptr("{your-password}"),
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
},
StorageProfile: &armcompute.StorageProfile{
DataDisks: []*armcompute.DataDisk{
{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesEmpty),
DiskSizeGB: to.Ptr[int32](1023),
Lun: to.Ptr[int32](0),
ManagedDisk: &armcompute.ManagedDiskParameters{
DiskEncryptionSet: &armcompute.DiskEncryptionSetParameters{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"),
},
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
{
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesAttach),
DiskSizeGB: to.Ptr[int32](1023),
Lun: to.Ptr[int32](1),
ManagedDisk: &armcompute.ManagedDiskParameters{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/{existing-managed-disk-name}"),
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.OSDisk{
Name: to.Ptr("myVMosdisk"),
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.ManagedDiskParameters{
DiskEncryptionSet: &armcompute.DiskEncryptionSetParameters{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"),
},
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
},
}, &armcompute.VirtualMachinesClientBeginCreateOrUpdateOptions{IfMatch: nil,
IfNoneMatch: 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)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.VirtualMachine = armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// Properties: &armcompute.VirtualMachineProperties{
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// }},
// },
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// ComputerName: to.Ptr("myVM"),
// LinuxConfiguration: &armcompute.LinuxConfiguration{
// DisablePasswordAuthentication: to.Ptr(false),
// },
// Secrets: []*armcompute.VaultSecretGroup{
// },
// },
// ProvisioningState: to.Ptr("Succeeded"),
// StorageProfile: &armcompute.StorageProfile{
// DataDisks: []*armcompute.DataDisk{
// {
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesEmpty),
// DiskSizeGB: to.Ptr[int32](1023),
// Lun: to.Ptr[int32](0),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// DiskEncryptionSet: &armcompute.DiskEncryptionSetParameters{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"),
// },
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// },
// {
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesAttach),
// DiskSizeGB: to.Ptr[int32](1023),
// Lun: to.Ptr[int32](1),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/{existing-managed-disk-name}"),
// 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/nsgcustom"),
// },
// OSDisk: &armcompute.OSDisk{
// Name: to.Ptr("myVMosdisk"),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// DiskSizeGB: to.Ptr[int32](30),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// DiskEncryptionSet: &armcompute.DiskEncryptionSetParameters{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskencryptionset-name}"),
// },
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// OSType: to.Ptr(armcompute.OperatingSystemTypesLinux),
// },
// },
// VMID: to.Ptr("71aa3d5a-d73d-4970-9182-8580433b2865"),
// },
// }
}
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");
/**
* This sample demonstrates how to The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithDiskEncryptionSetResource.json
*/
async function createAVMWithDiskEncryptionSetResourceIdInTheOSDiskAndDataDisk() {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP"] || "myResourceGroup";
const vmName = "myVM";
const parameters = {
hardwareProfile: { vmSize: "Standard_D1_v2" },
location: "westus",
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
osProfile: {
adminPassword: "{your-password}",
adminUsername: "{your-username}",
computerName: "myVM",
},
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",
},
},
{
caching: "ReadWrite",
createOption: "Attach",
diskSizeGB: 1023,
lun: 1,
managedDisk: {
diskEncryptionSet: {
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}",
},
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/{existing-managed-disk-name}",
storageAccountType: "Standard_LRS",
},
},
],
imageReference: {
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/{existing-custom-image-name}",
},
osDisk: {
name: "myVMosdisk",
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.virtualMachines.beginCreateOrUpdateAndWait(
resourceGroupName,
vmName,
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
範例回覆
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"linuxConfiguration": {
"disablePasswordAuthentication": false
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/nsgcustom"
},
"osDisk": {
"name": "myVMosdisk",
"diskSizeGB": 30,
"managedDisk": {
"storageAccountType": "Standard_LRS",
"diskEncryptionSet": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskencryptionset-name}"
}
},
"caching": "ReadWrite",
"createOption": "FromImage",
"osType": "Linux"
},
"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
},
{
"caching": "ReadWrite",
"managedDisk": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/{existing-managed-disk-name}",
"storageAccountType": "Standard_LRS",
"diskEncryptionSet": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"
}
},
"diskSizeGB": 1023,
"createOption": "Attach",
"lun": 1
}
]
},
"vmId": "71aa3d5a-d73d-4970-9182-8580433b2865",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"linuxConfiguration": {
"disablePasswordAuthentication": false
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/nsgcustom"
},
"osDisk": {
"name": "myVMosdisk",
"diskSizeGB": 30,
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"caching": "ReadWrite",
"createOption": "FromImage",
"osType": "Linux"
},
"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
},
{
"caching": "ReadWrite",
"managedDisk": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/{existing-managed-disk-name}",
"storageAccountType": "Standard_LRS",
"diskEncryptionSet": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"
}
},
"diskSizeGB": 1023,
"createOption": "Attach",
"lun": 1
}
]
},
"vmId": "71aa3d5a-d73d-4970-9182-8580433b2865",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Create a vm with empty data disks.
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2024-03-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D2_v2"
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
},
"dataDisks": [
{
"diskSizeGB": 1023,
"createOption": "Empty",
"lun": 0
},
{
"diskSizeGB": 1023,
"createOption": "Empty",
"lun": 1
}
]
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
from typing import Any, IO, Union
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_create_with_empty_data_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_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_D2_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"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",
"managedDisk": {"storageAccountType": "Standard_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithEmptyDataDisks.json
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/v5"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/92de53a5f1e0e03c94b40475d2135d97148ed014/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithEmptyDataDisks.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVmWithEmptyDataDisks() {
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.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD2V2),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
}},
},
OSProfile: &armcompute.OSProfile{
AdminPassword: to.Ptr("{your-password}"),
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
},
StorageProfile: &armcompute.StorageProfile{
DataDisks: []*armcompute.DataDisk{
{
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.OSDisk{
Name: to.Ptr("myVMosdisk"),
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
},
}, &armcompute.VirtualMachinesClientBeginCreateOrUpdateOptions{IfMatch: nil,
IfNoneMatch: 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)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.VirtualMachine = armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// Properties: &armcompute.VirtualMachineProperties{
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD2V2),
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// }},
// },
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// ComputerName: to.Ptr("myVM"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// EnableAutomaticUpdates: to.Ptr(true),
// ProvisionVMAgent: to.Ptr(true),
// },
// },
// ProvisioningState: to.Ptr("Succeeded"),
// StorageProfile: &armcompute.StorageProfile{
// DataDisks: []*armcompute.DataDisk{
// {
// Caching: to.Ptr(armcompute.CachingTypesNone),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesEmpty),
// DiskSizeGB: to.Ptr[int32](1023),
// Lun: to.Ptr[int32](0),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// },
// {
// Caching: to.Ptr(armcompute.CachingTypesNone),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesEmpty),
// DiskSizeGB: to.Ptr[int32](1023),
// Lun: to.Ptr[int32](1),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// }},
// ImageReference: &armcompute.ImageReference{
// Offer: to.Ptr("WindowsServer"),
// Publisher: to.Ptr("MicrosoftWindowsServer"),
// SKU: to.Ptr("2016-Datacenter"),
// Version: to.Ptr("latest"),
// },
// OSDisk: &armcompute.OSDisk{
// Name: to.Ptr("myVMosdisk"),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// },
// },
// VMID: to.Ptr("3906fef9-a1e5-4b83-a8a8-540858b41df0"),
// },
// }
}
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");
/**
* This sample demonstrates how to The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithEmptyDataDisks.json
*/
async function createAVMWithEmptyDataDisks() {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP"] || "myResourceGroup";
const vmName = "myVM";
const parameters = {
hardwareProfile: { vmSize: "Standard_D2_v2" },
location: "westus",
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
osProfile: {
adminPassword: "{your-password}",
adminUsername: "{your-username}",
computerName: "myVM",
},
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: {
name: "myVMosdisk",
caching: "ReadWrite",
createOption: "FromImage",
managedDisk: { storageAccountType: "Standard_LRS" },
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.beginCreateOrUpdateAndWait(
resourceGroupName,
vmName,
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
範例回覆
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"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
}
]
},
"vmId": "3906fef9-a1e5-4b83-a8a8-540858b41df0",
"hardwareProfile": {
"vmSize": "Standard_D2_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": [
{
"caching": "None",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"createOption": "Empty",
"lun": 0,
"diskSizeGB": 1023,
"toBeDetached": false
},
{
"caching": "None",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"createOption": "Empty",
"lun": 1,
"diskSizeGB": 1023,
"toBeDetached": false
}
]
},
"vmId": "3906fef9-a1e5-4b83-a8a8-540858b41df0",
"hardwareProfile": {
"vmSize": "Standard_D2_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Create a VM with encryption identity
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2024-03-01
{
"location": "westus",
"identity": {
"type": "UserAssigned",
"userAssignedIdentities": {
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/myIdentity": {}
}
},
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D2s_v3"
},
"securityProfile": {
"encryptionIdentity": {
"userAssignedIdentityResourceId": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/myIdentity"
}
},
"storageProfile": {
"imageReference": {
"publisher": "MicrosoftWindowsServer",
"offer": "WindowsServer",
"sku": "2019-Datacenter",
"version": "latest"
},
"osDisk": {
"caching": "ReadOnly",
"managedDisk": {
"storageAccountType": "StandardSSD_LRS"
},
"createOption": "FromImage",
"name": "myVMosdisk"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
from typing import Any, IO, Union
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_create_with_encryption_identity.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_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"identity": {
"type": "UserAssigned",
"userAssignedIdentities": {
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/myIdentity": {}
},
},
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_D2s_v3"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"securityProfile": {
"encryptionIdentity": {
"userAssignedIdentityResourceId": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/myIdentity"
}
},
"storageProfile": {
"imageReference": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2019-Datacenter",
"version": "latest",
},
"osDisk": {
"caching": "ReadOnly",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "StandardSSD_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithEncryptionIdentity.json
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/v5"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/92de53a5f1e0e03c94b40475d2135d97148ed014/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithEncryptionIdentity.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVmWithEncryptionIdentity() {
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.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Identity: &armcompute.VirtualMachineIdentity{
Type: to.Ptr(armcompute.ResourceIdentityTypeUserAssigned),
UserAssignedIdentities: map[string]*armcompute.UserAssignedIdentitiesValue{
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/myIdentity": {},
},
},
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD2SV3),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
}},
},
OSProfile: &armcompute.OSProfile{
AdminPassword: to.Ptr("{your-password}"),
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
},
SecurityProfile: &armcompute.SecurityProfile{
EncryptionIdentity: &armcompute.EncryptionIdentity{
UserAssignedIdentityResourceID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/myIdentity"),
},
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("WindowsServer"),
Publisher: to.Ptr("MicrosoftWindowsServer"),
SKU: to.Ptr("2019-Datacenter"),
Version: to.Ptr("latest"),
},
OSDisk: &armcompute.OSDisk{
Name: to.Ptr("myVMosdisk"),
Caching: to.Ptr(armcompute.CachingTypesReadOnly),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardSSDLRS),
},
},
},
},
}, &armcompute.VirtualMachinesClientBeginCreateOrUpdateOptions{IfMatch: nil,
IfNoneMatch: 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)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.VirtualMachine = armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// Identity: &armcompute.VirtualMachineIdentity{
// Type: to.Ptr(armcompute.ResourceIdentityTypeUserAssigned),
// UserAssignedIdentities: map[string]*armcompute.UserAssignedIdentitiesValue{
// "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/myIdentity": &armcompute.UserAssignedIdentitiesValue{
// },
// },
// },
// Properties: &armcompute.VirtualMachineProperties{
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD2SV3),
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// }},
// },
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// ComputerName: to.Ptr("myVM"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// EnableAutomaticUpdates: to.Ptr(true),
// ProvisionVMAgent: to.Ptr(true),
// },
// },
// ProvisioningState: to.Ptr("Succeeded"),
// SecurityProfile: &armcompute.SecurityProfile{
// EncryptionIdentity: &armcompute.EncryptionIdentity{
// UserAssignedIdentityResourceID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/myIdentity"),
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// DataDisks: []*armcompute.DataDisk{
// },
// ImageReference: &armcompute.ImageReference{
// Offer: to.Ptr("WindowsServer"),
// Publisher: to.Ptr("MicrosoftWindowsServer"),
// SKU: to.Ptr("2019-Datacenter"),
// Version: to.Ptr("latest"),
// },
// OSDisk: &armcompute.OSDisk{
// Name: to.Ptr("myVMosdisk"),
// Caching: to.Ptr(armcompute.CachingTypesReadOnly),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardSSDLRS),
// },
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// },
// },
// VMID: to.Ptr("5c0d55a7-c407-4ed6-bf7d-ddb810267c85"),
// },
// }
}
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");
/**
* This sample demonstrates how to The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithEncryptionIdentity.json
*/
async function createAVMWithEncryptionIdentity() {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP"] || "myResourceGroup";
const vmName = "myVM";
const parameters = {
hardwareProfile: { vmSize: "Standard_D2s_v3" },
identity: {
type: "UserAssigned",
userAssignedIdentities: {
"/subscriptions/{subscriptionId}/resourceGroups/myResourceGroup/providers/MicrosoftManagedIdentity/userAssignedIdentities/myIdentity":
{},
},
},
location: "westus",
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
osProfile: {
adminPassword: "{your-password}",
adminUsername: "{your-username}",
computerName: "myVM",
},
securityProfile: {
encryptionIdentity: {
userAssignedIdentityResourceId:
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/myIdentity",
},
},
storageProfile: {
imageReference: {
offer: "WindowsServer",
publisher: "MicrosoftWindowsServer",
sku: "2019-Datacenter",
version: "latest",
},
osDisk: {
name: "myVMosdisk",
caching: "ReadOnly",
createOption: "FromImage",
managedDisk: { storageAccountType: "StandardSSD_LRS" },
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.beginCreateOrUpdateAndWait(
resourceGroupName,
vmName,
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
import com.azure.core.management.SubResource;
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.AdditionalCapabilities;
import com.azure.resourcemanager.compute.models.ApiEntityReference;
import com.azure.resourcemanager.compute.models.ApplicationProfile;
import com.azure.resourcemanager.compute.models.BootDiagnostics;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DataDisk;
import com.azure.resourcemanager.compute.models.DeleteOptions;
import com.azure.resourcemanager.compute.models.DiagnosticsProfile;
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.DiskControllerTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.DiskEncryptionSetParameters;
import com.azure.resourcemanager.compute.models.DomainNameLabelScopeTypes;
import com.azure.resourcemanager.compute.models.EncryptionIdentity;
import com.azure.resourcemanager.compute.models.EventGridAndResourceGraph;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.LinuxConfiguration;
import com.azure.resourcemanager.compute.models.LinuxPatchAssessmentMode;
import com.azure.resourcemanager.compute.models.LinuxPatchSettings;
import com.azure.resourcemanager.compute.models.LinuxVMGuestPatchAutomaticByPlatformRebootSetting;
import com.azure.resourcemanager.compute.models.LinuxVMGuestPatchAutomaticByPlatformSettings;
import com.azure.resourcemanager.compute.models.LinuxVMGuestPatchMode;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.Mode;
import com.azure.resourcemanager.compute.models.NetworkApiVersion;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSImageNotificationProfile;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.OperatingSystemTypes;
import com.azure.resourcemanager.compute.models.PatchSettings;
import com.azure.resourcemanager.compute.models.Plan;
import com.azure.resourcemanager.compute.models.ProxyAgentSettings;
import com.azure.resourcemanager.compute.models.PublicIpAddressSku;
import com.azure.resourcemanager.compute.models.PublicIpAddressSkuName;
import com.azure.resourcemanager.compute.models.PublicIpAddressSkuTier;
import com.azure.resourcemanager.compute.models.PublicIpAllocationMethod;
import com.azure.resourcemanager.compute.models.ResourceIdentityType;
import com.azure.resourcemanager.compute.models.ScheduledEventsAdditionalPublishingTargets;
import com.azure.resourcemanager.compute.models.ScheduledEventsPolicy;
import com.azure.resourcemanager.compute.models.ScheduledEventsProfile;
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.SshConfiguration;
import com.azure.resourcemanager.compute.models.SshPublicKey;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.TerminateNotificationProfile;
import com.azure.resourcemanager.compute.models.UefiSettings;
import com.azure.resourcemanager.compute.models.UserInitiatedReboot;
import com.azure.resourcemanager.compute.models.UserInitiatedRedeploy;
import com.azure.resourcemanager.compute.models.VMDiskSecurityProfile;
import com.azure.resourcemanager.compute.models.VMGalleryApplication;
import com.azure.resourcemanager.compute.models.VMSizeProperties;
import com.azure.resourcemanager.compute.models.VirtualHardDisk;
import com.azure.resourcemanager.compute.models.VirtualMachineIdentity;
import com.azure.resourcemanager.compute.models.VirtualMachineIdentityUserAssignedIdentities;
import com.azure.resourcemanager.compute.models.VirtualMachineNetworkInterfaceConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineNetworkInterfaceIpConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachinePublicIpAddressConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachinePublicIpAddressDnsSettingsConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import com.azure.resourcemanager.compute.models.WindowsConfiguration;
import com.azure.resourcemanager.compute.models.WindowsPatchAssessmentMode;
import com.azure.resourcemanager.compute.models.WindowsVMGuestPatchAutomaticByPlatformRebootSetting;
import com.azure.resourcemanager.compute.models.WindowsVMGuestPatchAutomaticByPlatformSettings;
import com.azure.resourcemanager.compute.models.WindowsVMGuestPatchMode;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithEncryptionIdentity.json
*/
/**
* Sample code: Create a VM with encryption identity.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMWithEncryptionIdentity(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus").withIdentity(new VirtualMachineIdentity()
.withType(ResourceIdentityType.USER_ASSIGNED)
.withUserAssignedIdentities(mapOf(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/myIdentity",
new VirtualMachineIdentityUserAssignedIdentities())))
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2S_V3))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2019-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_SSD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withSecurityProfile(new SecurityProfile()
.withEncryptionIdentity(new EncryptionIdentity().withUserAssignedIdentityResourceId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/myIdentity"))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_CustomImageVmFromAnUnmanagedGeneralizedOsImage.json
*/
/**
* Sample code: Create a custom-image vm from an unmanaged generalized os image.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createACustomImageVmFromAnUnmanagedGeneralizedOsImage(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines()
.createOrUpdate("myResourceGroup", "{vm-name}", new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile().withOsDisk(new OSDisk()
.withOsType(OperatingSystemTypes.WINDOWS).withName("myVMosdisk")
.withVhd(new VirtualHardDisk().withUri(
"http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk.vhd"))
.withImage(new VirtualHardDisk().withUri(
"http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/{existing-generalized-os-image-blob-name}.vhd"))
.withCaching(CachingTypes.READ_WRITE).withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithEncryptionAtHost.json
*/
/**
* Sample code: Create a vm with Host Encryption using encryptionAtHost property.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createAVmWithHostEncryptionUsingEncryptionAtHostProperty(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withPlan(new Plan().withName("windows2016").withPublisher("microsoft-ads")
.withProduct("windows-data-science-vm"))
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_DS1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("microsoft-ads")
.withOffer("windows-data-science-vm").withSku("windows2016").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withSecurityProfile(new SecurityProfile().withEncryptionAtHost(true)),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_InAnAvailabilitySet.json
*/
/**
* Sample code: Create a vm in an availability set.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmInAnAvailabilitySet(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withAvailabilitySet(new SubResource().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/availabilitySets/{existing-availability-set-name}")),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithNetworkInterfaceConfiguration.json
*/
/**
* Sample code: Create a VM with network interface configuration.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createAVMWithNetworkInterfaceConfiguration(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(new NetworkProfile()
.withNetworkApiVersion(NetworkApiVersion.TWO_ZERO_TWO_ZERO_ONE_ONE_ZERO_ONE)
.withNetworkInterfaceConfigurations(
Arrays.asList(new VirtualMachineNetworkInterfaceConfiguration().withName("{nic-config-name}")
.withPrimary(true).withDeleteOption(DeleteOptions.DELETE)
.withIpConfigurations(Arrays.asList(new VirtualMachineNetworkInterfaceIpConfiguration()
.withName("{ip-config-name}").withPrimary(true)
.withPublicIpAddressConfiguration(new VirtualMachinePublicIpAddressConfiguration()
.withName("{publicIP-config-name}")
.withSku(new PublicIpAddressSku().withName(PublicIpAddressSkuName.BASIC)
.withTier(PublicIpAddressSkuTier.GLOBAL))
.withDeleteOption(DeleteOptions.DETACH)
.withPublicIpAllocationMethod(PublicIpAllocationMethod.STATIC))))))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithADiffOsDiskUsingDiffDiskPlacementAsNvmeDisk.json
*/
/**
* Sample code: Create a vm with ephemeral os disk provisioning in Nvme disk using placement property.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithEphemeralOsDiskProvisioningInNvmeDiskUsingPlacementProperty(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withPlan(new Plan().withName("windows2016").withPublisher("microsoft-ads")
.withProduct("windows-data-science-vm"))
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_DS1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("microsoft-ads")
.withOffer("windows-data-science-vm").withSku("windows2016").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withDiffDiskSettings(new DiffDiskSettings().withOption(DiffDiskOptions.LOCAL)
.withPlacement(DiffDiskPlacement.NVME_DISK))
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_FromASpecializedSharedImage.json
*/
/**
* Sample code: Create a vm from a specialized shared image.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmFromASpecializedSharedImage(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile().withImageReference(new ImageReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/mySharedGallery/images/mySharedImage"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithPasswordAuthentication.json
*/
/**
* Sample code: Create a vm with password authentication.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithPasswordAuthentication(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithScheduledEventsProfile.json
*/
/**
* Sample code: Create a vm with Scheduled Events Profile.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithScheduledEventsProfile(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withScheduledEventsPolicy(new ScheduledEventsPolicy()
.withUserInitiatedRedeploy(new UserInitiatedRedeploy().withAutomaticallyApprove(true))
.withUserInitiatedReboot(new UserInitiatedReboot().withAutomaticallyApprove(true))
.withScheduledEventsAdditionalPublishingTargets(new ScheduledEventsAdditionalPublishingTargets()
.withEventGridAndResourceGraph(new EventGridAndResourceGraph().withEnable(true))))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics()
.withEnabled(true).withStorageUri("http://{existing-storage-account-name}.blob.core.windows.net")))
.withScheduledEventsProfile(new ScheduledEventsProfile()
.withTerminateNotificationProfile(
new TerminateNotificationProfile().withNotBeforeTimeout("PT10M").withEnable(true))
.withOsImageNotificationProfile(
new OSImageNotificationProfile().withNotBeforeTimeout("PT15M").withEnable(true))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithADiffOsDiskUsingDiffDiskPlacementAsResourceDisk.json
*/
/**
* Sample code: Create a vm with ephemeral os disk provisioning in Resource disk using placement property.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithEphemeralOsDiskProvisioningInResourceDiskUsingPlacementProperty(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withPlan(new Plan().withName("windows2016").withPublisher("microsoft-ads")
.withProduct("windows-data-science-vm"))
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_DS1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("microsoft-ads")
.withOffer("windows-data-science-vm").withSku("windows2016").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withDiffDiskSettings(new DiffDiskSettings().withOption(DiffDiskOptions.LOCAL)
.withPlacement(DiffDiskPlacement.RESOURCE_DISK))
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithADiffOsDisk.json
*/
/**
* Sample code: Create a vm with ephemeral os disk.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithEphemeralOsDisk(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withPlan(new Plan().withName("windows2016").withPublisher("microsoft-ads")
.withProduct("windows-data-science-vm"))
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_DS1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("microsoft-ads")
.withOffer("windows-data-science-vm").withSku("windows2016").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withDiffDiskSettings(new DiffDiskSettings().withOption(DiffDiskOptions.LOCAL))
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithSecurityTypeConfidentialVMWithCustomerManagedKeys.json
*/
/**
* Sample code: Create a VM with securityType ConfidentialVM with Customer Managed Keys.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMWithSecurityTypeConfidentialVMWithCustomerManagedKeys(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(
new HardwareProfile().withVmSize(VirtualMachineSizeTypes.fromString("Standard_DC2as_v5")))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("2019-datacenter-cvm").withSku("windows-cvm").withVersion("17763.2183.2109130127"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)
.withManagedDisk(new ManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.STANDARD_SSD_LRS)
.withSecurityProfile(new VMDiskSecurityProfile()
.withSecurityEncryptionType(SecurityEncryptionTypes.DISK_WITH_VMGUEST_STATE)
.withDiskEncryptionSet(new DiskEncryptionSetParameters().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"))))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withSecurityProfile(new SecurityProfile()
.withUefiSettings(new UefiSettings().withSecureBootEnabled(true).withVTpmEnabled(true))
.withSecurityType(SecurityTypes.CONFIDENTIAL_VM)),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithDiskEncryptionSetResource.json
*/
/**
* Sample code: Create a vm with DiskEncryptionSet resource id in the os disk and data disk.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithDiskEncryptionSetResourceIdInTheOsDiskAndDataDisk(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile().withImageReference(new ImageReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/{existing-custom-image-name}"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)
.withManagedDisk(new ManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.STANDARD_LRS)
.withDiskEncryptionSet(new DiskEncryptionSetParameters().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"))))
.withDataDisks(Arrays.asList(new DataDisk().withLun(0).withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.EMPTY).withDiskSizeGB(1023)
.withManagedDisk(new ManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.STANDARD_LRS)
.withDiskEncryptionSet(new DiskEncryptionSetParameters().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"))),
new DataDisk().withLun(1).withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.ATTACH).withDiskSizeGB(1023)
.withManagedDisk(new ManagedDiskParameters().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/{existing-managed-disk-name}")
.withStorageAccountType(StorageAccountTypes.STANDARD_LRS)
.withDiskEncryptionSet(new DiskEncryptionSetParameters().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"))))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithDiskControllerType.json
*/
/**
* Sample code: Create a VM with Disk Controller Type.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMWithDiskControllerType(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D4_V3))
.withScheduledEventsPolicy(new ScheduledEventsPolicy()
.withUserInitiatedRedeploy(new UserInitiatedRedeploy().withAutomaticallyApprove(true))
.withUserInitiatedReboot(new UserInitiatedReboot().withAutomaticallyApprove(true))
.withScheduledEventsAdditionalPublishingTargets(new ScheduledEventsAdditionalPublishingTargets()
.withEventGridAndResourceGraph(new EventGridAndResourceGraph().withEnable(true))))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS)))
.withDiskControllerType(DiskControllerTypes.NVME))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics()
.withEnabled(true).withStorageUri("http://{existing-storage-account-name}.blob.core.windows.net")))
.withUserData("U29tZSBDdXN0b20gRGF0YQ=="),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_FromASharedGalleryImage.json
*/
/**
* Sample code: Create a VM from a shared gallery image.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMFromASharedGalleryImage(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withSharedGalleryImageId(
"/SharedGalleries/sharedGalleryName/Images/sharedGalleryImageName/Versions/sharedGalleryImageVersionName"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithVMSizeProperties.json
*/
/**
* Sample code: Create a VM with VM Size Properties.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMWithVMSizeProperties(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D4_V3)
.withVmSizeProperties(new VMSizeProperties().withVCpusAvailable(1).withVCpusPerCore(1)))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics()
.withEnabled(true).withStorageUri("http://{existing-storage-account-name}.blob.core.windows.net")))
.withUserData("U29tZSBDdXN0b20gRGF0YQ=="),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_PlatformImageVmWithUnmanagedOsAndDataDisks.json
*/
/**
* Sample code: Create a platform-image vm with unmanaged os and data disks.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createAPlatformImageVmWithUnmanagedOsAndDataDisks(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines()
.createOrUpdate("myResourceGroup", "{vm-name}", new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withVhd(new VirtualHardDisk().withUri(
"http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk.vhd"))
.withCaching(CachingTypes.READ_WRITE).withCreateOption(DiskCreateOptionTypes.FROM_IMAGE))
.withDataDisks(Arrays.asList(new DataDisk().withLun(0).withVhd(new VirtualHardDisk().withUri(
"http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk0.vhd"))
.withCreateOption(DiskCreateOptionTypes.EMPTY).withDiskSizeGB(1023),
new DataDisk().withLun(1).withVhd(new VirtualHardDisk().withUri(
"http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk1.vhd"))
.withCreateOption(DiskCreateOptionTypes.EMPTY).withDiskSizeGB(1023))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_LinuxVmWithPatchSettingModesOfAutomaticByPlatform.json
*/
/**
* Sample code: Create a Linux vm with a patch settings patchMode and assessmentMode set to AutomaticByPlatform.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createALinuxVmWithAPatchSettingsPatchModeAndAssessmentModeSetToAutomaticByPlatform(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2S_V3))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("Canonical").withOffer("UbuntuServer")
.withSku("16.04-LTS").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder")
.withLinuxConfiguration(new LinuxConfiguration().withProvisionVMAgent(true).withPatchSettings(
new LinuxPatchSettings().withPatchMode(LinuxVMGuestPatchMode.AUTOMATIC_BY_PLATFORM)
.withAssessmentMode(LinuxPatchAssessmentMode.AUTOMATIC_BY_PLATFORM))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithSecurityTypeConfidentialVMWithNonPersistedTPM.json
*/
/**
* Sample code: Create a VM with securityType ConfidentialVM with NonPersistedTPM securityEncryptionType.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMWithSecurityTypeConfidentialVMWithNonPersistedTPMSecurityEncryptionType(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(
new HardwareProfile().withVmSize(VirtualMachineSizeTypes.fromString("Standard_DC2es_v5")))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("UbuntuServer")
.withOffer("2022-datacenter-cvm").withSku("linux-cvm").withVersion("17763.2183.2109130127"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_SSD_LRS)
.withSecurityProfile(new VMDiskSecurityProfile()
.withSecurityEncryptionType(SecurityEncryptionTypes.NON_PERSISTED_TPM)))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withSecurityProfile(new SecurityProfile()
.withUefiSettings(new UefiSettings().withSecureBootEnabled(false).withVTpmEnabled(true))
.withSecurityType(SecurityTypes.CONFIDENTIAL_VM)),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithAMarketplaceImagePlan.json
*/
/**
* Sample code: Create a vm with a marketplace image plan.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithAMarketplaceImagePlan(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withPlan(new Plan().withName("windows2016").withPublisher("microsoft-ads")
.withProduct("windows-data-science-vm"))
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("microsoft-ads")
.withOffer("windows-data-science-vm").withSku("windows2016").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WindowsVmWithPatchSettingAssessmentModeOfImageDefault.json
*/
/**
* Sample code: Create a Windows vm with a patch setting assessmentMode of ImageDefault.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAWindowsVmWithAPatchSettingAssessmentModeOfImageDefault(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder")
.withWindowsConfiguration(new WindowsConfiguration().withProvisionVMAgent(true)
.withEnableAutomaticUpdates(true).withPatchSettings(
new PatchSettings().withAssessmentMode(WindowsPatchAssessmentMode.IMAGE_DEFAULT))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/
* VirtualMachine_Create_WindowsVmWithPatchSettingModeOfAutomaticByPlatformAndEnableHotPatchingTrue.json
*/
/**
* Sample code: Create a Windows vm with a patch setting patchMode of AutomaticByPlatform and enableHotpatching set
* to true.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAWindowsVmWithAPatchSettingPatchModeOfAutomaticByPlatformAndEnableHotpatchingSetToTrue(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder")
.withWindowsConfiguration(new WindowsConfiguration().withProvisionVMAgent(true)
.withEnableAutomaticUpdates(true)
.withPatchSettings(new PatchSettings()
.withPatchMode(WindowsVMGuestPatchMode.AUTOMATIC_BY_PLATFORM).withEnableHotpatching(true))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithExtensionsTimeBudget.json
*/
/**
* Sample code: Create a vm with an extensions time budget.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithAnExtensionsTimeBudget(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics()
.withEnabled(true).withStorageUri("http://{existing-storage-account-name}.blob.core.windows.net")))
.withExtensionsTimeBudget("PT30M"),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithEmptyDataDisks.json
*/
/**
* Sample code: Create a vm with empty data disks.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithEmptyDataDisks(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS)))
.withDataDisks(Arrays.asList(
new DataDisk().withLun(0).withCreateOption(DiskCreateOptionTypes.EMPTY).withDiskSizeGB(1023),
new DataDisk().withLun(1).withCreateOption(DiskCreateOptionTypes.EMPTY).withDiskSizeGB(1023))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithSecurityTypeConfidentialVM.json
*/
/**
* Sample code: Create a VM with securityType ConfidentialVM with Platform Managed Keys.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMWithSecurityTypeConfidentialVMWithPlatformManagedKeys(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(
new HardwareProfile().withVmSize(VirtualMachineSizeTypes.fromString("Standard_DC2as_v5")))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("2019-datacenter-cvm").withSku("windows-cvm").withVersion("17763.2183.2109130127"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_SSD_LRS)
.withSecurityProfile(new VMDiskSecurityProfile()
.withSecurityEncryptionType(SecurityEncryptionTypes.DISK_WITH_VMGUEST_STATE)))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withSecurityProfile(new SecurityProfile()
.withUefiSettings(new UefiSettings().withSecureBootEnabled(true).withVTpmEnabled(true))
.withSecurityType(SecurityTypes.CONFIDENTIAL_VM)),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithDataDisksFromSourceResource.json
*/
/**
* Sample code: Create a vm with data disks using 'Copy' and 'Restore' options.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createAVmWithDataDisksUsingCopyAndRestoreOptions(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS)))
.withDataDisks(Arrays.asList(new DataDisk().withLun(0).withCreateOption(DiskCreateOptionTypes.COPY)
.withDiskSizeGB(1023)
.withSourceResource(new ApiEntityReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/{existing-snapshot-name}")),
new DataDisk().withLun(1).withCreateOption(DiskCreateOptionTypes.COPY).withDiskSizeGB(1023)
.withSourceResource(new ApiEntityReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/{existing-disk-name}")),
new DataDisk().withLun(2).withCreateOption(DiskCreateOptionTypes.RESTORE).withDiskSizeGB(1023)
.withSourceResource(new ApiEntityReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/restorePointCollections/{existing-rpc-name}/restorePoints/{existing-rp-name}/diskRestorePoints/{existing-disk-restore-point-name}")))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_FromACustomImage.json
*/
/**
* Sample code: Create a vm from a custom image.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmFromACustomImage(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile().withImageReference(new ImageReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/{existing-custom-image-name}"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithHibernationEnabled.json
*/
/**
* Sample code: Create a VM with HibernationEnabled.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMWithHibernationEnabled(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup",
"{vm-name}",
new VirtualMachineInner().withLocation("eastus2euap")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2S_V3))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2019-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("vmOSdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withAdditionalCapabilities(new AdditionalCapabilities().withHibernationEnabled(true))
.withOsProfile(new OSProfile().withComputerName("{vm-name}").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics()
.withEnabled(true).withStorageUri("http://{existing-storage-account-name}.blob.core.windows.net"))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithUefiSettings.json
*/
/**
* Sample code: Create a VM with Uefi Settings of secureBoot and vTPM.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createAVMWithUefiSettingsOfSecureBootAndVTPM(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2S_V3))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference()
.withPublisher("MicrosoftWindowsServer").withOffer("windowsserver-gen2preview-preview")
.withSku("windows10-tvm").withVersion("18363.592.2001092016"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_SSD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withSecurityProfile(new SecurityProfile()
.withUefiSettings(new UefiSettings().withSecureBootEnabled(true).withVTpmEnabled(true))
.withSecurityType(SecurityTypes.TRUSTED_LAUNCH)),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithApplicationProfile.json
*/
/**
* Sample code: Create a vm with Application Profile.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithApplicationProfile(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("{image_publisher}")
.withOffer("{image_offer}").withSku("{image_sku}").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(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(false).withEnableAutomaticUpgrade(false),
new VMGalleryApplication().withPackageReferenceId(
"/subscriptions/32c17a9e-aa7b-4ba5-a45b-e324116b6fdg/resourceGroups/myresourceGroupName3/providers/Microsoft.Compute/galleries/myGallery2/applications/MyApplication2/versions/1.1")))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithNetworkInterfaceConfigurationDnsSettings.json
*/
/**
* Sample code: Create a VM with network interface configuration with public ip address dns settings.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMWithNetworkInterfaceConfigurationWithPublicIpAddressDnsSettings(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkApiVersion(NetworkApiVersion.TWO_ZERO_TWO_ZERO_ONE_ONE_ZERO_ONE)
.withNetworkInterfaceConfigurations(
Arrays.asList(new VirtualMachineNetworkInterfaceConfiguration()
.withName("{nic-config-name}").withPrimary(true).withDeleteOption(DeleteOptions.DELETE)
.withIpConfigurations(Arrays.asList(new VirtualMachineNetworkInterfaceIpConfiguration()
.withName("{ip-config-name}").withPrimary(true)
.withPublicIpAddressConfiguration(new VirtualMachinePublicIpAddressConfiguration()
.withName("{publicIP-config-name}")
.withSku(new PublicIpAddressSku().withName(PublicIpAddressSkuName.BASIC)
.withTier(PublicIpAddressSkuTier.GLOBAL))
.withDeleteOption(DeleteOptions.DETACH)
.withDnsSettings(new VirtualMachinePublicIpAddressDnsSettingsConfiguration()
.withDomainNameLabel("aaaaa")
.withDomainNameLabelScope(DomainNameLabelScopeTypes.TENANT_REUSE))
.withPublicIpAllocationMethod(PublicIpAllocationMethod.STATIC))))))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_InAVmssWithCustomerAssignedPlatformFaultDomain.json
*/
/**
* Sample code: Create a vm in a Virtual Machine Scale Set with customer assigned platformFaultDomain.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmInAVirtualMachineScaleSetWithCustomerAssignedPlatformFaultDomain(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withVirtualMachineScaleSet(new SubResource().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{existing-flex-vmss-name-with-platformFaultDomainCount-greater-than-1}"))
.withPlatformFaultDomain(1),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithBootDiagnostics.json
*/
/**
* Sample code: Create a vm with boot diagnostics.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithBootDiagnostics(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics()
.withEnabled(true).withStorageUri("http://{existing-storage-account-name}.blob.core.windows.net"))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithSshAuthentication.json
*/
/**
* Sample code: Create a vm with ssh authentication.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithSshAuthentication(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("{image_publisher}")
.withOffer("{image_offer}").withSku("{image_sku}").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").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"))))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_FromACommunityGalleryImage.json
*/
/**
* Sample code: Create a VM from a community gallery image.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMFromACommunityGalleryImage(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withCommunityGalleryImageId(
"/CommunityGalleries/galleryPublicName/Images/communityGalleryImageName/Versions/communityGalleryImageVersionName"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithUserData.json
*/
/**
* Sample code: Create a VM with UserData.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMWithUserData(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup",
"{vm-name}",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("vmOSdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("{vm-name}").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics()
.withEnabled(true).withStorageUri("http://{existing-storage-account-name}.blob.core.windows.net")))
.withUserData("RXhhbXBsZSBVc2VyRGF0YQ=="),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_FromAGeneralizedSharedImage.json
*/
/**
* Sample code: Create a vm from a generalized shared image.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmFromAGeneralizedSharedImage(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile().withImageReference(new ImageReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/mySharedGallery/images/mySharedImage"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_LinuxVmWithAutomaticByPlatformSettings.json
*/
/**
* Sample code: Create a Linux vm with a patch setting patchMode of AutomaticByPlatform and
* AutomaticByPlatformSettings.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createALinuxVmWithAPatchSettingPatchModeOfAutomaticByPlatformAndAutomaticByPlatformSettings(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2S_V3))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("Canonical").withOffer("UbuntuServer")
.withSku("16.04-LTS").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder")
.withLinuxConfiguration(new LinuxConfiguration().withProvisionVMAgent(true).withPatchSettings(
new LinuxPatchSettings().withPatchMode(LinuxVMGuestPatchMode.AUTOMATIC_BY_PLATFORM)
.withAssessmentMode(LinuxPatchAssessmentMode.AUTOMATIC_BY_PLATFORM)
.withAutomaticByPlatformSettings(new LinuxVMGuestPatchAutomaticByPlatformSettings()
.withRebootSetting(LinuxVMGuestPatchAutomaticByPlatformRebootSetting.NEVER)
.withBypassPlatformSafetyChecksOnUserSchedule(true)))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WindowsVmWithPatchSettingModeOfManual.json
*/
/**
* Sample code: Create a Windows vm with a patch setting patchMode of Manual.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createAWindowsVmWithAPatchSettingPatchModeOfManual(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder").withWindowsConfiguration(
new WindowsConfiguration().withProvisionVMAgent(true).withEnableAutomaticUpdates(true)
.withPatchSettings(new PatchSettings().withPatchMode(WindowsVMGuestPatchMode.MANUAL))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithProxyAgentSettings.json
*/
/**
* Sample code: Create a VM with ProxyAgent Settings of enabled and mode.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createAVMWithProxyAgentSettingsOfEnabledAndMode(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2S_V3))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2019-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_SSD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withSecurityProfile(new SecurityProfile()
.withProxyAgentSettings(new ProxyAgentSettings().withEnabled(true).withMode(Mode.ENFORCE))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_LinuxVmWithPatchSettingModeOfImageDefault.json
*/
/**
* Sample code: Create a Linux vm with a patch setting patchMode of ImageDefault.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createALinuxVmWithAPatchSettingPatchModeOfImageDefault(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2S_V3))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("Canonical").withOffer("UbuntuServer")
.withSku("16.04-LTS").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder")
.withLinuxConfiguration(new LinuxConfiguration().withProvisionVMAgent(true).withPatchSettings(
new LinuxPatchSettings().withPatchMode(LinuxVMGuestPatchMode.IMAGE_DEFAULT))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithManagedBootDiagnostics.json
*/
/**
* Sample code: Create a vm with managed boot diagnostics.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithManagedBootDiagnostics(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(
new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics().withEnabled(true))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WindowsVmWithAutomaticByPlatformSettings.json
*/
/**
* Sample code: Create a Windows vm with a patch setting patchMode of AutomaticByPlatform and
* AutomaticByPlatformSettings.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAWindowsVmWithAPatchSettingPatchModeOfAutomaticByPlatformAndAutomaticByPlatformSettings(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder").withWindowsConfiguration(
new WindowsConfiguration().withProvisionVMAgent(true).withEnableAutomaticUpdates(true)
.withPatchSettings(new PatchSettings()
.withPatchMode(WindowsVMGuestPatchMode.AUTOMATIC_BY_PLATFORM)
.withAssessmentMode(WindowsPatchAssessmentMode.AUTOMATIC_BY_PLATFORM)
.withAutomaticByPlatformSettings(new WindowsVMGuestPatchAutomaticByPlatformSettings()
.withRebootSetting(WindowsVMGuestPatchAutomaticByPlatformRebootSetting.NEVER)
.withBypassPlatformSafetyChecksOnUserSchedule(false)))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
範例回覆
{
"name": "myVM",
"identity": {
"type": "UserAssigned",
"userAssignedIdentities": {
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/myIdentity": {}
}
},
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"publisher": "MicrosoftWindowsServer",
"offer": "WindowsServer",
"sku": "2019-Datacenter",
"version": "latest"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadOnly",
"managedDisk": {
"storageAccountType": "StandardSSD_LRS"
},
"createOption": "FromImage",
"name": "myVMosdisk"
},
"dataDisks": []
},
"securityProfile": {
"encryptionIdentity": {
"userAssignedIdentityResourceId": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/myIdentity"
}
},
"vmId": "5c0d55a7-c407-4ed6-bf7d-ddb810267c85",
"hardwareProfile": {
"vmSize": "Standard_D2s_v3"
},
"provisioningState": "Creating"
},
"type": "Microsoft.Compute/virtualMachines",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"location": "westus"
}
{
"name": "myVM",
"identity": {
"type": "UserAssigned",
"userAssignedIdentities": {
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/myIdentity": {}
}
},
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"publisher": "MicrosoftWindowsServer",
"offer": "WindowsServer",
"sku": "2019-Datacenter",
"version": "latest"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadOnly",
"managedDisk": {
"storageAccountType": "StandardSSD_LRS"
},
"createOption": "FromImage",
"name": "myVMosdisk"
},
"dataDisks": []
},
"securityProfile": {
"encryptionIdentity": {
"userAssignedIdentityResourceId": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/myIdentity"
}
},
"vmId": "5c0d55a7-c407-4ed6-bf7d-ddb810267c85",
"hardwareProfile": {
"vmSize": "Standard_D2s_v3"
},
"provisioningState": "Creating"
},
"type": "Microsoft.Compute/virtualMachines",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"location": "westus"
}
Create a vm with ephemeral os disk provisioning in Cache disk using placement property.
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2024-03-01
{
"location": "westus",
"plan": {
"publisher": "microsoft-ads",
"product": "windows-data-science-vm",
"name": "windows2016"
},
"properties": {
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"storageProfile": {
"imageReference": {
"sku": "windows2016",
"publisher": "microsoft-ads",
"version": "latest",
"offer": "windows-data-science-vm"
},
"osDisk": {
"caching": "ReadOnly",
"diffDiskSettings": {
"option": "Local",
"placement": "CacheDisk"
},
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"createOption": "FromImage",
"name": "myVMosdisk"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
from typing import Any, IO, Union
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_create_with_adiff_os_disk_using_diff_disk_placement_as_cache_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_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"plan": {"name": "windows2016", "product": "windows-data-science-vm", "publisher": "microsoft-ads"},
"properties": {
"hardwareProfile": {"vmSize": "Standard_DS1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"storageProfile": {
"imageReference": {
"offer": "windows-data-science-vm",
"publisher": "microsoft-ads",
"sku": "windows2016",
"version": "latest",
},
"osDisk": {
"caching": "ReadOnly",
"createOption": "FromImage",
"diffDiskSettings": {"option": "Local", "placement": "CacheDisk"},
"managedDisk": {"storageAccountType": "Standard_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithADiffOsDiskUsingDiffDiskPlacementAsCacheDisk.json
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/v5"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/92de53a5f1e0e03c94b40475d2135d97148ed014/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithADiffOsDiskUsingDiffDiskPlacementAsCacheDisk.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVmWithEphemeralOsDiskProvisioningInCacheDiskUsingPlacementProperty() {
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.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
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.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardDS1V2),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
}},
},
OSProfile: &armcompute.OSProfile{
AdminPassword: to.Ptr("{your-password}"),
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
},
StorageProfile: &armcompute.StorageProfile{
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.OSDisk{
Name: to.Ptr("myVMosdisk"),
Caching: to.Ptr(armcompute.CachingTypesReadOnly),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
DiffDiskSettings: &armcompute.DiffDiskSettings{
Option: to.Ptr(armcompute.DiffDiskOptionsLocal),
Placement: to.Ptr(armcompute.DiffDiskPlacementCacheDisk),
},
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
},
}, &armcompute.VirtualMachinesClientBeginCreateOrUpdateOptions{IfMatch: nil,
IfNoneMatch: 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)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.VirtualMachine = armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// Plan: &armcompute.Plan{
// Name: to.Ptr("standard-data-science-vm"),
// Product: to.Ptr("standard-data-science-vm"),
// Publisher: to.Ptr("microsoft-ads"),
// },
// Properties: &armcompute.VirtualMachineProperties{
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardDS1V2),
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// }},
// },
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// ComputerName: to.Ptr("myVM"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// EnableAutomaticUpdates: to.Ptr(true),
// ProvisionVMAgent: to.Ptr(true),
// },
// },
// ProvisioningState: to.Ptr("Succeeded"),
// StorageProfile: &armcompute.StorageProfile{
// DataDisks: []*armcompute.DataDisk{
// },
// ImageReference: &armcompute.ImageReference{
// Offer: to.Ptr("standard-data-science-vm"),
// Publisher: to.Ptr("microsoft-ads"),
// SKU: to.Ptr("standard-data-science-vm"),
// Version: to.Ptr("latest"),
// },
// OSDisk: &armcompute.OSDisk{
// Name: to.Ptr("myVMosdisk"),
// Caching: to.Ptr(armcompute.CachingTypesReadOnly),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// DiffDiskSettings: &armcompute.DiffDiskSettings{
// Option: to.Ptr(armcompute.DiffDiskOptionsLocal),
// Placement: to.Ptr(armcompute.DiffDiskPlacementCacheDisk),
// },
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// },
// },
// VMID: to.Ptr("5c0d55a7-c407-4ed6-bf7d-ddb810267c85"),
// },
// }
}
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");
/**
* This sample demonstrates how to The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithADiffOsDiskUsingDiffDiskPlacementAsCacheDisk.json
*/
async function createAVMWithEphemeralOSDiskProvisioningInCacheDiskUsingPlacementProperty() {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP"] || "myResourceGroup";
const vmName = "myVM";
const parameters = {
hardwareProfile: { vmSize: "Standard_DS1_v2" },
location: "westus",
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
osProfile: {
adminPassword: "{your-password}",
adminUsername: "{your-username}",
computerName: "myVM",
},
plan: {
name: "windows2016",
product: "windows-data-science-vm",
publisher: "microsoft-ads",
},
storageProfile: {
imageReference: {
offer: "windows-data-science-vm",
publisher: "microsoft-ads",
sku: "windows2016",
version: "latest",
},
osDisk: {
name: "myVMosdisk",
caching: "ReadOnly",
createOption: "FromImage",
diffDiskSettings: { option: "Local", placement: "CacheDisk" },
managedDisk: { storageAccountType: "Standard_LRS" },
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.beginCreateOrUpdateAndWait(
resourceGroupName,
vmName,
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
import com.azure.core.management.SubResource;
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.AdditionalCapabilities;
import com.azure.resourcemanager.compute.models.ApiEntityReference;
import com.azure.resourcemanager.compute.models.ApplicationProfile;
import com.azure.resourcemanager.compute.models.BootDiagnostics;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DataDisk;
import com.azure.resourcemanager.compute.models.DeleteOptions;
import com.azure.resourcemanager.compute.models.DiagnosticsProfile;
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.DiskControllerTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.DiskEncryptionSetParameters;
import com.azure.resourcemanager.compute.models.DomainNameLabelScopeTypes;
import com.azure.resourcemanager.compute.models.EventGridAndResourceGraph;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.LinuxConfiguration;
import com.azure.resourcemanager.compute.models.LinuxPatchAssessmentMode;
import com.azure.resourcemanager.compute.models.LinuxPatchSettings;
import com.azure.resourcemanager.compute.models.LinuxVMGuestPatchAutomaticByPlatformRebootSetting;
import com.azure.resourcemanager.compute.models.LinuxVMGuestPatchAutomaticByPlatformSettings;
import com.azure.resourcemanager.compute.models.LinuxVMGuestPatchMode;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.Mode;
import com.azure.resourcemanager.compute.models.NetworkApiVersion;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSImageNotificationProfile;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.OperatingSystemTypes;
import com.azure.resourcemanager.compute.models.PatchSettings;
import com.azure.resourcemanager.compute.models.Plan;
import com.azure.resourcemanager.compute.models.ProxyAgentSettings;
import com.azure.resourcemanager.compute.models.PublicIpAddressSku;
import com.azure.resourcemanager.compute.models.PublicIpAddressSkuName;
import com.azure.resourcemanager.compute.models.PublicIpAddressSkuTier;
import com.azure.resourcemanager.compute.models.PublicIpAllocationMethod;
import com.azure.resourcemanager.compute.models.ScheduledEventsAdditionalPublishingTargets;
import com.azure.resourcemanager.compute.models.ScheduledEventsPolicy;
import com.azure.resourcemanager.compute.models.ScheduledEventsProfile;
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.SshConfiguration;
import com.azure.resourcemanager.compute.models.SshPublicKey;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.TerminateNotificationProfile;
import com.azure.resourcemanager.compute.models.UefiSettings;
import com.azure.resourcemanager.compute.models.UserInitiatedReboot;
import com.azure.resourcemanager.compute.models.UserInitiatedRedeploy;
import com.azure.resourcemanager.compute.models.VMDiskSecurityProfile;
import com.azure.resourcemanager.compute.models.VMGalleryApplication;
import com.azure.resourcemanager.compute.models.VMSizeProperties;
import com.azure.resourcemanager.compute.models.VirtualHardDisk;
import com.azure.resourcemanager.compute.models.VirtualMachineNetworkInterfaceConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineNetworkInterfaceIpConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachinePublicIpAddressConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachinePublicIpAddressDnsSettingsConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import com.azure.resourcemanager.compute.models.WindowsConfiguration;
import com.azure.resourcemanager.compute.models.WindowsPatchAssessmentMode;
import com.azure.resourcemanager.compute.models.WindowsVMGuestPatchAutomaticByPlatformRebootSetting;
import com.azure.resourcemanager.compute.models.WindowsVMGuestPatchAutomaticByPlatformSettings;
import com.azure.resourcemanager.compute.models.WindowsVMGuestPatchMode;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithADiffOsDiskUsingDiffDiskPlacementAsCacheDisk.json
*/
/**
* Sample code: Create a vm with ephemeral os disk provisioning in Cache disk using placement property.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithEphemeralOsDiskProvisioningInCacheDiskUsingPlacementProperty(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withPlan(new Plan().withName("windows2016").withPublisher("microsoft-ads")
.withProduct("windows-data-science-vm"))
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_DS1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("microsoft-ads")
.withOffer("windows-data-science-vm").withSku("windows2016").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withDiffDiskSettings(new DiffDiskSettings().withOption(DiffDiskOptions.LOCAL)
.withPlacement(DiffDiskPlacement.CACHE_DISK))
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_CustomImageVmFromAnUnmanagedGeneralizedOsImage.json
*/
/**
* Sample code: Create a custom-image vm from an unmanaged generalized os image.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createACustomImageVmFromAnUnmanagedGeneralizedOsImage(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines()
.createOrUpdate("myResourceGroup", "{vm-name}", new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile().withOsDisk(new OSDisk()
.withOsType(OperatingSystemTypes.WINDOWS).withName("myVMosdisk")
.withVhd(new VirtualHardDisk().withUri(
"http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk.vhd"))
.withImage(new VirtualHardDisk().withUri(
"http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/{existing-generalized-os-image-blob-name}.vhd"))
.withCaching(CachingTypes.READ_WRITE).withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithEncryptionAtHost.json
*/
/**
* Sample code: Create a vm with Host Encryption using encryptionAtHost property.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createAVmWithHostEncryptionUsingEncryptionAtHostProperty(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withPlan(new Plan().withName("windows2016").withPublisher("microsoft-ads")
.withProduct("windows-data-science-vm"))
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_DS1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("microsoft-ads")
.withOffer("windows-data-science-vm").withSku("windows2016").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withSecurityProfile(new SecurityProfile().withEncryptionAtHost(true)),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_InAnAvailabilitySet.json
*/
/**
* Sample code: Create a vm in an availability set.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmInAnAvailabilitySet(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withAvailabilitySet(new SubResource().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/availabilitySets/{existing-availability-set-name}")),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithNetworkInterfaceConfiguration.json
*/
/**
* Sample code: Create a VM with network interface configuration.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createAVMWithNetworkInterfaceConfiguration(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(new NetworkProfile()
.withNetworkApiVersion(NetworkApiVersion.TWO_ZERO_TWO_ZERO_ONE_ONE_ZERO_ONE)
.withNetworkInterfaceConfigurations(
Arrays.asList(new VirtualMachineNetworkInterfaceConfiguration().withName("{nic-config-name}")
.withPrimary(true).withDeleteOption(DeleteOptions.DELETE)
.withIpConfigurations(Arrays.asList(new VirtualMachineNetworkInterfaceIpConfiguration()
.withName("{ip-config-name}").withPrimary(true)
.withPublicIpAddressConfiguration(new VirtualMachinePublicIpAddressConfiguration()
.withName("{publicIP-config-name}")
.withSku(new PublicIpAddressSku().withName(PublicIpAddressSkuName.BASIC)
.withTier(PublicIpAddressSkuTier.GLOBAL))
.withDeleteOption(DeleteOptions.DETACH)
.withPublicIpAllocationMethod(PublicIpAllocationMethod.STATIC))))))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithADiffOsDiskUsingDiffDiskPlacementAsNvmeDisk.json
*/
/**
* Sample code: Create a vm with ephemeral os disk provisioning in Nvme disk using placement property.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithEphemeralOsDiskProvisioningInNvmeDiskUsingPlacementProperty(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withPlan(new Plan().withName("windows2016").withPublisher("microsoft-ads")
.withProduct("windows-data-science-vm"))
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_DS1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("microsoft-ads")
.withOffer("windows-data-science-vm").withSku("windows2016").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withDiffDiskSettings(new DiffDiskSettings().withOption(DiffDiskOptions.LOCAL)
.withPlacement(DiffDiskPlacement.NVME_DISK))
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_FromASpecializedSharedImage.json
*/
/**
* Sample code: Create a vm from a specialized shared image.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmFromASpecializedSharedImage(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile().withImageReference(new ImageReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/mySharedGallery/images/mySharedImage"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithPasswordAuthentication.json
*/
/**
* Sample code: Create a vm with password authentication.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithPasswordAuthentication(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithScheduledEventsProfile.json
*/
/**
* Sample code: Create a vm with Scheduled Events Profile.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithScheduledEventsProfile(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withScheduledEventsPolicy(new ScheduledEventsPolicy()
.withUserInitiatedRedeploy(new UserInitiatedRedeploy().withAutomaticallyApprove(true))
.withUserInitiatedReboot(new UserInitiatedReboot().withAutomaticallyApprove(true))
.withScheduledEventsAdditionalPublishingTargets(new ScheduledEventsAdditionalPublishingTargets()
.withEventGridAndResourceGraph(new EventGridAndResourceGraph().withEnable(true))))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics()
.withEnabled(true).withStorageUri("http://{existing-storage-account-name}.blob.core.windows.net")))
.withScheduledEventsProfile(new ScheduledEventsProfile()
.withTerminateNotificationProfile(
new TerminateNotificationProfile().withNotBeforeTimeout("PT10M").withEnable(true))
.withOsImageNotificationProfile(
new OSImageNotificationProfile().withNotBeforeTimeout("PT15M").withEnable(true))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithADiffOsDiskUsingDiffDiskPlacementAsResourceDisk.json
*/
/**
* Sample code: Create a vm with ephemeral os disk provisioning in Resource disk using placement property.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithEphemeralOsDiskProvisioningInResourceDiskUsingPlacementProperty(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withPlan(new Plan().withName("windows2016").withPublisher("microsoft-ads")
.withProduct("windows-data-science-vm"))
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_DS1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("microsoft-ads")
.withOffer("windows-data-science-vm").withSku("windows2016").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withDiffDiskSettings(new DiffDiskSettings().withOption(DiffDiskOptions.LOCAL)
.withPlacement(DiffDiskPlacement.RESOURCE_DISK))
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithADiffOsDisk.json
*/
/**
* Sample code: Create a vm with ephemeral os disk.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithEphemeralOsDisk(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withPlan(new Plan().withName("windows2016").withPublisher("microsoft-ads")
.withProduct("windows-data-science-vm"))
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_DS1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("microsoft-ads")
.withOffer("windows-data-science-vm").withSku("windows2016").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withDiffDiskSettings(new DiffDiskSettings().withOption(DiffDiskOptions.LOCAL))
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithSecurityTypeConfidentialVMWithCustomerManagedKeys.json
*/
/**
* Sample code: Create a VM with securityType ConfidentialVM with Customer Managed Keys.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMWithSecurityTypeConfidentialVMWithCustomerManagedKeys(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(
new HardwareProfile().withVmSize(VirtualMachineSizeTypes.fromString("Standard_DC2as_v5")))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("2019-datacenter-cvm").withSku("windows-cvm").withVersion("17763.2183.2109130127"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)
.withManagedDisk(new ManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.STANDARD_SSD_LRS)
.withSecurityProfile(new VMDiskSecurityProfile()
.withSecurityEncryptionType(SecurityEncryptionTypes.DISK_WITH_VMGUEST_STATE)
.withDiskEncryptionSet(new DiskEncryptionSetParameters().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"))))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withSecurityProfile(new SecurityProfile()
.withUefiSettings(new UefiSettings().withSecureBootEnabled(true).withVTpmEnabled(true))
.withSecurityType(SecurityTypes.CONFIDENTIAL_VM)),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithDiskEncryptionSetResource.json
*/
/**
* Sample code: Create a vm with DiskEncryptionSet resource id in the os disk and data disk.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithDiskEncryptionSetResourceIdInTheOsDiskAndDataDisk(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile().withImageReference(new ImageReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/{existing-custom-image-name}"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)
.withManagedDisk(new ManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.STANDARD_LRS)
.withDiskEncryptionSet(new DiskEncryptionSetParameters().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"))))
.withDataDisks(Arrays.asList(new DataDisk().withLun(0).withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.EMPTY).withDiskSizeGB(1023)
.withManagedDisk(new ManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.STANDARD_LRS)
.withDiskEncryptionSet(new DiskEncryptionSetParameters().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"))),
new DataDisk().withLun(1).withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.ATTACH).withDiskSizeGB(1023)
.withManagedDisk(new ManagedDiskParameters().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/{existing-managed-disk-name}")
.withStorageAccountType(StorageAccountTypes.STANDARD_LRS)
.withDiskEncryptionSet(new DiskEncryptionSetParameters().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"))))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithDiskControllerType.json
*/
/**
* Sample code: Create a VM with Disk Controller Type.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMWithDiskControllerType(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D4_V3))
.withScheduledEventsPolicy(new ScheduledEventsPolicy()
.withUserInitiatedRedeploy(new UserInitiatedRedeploy().withAutomaticallyApprove(true))
.withUserInitiatedReboot(new UserInitiatedReboot().withAutomaticallyApprove(true))
.withScheduledEventsAdditionalPublishingTargets(new ScheduledEventsAdditionalPublishingTargets()
.withEventGridAndResourceGraph(new EventGridAndResourceGraph().withEnable(true))))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS)))
.withDiskControllerType(DiskControllerTypes.NVME))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics()
.withEnabled(true).withStorageUri("http://{existing-storage-account-name}.blob.core.windows.net")))
.withUserData("U29tZSBDdXN0b20gRGF0YQ=="),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_FromASharedGalleryImage.json
*/
/**
* Sample code: Create a VM from a shared gallery image.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMFromASharedGalleryImage(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withSharedGalleryImageId(
"/SharedGalleries/sharedGalleryName/Images/sharedGalleryImageName/Versions/sharedGalleryImageVersionName"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithVMSizeProperties.json
*/
/**
* Sample code: Create a VM with VM Size Properties.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMWithVMSizeProperties(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D4_V3)
.withVmSizeProperties(new VMSizeProperties().withVCpusAvailable(1).withVCpusPerCore(1)))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics()
.withEnabled(true).withStorageUri("http://{existing-storage-account-name}.blob.core.windows.net")))
.withUserData("U29tZSBDdXN0b20gRGF0YQ=="),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_PlatformImageVmWithUnmanagedOsAndDataDisks.json
*/
/**
* Sample code: Create a platform-image vm with unmanaged os and data disks.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createAPlatformImageVmWithUnmanagedOsAndDataDisks(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines()
.createOrUpdate("myResourceGroup", "{vm-name}", new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withVhd(new VirtualHardDisk().withUri(
"http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk.vhd"))
.withCaching(CachingTypes.READ_WRITE).withCreateOption(DiskCreateOptionTypes.FROM_IMAGE))
.withDataDisks(Arrays.asList(new DataDisk().withLun(0).withVhd(new VirtualHardDisk().withUri(
"http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk0.vhd"))
.withCreateOption(DiskCreateOptionTypes.EMPTY).withDiskSizeGB(1023),
new DataDisk().withLun(1).withVhd(new VirtualHardDisk().withUri(
"http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk1.vhd"))
.withCreateOption(DiskCreateOptionTypes.EMPTY).withDiskSizeGB(1023))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_LinuxVmWithPatchSettingModesOfAutomaticByPlatform.json
*/
/**
* Sample code: Create a Linux vm with a patch settings patchMode and assessmentMode set to AutomaticByPlatform.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createALinuxVmWithAPatchSettingsPatchModeAndAssessmentModeSetToAutomaticByPlatform(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2S_V3))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("Canonical").withOffer("UbuntuServer")
.withSku("16.04-LTS").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder")
.withLinuxConfiguration(new LinuxConfiguration().withProvisionVMAgent(true).withPatchSettings(
new LinuxPatchSettings().withPatchMode(LinuxVMGuestPatchMode.AUTOMATIC_BY_PLATFORM)
.withAssessmentMode(LinuxPatchAssessmentMode.AUTOMATIC_BY_PLATFORM))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithSecurityTypeConfidentialVMWithNonPersistedTPM.json
*/
/**
* Sample code: Create a VM with securityType ConfidentialVM with NonPersistedTPM securityEncryptionType.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMWithSecurityTypeConfidentialVMWithNonPersistedTPMSecurityEncryptionType(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(
new HardwareProfile().withVmSize(VirtualMachineSizeTypes.fromString("Standard_DC2es_v5")))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("UbuntuServer")
.withOffer("2022-datacenter-cvm").withSku("linux-cvm").withVersion("17763.2183.2109130127"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_SSD_LRS)
.withSecurityProfile(new VMDiskSecurityProfile()
.withSecurityEncryptionType(SecurityEncryptionTypes.NON_PERSISTED_TPM)))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withSecurityProfile(new SecurityProfile()
.withUefiSettings(new UefiSettings().withSecureBootEnabled(false).withVTpmEnabled(true))
.withSecurityType(SecurityTypes.CONFIDENTIAL_VM)),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithAMarketplaceImagePlan.json
*/
/**
* Sample code: Create a vm with a marketplace image plan.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithAMarketplaceImagePlan(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withPlan(new Plan().withName("windows2016").withPublisher("microsoft-ads")
.withProduct("windows-data-science-vm"))
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("microsoft-ads")
.withOffer("windows-data-science-vm").withSku("windows2016").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WindowsVmWithPatchSettingAssessmentModeOfImageDefault.json
*/
/**
* Sample code: Create a Windows vm with a patch setting assessmentMode of ImageDefault.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAWindowsVmWithAPatchSettingAssessmentModeOfImageDefault(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder")
.withWindowsConfiguration(new WindowsConfiguration().withProvisionVMAgent(true)
.withEnableAutomaticUpdates(true).withPatchSettings(
new PatchSettings().withAssessmentMode(WindowsPatchAssessmentMode.IMAGE_DEFAULT))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/
* VirtualMachine_Create_WindowsVmWithPatchSettingModeOfAutomaticByPlatformAndEnableHotPatchingTrue.json
*/
/**
* Sample code: Create a Windows vm with a patch setting patchMode of AutomaticByPlatform and enableHotpatching set
* to true.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAWindowsVmWithAPatchSettingPatchModeOfAutomaticByPlatformAndEnableHotpatchingSetToTrue(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder")
.withWindowsConfiguration(new WindowsConfiguration().withProvisionVMAgent(true)
.withEnableAutomaticUpdates(true)
.withPatchSettings(new PatchSettings()
.withPatchMode(WindowsVMGuestPatchMode.AUTOMATIC_BY_PLATFORM).withEnableHotpatching(true))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithExtensionsTimeBudget.json
*/
/**
* Sample code: Create a vm with an extensions time budget.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithAnExtensionsTimeBudget(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics()
.withEnabled(true).withStorageUri("http://{existing-storage-account-name}.blob.core.windows.net")))
.withExtensionsTimeBudget("PT30M"),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithEmptyDataDisks.json
*/
/**
* Sample code: Create a vm with empty data disks.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithEmptyDataDisks(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS)))
.withDataDisks(Arrays.asList(
new DataDisk().withLun(0).withCreateOption(DiskCreateOptionTypes.EMPTY).withDiskSizeGB(1023),
new DataDisk().withLun(1).withCreateOption(DiskCreateOptionTypes.EMPTY).withDiskSizeGB(1023))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithSecurityTypeConfidentialVM.json
*/
/**
* Sample code: Create a VM with securityType ConfidentialVM with Platform Managed Keys.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMWithSecurityTypeConfidentialVMWithPlatformManagedKeys(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(
new HardwareProfile().withVmSize(VirtualMachineSizeTypes.fromString("Standard_DC2as_v5")))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("2019-datacenter-cvm").withSku("windows-cvm").withVersion("17763.2183.2109130127"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_SSD_LRS)
.withSecurityProfile(new VMDiskSecurityProfile()
.withSecurityEncryptionType(SecurityEncryptionTypes.DISK_WITH_VMGUEST_STATE)))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withSecurityProfile(new SecurityProfile()
.withUefiSettings(new UefiSettings().withSecureBootEnabled(true).withVTpmEnabled(true))
.withSecurityType(SecurityTypes.CONFIDENTIAL_VM)),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithDataDisksFromSourceResource.json
*/
/**
* Sample code: Create a vm with data disks using 'Copy' and 'Restore' options.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createAVmWithDataDisksUsingCopyAndRestoreOptions(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS)))
.withDataDisks(Arrays.asList(new DataDisk().withLun(0).withCreateOption(DiskCreateOptionTypes.COPY)
.withDiskSizeGB(1023)
.withSourceResource(new ApiEntityReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/{existing-snapshot-name}")),
new DataDisk().withLun(1).withCreateOption(DiskCreateOptionTypes.COPY).withDiskSizeGB(1023)
.withSourceResource(new ApiEntityReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/{existing-disk-name}")),
new DataDisk().withLun(2).withCreateOption(DiskCreateOptionTypes.RESTORE).withDiskSizeGB(1023)
.withSourceResource(new ApiEntityReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/restorePointCollections/{existing-rpc-name}/restorePoints/{existing-rp-name}/diskRestorePoints/{existing-disk-restore-point-name}")))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_FromACustomImage.json
*/
/**
* Sample code: Create a vm from a custom image.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmFromACustomImage(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile().withImageReference(new ImageReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/{existing-custom-image-name}"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithHibernationEnabled.json
*/
/**
* Sample code: Create a VM with HibernationEnabled.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMWithHibernationEnabled(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup",
"{vm-name}",
new VirtualMachineInner().withLocation("eastus2euap")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2S_V3))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2019-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("vmOSdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withAdditionalCapabilities(new AdditionalCapabilities().withHibernationEnabled(true))
.withOsProfile(new OSProfile().withComputerName("{vm-name}").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics()
.withEnabled(true).withStorageUri("http://{existing-storage-account-name}.blob.core.windows.net"))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithUefiSettings.json
*/
/**
* Sample code: Create a VM with Uefi Settings of secureBoot and vTPM.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createAVMWithUefiSettingsOfSecureBootAndVTPM(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2S_V3))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference()
.withPublisher("MicrosoftWindowsServer").withOffer("windowsserver-gen2preview-preview")
.withSku("windows10-tvm").withVersion("18363.592.2001092016"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_SSD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withSecurityProfile(new SecurityProfile()
.withUefiSettings(new UefiSettings().withSecureBootEnabled(true).withVTpmEnabled(true))
.withSecurityType(SecurityTypes.TRUSTED_LAUNCH)),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithApplicationProfile.json
*/
/**
* Sample code: Create a vm with Application Profile.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithApplicationProfile(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("{image_publisher}")
.withOffer("{image_offer}").withSku("{image_sku}").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(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(false).withEnableAutomaticUpgrade(false),
new VMGalleryApplication().withPackageReferenceId(
"/subscriptions/32c17a9e-aa7b-4ba5-a45b-e324116b6fdg/resourceGroups/myresourceGroupName3/providers/Microsoft.Compute/galleries/myGallery2/applications/MyApplication2/versions/1.1")))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithNetworkInterfaceConfigurationDnsSettings.json
*/
/**
* Sample code: Create a VM with network interface configuration with public ip address dns settings.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMWithNetworkInterfaceConfigurationWithPublicIpAddressDnsSettings(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkApiVersion(NetworkApiVersion.TWO_ZERO_TWO_ZERO_ONE_ONE_ZERO_ONE)
.withNetworkInterfaceConfigurations(
Arrays.asList(new VirtualMachineNetworkInterfaceConfiguration()
.withName("{nic-config-name}").withPrimary(true).withDeleteOption(DeleteOptions.DELETE)
.withIpConfigurations(Arrays.asList(new VirtualMachineNetworkInterfaceIpConfiguration()
.withName("{ip-config-name}").withPrimary(true)
.withPublicIpAddressConfiguration(new VirtualMachinePublicIpAddressConfiguration()
.withName("{publicIP-config-name}")
.withSku(new PublicIpAddressSku().withName(PublicIpAddressSkuName.BASIC)
.withTier(PublicIpAddressSkuTier.GLOBAL))
.withDeleteOption(DeleteOptions.DETACH)
.withDnsSettings(new VirtualMachinePublicIpAddressDnsSettingsConfiguration()
.withDomainNameLabel("aaaaa")
.withDomainNameLabelScope(DomainNameLabelScopeTypes.TENANT_REUSE))
.withPublicIpAllocationMethod(PublicIpAllocationMethod.STATIC))))))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_InAVmssWithCustomerAssignedPlatformFaultDomain.json
*/
/**
* Sample code: Create a vm in a Virtual Machine Scale Set with customer assigned platformFaultDomain.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmInAVirtualMachineScaleSetWithCustomerAssignedPlatformFaultDomain(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withVirtualMachineScaleSet(new SubResource().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{existing-flex-vmss-name-with-platformFaultDomainCount-greater-than-1}"))
.withPlatformFaultDomain(1),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithBootDiagnostics.json
*/
/**
* Sample code: Create a vm with boot diagnostics.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithBootDiagnostics(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics()
.withEnabled(true).withStorageUri("http://{existing-storage-account-name}.blob.core.windows.net"))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithSshAuthentication.json
*/
/**
* Sample code: Create a vm with ssh authentication.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithSshAuthentication(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("{image_publisher}")
.withOffer("{image_offer}").withSku("{image_sku}").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").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"))))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_FromACommunityGalleryImage.json
*/
/**
* Sample code: Create a VM from a community gallery image.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMFromACommunityGalleryImage(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withCommunityGalleryImageId(
"/CommunityGalleries/galleryPublicName/Images/communityGalleryImageName/Versions/communityGalleryImageVersionName"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithUserData.json
*/
/**
* Sample code: Create a VM with UserData.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMWithUserData(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup",
"{vm-name}",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("vmOSdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("{vm-name}").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics()
.withEnabled(true).withStorageUri("http://{existing-storage-account-name}.blob.core.windows.net")))
.withUserData("RXhhbXBsZSBVc2VyRGF0YQ=="),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_FromAGeneralizedSharedImage.json
*/
/**
* Sample code: Create a vm from a generalized shared image.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmFromAGeneralizedSharedImage(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile().withImageReference(new ImageReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/mySharedGallery/images/mySharedImage"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_LinuxVmWithAutomaticByPlatformSettings.json
*/
/**
* Sample code: Create a Linux vm with a patch setting patchMode of AutomaticByPlatform and
* AutomaticByPlatformSettings.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createALinuxVmWithAPatchSettingPatchModeOfAutomaticByPlatformAndAutomaticByPlatformSettings(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2S_V3))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("Canonical").withOffer("UbuntuServer")
.withSku("16.04-LTS").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder")
.withLinuxConfiguration(new LinuxConfiguration().withProvisionVMAgent(true).withPatchSettings(
new LinuxPatchSettings().withPatchMode(LinuxVMGuestPatchMode.AUTOMATIC_BY_PLATFORM)
.withAssessmentMode(LinuxPatchAssessmentMode.AUTOMATIC_BY_PLATFORM)
.withAutomaticByPlatformSettings(new LinuxVMGuestPatchAutomaticByPlatformSettings()
.withRebootSetting(LinuxVMGuestPatchAutomaticByPlatformRebootSetting.NEVER)
.withBypassPlatformSafetyChecksOnUserSchedule(true)))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WindowsVmWithPatchSettingModeOfManual.json
*/
/**
* Sample code: Create a Windows vm with a patch setting patchMode of Manual.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createAWindowsVmWithAPatchSettingPatchModeOfManual(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder").withWindowsConfiguration(
new WindowsConfiguration().withProvisionVMAgent(true).withEnableAutomaticUpdates(true)
.withPatchSettings(new PatchSettings().withPatchMode(WindowsVMGuestPatchMode.MANUAL))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithProxyAgentSettings.json
*/
/**
* Sample code: Create a VM with ProxyAgent Settings of enabled and mode.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createAVMWithProxyAgentSettingsOfEnabledAndMode(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2S_V3))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2019-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_SSD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withSecurityProfile(new SecurityProfile()
.withProxyAgentSettings(new ProxyAgentSettings().withEnabled(true).withMode(Mode.ENFORCE))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_LinuxVmWithPatchSettingModeOfImageDefault.json
*/
/**
* Sample code: Create a Linux vm with a patch setting patchMode of ImageDefault.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createALinuxVmWithAPatchSettingPatchModeOfImageDefault(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2S_V3))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("Canonical").withOffer("UbuntuServer")
.withSku("16.04-LTS").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder")
.withLinuxConfiguration(new LinuxConfiguration().withProvisionVMAgent(true).withPatchSettings(
new LinuxPatchSettings().withPatchMode(LinuxVMGuestPatchMode.IMAGE_DEFAULT))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithManagedBootDiagnostics.json
*/
/**
* Sample code: Create a vm with managed boot diagnostics.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithManagedBootDiagnostics(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(
new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics().withEnabled(true))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WindowsVmWithAutomaticByPlatformSettings.json
*/
/**
* Sample code: Create a Windows vm with a patch setting patchMode of AutomaticByPlatform and
* AutomaticByPlatformSettings.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAWindowsVmWithAPatchSettingPatchModeOfAutomaticByPlatformAndAutomaticByPlatformSettings(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder").withWindowsConfiguration(
new WindowsConfiguration().withProvisionVMAgent(true).withEnableAutomaticUpdates(true)
.withPatchSettings(new PatchSettings()
.withPatchMode(WindowsVMGuestPatchMode.AUTOMATIC_BY_PLATFORM)
.withAssessmentMode(WindowsPatchAssessmentMode.AUTOMATIC_BY_PLATFORM)
.withAutomaticByPlatformSettings(new WindowsVMGuestPatchAutomaticByPlatformSettings()
.withRebootSetting(WindowsVMGuestPatchAutomaticByPlatformRebootSetting.NEVER)
.withBypassPlatformSafetyChecksOnUserSchedule(false)))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
範例回覆
{
"name": "myVM",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "standard-data-science-vm",
"publisher": "microsoft-ads",
"version": "latest",
"offer": "standard-data-science-vm"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadOnly",
"diffDiskSettings": {
"option": "Local",
"placement": "CacheDisk"
},
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"createOption": "FromImage",
"name": "myVMosdisk"
},
"dataDisks": []
},
"vmId": "5c0d55a7-c407-4ed6-bf7d-ddb810267c85",
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"provisioningState": "Creating"
},
"plan": {
"publisher": "microsoft-ads",
"product": "standard-data-science-vm",
"name": "standard-data-science-vm"
},
"type": "Microsoft.Compute/virtualMachines",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"location": "westus"
}
{
"name": "myVM",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "standard-data-science-vm",
"publisher": "microsoft-ads",
"version": "latest",
"offer": "standard-data-science-vm"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadOnly",
"diffDiskSettings": {
"option": "Local",
"placement": "CacheDisk"
},
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"createOption": "FromImage",
"name": "myVMosdisk"
},
"dataDisks": []
},
"vmId": "5c0d55a7-c407-4ed6-bf7d-ddb810267c85",
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"provisioningState": "Creating"
},
"plan": {
"publisher": "microsoft-ads",
"product": "standard-data-science-vm",
"name": "standard-data-science-vm"
},
"type": "Microsoft.Compute/virtualMachines",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"location": "westus"
}
Create a vm with ephemeral os disk provisioning in Nvme disk using placement property.
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2024-03-01
{
"location": "westus",
"plan": {
"publisher": "microsoft-ads",
"product": "windows-data-science-vm",
"name": "windows2016"
},
"properties": {
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"storageProfile": {
"imageReference": {
"sku": "windows2016",
"publisher": "microsoft-ads",
"version": "latest",
"offer": "windows-data-science-vm"
},
"osDisk": {
"caching": "ReadOnly",
"diffDiskSettings": {
"option": "Local",
"placement": "NvmeDisk"
},
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"createOption": "FromImage",
"name": "myVMosdisk"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
from typing import Any, IO, Union
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_create_with_adiff_os_disk_using_diff_disk_placement_as_nvme_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_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"plan": {"name": "windows2016", "product": "windows-data-science-vm", "publisher": "microsoft-ads"},
"properties": {
"hardwareProfile": {"vmSize": "Standard_DS1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"storageProfile": {
"imageReference": {
"offer": "windows-data-science-vm",
"publisher": "microsoft-ads",
"sku": "windows2016",
"version": "latest",
},
"osDisk": {
"caching": "ReadOnly",
"createOption": "FromImage",
"diffDiskSettings": {"option": "Local", "placement": "NvmeDisk"},
"managedDisk": {"storageAccountType": "Standard_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithADiffOsDiskUsingDiffDiskPlacementAsNvmeDisk.json
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/v5"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/92de53a5f1e0e03c94b40475d2135d97148ed014/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithADiffOsDiskUsingDiffDiskPlacementAsNvmeDisk.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVmWithEphemeralOsDiskProvisioningInNvmeDiskUsingPlacementProperty() {
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.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
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.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardDS1V2),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
}},
},
OSProfile: &armcompute.OSProfile{
AdminPassword: to.Ptr("{your-password}"),
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
},
StorageProfile: &armcompute.StorageProfile{
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.OSDisk{
Name: to.Ptr("myVMosdisk"),
Caching: to.Ptr(armcompute.CachingTypesReadOnly),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
DiffDiskSettings: &armcompute.DiffDiskSettings{
Option: to.Ptr(armcompute.DiffDiskOptionsLocal),
Placement: to.Ptr(armcompute.DiffDiskPlacementNvmeDisk),
},
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
},
}, &armcompute.VirtualMachinesClientBeginCreateOrUpdateOptions{IfMatch: nil,
IfNoneMatch: 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)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.VirtualMachine = armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// Plan: &armcompute.Plan{
// Name: to.Ptr("standard-data-science-vm"),
// Product: to.Ptr("standard-data-science-vm"),
// Publisher: to.Ptr("microsoft-ads"),
// },
// Properties: &armcompute.VirtualMachineProperties{
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardDS1V2),
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// }},
// },
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// ComputerName: to.Ptr("myVM"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// EnableAutomaticUpdates: to.Ptr(true),
// ProvisionVMAgent: to.Ptr(true),
// },
// },
// ProvisioningState: to.Ptr("Succeeded"),
// StorageProfile: &armcompute.StorageProfile{
// DataDisks: []*armcompute.DataDisk{
// },
// ImageReference: &armcompute.ImageReference{
// Offer: to.Ptr("standard-data-science-vm"),
// Publisher: to.Ptr("microsoft-ads"),
// SKU: to.Ptr("standard-data-science-vm"),
// Version: to.Ptr("latest"),
// },
// OSDisk: &armcompute.OSDisk{
// Name: to.Ptr("myVMosdisk"),
// Caching: to.Ptr(armcompute.CachingTypesReadOnly),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// DiffDiskSettings: &armcompute.DiffDiskSettings{
// Option: to.Ptr(armcompute.DiffDiskOptionsLocal),
// Placement: to.Ptr(armcompute.DiffDiskPlacementNvmeDisk),
// },
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// },
// },
// VMID: to.Ptr("5c0d55a7-c407-4ed6-bf7d-ddb810267c85"),
// },
// }
}
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");
/**
* This sample demonstrates how to The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithADiffOsDiskUsingDiffDiskPlacementAsNvmeDisk.json
*/
async function createAVMWithEphemeralOSDiskProvisioningInNvmeDiskUsingPlacementProperty() {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP"] || "myResourceGroup";
const vmName = "myVM";
const parameters = {
hardwareProfile: { vmSize: "Standard_DS1_v2" },
location: "westus",
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
osProfile: {
adminPassword: "{your-password}",
adminUsername: "{your-username}",
computerName: "myVM",
},
plan: {
name: "windows2016",
product: "windows-data-science-vm",
publisher: "microsoft-ads",
},
storageProfile: {
imageReference: {
offer: "windows-data-science-vm",
publisher: "microsoft-ads",
sku: "windows2016",
version: "latest",
},
osDisk: {
name: "myVMosdisk",
caching: "ReadOnly",
createOption: "FromImage",
diffDiskSettings: { option: "Local", placement: "NvmeDisk" },
managedDisk: { storageAccountType: "Standard_LRS" },
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.beginCreateOrUpdateAndWait(
resourceGroupName,
vmName,
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
範例回覆
{
"name": "myVM",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "standard-data-science-vm",
"publisher": "microsoft-ads",
"version": "latest",
"offer": "standard-data-science-vm"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadOnly",
"diffDiskSettings": {
"option": "Local",
"placement": "NvmeDisk"
},
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"createOption": "FromImage",
"name": "myVMosdisk"
},
"dataDisks": []
},
"vmId": "5c0d55a7-c407-4ed6-bf7d-ddb810267c85",
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"provisioningState": "Creating"
},
"plan": {
"publisher": "microsoft-ads",
"product": "standard-data-science-vm",
"name": "standard-data-science-vm"
},
"type": "Microsoft.Compute/virtualMachines",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"location": "westus"
}
{
"name": "myVM",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "standard-data-science-vm",
"publisher": "microsoft-ads",
"version": "latest",
"offer": "standard-data-science-vm"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadOnly",
"diffDiskSettings": {
"option": "Local",
"placement": "NvmeDisk"
},
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"createOption": "FromImage",
"name": "myVMosdisk"
},
"dataDisks": []
},
"vmId": "5c0d55a7-c407-4ed6-bf7d-ddb810267c85",
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"provisioningState": "Creating"
},
"plan": {
"publisher": "microsoft-ads",
"product": "standard-data-science-vm",
"name": "standard-data-science-vm"
},
"type": "Microsoft.Compute/virtualMachines",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"location": "westus"
}
Create a vm with ephemeral os disk provisioning in Resource disk using placement property.
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2024-03-01
{
"location": "westus",
"plan": {
"publisher": "microsoft-ads",
"product": "windows-data-science-vm",
"name": "windows2016"
},
"properties": {
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"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",
"name": "myVMosdisk"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
from typing import Any, IO, Union
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_create_with_adiff_os_disk_using_diff_disk_placement_as_resource_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_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"plan": {"name": "windows2016", "product": "windows-data-science-vm", "publisher": "microsoft-ads"},
"properties": {
"hardwareProfile": {"vmSize": "Standard_DS1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"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"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithADiffOsDiskUsingDiffDiskPlacementAsResourceDisk.json
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/v5"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/92de53a5f1e0e03c94b40475d2135d97148ed014/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithADiffOsDiskUsingDiffDiskPlacementAsResourceDisk.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVmWithEphemeralOsDiskProvisioningInResourceDiskUsingPlacementProperty() {
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.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
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.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardDS1V2),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
}},
},
OSProfile: &armcompute.OSProfile{
AdminPassword: to.Ptr("{your-password}"),
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
},
StorageProfile: &armcompute.StorageProfile{
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.OSDisk{
Name: to.Ptr("myVMosdisk"),
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.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
},
}, &armcompute.VirtualMachinesClientBeginCreateOrUpdateOptions{IfMatch: nil,
IfNoneMatch: 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)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.VirtualMachine = armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// Plan: &armcompute.Plan{
// Name: to.Ptr("standard-data-science-vm"),
// Product: to.Ptr("standard-data-science-vm"),
// Publisher: to.Ptr("microsoft-ads"),
// },
// Properties: &armcompute.VirtualMachineProperties{
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardDS1V2),
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// }},
// },
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// ComputerName: to.Ptr("myVM"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// EnableAutomaticUpdates: to.Ptr(true),
// ProvisionVMAgent: to.Ptr(true),
// },
// },
// ProvisioningState: to.Ptr("Succeeded"),
// StorageProfile: &armcompute.StorageProfile{
// DataDisks: []*armcompute.DataDisk{
// },
// ImageReference: &armcompute.ImageReference{
// Offer: to.Ptr("standard-data-science-vm"),
// Publisher: to.Ptr("microsoft-ads"),
// SKU: to.Ptr("standard-data-science-vm"),
// Version: to.Ptr("latest"),
// },
// OSDisk: &armcompute.OSDisk{
// Name: to.Ptr("myVMosdisk"),
// 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.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// },
// },
// VMID: to.Ptr("5c0d55a7-c407-4ed6-bf7d-ddb810267c85"),
// },
// }
}
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");
/**
* This sample demonstrates how to The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithADiffOsDiskUsingDiffDiskPlacementAsResourceDisk.json
*/
async function createAVMWithEphemeralOSDiskProvisioningInResourceDiskUsingPlacementProperty() {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP"] || "myResourceGroup";
const vmName = "myVM";
const parameters = {
hardwareProfile: { vmSize: "Standard_DS1_v2" },
location: "westus",
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
osProfile: {
adminPassword: "{your-password}",
adminUsername: "{your-username}",
computerName: "myVM",
},
plan: {
name: "windows2016",
product: "windows-data-science-vm",
publisher: "microsoft-ads",
},
storageProfile: {
imageReference: {
offer: "windows-data-science-vm",
publisher: "microsoft-ads",
sku: "windows2016",
version: "latest",
},
osDisk: {
name: "myVMosdisk",
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.virtualMachines.beginCreateOrUpdateAndWait(
resourceGroupName,
vmName,
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
範例回覆
{
"name": "myVM",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "standard-data-science-vm",
"publisher": "microsoft-ads",
"version": "latest",
"offer": "standard-data-science-vm"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadOnly",
"diffDiskSettings": {
"option": "Local",
"placement": "ResourceDisk"
},
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"createOption": "FromImage",
"name": "myVMosdisk"
},
"dataDisks": []
},
"vmId": "5c0d55a7-c407-4ed6-bf7d-ddb810267c85",
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"provisioningState": "Creating"
},
"plan": {
"publisher": "microsoft-ads",
"product": "standard-data-science-vm",
"name": "standard-data-science-vm"
},
"type": "Microsoft.Compute/virtualMachines",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"location": "westus"
}
{
"name": "myVM",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "standard-data-science-vm",
"publisher": "microsoft-ads",
"version": "latest",
"offer": "standard-data-science-vm"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadOnly",
"diffDiskSettings": {
"option": "Local",
"placement": "ResourceDisk"
},
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"createOption": "FromImage",
"name": "myVMosdisk"
},
"dataDisks": []
},
"vmId": "5c0d55a7-c407-4ed6-bf7d-ddb810267c85",
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"provisioningState": "Creating"
},
"plan": {
"publisher": "microsoft-ads",
"product": "standard-data-science-vm",
"name": "standard-data-science-vm"
},
"type": "Microsoft.Compute/virtualMachines",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"location": "westus"
}
Create a vm with ephemeral os disk.
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2024-03-01
{
"location": "westus",
"plan": {
"publisher": "microsoft-ads",
"product": "windows-data-science-vm",
"name": "windows2016"
},
"properties": {
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"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",
"name": "myVMosdisk"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
from typing import Any, IO, Union
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_create_with_adiff_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_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"plan": {"name": "windows2016", "product": "windows-data-science-vm", "publisher": "microsoft-ads"},
"properties": {
"hardwareProfile": {"vmSize": "Standard_DS1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"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"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithADiffOsDisk.json
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/v5"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/92de53a5f1e0e03c94b40475d2135d97148ed014/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithADiffOsDisk.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVmWithEphemeralOsDisk() {
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.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
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.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardDS1V2),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
}},
},
OSProfile: &armcompute.OSProfile{
AdminPassword: to.Ptr("{your-password}"),
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
},
StorageProfile: &armcompute.StorageProfile{
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.OSDisk{
Name: to.Ptr("myVMosdisk"),
Caching: to.Ptr(armcompute.CachingTypesReadOnly),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
DiffDiskSettings: &armcompute.DiffDiskSettings{
Option: to.Ptr(armcompute.DiffDiskOptionsLocal),
},
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
},
}, &armcompute.VirtualMachinesClientBeginCreateOrUpdateOptions{IfMatch: nil,
IfNoneMatch: 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)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.VirtualMachine = armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// Plan: &armcompute.Plan{
// Name: to.Ptr("standard-data-science-vm"),
// Product: to.Ptr("standard-data-science-vm"),
// Publisher: to.Ptr("microsoft-ads"),
// },
// Properties: &armcompute.VirtualMachineProperties{
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardDS1V2),
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// }},
// },
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// ComputerName: to.Ptr("myVM"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// EnableAutomaticUpdates: to.Ptr(true),
// ProvisionVMAgent: to.Ptr(true),
// },
// },
// ProvisioningState: to.Ptr("Succeeded"),
// StorageProfile: &armcompute.StorageProfile{
// DataDisks: []*armcompute.DataDisk{
// },
// ImageReference: &armcompute.ImageReference{
// Offer: to.Ptr("standard-data-science-vm"),
// Publisher: to.Ptr("microsoft-ads"),
// SKU: to.Ptr("standard-data-science-vm"),
// Version: to.Ptr("latest"),
// },
// OSDisk: &armcompute.OSDisk{
// Name: to.Ptr("myVMosdisk"),
// Caching: to.Ptr(armcompute.CachingTypesReadOnly),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// DiffDiskSettings: &armcompute.DiffDiskSettings{
// Option: to.Ptr(armcompute.DiffDiskOptionsLocal),
// },
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// },
// },
// VMID: to.Ptr("5c0d55a7-c407-4ed6-bf7d-ddb810267c85"),
// },
// }
}
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");
/**
* This sample demonstrates how to The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithADiffOsDisk.json
*/
async function createAVMWithEphemeralOSDisk() {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP"] || "myResourceGroup";
const vmName = "myVM";
const parameters = {
hardwareProfile: { vmSize: "Standard_DS1_v2" },
location: "westus",
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
osProfile: {
adminPassword: "{your-password}",
adminUsername: "{your-username}",
computerName: "myVM",
},
plan: {
name: "windows2016",
product: "windows-data-science-vm",
publisher: "microsoft-ads",
},
storageProfile: {
imageReference: {
offer: "windows-data-science-vm",
publisher: "microsoft-ads",
sku: "windows2016",
version: "latest",
},
osDisk: {
name: "myVMosdisk",
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.virtualMachines.beginCreateOrUpdateAndWait(
resourceGroupName,
vmName,
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
範例回覆
{
"name": "myVM",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "standard-data-science-vm",
"publisher": "microsoft-ads",
"version": "latest",
"offer": "standard-data-science-vm"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadOnly",
"diffDiskSettings": {
"option": "Local"
},
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"createOption": "FromImage",
"name": "myVMosdisk"
},
"dataDisks": []
},
"vmId": "5c0d55a7-c407-4ed6-bf7d-ddb810267c85",
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"provisioningState": "Creating"
},
"plan": {
"publisher": "microsoft-ads",
"product": "standard-data-science-vm",
"name": "standard-data-science-vm"
},
"type": "Microsoft.Compute/virtualMachines",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"location": "westus"
}
{
"name": "myVM",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "standard-data-science-vm",
"publisher": "microsoft-ads",
"version": "latest",
"offer": "standard-data-science-vm"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadOnly",
"diffDiskSettings": {
"option": "Local"
},
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"createOption": "FromImage",
"name": "myVMosdisk"
},
"dataDisks": []
},
"vmId": "5c0d55a7-c407-4ed6-bf7d-ddb810267c85",
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"provisioningState": "Creating"
},
"plan": {
"publisher": "microsoft-ads",
"product": "standard-data-science-vm",
"name": "standard-data-science-vm"
},
"type": "Microsoft.Compute/virtualMachines",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"location": "westus"
}
Create a VM with HibernationEnabled
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/{vm-name}?api-version=2024-03-01
{
"location": "eastus2euap",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D2s_v3"
},
"additionalCapabilities": {
"hibernationEnabled": true
},
"storageProfile": {
"imageReference": {
"publisher": "MicrosoftWindowsServer",
"offer": "WindowsServer",
"sku": "2019-Datacenter",
"version": "latest"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"name": "vmOSdisk",
"createOption": "FromImage"
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "{vm-name}",
"adminPassword": "{your-password}"
},
"diagnosticsProfile": {
"bootDiagnostics": {
"storageUri": "http://{existing-storage-account-name}.blob.core.windows.net",
"enabled": true
}
}
}
}
from typing import Any, IO, Union
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_create_with_hibernation_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_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="{vm-name}",
parameters={
"location": "eastus2euap",
"properties": {
"additionalCapabilities": {"hibernationEnabled": True},
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": True,
"storageUri": "http://{existing-storage-account-name}.blob.core.windows.net",
}
},
"hardwareProfile": {"vmSize": "Standard_D2s_v3"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "{vm-name}",
},
"storageProfile": {
"imageReference": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2019-Datacenter",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Standard_LRS"},
"name": "vmOSdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithHibernationEnabled.json
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/v5"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/92de53a5f1e0e03c94b40475d2135d97148ed014/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithHibernationEnabled.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVmWithHibernationEnabled() {
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.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "{vm-name}", armcompute.VirtualMachine{
Location: to.Ptr("eastus2euap"),
Properties: &armcompute.VirtualMachineProperties{
AdditionalCapabilities: &armcompute.AdditionalCapabilities{
HibernationEnabled: to.Ptr(true),
},
DiagnosticsProfile: &armcompute.DiagnosticsProfile{
BootDiagnostics: &armcompute.BootDiagnostics{
Enabled: to.Ptr(true),
StorageURI: to.Ptr("http://{existing-storage-account-name}.blob.core.windows.net"),
},
},
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD2SV3),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
}},
},
OSProfile: &armcompute.OSProfile{
AdminPassword: to.Ptr("{your-password}"),
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("{vm-name}"),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("WindowsServer"),
Publisher: to.Ptr("MicrosoftWindowsServer"),
SKU: to.Ptr("2019-Datacenter"),
Version: to.Ptr("latest"),
},
OSDisk: &armcompute.OSDisk{
Name: to.Ptr("vmOSdisk"),
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
},
}, &armcompute.VirtualMachinesClientBeginCreateOrUpdateOptions{IfMatch: nil,
IfNoneMatch: 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)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.VirtualMachine = armcompute.VirtualMachine{
// Name: to.Ptr("{vm-name}"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/{vm-name}"),
// Location: to.Ptr("eastus2euap"),
// Properties: &armcompute.VirtualMachineProperties{
// AdditionalCapabilities: &armcompute.AdditionalCapabilities{
// HibernationEnabled: to.Ptr(true),
// },
// DiagnosticsProfile: &armcompute.DiagnosticsProfile{
// BootDiagnostics: &armcompute.BootDiagnostics{
// Enabled: to.Ptr(true),
// StorageURI: to.Ptr("http://nsgdiagnostic.blob.core.windows.net"),
// },
// },
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD2SV3),
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// }},
// },
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// ComputerName: to.Ptr("{vm-name}"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// EnableAutomaticUpdates: to.Ptr(true),
// ProvisionVMAgent: to.Ptr(true),
// },
// },
// ProvisioningState: to.Ptr("Succeeded"),
// StorageProfile: &armcompute.StorageProfile{
// DataDisks: []*armcompute.DataDisk{
// },
// ImageReference: &armcompute.ImageReference{
// Offer: to.Ptr("WindowsServer"),
// Publisher: to.Ptr("MicrosoftWindowsServer"),
// SKU: to.Ptr("2019-Datacenter"),
// Version: to.Ptr("latest"),
// },
// OSDisk: &armcompute.OSDisk{
// Name: to.Ptr("vmOSdisk"),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// },
// },
// VMID: to.Ptr("676420ba-7a24-4bfe-80bd-9c841ee184fa"),
// },
// }
}
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");
/**
* This sample demonstrates how to The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithHibernationEnabled.json
*/
async function createAVMWithHibernationEnabled() {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP"] || "myResourceGroup";
const vmName = "{vm-name}";
const parameters = {
additionalCapabilities: { hibernationEnabled: true },
diagnosticsProfile: {
bootDiagnostics: {
enabled: true,
storageUri: "http://{existing-storage-account-name}.blob.core.windows.net",
},
},
hardwareProfile: { vmSize: "Standard_D2s_v3" },
location: "eastus2euap",
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
osProfile: {
adminPassword: "{your-password}",
adminUsername: "{your-username}",
computerName: "{vm-name}",
},
storageProfile: {
imageReference: {
offer: "WindowsServer",
publisher: "MicrosoftWindowsServer",
sku: "2019-Datacenter",
version: "latest",
},
osDisk: {
name: "vmOSdisk",
caching: "ReadWrite",
createOption: "FromImage",
managedDisk: { storageAccountType: "Standard_LRS" },
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.beginCreateOrUpdateAndWait(
resourceGroupName,
vmName,
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
範例回覆
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/{vm-name}",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "{vm-name}",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"publisher": "MicrosoftWindowsServer",
"offer": "WindowsServer",
"sku": "2019-Datacenter",
"version": "latest"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "vmOSdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"diagnosticsProfile": {
"bootDiagnostics": {
"storageUri": "http://nsgdiagnostic.blob.core.windows.net",
"enabled": true
}
},
"vmId": "676420ba-7a24-4bfe-80bd-9c841ee184fa",
"hardwareProfile": {
"vmSize": "Standard_D2s_v3"
},
"additionalCapabilities": {
"hibernationEnabled": true
},
"provisioningState": "Updating"
},
"name": "{vm-name}",
"location": "eastus2euap"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/{vm-name}",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "{vm-name}",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"publisher": "MicrosoftWindowsServer",
"offer": "WindowsServer",
"sku": "2019-Datacenter",
"version": "latest"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "vmOSdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"diagnosticsProfile": {
"bootDiagnostics": {
"storageUri": "http://nsgdiagnostic.blob.core.windows.net",
"enabled": true
}
},
"vmId": "676420ba-7a24-4bfe-80bd-9c841ee184fa",
"hardwareProfile": {
"vmSize": "Standard_D2s_v3"
},
"additionalCapabilities": {
"hibernationEnabled": true
},
"provisioningState": "Creating"
},
"name": "{vm-name}",
"location": "eastus2euap"
}
Create a vm with Host Encryption using encryptionAtHost property.
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2024-03-01
{
"location": "westus",
"plan": {
"publisher": "microsoft-ads",
"product": "windows-data-science-vm",
"name": "windows2016"
},
"properties": {
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"securityProfile": {
"encryptionAtHost": true
},
"storageProfile": {
"imageReference": {
"sku": "windows2016",
"publisher": "microsoft-ads",
"version": "latest",
"offer": "windows-data-science-vm"
},
"osDisk": {
"caching": "ReadOnly",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"createOption": "FromImage",
"name": "myVMosdisk"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
from typing import Any, IO, Union
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_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_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"plan": {"name": "windows2016", "product": "windows-data-science-vm", "publisher": "microsoft-ads"},
"properties": {
"hardwareProfile": {"vmSize": "Standard_DS1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"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"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithEncryptionAtHost.json
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/v5"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/92de53a5f1e0e03c94b40475d2135d97148ed014/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithEncryptionAtHost.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVmWithHostEncryptionUsingEncryptionAtHostProperty() {
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.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
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.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardDS1V2),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
}},
},
OSProfile: &armcompute.OSProfile{
AdminPassword: to.Ptr("{your-password}"),
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
},
SecurityProfile: &armcompute.SecurityProfile{
EncryptionAtHost: to.Ptr(true),
},
StorageProfile: &armcompute.StorageProfile{
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.OSDisk{
Name: to.Ptr("myVMosdisk"),
Caching: to.Ptr(armcompute.CachingTypesReadOnly),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
},
}, &armcompute.VirtualMachinesClientBeginCreateOrUpdateOptions{IfMatch: nil,
IfNoneMatch: 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)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.VirtualMachine = armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// Plan: &armcompute.Plan{
// Name: to.Ptr("standard-data-science-vm"),
// Product: to.Ptr("standard-data-science-vm"),
// Publisher: to.Ptr("microsoft-ads"),
// },
// Properties: &armcompute.VirtualMachineProperties{
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardDS1V2),
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// }},
// },
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// ComputerName: to.Ptr("myVM"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// EnableAutomaticUpdates: to.Ptr(true),
// ProvisionVMAgent: to.Ptr(true),
// },
// },
// ProvisioningState: to.Ptr("Succeeded"),
// SecurityProfile: &armcompute.SecurityProfile{
// EncryptionAtHost: to.Ptr(true),
// },
// StorageProfile: &armcompute.StorageProfile{
// DataDisks: []*armcompute.DataDisk{
// },
// ImageReference: &armcompute.ImageReference{
// Offer: to.Ptr("standard-data-science-vm"),
// Publisher: to.Ptr("microsoft-ads"),
// SKU: to.Ptr("standard-data-science-vm"),
// Version: to.Ptr("latest"),
// },
// OSDisk: &armcompute.OSDisk{
// Name: to.Ptr("myVMosdisk"),
// Caching: to.Ptr(armcompute.CachingTypesReadOnly),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// },
// },
// VMID: to.Ptr("5c0d55a7-c407-4ed6-bf7d-ddb810267c85"),
// },
// }
}
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");
/**
* This sample demonstrates how to The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithEncryptionAtHost.json
*/
async function createAVMWithHostEncryptionUsingEncryptionAtHostProperty() {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP"] || "myResourceGroup";
const vmName = "myVM";
const parameters = {
hardwareProfile: { vmSize: "Standard_DS1_v2" },
location: "westus",
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
osProfile: {
adminPassword: "{your-password}",
adminUsername: "{your-username}",
computerName: "myVM",
},
plan: {
name: "windows2016",
product: "windows-data-science-vm",
publisher: "microsoft-ads",
},
securityProfile: { encryptionAtHost: true },
storageProfile: {
imageReference: {
offer: "windows-data-science-vm",
publisher: "microsoft-ads",
sku: "windows2016",
version: "latest",
},
osDisk: {
name: "myVMosdisk",
caching: "ReadOnly",
createOption: "FromImage",
managedDisk: { storageAccountType: "Standard_LRS" },
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.beginCreateOrUpdateAndWait(
resourceGroupName,
vmName,
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
範例回覆
{
"name": "myVM",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "standard-data-science-vm",
"publisher": "microsoft-ads",
"version": "latest",
"offer": "standard-data-science-vm"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadOnly",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"createOption": "FromImage",
"name": "myVMosdisk"
},
"dataDisks": []
},
"securityProfile": {
"encryptionAtHost": true
},
"vmId": "5c0d55a7-c407-4ed6-bf7d-ddb810267c85",
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"provisioningState": "Creating"
},
"plan": {
"publisher": "microsoft-ads",
"product": "standard-data-science-vm",
"name": "standard-data-science-vm"
},
"type": "Microsoft.Compute/virtualMachines",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"location": "westus"
}
{
"name": "myVM",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "standard-data-science-vm",
"publisher": "microsoft-ads",
"version": "latest",
"offer": "standard-data-science-vm"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadOnly",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"createOption": "FromImage",
"name": "myVMosdisk"
},
"dataDisks": []
},
"securityProfile": {
"encryptionAtHost": true
},
"vmId": "5c0d55a7-c407-4ed6-bf7d-ddb810267c85",
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"provisioningState": "Creating"
},
"plan": {
"publisher": "microsoft-ads",
"product": "standard-data-science-vm",
"name": "standard-data-science-vm"
},
"type": "Microsoft.Compute/virtualMachines",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"location": "westus"
}
Create a vm with managed boot diagnostics.
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2024-03-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": true
}
}
}
}
from typing import Any, IO, Union
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_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_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"diagnosticsProfile": {"bootDiagnostics": {"enabled": True}},
"hardwareProfile": {"vmSize": "Standard_D1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"storageProfile": {
"imageReference": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2016-Datacenter",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Standard_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithManagedBootDiagnostics.json
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/v5"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/92de53a5f1e0e03c94b40475d2135d97148ed014/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithManagedBootDiagnostics.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVmWithManagedBootDiagnostics() {
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.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
DiagnosticsProfile: &armcompute.DiagnosticsProfile{
BootDiagnostics: &armcompute.BootDiagnostics{
Enabled: to.Ptr(true),
},
},
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
}},
},
OSProfile: &armcompute.OSProfile{
AdminPassword: to.Ptr("{your-password}"),
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("WindowsServer"),
Publisher: to.Ptr("MicrosoftWindowsServer"),
SKU: to.Ptr("2016-Datacenter"),
Version: to.Ptr("latest"),
},
OSDisk: &armcompute.OSDisk{
Name: to.Ptr("myVMosdisk"),
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
},
}, &armcompute.VirtualMachinesClientBeginCreateOrUpdateOptions{IfMatch: nil,
IfNoneMatch: 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)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.VirtualMachine = armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// Properties: &armcompute.VirtualMachineProperties{
// DiagnosticsProfile: &armcompute.DiagnosticsProfile{
// BootDiagnostics: &armcompute.BootDiagnostics{
// Enabled: to.Ptr(true),
// },
// },
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// }},
// },
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// ComputerName: to.Ptr("myVM"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// EnableAutomaticUpdates: to.Ptr(true),
// ProvisionVMAgent: to.Ptr(true),
// },
// },
// ProvisioningState: to.Ptr("Succeeded"),
// StorageProfile: &armcompute.StorageProfile{
// DataDisks: []*armcompute.DataDisk{
// },
// ImageReference: &armcompute.ImageReference{
// Offer: to.Ptr("WindowsServer"),
// Publisher: to.Ptr("MicrosoftWindowsServer"),
// SKU: to.Ptr("2016-Datacenter"),
// Version: to.Ptr("latest"),
// },
// OSDisk: &armcompute.OSDisk{
// Name: to.Ptr("myVMosdisk"),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// },
// },
// VMID: to.Ptr("676420ba-7a24-4bfe-80bd-9c841ee184fa"),
// },
// }
}
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");
/**
* This sample demonstrates how to The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithManagedBootDiagnostics.json
*/
async function createAVMWithManagedBootDiagnostics() {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP"] || "myResourceGroup";
const vmName = "myVM";
const parameters = {
diagnosticsProfile: { bootDiagnostics: { enabled: true } },
hardwareProfile: { vmSize: "Standard_D1_v2" },
location: "westus",
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
osProfile: {
adminPassword: "{your-password}",
adminUsername: "{your-username}",
computerName: "myVM",
},
storageProfile: {
imageReference: {
offer: "WindowsServer",
publisher: "MicrosoftWindowsServer",
sku: "2016-Datacenter",
version: "latest",
},
osDisk: {
name: "myVMosdisk",
caching: "ReadWrite",
createOption: "FromImage",
managedDisk: { storageAccountType: "Standard_LRS" },
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.beginCreateOrUpdateAndWait(
resourceGroupName,
vmName,
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
範例回覆
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": true
}
},
"vmId": "676420ba-7a24-4bfe-80bd-9c841ee184fa",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": true
}
},
"vmId": "676420ba-7a24-4bfe-80bd-9c841ee184fa",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Create a VM with network interface configuration
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2024-03-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"networkProfile": {
"networkApiVersion": "2020-11-01",
"networkInterfaceConfigurations": [
{
"name": "{nic-config-name}",
"properties": {
"primary": true,
"deleteOption": "Delete",
"ipConfigurations": [
{
"name": "{ip-config-name}",
"properties": {
"primary": true,
"publicIPAddressConfiguration": {
"name": "{publicIP-config-name}",
"sku": {
"name": "Basic",
"tier": "Global"
},
"properties": {
"deleteOption": "Detach",
"publicIPAllocationMethod": "Static"
}
}
}
}
]
}
}
]
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
}
}
}
from typing import Any, IO, Union
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_create_with_network_interface_configuration.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_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_D1_v2"},
"networkProfile": {
"networkApiVersion": "2020-11-01",
"networkInterfaceConfigurations": [
{
"name": "{nic-config-name}",
"properties": {
"deleteOption": "Delete",
"ipConfigurations": [
{
"name": "{ip-config-name}",
"properties": {
"primary": True,
"publicIPAddressConfiguration": {
"name": "{publicIP-config-name}",
"properties": {
"deleteOption": "Detach",
"publicIPAllocationMethod": "Static",
},
"sku": {"name": "Basic", "tier": "Global"},
},
},
}
],
"primary": True,
},
}
],
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"storageProfile": {
"imageReference": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2016-Datacenter",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Standard_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithNetworkInterfaceConfiguration.json
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/v5"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/92de53a5f1e0e03c94b40475d2135d97148ed014/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithNetworkInterfaceConfiguration.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVmWithNetworkInterfaceConfiguration() {
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.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkAPIVersion: to.Ptr(armcompute.NetworkAPIVersionTwoThousandTwenty1101),
NetworkInterfaceConfigurations: []*armcompute.VirtualMachineNetworkInterfaceConfiguration{
{
Name: to.Ptr("{nic-config-name}"),
Properties: &armcompute.VirtualMachineNetworkInterfaceConfigurationProperties{
DeleteOption: to.Ptr(armcompute.DeleteOptionsDelete),
IPConfigurations: []*armcompute.VirtualMachineNetworkInterfaceIPConfiguration{
{
Name: to.Ptr("{ip-config-name}"),
Properties: &armcompute.VirtualMachineNetworkInterfaceIPConfigurationProperties{
Primary: to.Ptr(true),
PublicIPAddressConfiguration: &armcompute.VirtualMachinePublicIPAddressConfiguration{
Name: to.Ptr("{publicIP-config-name}"),
Properties: &armcompute.VirtualMachinePublicIPAddressConfigurationProperties{
DeleteOption: to.Ptr(armcompute.DeleteOptionsDetach),
PublicIPAllocationMethod: to.Ptr(armcompute.PublicIPAllocationMethodStatic),
},
SKU: &armcompute.PublicIPAddressSKU{
Name: to.Ptr(armcompute.PublicIPAddressSKUNameBasic),
Tier: to.Ptr(armcompute.PublicIPAddressSKUTierGlobal),
},
},
},
}},
Primary: to.Ptr(true),
},
}},
},
OSProfile: &armcompute.OSProfile{
AdminPassword: to.Ptr("{your-password}"),
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("WindowsServer"),
Publisher: to.Ptr("MicrosoftWindowsServer"),
SKU: to.Ptr("2016-Datacenter"),
Version: to.Ptr("latest"),
},
OSDisk: &armcompute.OSDisk{
Name: to.Ptr("myVMosdisk"),
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
},
}, &armcompute.VirtualMachinesClientBeginCreateOrUpdateOptions{IfMatch: nil,
IfNoneMatch: 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)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.VirtualMachine = armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// Properties: &armcompute.VirtualMachineProperties{
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/toBeCreatedNetworkInterface"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// }},
// },
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// ComputerName: to.Ptr("myVM"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// EnableAutomaticUpdates: to.Ptr(true),
// ProvisionVMAgent: to.Ptr(true),
// },
// },
// ProvisioningState: to.Ptr("Succeeded"),
// StorageProfile: &armcompute.StorageProfile{
// DataDisks: []*armcompute.DataDisk{
// },
// ImageReference: &armcompute.ImageReference{
// Offer: to.Ptr("WindowsServer"),
// Publisher: to.Ptr("MicrosoftWindowsServer"),
// SKU: to.Ptr("2016-Datacenter"),
// Version: to.Ptr("latest"),
// },
// OSDisk: &armcompute.OSDisk{
// Name: to.Ptr("myVMosdisk"),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// },
// },
// VMID: to.Ptr("b7a098cc-b0b8-46e8-a205-62f301a62a8f"),
// },
// }
}
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");
/**
* This sample demonstrates how to The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithNetworkInterfaceConfiguration.json
*/
async function createAVMWithNetworkInterfaceConfiguration() {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP"] || "myResourceGroup";
const vmName = "myVM";
const parameters = {
hardwareProfile: { vmSize: "Standard_D1_v2" },
location: "westus",
networkProfile: {
networkApiVersion: "2020-11-01",
networkInterfaceConfigurations: [
{
name: "{nic-config-name}",
deleteOption: "Delete",
ipConfigurations: [
{
name: "{ip-config-name}",
primary: true,
publicIPAddressConfiguration: {
name: "{publicIP-config-name}",
deleteOption: "Detach",
publicIPAllocationMethod: "Static",
sku: { name: "Basic", tier: "Global" },
},
},
],
primary: true,
},
],
},
osProfile: {
adminPassword: "{your-password}",
adminUsername: "{your-username}",
computerName: "myVM",
},
storageProfile: {
imageReference: {
offer: "WindowsServer",
publisher: "MicrosoftWindowsServer",
sku: "2016-Datacenter",
version: "latest",
},
osDisk: {
name: "myVMosdisk",
caching: "ReadWrite",
createOption: "FromImage",
managedDisk: { storageAccountType: "Standard_LRS" },
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.beginCreateOrUpdateAndWait(
resourceGroupName,
vmName,
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
範例回覆
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/toBeCreatedNetworkInterface",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"vmId": "b7a098cc-b0b8-46e8-a205-62f301a62a8f",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/toBeCreatedNetworkInterface",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"vmId": "b7a098cc-b0b8-46e8-a205-62f301a62a8f",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Create a VM with network interface configuration with public ip address dns settings
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2024-03-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"networkProfile": {
"networkApiVersion": "2020-11-01",
"networkInterfaceConfigurations": [
{
"name": "{nic-config-name}",
"properties": {
"primary": true,
"deleteOption": "Delete",
"ipConfigurations": [
{
"name": "{ip-config-name}",
"properties": {
"primary": true,
"publicIPAddressConfiguration": {
"name": "{publicIP-config-name}",
"sku": {
"name": "Basic",
"tier": "Global"
},
"properties": {
"deleteOption": "Detach",
"publicIPAllocationMethod": "Static",
"dnsSettings": {
"domainNameLabel": "aaaaa",
"domainNameLabelScope": "TenantReuse"
}
}
}
}
}
]
}
}
]
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
}
}
}
from typing import Any, IO, Union
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_create_with_network_interface_configuration_dns_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_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_D1_v2"},
"networkProfile": {
"networkApiVersion": "2020-11-01",
"networkInterfaceConfigurations": [
{
"name": "{nic-config-name}",
"properties": {
"deleteOption": "Delete",
"ipConfigurations": [
{
"name": "{ip-config-name}",
"properties": {
"primary": True,
"publicIPAddressConfiguration": {
"name": "{publicIP-config-name}",
"properties": {
"deleteOption": "Detach",
"dnsSettings": {
"domainNameLabel": "aaaaa",
"domainNameLabelScope": "TenantReuse",
},
"publicIPAllocationMethod": "Static",
},
"sku": {"name": "Basic", "tier": "Global"},
},
},
}
],
"primary": True,
},
}
],
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"storageProfile": {
"imageReference": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2016-Datacenter",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Standard_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithNetworkInterfaceConfigurationDnsSettings.json
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/v5"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/92de53a5f1e0e03c94b40475d2135d97148ed014/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithNetworkInterfaceConfigurationDnsSettings.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVmWithNetworkInterfaceConfigurationWithPublicIpAddressDnsSettings() {
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.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkAPIVersion: to.Ptr(armcompute.NetworkAPIVersionTwoThousandTwenty1101),
NetworkInterfaceConfigurations: []*armcompute.VirtualMachineNetworkInterfaceConfiguration{
{
Name: to.Ptr("{nic-config-name}"),
Properties: &armcompute.VirtualMachineNetworkInterfaceConfigurationProperties{
DeleteOption: to.Ptr(armcompute.DeleteOptionsDelete),
IPConfigurations: []*armcompute.VirtualMachineNetworkInterfaceIPConfiguration{
{
Name: to.Ptr("{ip-config-name}"),
Properties: &armcompute.VirtualMachineNetworkInterfaceIPConfigurationProperties{
Primary: to.Ptr(true),
PublicIPAddressConfiguration: &armcompute.VirtualMachinePublicIPAddressConfiguration{
Name: to.Ptr("{publicIP-config-name}"),
Properties: &armcompute.VirtualMachinePublicIPAddressConfigurationProperties{
DeleteOption: to.Ptr(armcompute.DeleteOptionsDetach),
DNSSettings: &armcompute.VirtualMachinePublicIPAddressDNSSettingsConfiguration{
DomainNameLabel: to.Ptr("aaaaa"),
DomainNameLabelScope: to.Ptr(armcompute.DomainNameLabelScopeTypesTenantReuse),
},
PublicIPAllocationMethod: to.Ptr(armcompute.PublicIPAllocationMethodStatic),
},
SKU: &armcompute.PublicIPAddressSKU{
Name: to.Ptr(armcompute.PublicIPAddressSKUNameBasic),
Tier: to.Ptr(armcompute.PublicIPAddressSKUTierGlobal),
},
},
},
}},
Primary: to.Ptr(true),
},
}},
},
OSProfile: &armcompute.OSProfile{
AdminPassword: to.Ptr("{your-password}"),
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("WindowsServer"),
Publisher: to.Ptr("MicrosoftWindowsServer"),
SKU: to.Ptr("2016-Datacenter"),
Version: to.Ptr("latest"),
},
OSDisk: &armcompute.OSDisk{
Name: to.Ptr("myVMosdisk"),
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
},
}, &armcompute.VirtualMachinesClientBeginCreateOrUpdateOptions{IfMatch: nil,
IfNoneMatch: 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)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.VirtualMachine = armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// Properties: &armcompute.VirtualMachineProperties{
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/toBeCreatedNetworkInterface"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// }},
// },
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// ComputerName: to.Ptr("myVM"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// EnableAutomaticUpdates: to.Ptr(true),
// ProvisionVMAgent: to.Ptr(true),
// },
// },
// ProvisioningState: to.Ptr("Succeeded"),
// StorageProfile: &armcompute.StorageProfile{
// DataDisks: []*armcompute.DataDisk{
// },
// ImageReference: &armcompute.ImageReference{
// Offer: to.Ptr("WindowsServer"),
// Publisher: to.Ptr("MicrosoftWindowsServer"),
// SKU: to.Ptr("2016-Datacenter"),
// Version: to.Ptr("latest"),
// },
// OSDisk: &armcompute.OSDisk{
// Name: to.Ptr("myVMosdisk"),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// },
// },
// VMID: to.Ptr("b7a098cc-b0b8-46e8-a205-62f301a62a8f"),
// },
// }
}
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");
/**
* This sample demonstrates how to The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithNetworkInterfaceConfigurationDnsSettings.json
*/
async function createAVMWithNetworkInterfaceConfigurationWithPublicIPAddressDnsSettings() {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP"] || "myResourceGroup";
const vmName = "myVM";
const parameters = {
hardwareProfile: { vmSize: "Standard_D1_v2" },
location: "westus",
networkProfile: {
networkApiVersion: "2020-11-01",
networkInterfaceConfigurations: [
{
name: "{nic-config-name}",
deleteOption: "Delete",
ipConfigurations: [
{
name: "{ip-config-name}",
primary: true,
publicIPAddressConfiguration: {
name: "{publicIP-config-name}",
deleteOption: "Detach",
dnsSettings: {
domainNameLabel: "aaaaa",
domainNameLabelScope: "TenantReuse",
},
publicIPAllocationMethod: "Static",
sku: { name: "Basic", tier: "Global" },
},
},
],
primary: true,
},
],
},
osProfile: {
adminPassword: "{your-password}",
adminUsername: "{your-username}",
computerName: "myVM",
},
storageProfile: {
imageReference: {
offer: "WindowsServer",
publisher: "MicrosoftWindowsServer",
sku: "2016-Datacenter",
version: "latest",
},
osDisk: {
name: "myVMosdisk",
caching: "ReadWrite",
createOption: "FromImage",
managedDisk: { storageAccountType: "Standard_LRS" },
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.beginCreateOrUpdateAndWait(
resourceGroupName,
vmName,
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
範例回覆
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/toBeCreatedNetworkInterface",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"vmId": "b7a098cc-b0b8-46e8-a205-62f301a62a8f",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/toBeCreatedNetworkInterface",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"vmId": "b7a098cc-b0b8-46e8-a205-62f301a62a8f",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Create a vm with password authentication.
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2024-03-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
from typing import Any, IO, Union
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_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_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_D1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"storageProfile": {
"imageReference": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2016-Datacenter",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Standard_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithPasswordAuthentication.json
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/v5"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/92de53a5f1e0e03c94b40475d2135d97148ed014/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithPasswordAuthentication.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVmWithPasswordAuthentication() {
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.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
}},
},
OSProfile: &armcompute.OSProfile{
AdminPassword: to.Ptr("{your-password}"),
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("WindowsServer"),
Publisher: to.Ptr("MicrosoftWindowsServer"),
SKU: to.Ptr("2016-Datacenter"),
Version: to.Ptr("latest"),
},
OSDisk: &armcompute.OSDisk{
Name: to.Ptr("myVMosdisk"),
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
},
}, &armcompute.VirtualMachinesClientBeginCreateOrUpdateOptions{IfMatch: nil,
IfNoneMatch: 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)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.VirtualMachine = armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// Properties: &armcompute.VirtualMachineProperties{
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// }},
// },
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// ComputerName: to.Ptr("myVM"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// EnableAutomaticUpdates: to.Ptr(true),
// ProvisionVMAgent: to.Ptr(true),
// },
// },
// ProvisioningState: to.Ptr("Succeeded"),
// StorageProfile: &armcompute.StorageProfile{
// DataDisks: []*armcompute.DataDisk{
// },
// ImageReference: &armcompute.ImageReference{
// Offer: to.Ptr("WindowsServer"),
// Publisher: to.Ptr("MicrosoftWindowsServer"),
// SKU: to.Ptr("2016-Datacenter"),
// Version: to.Ptr("latest"),
// },
// OSDisk: &armcompute.OSDisk{
// Name: to.Ptr("myVMosdisk"),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// },
// },
// VMID: to.Ptr("b248db33-62ba-4d2d-b791-811e075ee0f5"),
// },
// }
}
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");
/**
* This sample demonstrates how to The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithPasswordAuthentication.json
*/
async function createAVMWithPasswordAuthentication() {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP"] || "myResourceGroup";
const vmName = "myVM";
const parameters = {
hardwareProfile: { vmSize: "Standard_D1_v2" },
location: "westus",
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
osProfile: {
adminPassword: "{your-password}",
adminUsername: "{your-username}",
computerName: "myVM",
},
storageProfile: {
imageReference: {
offer: "WindowsServer",
publisher: "MicrosoftWindowsServer",
sku: "2016-Datacenter",
version: "latest",
},
osDisk: {
name: "myVMosdisk",
caching: "ReadWrite",
createOption: "FromImage",
managedDisk: { storageAccountType: "Standard_LRS" },
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.beginCreateOrUpdateAndWait(
resourceGroupName,
vmName,
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
範例回覆
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"vmId": "b248db33-62ba-4d2d-b791-811e075ee0f5",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"vmId": "b248db33-62ba-4d2d-b791-811e075ee0f5",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Create a vm with premium storage.
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2024-03-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Premium_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
from typing import Any, IO, Union
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_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_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_D1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"storageProfile": {
"imageReference": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2016-Datacenter",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Premium_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithPremiumStorage.json
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/v5"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/92de53a5f1e0e03c94b40475d2135d97148ed014/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithPremiumStorage.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVmWithPremiumStorage() {
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.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
}},
},
OSProfile: &armcompute.OSProfile{
AdminPassword: to.Ptr("{your-password}"),
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("WindowsServer"),
Publisher: to.Ptr("MicrosoftWindowsServer"),
SKU: to.Ptr("2016-Datacenter"),
Version: to.Ptr("latest"),
},
OSDisk: &armcompute.OSDisk{
Name: to.Ptr("myVMosdisk"),
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesPremiumLRS),
},
},
},
},
}, &armcompute.VirtualMachinesClientBeginCreateOrUpdateOptions{IfMatch: nil,
IfNoneMatch: 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)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.VirtualMachine = armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// Properties: &armcompute.VirtualMachineProperties{
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardDS1V2),
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// }},
// },
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// ComputerName: to.Ptr("myVM"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// EnableAutomaticUpdates: to.Ptr(true),
// ProvisionVMAgent: to.Ptr(true),
// },
// },
// ProvisioningState: to.Ptr("Succeeded"),
// StorageProfile: &armcompute.StorageProfile{
// DataDisks: []*armcompute.DataDisk{
// },
// ImageReference: &armcompute.ImageReference{
// Offer: to.Ptr("WindowsServer"),
// Publisher: to.Ptr("MicrosoftWindowsServer"),
// SKU: to.Ptr("2016-Datacenter"),
// Version: to.Ptr("latest"),
// },
// OSDisk: &armcompute.OSDisk{
// Name: to.Ptr("myVMosdisk"),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesPremiumLRS),
// },
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// },
// },
// VMID: to.Ptr("a149cd25-409f-41af-8088-275f5486bc93"),
// },
// }
}
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");
/**
* This sample demonstrates how to The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithPremiumStorage.json
*/
async function createAVMWithPremiumStorage() {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP"] || "myResourceGroup";
const vmName = "myVM";
const parameters = {
hardwareProfile: { vmSize: "Standard_D1_v2" },
location: "westus",
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
osProfile: {
adminPassword: "{your-password}",
adminUsername: "{your-username}",
computerName: "myVM",
},
storageProfile: {
imageReference: {
offer: "WindowsServer",
publisher: "MicrosoftWindowsServer",
sku: "2016-Datacenter",
version: "latest",
},
osDisk: {
name: "myVMosdisk",
caching: "ReadWrite",
createOption: "FromImage",
managedDisk: { storageAccountType: "Premium_LRS" },
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.beginCreateOrUpdateAndWait(
resourceGroupName,
vmName,
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
import com.azure.core.management.SubResource;
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.AdditionalCapabilities;
import com.azure.resourcemanager.compute.models.ApiEntityReference;
import com.azure.resourcemanager.compute.models.ApplicationProfile;
import com.azure.resourcemanager.compute.models.BootDiagnostics;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DataDisk;
import com.azure.resourcemanager.compute.models.DeleteOptions;
import com.azure.resourcemanager.compute.models.DiagnosticsProfile;
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.DiskControllerTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.DiskEncryptionSetParameters;
import com.azure.resourcemanager.compute.models.DomainNameLabelScopeTypes;
import com.azure.resourcemanager.compute.models.EventGridAndResourceGraph;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.LinuxConfiguration;
import com.azure.resourcemanager.compute.models.LinuxPatchAssessmentMode;
import com.azure.resourcemanager.compute.models.LinuxPatchSettings;
import com.azure.resourcemanager.compute.models.LinuxVMGuestPatchAutomaticByPlatformRebootSetting;
import com.azure.resourcemanager.compute.models.LinuxVMGuestPatchAutomaticByPlatformSettings;
import com.azure.resourcemanager.compute.models.LinuxVMGuestPatchMode;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.Mode;
import com.azure.resourcemanager.compute.models.NetworkApiVersion;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSImageNotificationProfile;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.OperatingSystemTypes;
import com.azure.resourcemanager.compute.models.PatchSettings;
import com.azure.resourcemanager.compute.models.Plan;
import com.azure.resourcemanager.compute.models.ProxyAgentSettings;
import com.azure.resourcemanager.compute.models.PublicIpAddressSku;
import com.azure.resourcemanager.compute.models.PublicIpAddressSkuName;
import com.azure.resourcemanager.compute.models.PublicIpAddressSkuTier;
import com.azure.resourcemanager.compute.models.PublicIpAllocationMethod;
import com.azure.resourcemanager.compute.models.ScheduledEventsAdditionalPublishingTargets;
import com.azure.resourcemanager.compute.models.ScheduledEventsPolicy;
import com.azure.resourcemanager.compute.models.ScheduledEventsProfile;
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.SshConfiguration;
import com.azure.resourcemanager.compute.models.SshPublicKey;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.TerminateNotificationProfile;
import com.azure.resourcemanager.compute.models.UefiSettings;
import com.azure.resourcemanager.compute.models.UserInitiatedReboot;
import com.azure.resourcemanager.compute.models.UserInitiatedRedeploy;
import com.azure.resourcemanager.compute.models.VMDiskSecurityProfile;
import com.azure.resourcemanager.compute.models.VMGalleryApplication;
import com.azure.resourcemanager.compute.models.VMSizeProperties;
import com.azure.resourcemanager.compute.models.VirtualHardDisk;
import com.azure.resourcemanager.compute.models.VirtualMachineNetworkInterfaceConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineNetworkInterfaceIpConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachinePublicIpAddressConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachinePublicIpAddressDnsSettingsConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import com.azure.resourcemanager.compute.models.WindowsConfiguration;
import com.azure.resourcemanager.compute.models.WindowsPatchAssessmentMode;
import com.azure.resourcemanager.compute.models.WindowsVMGuestPatchAutomaticByPlatformRebootSetting;
import com.azure.resourcemanager.compute.models.WindowsVMGuestPatchAutomaticByPlatformSettings;
import com.azure.resourcemanager.compute.models.WindowsVMGuestPatchMode;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithPremiumStorage.json
*/
/**
* Sample code: Create a vm with premium storage.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithPremiumStorage(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_CustomImageVmFromAnUnmanagedGeneralizedOsImage.json
*/
/**
* Sample code: Create a custom-image vm from an unmanaged generalized os image.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createACustomImageVmFromAnUnmanagedGeneralizedOsImage(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines()
.createOrUpdate("myResourceGroup", "{vm-name}", new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile().withOsDisk(new OSDisk()
.withOsType(OperatingSystemTypes.WINDOWS).withName("myVMosdisk")
.withVhd(new VirtualHardDisk().withUri(
"http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk.vhd"))
.withImage(new VirtualHardDisk().withUri(
"http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/{existing-generalized-os-image-blob-name}.vhd"))
.withCaching(CachingTypes.READ_WRITE).withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithEncryptionAtHost.json
*/
/**
* Sample code: Create a vm with Host Encryption using encryptionAtHost property.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createAVmWithHostEncryptionUsingEncryptionAtHostProperty(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withPlan(new Plan().withName("windows2016").withPublisher("microsoft-ads")
.withProduct("windows-data-science-vm"))
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_DS1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("microsoft-ads")
.withOffer("windows-data-science-vm").withSku("windows2016").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withSecurityProfile(new SecurityProfile().withEncryptionAtHost(true)),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_InAnAvailabilitySet.json
*/
/**
* Sample code: Create a vm in an availability set.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmInAnAvailabilitySet(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withAvailabilitySet(new SubResource().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/availabilitySets/{existing-availability-set-name}")),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithNetworkInterfaceConfiguration.json
*/
/**
* Sample code: Create a VM with network interface configuration.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createAVMWithNetworkInterfaceConfiguration(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(new NetworkProfile()
.withNetworkApiVersion(NetworkApiVersion.TWO_ZERO_TWO_ZERO_ONE_ONE_ZERO_ONE)
.withNetworkInterfaceConfigurations(
Arrays.asList(new VirtualMachineNetworkInterfaceConfiguration().withName("{nic-config-name}")
.withPrimary(true).withDeleteOption(DeleteOptions.DELETE)
.withIpConfigurations(Arrays.asList(new VirtualMachineNetworkInterfaceIpConfiguration()
.withName("{ip-config-name}").withPrimary(true)
.withPublicIpAddressConfiguration(new VirtualMachinePublicIpAddressConfiguration()
.withName("{publicIP-config-name}")
.withSku(new PublicIpAddressSku().withName(PublicIpAddressSkuName.BASIC)
.withTier(PublicIpAddressSkuTier.GLOBAL))
.withDeleteOption(DeleteOptions.DETACH)
.withPublicIpAllocationMethod(PublicIpAllocationMethod.STATIC))))))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithADiffOsDiskUsingDiffDiskPlacementAsNvmeDisk.json
*/
/**
* Sample code: Create a vm with ephemeral os disk provisioning in Nvme disk using placement property.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithEphemeralOsDiskProvisioningInNvmeDiskUsingPlacementProperty(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withPlan(new Plan().withName("windows2016").withPublisher("microsoft-ads")
.withProduct("windows-data-science-vm"))
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_DS1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("microsoft-ads")
.withOffer("windows-data-science-vm").withSku("windows2016").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withDiffDiskSettings(new DiffDiskSettings().withOption(DiffDiskOptions.LOCAL)
.withPlacement(DiffDiskPlacement.NVME_DISK))
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_FromASpecializedSharedImage.json
*/
/**
* Sample code: Create a vm from a specialized shared image.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmFromASpecializedSharedImage(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile().withImageReference(new ImageReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/mySharedGallery/images/mySharedImage"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithPasswordAuthentication.json
*/
/**
* Sample code: Create a vm with password authentication.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithPasswordAuthentication(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithScheduledEventsProfile.json
*/
/**
* Sample code: Create a vm with Scheduled Events Profile.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithScheduledEventsProfile(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withScheduledEventsPolicy(new ScheduledEventsPolicy()
.withUserInitiatedRedeploy(new UserInitiatedRedeploy().withAutomaticallyApprove(true))
.withUserInitiatedReboot(new UserInitiatedReboot().withAutomaticallyApprove(true))
.withScheduledEventsAdditionalPublishingTargets(new ScheduledEventsAdditionalPublishingTargets()
.withEventGridAndResourceGraph(new EventGridAndResourceGraph().withEnable(true))))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics()
.withEnabled(true).withStorageUri("http://{existing-storage-account-name}.blob.core.windows.net")))
.withScheduledEventsProfile(new ScheduledEventsProfile()
.withTerminateNotificationProfile(
new TerminateNotificationProfile().withNotBeforeTimeout("PT10M").withEnable(true))
.withOsImageNotificationProfile(
new OSImageNotificationProfile().withNotBeforeTimeout("PT15M").withEnable(true))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithADiffOsDiskUsingDiffDiskPlacementAsResourceDisk.json
*/
/**
* Sample code: Create a vm with ephemeral os disk provisioning in Resource disk using placement property.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithEphemeralOsDiskProvisioningInResourceDiskUsingPlacementProperty(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withPlan(new Plan().withName("windows2016").withPublisher("microsoft-ads")
.withProduct("windows-data-science-vm"))
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_DS1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("microsoft-ads")
.withOffer("windows-data-science-vm").withSku("windows2016").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withDiffDiskSettings(new DiffDiskSettings().withOption(DiffDiskOptions.LOCAL)
.withPlacement(DiffDiskPlacement.RESOURCE_DISK))
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithADiffOsDisk.json
*/
/**
* Sample code: Create a vm with ephemeral os disk.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithEphemeralOsDisk(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withPlan(new Plan().withName("windows2016").withPublisher("microsoft-ads")
.withProduct("windows-data-science-vm"))
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_DS1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("microsoft-ads")
.withOffer("windows-data-science-vm").withSku("windows2016").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withDiffDiskSettings(new DiffDiskSettings().withOption(DiffDiskOptions.LOCAL))
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithSecurityTypeConfidentialVMWithCustomerManagedKeys.json
*/
/**
* Sample code: Create a VM with securityType ConfidentialVM with Customer Managed Keys.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMWithSecurityTypeConfidentialVMWithCustomerManagedKeys(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(
new HardwareProfile().withVmSize(VirtualMachineSizeTypes.fromString("Standard_DC2as_v5")))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("2019-datacenter-cvm").withSku("windows-cvm").withVersion("17763.2183.2109130127"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)
.withManagedDisk(new ManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.STANDARD_SSD_LRS)
.withSecurityProfile(new VMDiskSecurityProfile()
.withSecurityEncryptionType(SecurityEncryptionTypes.DISK_WITH_VMGUEST_STATE)
.withDiskEncryptionSet(new DiskEncryptionSetParameters().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"))))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withSecurityProfile(new SecurityProfile()
.withUefiSettings(new UefiSettings().withSecureBootEnabled(true).withVTpmEnabled(true))
.withSecurityType(SecurityTypes.CONFIDENTIAL_VM)),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithDiskEncryptionSetResource.json
*/
/**
* Sample code: Create a vm with DiskEncryptionSet resource id in the os disk and data disk.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithDiskEncryptionSetResourceIdInTheOsDiskAndDataDisk(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile().withImageReference(new ImageReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/{existing-custom-image-name}"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)
.withManagedDisk(new ManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.STANDARD_LRS)
.withDiskEncryptionSet(new DiskEncryptionSetParameters().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"))))
.withDataDisks(Arrays.asList(new DataDisk().withLun(0).withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.EMPTY).withDiskSizeGB(1023)
.withManagedDisk(new ManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.STANDARD_LRS)
.withDiskEncryptionSet(new DiskEncryptionSetParameters().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"))),
new DataDisk().withLun(1).withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.ATTACH).withDiskSizeGB(1023)
.withManagedDisk(new ManagedDiskParameters().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/{existing-managed-disk-name}")
.withStorageAccountType(StorageAccountTypes.STANDARD_LRS)
.withDiskEncryptionSet(new DiskEncryptionSetParameters().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"))))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithDiskControllerType.json
*/
/**
* Sample code: Create a VM with Disk Controller Type.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMWithDiskControllerType(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D4_V3))
.withScheduledEventsPolicy(new ScheduledEventsPolicy()
.withUserInitiatedRedeploy(new UserInitiatedRedeploy().withAutomaticallyApprove(true))
.withUserInitiatedReboot(new UserInitiatedReboot().withAutomaticallyApprove(true))
.withScheduledEventsAdditionalPublishingTargets(new ScheduledEventsAdditionalPublishingTargets()
.withEventGridAndResourceGraph(new EventGridAndResourceGraph().withEnable(true))))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS)))
.withDiskControllerType(DiskControllerTypes.NVME))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics()
.withEnabled(true).withStorageUri("http://{existing-storage-account-name}.blob.core.windows.net")))
.withUserData("U29tZSBDdXN0b20gRGF0YQ=="),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_FromASharedGalleryImage.json
*/
/**
* Sample code: Create a VM from a shared gallery image.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMFromASharedGalleryImage(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withSharedGalleryImageId(
"/SharedGalleries/sharedGalleryName/Images/sharedGalleryImageName/Versions/sharedGalleryImageVersionName"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithVMSizeProperties.json
*/
/**
* Sample code: Create a VM with VM Size Properties.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMWithVMSizeProperties(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D4_V3)
.withVmSizeProperties(new VMSizeProperties().withVCpusAvailable(1).withVCpusPerCore(1)))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics()
.withEnabled(true).withStorageUri("http://{existing-storage-account-name}.blob.core.windows.net")))
.withUserData("U29tZSBDdXN0b20gRGF0YQ=="),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_PlatformImageVmWithUnmanagedOsAndDataDisks.json
*/
/**
* Sample code: Create a platform-image vm with unmanaged os and data disks.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createAPlatformImageVmWithUnmanagedOsAndDataDisks(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines()
.createOrUpdate("myResourceGroup", "{vm-name}", new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withVhd(new VirtualHardDisk().withUri(
"http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk.vhd"))
.withCaching(CachingTypes.READ_WRITE).withCreateOption(DiskCreateOptionTypes.FROM_IMAGE))
.withDataDisks(Arrays.asList(new DataDisk().withLun(0).withVhd(new VirtualHardDisk().withUri(
"http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk0.vhd"))
.withCreateOption(DiskCreateOptionTypes.EMPTY).withDiskSizeGB(1023),
new DataDisk().withLun(1).withVhd(new VirtualHardDisk().withUri(
"http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk1.vhd"))
.withCreateOption(DiskCreateOptionTypes.EMPTY).withDiskSizeGB(1023))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_LinuxVmWithPatchSettingModesOfAutomaticByPlatform.json
*/
/**
* Sample code: Create a Linux vm with a patch settings patchMode and assessmentMode set to AutomaticByPlatform.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createALinuxVmWithAPatchSettingsPatchModeAndAssessmentModeSetToAutomaticByPlatform(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2S_V3))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("Canonical").withOffer("UbuntuServer")
.withSku("16.04-LTS").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder")
.withLinuxConfiguration(new LinuxConfiguration().withProvisionVMAgent(true).withPatchSettings(
new LinuxPatchSettings().withPatchMode(LinuxVMGuestPatchMode.AUTOMATIC_BY_PLATFORM)
.withAssessmentMode(LinuxPatchAssessmentMode.AUTOMATIC_BY_PLATFORM))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithSecurityTypeConfidentialVMWithNonPersistedTPM.json
*/
/**
* Sample code: Create a VM with securityType ConfidentialVM with NonPersistedTPM securityEncryptionType.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMWithSecurityTypeConfidentialVMWithNonPersistedTPMSecurityEncryptionType(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(
new HardwareProfile().withVmSize(VirtualMachineSizeTypes.fromString("Standard_DC2es_v5")))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("UbuntuServer")
.withOffer("2022-datacenter-cvm").withSku("linux-cvm").withVersion("17763.2183.2109130127"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_SSD_LRS)
.withSecurityProfile(new VMDiskSecurityProfile()
.withSecurityEncryptionType(SecurityEncryptionTypes.NON_PERSISTED_TPM)))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withSecurityProfile(new SecurityProfile()
.withUefiSettings(new UefiSettings().withSecureBootEnabled(false).withVTpmEnabled(true))
.withSecurityType(SecurityTypes.CONFIDENTIAL_VM)),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithAMarketplaceImagePlan.json
*/
/**
* Sample code: Create a vm with a marketplace image plan.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithAMarketplaceImagePlan(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withPlan(new Plan().withName("windows2016").withPublisher("microsoft-ads")
.withProduct("windows-data-science-vm"))
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("microsoft-ads")
.withOffer("windows-data-science-vm").withSku("windows2016").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WindowsVmWithPatchSettingAssessmentModeOfImageDefault.json
*/
/**
* Sample code: Create a Windows vm with a patch setting assessmentMode of ImageDefault.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAWindowsVmWithAPatchSettingAssessmentModeOfImageDefault(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder")
.withWindowsConfiguration(new WindowsConfiguration().withProvisionVMAgent(true)
.withEnableAutomaticUpdates(true).withPatchSettings(
new PatchSettings().withAssessmentMode(WindowsPatchAssessmentMode.IMAGE_DEFAULT))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/
* VirtualMachine_Create_WindowsVmWithPatchSettingModeOfAutomaticByPlatformAndEnableHotPatchingTrue.json
*/
/**
* Sample code: Create a Windows vm with a patch setting patchMode of AutomaticByPlatform and enableHotpatching set
* to true.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAWindowsVmWithAPatchSettingPatchModeOfAutomaticByPlatformAndEnableHotpatchingSetToTrue(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder")
.withWindowsConfiguration(new WindowsConfiguration().withProvisionVMAgent(true)
.withEnableAutomaticUpdates(true)
.withPatchSettings(new PatchSettings()
.withPatchMode(WindowsVMGuestPatchMode.AUTOMATIC_BY_PLATFORM).withEnableHotpatching(true))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithExtensionsTimeBudget.json
*/
/**
* Sample code: Create a vm with an extensions time budget.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithAnExtensionsTimeBudget(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics()
.withEnabled(true).withStorageUri("http://{existing-storage-account-name}.blob.core.windows.net")))
.withExtensionsTimeBudget("PT30M"),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithEmptyDataDisks.json
*/
/**
* Sample code: Create a vm with empty data disks.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithEmptyDataDisks(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS)))
.withDataDisks(Arrays.asList(
new DataDisk().withLun(0).withCreateOption(DiskCreateOptionTypes.EMPTY).withDiskSizeGB(1023),
new DataDisk().withLun(1).withCreateOption(DiskCreateOptionTypes.EMPTY).withDiskSizeGB(1023))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithSecurityTypeConfidentialVM.json
*/
/**
* Sample code: Create a VM with securityType ConfidentialVM with Platform Managed Keys.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMWithSecurityTypeConfidentialVMWithPlatformManagedKeys(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(
new HardwareProfile().withVmSize(VirtualMachineSizeTypes.fromString("Standard_DC2as_v5")))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("2019-datacenter-cvm").withSku("windows-cvm").withVersion("17763.2183.2109130127"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_SSD_LRS)
.withSecurityProfile(new VMDiskSecurityProfile()
.withSecurityEncryptionType(SecurityEncryptionTypes.DISK_WITH_VMGUEST_STATE)))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withSecurityProfile(new SecurityProfile()
.withUefiSettings(new UefiSettings().withSecureBootEnabled(true).withVTpmEnabled(true))
.withSecurityType(SecurityTypes.CONFIDENTIAL_VM)),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithDataDisksFromSourceResource.json
*/
/**
* Sample code: Create a vm with data disks using 'Copy' and 'Restore' options.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createAVmWithDataDisksUsingCopyAndRestoreOptions(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS)))
.withDataDisks(Arrays.asList(new DataDisk().withLun(0).withCreateOption(DiskCreateOptionTypes.COPY)
.withDiskSizeGB(1023)
.withSourceResource(new ApiEntityReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/{existing-snapshot-name}")),
new DataDisk().withLun(1).withCreateOption(DiskCreateOptionTypes.COPY).withDiskSizeGB(1023)
.withSourceResource(new ApiEntityReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/{existing-disk-name}")),
new DataDisk().withLun(2).withCreateOption(DiskCreateOptionTypes.RESTORE).withDiskSizeGB(1023)
.withSourceResource(new ApiEntityReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/restorePointCollections/{existing-rpc-name}/restorePoints/{existing-rp-name}/diskRestorePoints/{existing-disk-restore-point-name}")))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_FromACustomImage.json
*/
/**
* Sample code: Create a vm from a custom image.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmFromACustomImage(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile().withImageReference(new ImageReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/{existing-custom-image-name}"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithHibernationEnabled.json
*/
/**
* Sample code: Create a VM with HibernationEnabled.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMWithHibernationEnabled(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup",
"{vm-name}",
new VirtualMachineInner().withLocation("eastus2euap")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2S_V3))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2019-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("vmOSdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withAdditionalCapabilities(new AdditionalCapabilities().withHibernationEnabled(true))
.withOsProfile(new OSProfile().withComputerName("{vm-name}").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics()
.withEnabled(true).withStorageUri("http://{existing-storage-account-name}.blob.core.windows.net"))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithUefiSettings.json
*/
/**
* Sample code: Create a VM with Uefi Settings of secureBoot and vTPM.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createAVMWithUefiSettingsOfSecureBootAndVTPM(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2S_V3))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference()
.withPublisher("MicrosoftWindowsServer").withOffer("windowsserver-gen2preview-preview")
.withSku("windows10-tvm").withVersion("18363.592.2001092016"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_SSD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withSecurityProfile(new SecurityProfile()
.withUefiSettings(new UefiSettings().withSecureBootEnabled(true).withVTpmEnabled(true))
.withSecurityType(SecurityTypes.TRUSTED_LAUNCH)),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithApplicationProfile.json
*/
/**
* Sample code: Create a vm with Application Profile.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithApplicationProfile(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("{image_publisher}")
.withOffer("{image_offer}").withSku("{image_sku}").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(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(false).withEnableAutomaticUpgrade(false),
new VMGalleryApplication().withPackageReferenceId(
"/subscriptions/32c17a9e-aa7b-4ba5-a45b-e324116b6fdg/resourceGroups/myresourceGroupName3/providers/Microsoft.Compute/galleries/myGallery2/applications/MyApplication2/versions/1.1")))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithNetworkInterfaceConfigurationDnsSettings.json
*/
/**
* Sample code: Create a VM with network interface configuration with public ip address dns settings.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMWithNetworkInterfaceConfigurationWithPublicIpAddressDnsSettings(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkApiVersion(NetworkApiVersion.TWO_ZERO_TWO_ZERO_ONE_ONE_ZERO_ONE)
.withNetworkInterfaceConfigurations(
Arrays.asList(new VirtualMachineNetworkInterfaceConfiguration()
.withName("{nic-config-name}").withPrimary(true).withDeleteOption(DeleteOptions.DELETE)
.withIpConfigurations(Arrays.asList(new VirtualMachineNetworkInterfaceIpConfiguration()
.withName("{ip-config-name}").withPrimary(true)
.withPublicIpAddressConfiguration(new VirtualMachinePublicIpAddressConfiguration()
.withName("{publicIP-config-name}")
.withSku(new PublicIpAddressSku().withName(PublicIpAddressSkuName.BASIC)
.withTier(PublicIpAddressSkuTier.GLOBAL))
.withDeleteOption(DeleteOptions.DETACH)
.withDnsSettings(new VirtualMachinePublicIpAddressDnsSettingsConfiguration()
.withDomainNameLabel("aaaaa")
.withDomainNameLabelScope(DomainNameLabelScopeTypes.TENANT_REUSE))
.withPublicIpAllocationMethod(PublicIpAllocationMethod.STATIC))))))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_InAVmssWithCustomerAssignedPlatformFaultDomain.json
*/
/**
* Sample code: Create a vm in a Virtual Machine Scale Set with customer assigned platformFaultDomain.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmInAVirtualMachineScaleSetWithCustomerAssignedPlatformFaultDomain(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withVirtualMachineScaleSet(new SubResource().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{existing-flex-vmss-name-with-platformFaultDomainCount-greater-than-1}"))
.withPlatformFaultDomain(1),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithBootDiagnostics.json
*/
/**
* Sample code: Create a vm with boot diagnostics.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithBootDiagnostics(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics()
.withEnabled(true).withStorageUri("http://{existing-storage-account-name}.blob.core.windows.net"))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithSshAuthentication.json
*/
/**
* Sample code: Create a vm with ssh authentication.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithSshAuthentication(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("{image_publisher}")
.withOffer("{image_offer}").withSku("{image_sku}").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").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"))))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_FromACommunityGalleryImage.json
*/
/**
* Sample code: Create a VM from a community gallery image.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMFromACommunityGalleryImage(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withCommunityGalleryImageId(
"/CommunityGalleries/galleryPublicName/Images/communityGalleryImageName/Versions/communityGalleryImageVersionName"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithUserData.json
*/
/**
* Sample code: Create a VM with UserData.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMWithUserData(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup",
"{vm-name}",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("vmOSdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("{vm-name}").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics()
.withEnabled(true).withStorageUri("http://{existing-storage-account-name}.blob.core.windows.net")))
.withUserData("RXhhbXBsZSBVc2VyRGF0YQ=="),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_FromAGeneralizedSharedImage.json
*/
/**
* Sample code: Create a vm from a generalized shared image.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmFromAGeneralizedSharedImage(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile().withImageReference(new ImageReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/mySharedGallery/images/mySharedImage"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_LinuxVmWithAutomaticByPlatformSettings.json
*/
/**
* Sample code: Create a Linux vm with a patch setting patchMode of AutomaticByPlatform and
* AutomaticByPlatformSettings.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createALinuxVmWithAPatchSettingPatchModeOfAutomaticByPlatformAndAutomaticByPlatformSettings(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2S_V3))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("Canonical").withOffer("UbuntuServer")
.withSku("16.04-LTS").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder")
.withLinuxConfiguration(new LinuxConfiguration().withProvisionVMAgent(true).withPatchSettings(
new LinuxPatchSettings().withPatchMode(LinuxVMGuestPatchMode.AUTOMATIC_BY_PLATFORM)
.withAssessmentMode(LinuxPatchAssessmentMode.AUTOMATIC_BY_PLATFORM)
.withAutomaticByPlatformSettings(new LinuxVMGuestPatchAutomaticByPlatformSettings()
.withRebootSetting(LinuxVMGuestPatchAutomaticByPlatformRebootSetting.NEVER)
.withBypassPlatformSafetyChecksOnUserSchedule(true)))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WindowsVmWithPatchSettingModeOfManual.json
*/
/**
* Sample code: Create a Windows vm with a patch setting patchMode of Manual.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createAWindowsVmWithAPatchSettingPatchModeOfManual(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder").withWindowsConfiguration(
new WindowsConfiguration().withProvisionVMAgent(true).withEnableAutomaticUpdates(true)
.withPatchSettings(new PatchSettings().withPatchMode(WindowsVMGuestPatchMode.MANUAL))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithProxyAgentSettings.json
*/
/**
* Sample code: Create a VM with ProxyAgent Settings of enabled and mode.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createAVMWithProxyAgentSettingsOfEnabledAndMode(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2S_V3))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2019-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_SSD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withSecurityProfile(new SecurityProfile()
.withProxyAgentSettings(new ProxyAgentSettings().withEnabled(true).withMode(Mode.ENFORCE))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_LinuxVmWithPatchSettingModeOfImageDefault.json
*/
/**
* Sample code: Create a Linux vm with a patch setting patchMode of ImageDefault.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createALinuxVmWithAPatchSettingPatchModeOfImageDefault(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2S_V3))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("Canonical").withOffer("UbuntuServer")
.withSku("16.04-LTS").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder")
.withLinuxConfiguration(new LinuxConfiguration().withProvisionVMAgent(true).withPatchSettings(
new LinuxPatchSettings().withPatchMode(LinuxVMGuestPatchMode.IMAGE_DEFAULT))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithManagedBootDiagnostics.json
*/
/**
* Sample code: Create a vm with managed boot diagnostics.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithManagedBootDiagnostics(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(
new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics().withEnabled(true))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WindowsVmWithAutomaticByPlatformSettings.json
*/
/**
* Sample code: Create a Windows vm with a patch setting patchMode of AutomaticByPlatform and
* AutomaticByPlatformSettings.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAWindowsVmWithAPatchSettingPatchModeOfAutomaticByPlatformAndAutomaticByPlatformSettings(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder").withWindowsConfiguration(
new WindowsConfiguration().withProvisionVMAgent(true).withEnableAutomaticUpdates(true)
.withPatchSettings(new PatchSettings()
.withPatchMode(WindowsVMGuestPatchMode.AUTOMATIC_BY_PLATFORM)
.withAssessmentMode(WindowsPatchAssessmentMode.AUTOMATIC_BY_PLATFORM)
.withAutomaticByPlatformSettings(new WindowsVMGuestPatchAutomaticByPlatformSettings()
.withRebootSetting(WindowsVMGuestPatchAutomaticByPlatformRebootSetting.NEVER)
.withBypassPlatformSafetyChecksOnUserSchedule(false)))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
範例回覆
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Premium_LRS"
}
},
"dataDisks": []
},
"vmId": "a149cd25-409f-41af-8088-275f5486bc93",
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Premium_LRS"
}
},
"dataDisks": []
},
"vmId": "a149cd25-409f-41af-8088-275f5486bc93",
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Create a VM with ProxyAgent Settings of enabled and mode.
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2024-03-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D2s_v3"
},
"securityProfile": {
"proxyAgentSettings": {
"enabled": true,
"mode": "Enforce"
}
},
"storageProfile": {
"imageReference": {
"publisher": "MicrosoftWindowsServer",
"offer": "WindowsServer",
"sku": "2019-Datacenter",
"version": "latest"
},
"osDisk": {
"caching": "ReadOnly",
"managedDisk": {
"storageAccountType": "StandardSSD_LRS"
},
"createOption": "FromImage",
"name": "myVMosdisk"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
from typing import Any, IO, Union
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_create_with_proxy_agent_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_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_D2s_v3"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"securityProfile": {"proxyAgentSettings": {"enabled": True, "mode": "Enforce"}},
"storageProfile": {
"imageReference": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2019-Datacenter",
"version": "latest",
},
"osDisk": {
"caching": "ReadOnly",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "StandardSSD_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithProxyAgentSettings.json
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/v5"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/92de53a5f1e0e03c94b40475d2135d97148ed014/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithProxyAgentSettings.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVmWithProxyAgentSettingsOfEnabledAndMode() {
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.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD2SV3),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
}},
},
OSProfile: &armcompute.OSProfile{
AdminPassword: to.Ptr("{your-password}"),
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
},
SecurityProfile: &armcompute.SecurityProfile{
ProxyAgentSettings: &armcompute.ProxyAgentSettings{
Enabled: to.Ptr(true),
Mode: to.Ptr(armcompute.ModeEnforce),
},
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("WindowsServer"),
Publisher: to.Ptr("MicrosoftWindowsServer"),
SKU: to.Ptr("2019-Datacenter"),
Version: to.Ptr("latest"),
},
OSDisk: &armcompute.OSDisk{
Name: to.Ptr("myVMosdisk"),
Caching: to.Ptr(armcompute.CachingTypesReadOnly),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardSSDLRS),
},
},
},
},
}, &armcompute.VirtualMachinesClientBeginCreateOrUpdateOptions{IfMatch: nil,
IfNoneMatch: 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)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.VirtualMachine = armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// Properties: &armcompute.VirtualMachineProperties{
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD2SV3),
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// }},
// },
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// ComputerName: to.Ptr("myVM"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// EnableAutomaticUpdates: to.Ptr(true),
// ProvisionVMAgent: to.Ptr(true),
// },
// },
// ProvisioningState: to.Ptr("Succeeded"),
// SecurityProfile: &armcompute.SecurityProfile{
// ProxyAgentSettings: &armcompute.ProxyAgentSettings{
// Enabled: to.Ptr(true),
// Mode: to.Ptr(armcompute.ModeEnforce),
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// DataDisks: []*armcompute.DataDisk{
// },
// ImageReference: &armcompute.ImageReference{
// Offer: to.Ptr("WindowsServer"),
// Publisher: to.Ptr("MicrosoftWindowsServer"),
// SKU: to.Ptr("2019-Datacenter"),
// Version: to.Ptr("latest"),
// },
// OSDisk: &armcompute.OSDisk{
// Name: to.Ptr("myVMosdisk"),
// Caching: to.Ptr(armcompute.CachingTypesReadOnly),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardSSDLRS),
// },
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// },
// },
// VMID: to.Ptr("5c0d55a7-c407-4ed6-bf7d-ddb810267c85"),
// },
// }
}
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");
/**
* This sample demonstrates how to The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithProxyAgentSettings.json
*/
async function createAVMWithProxyAgentSettingsOfEnabledAndMode() {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP"] || "myResourceGroup";
const vmName = "myVM";
const parameters = {
hardwareProfile: { vmSize: "Standard_D2s_v3" },
location: "westus",
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
osProfile: {
adminPassword: "{your-password}",
adminUsername: "{your-username}",
computerName: "myVM",
},
securityProfile: { proxyAgentSettings: { enabled: true, mode: "Enforce" } },
storageProfile: {
imageReference: {
offer: "WindowsServer",
publisher: "MicrosoftWindowsServer",
sku: "2019-Datacenter",
version: "latest",
},
osDisk: {
name: "myVMosdisk",
caching: "ReadOnly",
createOption: "FromImage",
managedDisk: { storageAccountType: "StandardSSD_LRS" },
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.beginCreateOrUpdateAndWait(
resourceGroupName,
vmName,
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
範例回覆
{
"name": "myVM",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"publisher": "MicrosoftWindowsServer",
"offer": "WindowsServer",
"sku": "2019-Datacenter",
"version": "latest"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadOnly",
"managedDisk": {
"storageAccountType": "StandardSSD_LRS"
},
"createOption": "FromImage",
"name": "myVMosdisk"
},
"dataDisks": []
},
"securityProfile": {
"proxyAgentSettings": {
"enabled": true,
"mode": "Enforce"
}
},
"vmId": "5c0d55a7-c407-4ed6-bf7d-ddb810267c85",
"hardwareProfile": {
"vmSize": "Standard_D2s_v3"
},
"provisioningState": "Creating"
},
"type": "Microsoft.Compute/virtualMachines",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"location": "westus"
}
{
"name": "myVM",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"publisher": "MicrosoftWindowsServer",
"offer": "WindowsServer",
"sku": "2019-Datacenter",
"version": "latest"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadOnly",
"managedDisk": {
"storageAccountType": "StandardSSD_LRS"
},
"createOption": "FromImage",
"name": "myVMosdisk"
},
"dataDisks": []
},
"securityProfile": {
"proxyAgentSettings": {
"enabled": true,
"mode": "Enforce"
}
},
"vmId": "5c0d55a7-c407-4ed6-bf7d-ddb810267c85",
"hardwareProfile": {
"vmSize": "Standard_D2s_v3"
},
"provisioningState": "Creating"
},
"type": "Microsoft.Compute/virtualMachines",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"location": "westus"
}
Create a vm with Scheduled Events Profile
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2024-03-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"scheduledEventsPolicy": {
"scheduledEventsAdditionalPublishingTargets": {
"eventGridAndResourceGraph": {
"enable": true
}
},
"userInitiatedRedeploy": {
"automaticallyApprove": true
},
"userInitiatedReboot": {
"automaticallyApprove": true
}
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"diagnosticsProfile": {
"bootDiagnostics": {
"storageUri": "http://{existing-storage-account-name}.blob.core.windows.net",
"enabled": true
}
},
"scheduledEventsProfile": {
"terminateNotificationProfile": {
"notBeforeTimeout": "PT10M",
"enable": true
},
"osImageNotificationProfile": {
"notBeforeTimeout": "PT15M",
"enable": true
}
}
}
}
from typing import Any, IO, Union
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_create_with_scheduled_events_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_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": True,
"storageUri": "http://{existing-storage-account-name}.blob.core.windows.net",
}
},
"hardwareProfile": {"vmSize": "Standard_D1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"scheduledEventsPolicy": {
"scheduledEventsAdditionalPublishingTargets": {"eventGridAndResourceGraph": {"enable": True}},
"userInitiatedReboot": {"automaticallyApprove": True},
"userInitiatedRedeploy": {"automaticallyApprove": True},
},
"scheduledEventsProfile": {
"osImageNotificationProfile": {"enable": True, "notBeforeTimeout": "PT15M"},
"terminateNotificationProfile": {"enable": True, "notBeforeTimeout": "PT10M"},
},
"storageProfile": {
"imageReference": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2016-Datacenter",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Standard_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithScheduledEventsProfile.json
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/v5"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/92de53a5f1e0e03c94b40475d2135d97148ed014/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithScheduledEventsProfile.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVmWithScheduledEventsProfile() {
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.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
DiagnosticsProfile: &armcompute.DiagnosticsProfile{
BootDiagnostics: &armcompute.BootDiagnostics{
Enabled: to.Ptr(true),
StorageURI: to.Ptr("http://{existing-storage-account-name}.blob.core.windows.net"),
},
},
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
}},
},
OSProfile: &armcompute.OSProfile{
AdminPassword: to.Ptr("{your-password}"),
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
},
ScheduledEventsPolicy: &armcompute.ScheduledEventsPolicy{
ScheduledEventsAdditionalPublishingTargets: &armcompute.ScheduledEventsAdditionalPublishingTargets{
EventGridAndResourceGraph: &armcompute.EventGridAndResourceGraph{
Enable: to.Ptr(true),
},
},
UserInitiatedReboot: &armcompute.UserInitiatedReboot{
AutomaticallyApprove: to.Ptr(true),
},
UserInitiatedRedeploy: &armcompute.UserInitiatedRedeploy{
AutomaticallyApprove: to.Ptr(true),
},
},
ScheduledEventsProfile: &armcompute.ScheduledEventsProfile{
OSImageNotificationProfile: &armcompute.OSImageNotificationProfile{
Enable: to.Ptr(true),
NotBeforeTimeout: to.Ptr("PT15M"),
},
TerminateNotificationProfile: &armcompute.TerminateNotificationProfile{
Enable: to.Ptr(true),
NotBeforeTimeout: to.Ptr("PT10M"),
},
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("WindowsServer"),
Publisher: to.Ptr("MicrosoftWindowsServer"),
SKU: to.Ptr("2016-Datacenter"),
Version: to.Ptr("latest"),
},
OSDisk: &armcompute.OSDisk{
Name: to.Ptr("myVMosdisk"),
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
},
}, &armcompute.VirtualMachinesClientBeginCreateOrUpdateOptions{IfMatch: nil,
IfNoneMatch: 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)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.VirtualMachine = armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// Properties: &armcompute.VirtualMachineProperties{
// DiagnosticsProfile: &armcompute.DiagnosticsProfile{
// BootDiagnostics: &armcompute.BootDiagnostics{
// Enabled: to.Ptr(true),
// StorageURI: to.Ptr("http://nsgdiagnostic.blob.core.windows.net"),
// },
// },
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// }},
// },
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// ComputerName: to.Ptr("myVM"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// EnableAutomaticUpdates: to.Ptr(true),
// ProvisionVMAgent: to.Ptr(true),
// },
// },
// ProvisioningState: to.Ptr("Succeeded"),
// ScheduledEventsPolicy: &armcompute.ScheduledEventsPolicy{
// ScheduledEventsAdditionalPublishingTargets: &armcompute.ScheduledEventsAdditionalPublishingTargets{
// EventGridAndResourceGraph: &armcompute.EventGridAndResourceGraph{
// Enable: to.Ptr(true),
// },
// },
// UserInitiatedReboot: &armcompute.UserInitiatedReboot{
// AutomaticallyApprove: to.Ptr(true),
// },
// UserInitiatedRedeploy: &armcompute.UserInitiatedRedeploy{
// AutomaticallyApprove: to.Ptr(true),
// },
// },
// ScheduledEventsProfile: &armcompute.ScheduledEventsProfile{
// OSImageNotificationProfile: &armcompute.OSImageNotificationProfile{
// Enable: to.Ptr(true),
// NotBeforeTimeout: to.Ptr("PT15M"),
// },
// TerminateNotificationProfile: &armcompute.TerminateNotificationProfile{
// Enable: to.Ptr(true),
// NotBeforeTimeout: to.Ptr("PT10M"),
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// DataDisks: []*armcompute.DataDisk{
// },
// ImageReference: &armcompute.ImageReference{
// Offer: to.Ptr("WindowsServer"),
// Publisher: to.Ptr("MicrosoftWindowsServer"),
// SKU: to.Ptr("2016-Datacenter"),
// Version: to.Ptr("latest"),
// },
// OSDisk: &armcompute.OSDisk{
// Name: to.Ptr("myVMosdisk"),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// },
// },
// VMID: to.Ptr("676420ba-7a24-4bfe-80bd-9c841ee184fa"),
// },
// }
}
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");
/**
* This sample demonstrates how to The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithScheduledEventsProfile.json
*/
async function createAVMWithScheduledEventsProfile() {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP"] || "myResourceGroup";
const vmName = "myVM";
const parameters = {
diagnosticsProfile: {
bootDiagnostics: {
enabled: true,
storageUri: "http://{existing-storage-account-name}.blob.core.windows.net",
},
},
hardwareProfile: { vmSize: "Standard_D1_v2" },
location: "westus",
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
osProfile: {
adminPassword: "{your-password}",
adminUsername: "{your-username}",
computerName: "myVM",
},
scheduledEventsPolicy: {
scheduledEventsAdditionalPublishingTargets: {
eventGridAndResourceGraph: { enable: true },
},
userInitiatedReboot: { automaticallyApprove: true },
userInitiatedRedeploy: { automaticallyApprove: true },
},
scheduledEventsProfile: {
osImageNotificationProfile: { enable: true, notBeforeTimeout: "PT15M" },
terminateNotificationProfile: { enable: true, notBeforeTimeout: "PT10M" },
},
storageProfile: {
imageReference: {
offer: "WindowsServer",
publisher: "MicrosoftWindowsServer",
sku: "2016-Datacenter",
version: "latest",
},
osDisk: {
name: "myVMosdisk",
caching: "ReadWrite",
createOption: "FromImage",
managedDisk: { storageAccountType: "Standard_LRS" },
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.beginCreateOrUpdateAndWait(
resourceGroupName,
vmName,
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
範例回覆
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"diagnosticsProfile": {
"bootDiagnostics": {
"storageUri": "http://nsgdiagnostic.blob.core.windows.net",
"enabled": true
}
},
"vmId": "676420ba-7a24-4bfe-80bd-9c841ee184fa",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"scheduledEventsPolicy": {
"scheduledEventsAdditionalPublishingTargets": {
"eventGridAndResourceGraph": {
"enable": true
}
},
"userInitiatedRedeploy": {
"automaticallyApprove": true
},
"userInitiatedReboot": {
"automaticallyApprove": true
}
},
"scheduledEventsProfile": {
"terminateNotificationProfile": {
"notBeforeTimeout": "PT10M",
"enable": true
},
"osImageNotificationProfile": {
"notBeforeTimeout": "PT15M",
"enable": true
}
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"diagnosticsProfile": {
"bootDiagnostics": {
"storageUri": "http://nsgdiagnostic.blob.core.windows.net",
"enabled": true
}
},
"vmId": "676420ba-7a24-4bfe-80bd-9c841ee184fa",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"scheduledEventsPolicy": {
"scheduledEventsAdditionalPublishingTargets": {
"eventGridAndResourceGraph": {
"enable": true
}
},
"userInitiatedRedeploy": {
"automaticallyApprove": true
},
"userInitiatedReboot": {
"automaticallyApprove": true
}
},
"scheduledEventsProfile": {
"terminateNotificationProfile": {
"notBeforeTimeout": "PT10M",
"enable": true
},
"osImageNotificationProfile": {
"notBeforeTimeout": "PT15M",
"enable": true
}
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Create a VM with securityType ConfidentialVM with Customer Managed Keys
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2024-03-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_DC2as_v5"
},
"securityProfile": {
"uefiSettings": {
"secureBootEnabled": true,
"vTpmEnabled": true
},
"securityType": "ConfidentialVM"
},
"storageProfile": {
"imageReference": {
"sku": "windows-cvm",
"publisher": "MicrosoftWindowsServer",
"version": "17763.2183.2109130127",
"offer": "2019-datacenter-cvm"
},
"osDisk": {
"caching": "ReadOnly",
"managedDisk": {
"storageAccountType": "StandardSSD_LRS",
"securityProfile": {
"securityEncryptionType": "DiskWithVMGuestState",
"diskEncryptionSet": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"
}
}
},
"createOption": "FromImage",
"name": "myVMosdisk"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
from typing import Any, IO, Union
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_create_with_security_type_confidential_vm_with_customer_managed_keys.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_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_DC2as_v5"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"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": {
"diskEncryptionSet": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"
},
"securityEncryptionType": "DiskWithVMGuestState",
},
"storageAccountType": "StandardSSD_LRS",
},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithSecurityTypeConfidentialVMWithCustomerManagedKeys.json
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/v5"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/92de53a5f1e0e03c94b40475d2135d97148ed014/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithSecurityTypeConfidentialVMWithCustomerManagedKeys.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVmWithSecurityTypeConfidentialVmWithCustomerManagedKeys() {
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.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypes("Standard_DC2as_v5")),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
}},
},
OSProfile: &armcompute.OSProfile{
AdminPassword: to.Ptr("{your-password}"),
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
},
SecurityProfile: &armcompute.SecurityProfile{
SecurityType: to.Ptr(armcompute.SecurityTypesConfidentialVM),
UefiSettings: &armcompute.UefiSettings{
SecureBootEnabled: to.Ptr(true),
VTpmEnabled: to.Ptr(true),
},
},
StorageProfile: &armcompute.StorageProfile{
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.OSDisk{
Name: to.Ptr("myVMosdisk"),
Caching: to.Ptr(armcompute.CachingTypesReadOnly),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.ManagedDiskParameters{
SecurityProfile: &armcompute.VMDiskSecurityProfile{
DiskEncryptionSet: &armcompute.DiskEncryptionSetParameters{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"),
},
SecurityEncryptionType: to.Ptr(armcompute.SecurityEncryptionTypesDiskWithVMGuestState),
},
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardSSDLRS),
},
},
},
},
}, &armcompute.VirtualMachinesClientBeginCreateOrUpdateOptions{IfMatch: nil,
IfNoneMatch: 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)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.VirtualMachine = armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// Properties: &armcompute.VirtualMachineProperties{
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypes("Standard_DC2as_v5")),
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// }},
// },
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// ComputerName: to.Ptr("myVM"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// EnableAutomaticUpdates: to.Ptr(true),
// ProvisionVMAgent: to.Ptr(true),
// },
// },
// ProvisioningState: to.Ptr("Succeeded"),
// SecurityProfile: &armcompute.SecurityProfile{
// SecurityType: to.Ptr(armcompute.SecurityTypesConfidentialVM),
// UefiSettings: &armcompute.UefiSettings{
// SecureBootEnabled: to.Ptr(true),
// VTpmEnabled: to.Ptr(true),
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// DataDisks: []*armcompute.DataDisk{
// },
// 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.OSDisk{
// Name: to.Ptr("myVMosdisk"),
// Caching: to.Ptr(armcompute.CachingTypesReadOnly),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// SecurityProfile: &armcompute.VMDiskSecurityProfile{
// DiskEncryptionSet: &armcompute.DiskEncryptionSetParameters{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"),
// },
// SecurityEncryptionType: to.Ptr(armcompute.SecurityEncryptionTypesDiskWithVMGuestState),
// },
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardSSDLRS),
// },
// },
// },
// VMID: to.Ptr("5c0d55a7-c407-4ed6-bf7d-ddb810267c85"),
// },
// }
}
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");
/**
* This sample demonstrates how to The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithSecurityTypeConfidentialVMWithCustomerManagedKeys.json
*/
async function createAVMWithSecurityTypeConfidentialVMWithCustomerManagedKeys() {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP"] || "myResourceGroup";
const vmName = "myVM";
const parameters = {
hardwareProfile: { vmSize: "Standard_DC2as_v5" },
location: "westus",
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
osProfile: {
adminPassword: "{your-password}",
adminUsername: "{your-username}",
computerName: "myVM",
},
securityProfile: {
securityType: "ConfidentialVM",
uefiSettings: { secureBootEnabled: true, vTpmEnabled: true },
},
storageProfile: {
imageReference: {
offer: "2019-datacenter-cvm",
publisher: "MicrosoftWindowsServer",
sku: "windows-cvm",
version: "17763.2183.2109130127",
},
osDisk: {
name: "myVMosdisk",
caching: "ReadOnly",
createOption: "FromImage",
managedDisk: {
securityProfile: {
diskEncryptionSet: {
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}",
},
securityEncryptionType: "DiskWithVMGuestState",
},
storageAccountType: "StandardSSD_LRS",
},
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.beginCreateOrUpdateAndWait(
resourceGroupName,
vmName,
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
範例回覆
{
"name": "myVM",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "windows-cvm",
"publisher": "MicrosoftWindowsServer",
"version": "17763.2183.2109130127",
"offer": "2019-datacenter-cvm"
},
"osDisk": {
"caching": "ReadOnly",
"managedDisk": {
"storageAccountType": "StandardSSD_LRS",
"securityProfile": {
"securityEncryptionType": "DiskWithVMGuestState",
"diskEncryptionSet": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"
}
}
},
"createOption": "FromImage",
"name": "myVMosdisk"
},
"dataDisks": []
},
"securityProfile": {
"uefiSettings": {
"secureBootEnabled": true,
"vTpmEnabled": true
},
"securityType": "ConfidentialVM"
},
"vmId": "5c0d55a7-c407-4ed6-bf7d-ddb810267c85",
"hardwareProfile": {
"vmSize": "Standard_DC2as_v5"
},
"provisioningState": "Creating"
},
"type": "Microsoft.Compute/virtualMachines",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"location": "westus"
}
{
"name": "myVM",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "windows-cvm",
"publisher": "MicrosoftWindowsServer",
"version": "17763.2183.2109130127",
"offer": "2019-datacenter-cvm"
},
"osDisk": {
"caching": "ReadOnly",
"managedDisk": {
"storageAccountType": "StandardSSD_LRS",
"securityProfile": {
"securityEncryptionType": "DiskWithVMGuestState",
"diskEncryptionSet": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"
}
}
},
"createOption": "FromImage",
"name": "myVMosdisk"
},
"dataDisks": []
},
"securityProfile": {
"uefiSettings": {
"secureBootEnabled": true,
"vTpmEnabled": true
},
"securityType": "ConfidentialVM"
},
"vmId": "5c0d55a7-c407-4ed6-bf7d-ddb810267c85",
"hardwareProfile": {
"vmSize": "Standard_DC2as_v5"
},
"provisioningState": "Creating"
},
"type": "Microsoft.Compute/virtualMachines",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"location": "westus"
}
Create a VM with securityType ConfidentialVM with NonPersistedTPM securityEncryptionType
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2024-03-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_DC2es_v5"
},
"securityProfile": {
"uefiSettings": {
"secureBootEnabled": false,
"vTpmEnabled": true
},
"securityType": "ConfidentialVM"
},
"storageProfile": {
"imageReference": {
"sku": "linux-cvm",
"publisher": "UbuntuServer",
"version": "17763.2183.2109130127",
"offer": "2022-datacenter-cvm"
},
"osDisk": {
"caching": "ReadOnly",
"managedDisk": {
"storageAccountType": "StandardSSD_LRS",
"securityProfile": {
"securityEncryptionType": "NonPersistedTPM"
}
},
"createOption": "FromImage",
"name": "myVMosdisk"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
from typing import Any, IO, Union
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_create_with_security_type_confidential_vm_with_non_persisted_tpm.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_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_DC2es_v5"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"securityProfile": {
"securityType": "ConfidentialVM",
"uefiSettings": {"secureBootEnabled": False, "vTpmEnabled": True},
},
"storageProfile": {
"imageReference": {
"offer": "2022-datacenter-cvm",
"publisher": "UbuntuServer",
"sku": "linux-cvm",
"version": "17763.2183.2109130127",
},
"osDisk": {
"caching": "ReadOnly",
"createOption": "FromImage",
"managedDisk": {
"securityProfile": {"securityEncryptionType": "NonPersistedTPM"},
"storageAccountType": "StandardSSD_LRS",
},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithSecurityTypeConfidentialVMWithNonPersistedTPM.json
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/v5"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/92de53a5f1e0e03c94b40475d2135d97148ed014/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithSecurityTypeConfidentialVMWithNonPersistedTPM.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVmWithSecurityTypeConfidentialVmWithNonPersistedTpmSecurityEncryptionType() {
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.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypes("Standard_DC2es_v5")),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
}},
},
OSProfile: &armcompute.OSProfile{
AdminPassword: to.Ptr("{your-password}"),
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
},
SecurityProfile: &armcompute.SecurityProfile{
SecurityType: to.Ptr(armcompute.SecurityTypesConfidentialVM),
UefiSettings: &armcompute.UefiSettings{
SecureBootEnabled: to.Ptr(false),
VTpmEnabled: to.Ptr(true),
},
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("2022-datacenter-cvm"),
Publisher: to.Ptr("UbuntuServer"),
SKU: to.Ptr("linux-cvm"),
Version: to.Ptr("17763.2183.2109130127"),
},
OSDisk: &armcompute.OSDisk{
Name: to.Ptr("myVMosdisk"),
Caching: to.Ptr(armcompute.CachingTypesReadOnly),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.ManagedDiskParameters{
SecurityProfile: &armcompute.VMDiskSecurityProfile{
SecurityEncryptionType: to.Ptr(armcompute.SecurityEncryptionTypesNonPersistedTPM),
},
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardSSDLRS),
},
},
},
},
}, &armcompute.VirtualMachinesClientBeginCreateOrUpdateOptions{IfMatch: nil,
IfNoneMatch: 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)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.VirtualMachine = armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// Properties: &armcompute.VirtualMachineProperties{
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypes("Standard_DC2es_v5")),
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// }},
// },
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// ComputerName: to.Ptr("myVM"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// EnableAutomaticUpdates: to.Ptr(true),
// ProvisionVMAgent: to.Ptr(true),
// },
// },
// ProvisioningState: to.Ptr("Succeeded"),
// SecurityProfile: &armcompute.SecurityProfile{
// SecurityType: to.Ptr(armcompute.SecurityTypesConfidentialVM),
// UefiSettings: &armcompute.UefiSettings{
// SecureBootEnabled: to.Ptr(false),
// VTpmEnabled: to.Ptr(true),
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// DataDisks: []*armcompute.DataDisk{
// },
// ImageReference: &armcompute.ImageReference{
// Offer: to.Ptr("2022-datacenter-cvm"),
// Publisher: to.Ptr("UbuntuServer"),
// SKU: to.Ptr("linux-cvm"),
// Version: to.Ptr("17763.2183.2109130127"),
// },
// OSDisk: &armcompute.OSDisk{
// Name: to.Ptr("myVMosdisk"),
// Caching: to.Ptr(armcompute.CachingTypesReadOnly),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// SecurityProfile: &armcompute.VMDiskSecurityProfile{
// SecurityEncryptionType: to.Ptr(armcompute.SecurityEncryptionTypesNonPersistedTPM),
// },
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardSSDLRS),
// },
// },
// },
// VMID: to.Ptr("5c0d55a7-c407-4ed6-bf7d-ddb810267c85"),
// },
// }
}
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");
/**
* This sample demonstrates how to The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithSecurityTypeConfidentialVMWithNonPersistedTPM.json
*/
async function createAVMWithSecurityTypeConfidentialVMWithNonPersistedTpmSecurityEncryptionType() {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP"] || "myResourceGroup";
const vmName = "myVM";
const parameters = {
hardwareProfile: { vmSize: "Standard_DC2es_v5" },
location: "westus",
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
osProfile: {
adminPassword: "{your-password}",
adminUsername: "{your-username}",
computerName: "myVM",
},
securityProfile: {
securityType: "ConfidentialVM",
uefiSettings: { secureBootEnabled: false, vTpmEnabled: true },
},
storageProfile: {
imageReference: {
offer: "2022-datacenter-cvm",
publisher: "UbuntuServer",
sku: "linux-cvm",
version: "17763.2183.2109130127",
},
osDisk: {
name: "myVMosdisk",
caching: "ReadOnly",
createOption: "FromImage",
managedDisk: {
securityProfile: { securityEncryptionType: "NonPersistedTPM" },
storageAccountType: "StandardSSD_LRS",
},
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.beginCreateOrUpdateAndWait(
resourceGroupName,
vmName,
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
範例回覆
{
"name": "myVM",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "linux-cvm",
"publisher": "UbuntuServer",
"version": "17763.2183.2109130127",
"offer": "2022-datacenter-cvm"
},
"osDisk": {
"caching": "ReadOnly",
"managedDisk": {
"storageAccountType": "StandardSSD_LRS",
"securityProfile": {
"securityEncryptionType": "NonPersistedTPM"
}
},
"createOption": "FromImage",
"name": "myVMosdisk"
},
"dataDisks": []
},
"securityProfile": {
"uefiSettings": {
"secureBootEnabled": false,
"vTpmEnabled": true
},
"securityType": "ConfidentialVM"
},
"vmId": "5c0d55a7-c407-4ed6-bf7d-ddb810267c85",
"hardwareProfile": {
"vmSize": "Standard_DC2es_v5"
},
"provisioningState": "Creating"
},
"type": "Microsoft.Compute/virtualMachines",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"location": "westus"
}
{
"name": "myVM",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "linux-cvm",
"publisher": "UbuntuServer",
"version": "17763.2183.2109130127",
"offer": "2022-datacenter-cvm"
},
"osDisk": {
"caching": "ReadOnly",
"managedDisk": {
"storageAccountType": "StandardSSD_LRS",
"securityProfile": {
"securityEncryptionType": "NonPersistedTPM"
}
},
"createOption": "FromImage",
"name": "myVMosdisk"
},
"dataDisks": []
},
"securityProfile": {
"uefiSettings": {
"secureBootEnabled": false,
"vTpmEnabled": true
},
"securityType": "ConfidentialVM"
},
"vmId": "5c0d55a7-c407-4ed6-bf7d-ddb810267c85",
"hardwareProfile": {
"vmSize": "Standard_DC2es_v5"
},
"provisioningState": "Creating"
},
"type": "Microsoft.Compute/virtualMachines",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"location": "westus"
}
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2024-03-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_DC2as_v5"
},
"securityProfile": {
"uefiSettings": {
"secureBootEnabled": true,
"vTpmEnabled": true
},
"securityType": "ConfidentialVM"
},
"storageProfile": {
"imageReference": {
"sku": "windows-cvm",
"publisher": "MicrosoftWindowsServer",
"version": "17763.2183.2109130127",
"offer": "2019-datacenter-cvm"
},
"osDisk": {
"caching": "ReadOnly",
"managedDisk": {
"storageAccountType": "StandardSSD_LRS",
"securityProfile": {
"securityEncryptionType": "DiskWithVMGuestState"
}
},
"createOption": "FromImage",
"name": "myVMosdisk"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
from typing import Any, IO, Union
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_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_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_DC2as_v5"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"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": "DiskWithVMGuestState"},
"storageAccountType": "StandardSSD_LRS",
},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithSecurityTypeConfidentialVM.json
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/v5"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/92de53a5f1e0e03c94b40475d2135d97148ed014/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithSecurityTypeConfidentialVM.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVmWithSecurityTypeConfidentialVmWithPlatformManagedKeys() {
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.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypes("Standard_DC2as_v5")),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
}},
},
OSProfile: &armcompute.OSProfile{
AdminPassword: to.Ptr("{your-password}"),
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
},
SecurityProfile: &armcompute.SecurityProfile{
SecurityType: to.Ptr(armcompute.SecurityTypesConfidentialVM),
UefiSettings: &armcompute.UefiSettings{
SecureBootEnabled: to.Ptr(true),
VTpmEnabled: to.Ptr(true),
},
},
StorageProfile: &armcompute.StorageProfile{
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.OSDisk{
Name: to.Ptr("myVMosdisk"),
Caching: to.Ptr(armcompute.CachingTypesReadOnly),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.ManagedDiskParameters{
SecurityProfile: &armcompute.VMDiskSecurityProfile{
SecurityEncryptionType: to.Ptr(armcompute.SecurityEncryptionTypesDiskWithVMGuestState),
},
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardSSDLRS),
},
},
},
},
}, &armcompute.VirtualMachinesClientBeginCreateOrUpdateOptions{IfMatch: nil,
IfNoneMatch: 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)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.VirtualMachine = armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// Properties: &armcompute.VirtualMachineProperties{
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypes("Standard_DC2as_v5")),
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// }},
// },
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// ComputerName: to.Ptr("myVM"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// EnableAutomaticUpdates: to.Ptr(true),
// ProvisionVMAgent: to.Ptr(true),
// },
// },
// ProvisioningState: to.Ptr("Succeeded"),
// SecurityProfile: &armcompute.SecurityProfile{
// SecurityType: to.Ptr(armcompute.SecurityTypesConfidentialVM),
// UefiSettings: &armcompute.UefiSettings{
// SecureBootEnabled: to.Ptr(true),
// VTpmEnabled: to.Ptr(true),
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// DataDisks: []*armcompute.DataDisk{
// },
// 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.OSDisk{
// Name: to.Ptr("myVMosdisk"),
// Caching: to.Ptr(armcompute.CachingTypesReadOnly),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// SecurityProfile: &armcompute.VMDiskSecurityProfile{
// SecurityEncryptionType: to.Ptr(armcompute.SecurityEncryptionTypesDiskWithVMGuestState),
// },
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardSSDLRS),
// },
// },
// },
// VMID: to.Ptr("5c0d55a7-c407-4ed6-bf7d-ddb810267c85"),
// },
// }
}
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");
/**
* This sample demonstrates how to The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithSecurityTypeConfidentialVM.json
*/
async function createAVMWithSecurityTypeConfidentialVMWithPlatformManagedKeys() {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP"] || "myResourceGroup";
const vmName = "myVM";
const parameters = {
hardwareProfile: { vmSize: "Standard_DC2as_v5" },
location: "westus",
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
osProfile: {
adminPassword: "{your-password}",
adminUsername: "{your-username}",
computerName: "myVM",
},
securityProfile: {
securityType: "ConfidentialVM",
uefiSettings: { secureBootEnabled: true, vTpmEnabled: true },
},
storageProfile: {
imageReference: {
offer: "2019-datacenter-cvm",
publisher: "MicrosoftWindowsServer",
sku: "windows-cvm",
version: "17763.2183.2109130127",
},
osDisk: {
name: "myVMosdisk",
caching: "ReadOnly",
createOption: "FromImage",
managedDisk: {
securityProfile: { securityEncryptionType: "DiskWithVMGuestState" },
storageAccountType: "StandardSSD_LRS",
},
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.beginCreateOrUpdateAndWait(
resourceGroupName,
vmName,
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
範例回覆
{
"name": "myVM",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "windows-cvm",
"publisher": "MicrosoftWindowsServer",
"version": "17763.2183.2109130127",
"offer": "2019-datacenter-cvm"
},
"osDisk": {
"caching": "ReadOnly",
"managedDisk": {
"storageAccountType": "StandardSSD_LRS",
"securityProfile": {
"securityEncryptionType": "DiskWithVMGuestState"
}
},
"createOption": "FromImage",
"name": "myVMosdisk"
},
"dataDisks": []
},
"securityProfile": {
"uefiSettings": {
"secureBootEnabled": true,
"vTpmEnabled": true
},
"securityType": "ConfidentialVM"
},
"vmId": "5c0d55a7-c407-4ed6-bf7d-ddb810267c85",
"hardwareProfile": {
"vmSize": "Standard_DC2as_v5"
},
"provisioningState": "Creating"
},
"type": "Microsoft.Compute/virtualMachines",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"location": "westus"
}
{
"name": "myVM",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "windows-cvm",
"publisher": "MicrosoftWindowsServer",
"version": "17763.2183.2109130127",
"offer": "2019-datacenter-cvm"
},
"osDisk": {
"caching": "ReadOnly",
"managedDisk": {
"storageAccountType": "StandardSSD_LRS",
"securityProfile": {
"securityEncryptionType": "DiskWithVMGuestState"
}
},
"createOption": "FromImage",
"name": "myVMosdisk"
},
"dataDisks": []
},
"securityProfile": {
"uefiSettings": {
"secureBootEnabled": true,
"vTpmEnabled": true
},
"securityType": "ConfidentialVM"
},
"vmId": "5c0d55a7-c407-4ed6-bf7d-ddb810267c85",
"hardwareProfile": {
"vmSize": "Standard_DC2as_v5"
},
"provisioningState": "Creating"
},
"type": "Microsoft.Compute/virtualMachines",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"location": "westus"
}
Create a vm with ssh authentication.
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2024-03-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"storageProfile": {
"imageReference": {
"sku": "{image_sku}",
"publisher": "{image_publisher}",
"version": "latest",
"offer": "{image_offer}"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"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": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
from typing import Any, IO, Union
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_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_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_D1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"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": "{image_offer}",
"publisher": "{image_publisher}",
"sku": "{image_sku}",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Standard_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithSshAuthentication.json
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/v5"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/92de53a5f1e0e03c94b40475d2135d97148ed014/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithSshAuthentication.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVmWithSshAuthentication() {
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.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
}},
},
OSProfile: &armcompute.OSProfile{
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
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.StorageProfile{
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("{image_offer}"),
Publisher: to.Ptr("{image_publisher}"),
SKU: to.Ptr("{image_sku}"),
Version: to.Ptr("latest"),
},
OSDisk: &armcompute.OSDisk{
Name: to.Ptr("myVMosdisk"),
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
},
}, &armcompute.VirtualMachinesClientBeginCreateOrUpdateOptions{IfMatch: nil,
IfNoneMatch: 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)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.VirtualMachine = armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// Properties: &armcompute.VirtualMachineProperties{
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// }},
// },
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// ComputerName: to.Ptr("myVM"),
// 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"),
// }},
// },
// },
// Secrets: []*armcompute.VaultSecretGroup{
// },
// },
// ProvisioningState: to.Ptr("Succeeded"),
// StorageProfile: &armcompute.StorageProfile{
// DataDisks: []*armcompute.DataDisk{
// },
// ImageReference: &armcompute.ImageReference{
// Offer: to.Ptr("UbuntuServer"),
// Publisher: to.Ptr("Canonical"),
// SKU: to.Ptr("16.04-LTS"),
// Version: to.Ptr("latest"),
// },
// OSDisk: &armcompute.OSDisk{
// Name: to.Ptr("myVMosdisk"),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// OSType: to.Ptr(armcompute.OperatingSystemTypesLinux),
// },
// },
// VMID: to.Ptr("e0de9b84-a506-4b95-9623-00a425d05c90"),
// },
// }
}
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");
/**
* This sample demonstrates how to The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithSshAuthentication.json
*/
async function createAVMWithSshAuthentication() {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP"] || "myResourceGroup";
const vmName = "myVM";
const parameters = {
hardwareProfile: { vmSize: "Standard_D1_v2" },
location: "westus",
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
osProfile: {
adminUsername: "{your-username}",
computerName: "myVM",
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: "{image_offer}",
publisher: "{image_publisher}",
sku: "{image_sku}",
version: "latest",
},
osDisk: {
name: "myVMosdisk",
caching: "ReadWrite",
createOption: "FromImage",
managedDisk: { storageAccountType: "Standard_LRS" },
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.beginCreateOrUpdateAndWait(
resourceGroupName,
vmName,
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
範例回覆
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"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": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "16.04-LTS",
"publisher": "Canonical",
"version": "latest",
"offer": "UbuntuServer"
},
"osDisk": {
"osType": "Linux",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"vmId": "e0de9b84-a506-4b95-9623-00a425d05c90",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"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": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "16.04-LTS",
"publisher": "Canonical",
"version": "latest",
"offer": "UbuntuServer"
},
"osDisk": {
"osType": "Linux",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"vmId": "e0de9b84-a506-4b95-9623-00a425d05c90",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Create a VM with Uefi Settings of secureBoot and vTPM.
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2024-03-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D2s_v3"
},
"securityProfile": {
"uefiSettings": {
"secureBootEnabled": true,
"vTpmEnabled": true
},
"securityType": "TrustedLaunch"
},
"storageProfile": {
"imageReference": {
"sku": "windows10-tvm",
"publisher": "MicrosoftWindowsServer",
"version": "18363.592.2001092016",
"offer": "windowsserver-gen2preview-preview"
},
"osDisk": {
"caching": "ReadOnly",
"managedDisk": {
"storageAccountType": "StandardSSD_LRS"
},
"createOption": "FromImage",
"name": "myVMosdisk"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
from typing import Any, IO, Union
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_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_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_D2s_v3"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"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"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithUefiSettings.json
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/v5"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/92de53a5f1e0e03c94b40475d2135d97148ed014/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithUefiSettings.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVmWithUefiSettingsOfSecureBootAndVTpm() {
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.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD2SV3),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
}},
},
OSProfile: &armcompute.OSProfile{
AdminPassword: to.Ptr("{your-password}"),
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
},
SecurityProfile: &armcompute.SecurityProfile{
SecurityType: to.Ptr(armcompute.SecurityTypesTrustedLaunch),
UefiSettings: &armcompute.UefiSettings{
SecureBootEnabled: to.Ptr(true),
VTpmEnabled: to.Ptr(true),
},
},
StorageProfile: &armcompute.StorageProfile{
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.OSDisk{
Name: to.Ptr("myVMosdisk"),
Caching: to.Ptr(armcompute.CachingTypesReadOnly),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardSSDLRS),
},
},
},
},
}, &armcompute.VirtualMachinesClientBeginCreateOrUpdateOptions{IfMatch: nil,
IfNoneMatch: 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)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.VirtualMachine = armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// Properties: &armcompute.VirtualMachineProperties{
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD2SV3),
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// }},
// },
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// ComputerName: to.Ptr("myVM"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// EnableAutomaticUpdates: to.Ptr(true),
// ProvisionVMAgent: to.Ptr(true),
// },
// },
// ProvisioningState: to.Ptr("Succeeded"),
// SecurityProfile: &armcompute.SecurityProfile{
// SecurityType: to.Ptr(armcompute.SecurityTypesTrustedLaunch),
// UefiSettings: &armcompute.UefiSettings{
// SecureBootEnabled: to.Ptr(true),
// VTpmEnabled: to.Ptr(true),
// },
// },
// StorageProfile: &armcompute.StorageProfile{
// DataDisks: []*armcompute.DataDisk{
// },
// 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.OSDisk{
// Name: to.Ptr("myVMosdisk"),
// Caching: to.Ptr(armcompute.CachingTypesReadOnly),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardSSDLRS),
// },
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// },
// },
// VMID: to.Ptr("5c0d55a7-c407-4ed6-bf7d-ddb810267c85"),
// },
// }
}
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");
/**
* This sample demonstrates how to The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithUefiSettings.json
*/
async function createAVMWithUefiSettingsOfSecureBootAndVTpm() {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP"] || "myResourceGroup";
const vmName = "myVM";
const parameters = {
hardwareProfile: { vmSize: "Standard_D2s_v3" },
location: "westus",
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
osProfile: {
adminPassword: "{your-password}",
adminUsername: "{your-username}",
computerName: "myVM",
},
securityProfile: {
securityType: "TrustedLaunch",
uefiSettings: { secureBootEnabled: true, vTpmEnabled: true },
},
storageProfile: {
imageReference: {
offer: "windowsserver-gen2preview-preview",
publisher: "MicrosoftWindowsServer",
sku: "windows10-tvm",
version: "18363.592.2001092016",
},
osDisk: {
name: "myVMosdisk",
caching: "ReadOnly",
createOption: "FromImage",
managedDisk: { storageAccountType: "StandardSSD_LRS" },
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.beginCreateOrUpdateAndWait(
resourceGroupName,
vmName,
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
範例回覆
{
"name": "myVM",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "windows10-tvm",
"publisher": "MicrosoftWindowsServer",
"version": "18363.592.2001092016",
"offer": "windowsserver-gen2preview-preview"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadOnly",
"managedDisk": {
"storageAccountType": "StandardSSD_LRS"
},
"createOption": "FromImage",
"name": "myVMosdisk"
},
"dataDisks": []
},
"securityProfile": {
"uefiSettings": {
"secureBootEnabled": true,
"vTpmEnabled": true
},
"securityType": "TrustedLaunch"
},
"vmId": "5c0d55a7-c407-4ed6-bf7d-ddb810267c85",
"hardwareProfile": {
"vmSize": "Standard_D2s_v3"
},
"provisioningState": "Creating"
},
"type": "Microsoft.Compute/virtualMachines",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"location": "westus"
}
{
"name": "myVM",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "windows10-tvm",
"publisher": "MicrosoftWindowsServer",
"version": "18363.592.2001092016",
"offer": "windowsserver-gen2preview-preview"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadOnly",
"managedDisk": {
"storageAccountType": "StandardSSD_LRS"
},
"createOption": "FromImage",
"name": "myVMosdisk"
},
"dataDisks": []
},
"securityProfile": {
"uefiSettings": {
"secureBootEnabled": true,
"vTpmEnabled": true
},
"securityType": "TrustedLaunch"
},
"vmId": "5c0d55a7-c407-4ed6-bf7d-ddb810267c85",
"hardwareProfile": {
"vmSize": "Standard_D2s_v3"
},
"provisioningState": "Creating"
},
"type": "Microsoft.Compute/virtualMachines",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"location": "westus"
}
Create a VM with UserData
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/{vm-name}?api-version=2024-03-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"name": "vmOSdisk",
"createOption": "FromImage"
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "{vm-name}",
"adminPassword": "{your-password}"
},
"diagnosticsProfile": {
"bootDiagnostics": {
"storageUri": "http://{existing-storage-account-name}.blob.core.windows.net",
"enabled": true
}
},
"userData": "RXhhbXBsZSBVc2VyRGF0YQ=="
}
}
from typing import Any, IO, Union
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_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_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="{vm-name}",
parameters={
"location": "westus",
"properties": {
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": True,
"storageUri": "http://{existing-storage-account-name}.blob.core.windows.net",
}
},
"hardwareProfile": {"vmSize": "Standard_D1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "{vm-name}",
},
"storageProfile": {
"imageReference": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2016-Datacenter",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Standard_LRS"},
"name": "vmOSdisk",
},
},
"userData": "RXhhbXBsZSBVc2VyRGF0YQ==",
},
},
).result()
print(response)
# x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithUserData.json
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/v5"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/92de53a5f1e0e03c94b40475d2135d97148ed014/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithUserData.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVmWithUserData() {
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.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "{vm-name}", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
DiagnosticsProfile: &armcompute.DiagnosticsProfile{
BootDiagnostics: &armcompute.BootDiagnostics{
Enabled: to.Ptr(true),
StorageURI: to.Ptr("http://{existing-storage-account-name}.blob.core.windows.net"),
},
},
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
}},
},
OSProfile: &armcompute.OSProfile{
AdminPassword: to.Ptr("{your-password}"),
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("{vm-name}"),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("WindowsServer"),
Publisher: to.Ptr("MicrosoftWindowsServer"),
SKU: to.Ptr("2016-Datacenter"),
Version: to.Ptr("latest"),
},
OSDisk: &armcompute.OSDisk{
Name: to.Ptr("vmOSdisk"),
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
UserData: to.Ptr("RXhhbXBsZSBVc2VyRGF0YQ=="),
},
}, &armcompute.VirtualMachinesClientBeginCreateOrUpdateOptions{IfMatch: nil,
IfNoneMatch: 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)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.VirtualMachine = armcompute.VirtualMachine{
// Name: to.Ptr("{vm-name}"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/{vm-name}"),
// Location: to.Ptr("westus"),
// Properties: &armcompute.VirtualMachineProperties{
// DiagnosticsProfile: &armcompute.DiagnosticsProfile{
// BootDiagnostics: &armcompute.BootDiagnostics{
// Enabled: to.Ptr(true),
// StorageURI: to.Ptr("http://nsgdiagnostic.blob.core.windows.net"),
// },
// },
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// }},
// },
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// ComputerName: to.Ptr("{vm-name}"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// EnableAutomaticUpdates: to.Ptr(true),
// ProvisionVMAgent: to.Ptr(true),
// },
// },
// ProvisioningState: to.Ptr("Succeeded"),
// StorageProfile: &armcompute.StorageProfile{
// DataDisks: []*armcompute.DataDisk{
// },
// ImageReference: &armcompute.ImageReference{
// Offer: to.Ptr("WindowsServer"),
// Publisher: to.Ptr("MicrosoftWindowsServer"),
// SKU: to.Ptr("2016-Datacenter"),
// Version: to.Ptr("latest"),
// },
// OSDisk: &armcompute.OSDisk{
// Name: to.Ptr("vmOSdisk"),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// },
// },
// VMID: to.Ptr("676420ba-7a24-4bfe-80bd-9c841ee184fa"),
// },
// }
}
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");
/**
* This sample demonstrates how to The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithUserData.json
*/
async function createAVMWithUserData() {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP"] || "myResourceGroup";
const vmName = "{vm-name}";
const parameters = {
diagnosticsProfile: {
bootDiagnostics: {
enabled: true,
storageUri: "http://{existing-storage-account-name}.blob.core.windows.net",
},
},
hardwareProfile: { vmSize: "Standard_D1_v2" },
location: "westus",
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
osProfile: {
adminPassword: "{your-password}",
adminUsername: "{your-username}",
computerName: "{vm-name}",
},
storageProfile: {
imageReference: {
offer: "WindowsServer",
publisher: "MicrosoftWindowsServer",
sku: "2016-Datacenter",
version: "latest",
},
osDisk: {
name: "vmOSdisk",
caching: "ReadWrite",
createOption: "FromImage",
managedDisk: { storageAccountType: "Standard_LRS" },
},
},
userData: "RXhhbXBsZSBVc2VyRGF0YQ==",
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.beginCreateOrUpdateAndWait(
resourceGroupName,
vmName,
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
範例回覆
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/{vm-name}",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "{vm-name}",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "vmOSdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"diagnosticsProfile": {
"bootDiagnostics": {
"storageUri": "http://nsgdiagnostic.blob.core.windows.net",
"enabled": true
}
},
"vmId": "676420ba-7a24-4bfe-80bd-9c841ee184fa",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "{vm-name}",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/{vm-name}",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "{vm-name}",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "vmOSdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"diagnosticsProfile": {
"bootDiagnostics": {
"storageUri": "http://nsgdiagnostic.blob.core.windows.net",
"enabled": true
}
},
"vmId": "676420ba-7a24-4bfe-80bd-9c841ee184fa",
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"provisioningState": "Creating"
},
"name": "{vm-name}",
"location": "westus"
}
Create a VM with VM Size Properties
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2024-03-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D4_v3",
"vmSizeProperties": {
"vCPUsAvailable": 1,
"vCPUsPerCore": 1
}
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"diagnosticsProfile": {
"bootDiagnostics": {
"storageUri": "http://{existing-storage-account-name}.blob.core.windows.net",
"enabled": true
}
},
"userData": "U29tZSBDdXN0b20gRGF0YQ=="
}
}
from typing import Any, IO, Union
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_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_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": True,
"storageUri": "http://{existing-storage-account-name}.blob.core.windows.net",
}
},
"hardwareProfile": {
"vmSize": "Standard_D4_v3",
"vmSizeProperties": {"vCPUsAvailable": 1, "vCPUsPerCore": 1},
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"storageProfile": {
"imageReference": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2016-Datacenter",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Standard_LRS"},
"name": "myVMosdisk",
},
},
"userData": "U29tZSBDdXN0b20gRGF0YQ==",
},
},
).result()
print(response)
# x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithVMSizeProperties.json
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/v5"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/92de53a5f1e0e03c94b40475d2135d97148ed014/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithVMSizeProperties.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAVmWithVmSizeProperties() {
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.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
DiagnosticsProfile: &armcompute.DiagnosticsProfile{
BootDiagnostics: &armcompute.BootDiagnostics{
Enabled: to.Ptr(true),
StorageURI: to.Ptr("http://{existing-storage-account-name}.blob.core.windows.net"),
},
},
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD4V3),
VMSizeProperties: &armcompute.VMSizeProperties{
VCPUsAvailable: to.Ptr[int32](1),
VCPUsPerCore: to.Ptr[int32](1),
},
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
}},
},
OSProfile: &armcompute.OSProfile{
AdminPassword: to.Ptr("{your-password}"),
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("WindowsServer"),
Publisher: to.Ptr("MicrosoftWindowsServer"),
SKU: to.Ptr("2016-Datacenter"),
Version: to.Ptr("latest"),
},
OSDisk: &armcompute.OSDisk{
Name: to.Ptr("myVMosdisk"),
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
UserData: to.Ptr("U29tZSBDdXN0b20gRGF0YQ=="),
},
}, &armcompute.VirtualMachinesClientBeginCreateOrUpdateOptions{IfMatch: nil,
IfNoneMatch: 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)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.VirtualMachine = armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// Properties: &armcompute.VirtualMachineProperties{
// DiagnosticsProfile: &armcompute.DiagnosticsProfile{
// BootDiagnostics: &armcompute.BootDiagnostics{
// Enabled: to.Ptr(true),
// StorageURI: to.Ptr("http://nsgdiagnostic.blob.core.windows.net"),
// },
// },
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD4V3),
// VMSizeProperties: &armcompute.VMSizeProperties{
// VCPUsAvailable: to.Ptr[int32](1),
// VCPUsPerCore: to.Ptr[int32](1),
// },
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// }},
// },
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// ComputerName: to.Ptr("myVM"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// EnableAutomaticUpdates: to.Ptr(true),
// ProvisionVMAgent: to.Ptr(true),
// },
// },
// ProvisioningState: to.Ptr("Succeeded"),
// StorageProfile: &armcompute.StorageProfile{
// DataDisks: []*armcompute.DataDisk{
// },
// ImageReference: &armcompute.ImageReference{
// Offer: to.Ptr("WindowsServer"),
// Publisher: to.Ptr("MicrosoftWindowsServer"),
// SKU: to.Ptr("2016-Datacenter"),
// Version: to.Ptr("latest"),
// },
// OSDisk: &armcompute.OSDisk{
// Name: to.Ptr("myVMosdisk"),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// },
// },
// VMID: to.Ptr("676420ba-7a24-4bfe-80bd-9c841ee184fa"),
// },
// }
}
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");
/**
* This sample demonstrates how to The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithVMSizeProperties.json
*/
async function createAVMWithVMSizeProperties() {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP"] || "myResourceGroup";
const vmName = "myVM";
const parameters = {
diagnosticsProfile: {
bootDiagnostics: {
enabled: true,
storageUri: "http://{existing-storage-account-name}.blob.core.windows.net",
},
},
hardwareProfile: {
vmSize: "Standard_D4_v3",
vmSizeProperties: { vCPUsAvailable: 1, vCPUsPerCore: 1 },
},
location: "westus",
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
osProfile: {
adminPassword: "{your-password}",
adminUsername: "{your-username}",
computerName: "myVM",
},
storageProfile: {
imageReference: {
offer: "WindowsServer",
publisher: "MicrosoftWindowsServer",
sku: "2016-Datacenter",
version: "latest",
},
osDisk: {
name: "myVMosdisk",
caching: "ReadWrite",
createOption: "FromImage",
managedDisk: { storageAccountType: "Standard_LRS" },
},
},
userData: "U29tZSBDdXN0b20gRGF0YQ==",
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.beginCreateOrUpdateAndWait(
resourceGroupName,
vmName,
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
範例回覆
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"diagnosticsProfile": {
"bootDiagnostics": {
"storageUri": "http://nsgdiagnostic.blob.core.windows.net",
"enabled": true
}
},
"vmId": "676420ba-7a24-4bfe-80bd-9c841ee184fa",
"hardwareProfile": {
"vmSize": "Standard_D4_v3",
"vmSizeProperties": {
"vCPUsAvailable": 1,
"vCPUsPerCore": 1
}
},
"provisioningState": "Updating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"dataDisks": []
},
"diagnosticsProfile": {
"bootDiagnostics": {
"storageUri": "http://nsgdiagnostic.blob.core.windows.net",
"enabled": true
}
},
"vmId": "676420ba-7a24-4bfe-80bd-9c841ee184fa",
"hardwareProfile": {
"vmSize": "Standard_D4_v3",
"vmSizeProperties": {
"vCPUsAvailable": 1,
"vCPUsPerCore": 1
}
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Create a Windows vm with a patch setting assessmentMode of ImageDefault.
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2024-03-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Premium_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true,
"patchSettings": {
"assessmentMode": "ImageDefault"
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
from typing import Any, IO, Union
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_create_windows_vm_with_patch_setting_assessment_mode_of_image_default.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_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_D1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
"windowsConfiguration": {
"enableAutomaticUpdates": True,
"patchSettings": {"assessmentMode": "ImageDefault"},
"provisionVMAgent": True,
},
},
"storageProfile": {
"imageReference": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2016-Datacenter",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Premium_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WindowsVmWithPatchSettingAssessmentModeOfImageDefault.json
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/v5"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/92de53a5f1e0e03c94b40475d2135d97148ed014/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WindowsVmWithPatchSettingAssessmentModeOfImageDefault.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAWindowsVmWithAPatchSettingAssessmentModeOfImageDefault() {
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.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
}},
},
OSProfile: &armcompute.OSProfile{
AdminPassword: to.Ptr("{your-password}"),
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
WindowsConfiguration: &armcompute.WindowsConfiguration{
EnableAutomaticUpdates: to.Ptr(true),
PatchSettings: &armcompute.PatchSettings{
AssessmentMode: to.Ptr(armcompute.WindowsPatchAssessmentModeImageDefault),
},
ProvisionVMAgent: to.Ptr(true),
},
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("WindowsServer"),
Publisher: to.Ptr("MicrosoftWindowsServer"),
SKU: to.Ptr("2016-Datacenter"),
Version: to.Ptr("latest"),
},
OSDisk: &armcompute.OSDisk{
Name: to.Ptr("myVMosdisk"),
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesPremiumLRS),
},
},
},
},
}, &armcompute.VirtualMachinesClientBeginCreateOrUpdateOptions{IfMatch: nil,
IfNoneMatch: 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)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.VirtualMachine = armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// Properties: &armcompute.VirtualMachineProperties{
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardDS1V2),
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// }},
// },
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// ComputerName: to.Ptr("myVM"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// EnableAutomaticUpdates: to.Ptr(true),
// PatchSettings: &armcompute.PatchSettings{
// AssessmentMode: to.Ptr(armcompute.WindowsPatchAssessmentModeImageDefault),
// },
// ProvisionVMAgent: to.Ptr(true),
// },
// },
// ProvisioningState: to.Ptr("Succeeded"),
// StorageProfile: &armcompute.StorageProfile{
// DataDisks: []*armcompute.DataDisk{
// },
// ImageReference: &armcompute.ImageReference{
// Offer: to.Ptr("WindowsServer"),
// Publisher: to.Ptr("MicrosoftWindowsServer"),
// SKU: to.Ptr("2016-Datacenter"),
// Version: to.Ptr("latest"),
// },
// OSDisk: &armcompute.OSDisk{
// Name: to.Ptr("myVMosdisk"),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesPremiumLRS),
// },
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// },
// },
// VMID: to.Ptr("a149cd25-409f-41af-8088-275f5486bc93"),
// },
// }
}
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");
/**
* This sample demonstrates how to The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WindowsVmWithPatchSettingAssessmentModeOfImageDefault.json
*/
async function createAWindowsVMWithAPatchSettingAssessmentModeOfImageDefault() {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP"] || "myResourceGroup";
const vmName = "myVM";
const parameters = {
hardwareProfile: { vmSize: "Standard_D1_v2" },
location: "westus",
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
osProfile: {
adminPassword: "{your-password}",
adminUsername: "{your-username}",
computerName: "myVM",
windowsConfiguration: {
enableAutomaticUpdates: true,
patchSettings: { assessmentMode: "ImageDefault" },
provisionVMAgent: true,
},
},
storageProfile: {
imageReference: {
offer: "WindowsServer",
publisher: "MicrosoftWindowsServer",
sku: "2016-Datacenter",
version: "latest",
},
osDisk: {
name: "myVMosdisk",
caching: "ReadWrite",
createOption: "FromImage",
managedDisk: { storageAccountType: "Premium_LRS" },
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.beginCreateOrUpdateAndWait(
resourceGroupName,
vmName,
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
範例回覆
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true,
"patchSettings": {
"assessmentMode": "ImageDefault"
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Premium_LRS"
}
},
"dataDisks": []
},
"vmId": "a149cd25-409f-41af-8088-275f5486bc93",
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": false,
"patchSettings": {
"assessmentMode": "ImageDefault"
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Premium_LRS"
}
},
"dataDisks": []
},
"vmId": "a149cd25-409f-41af-8088-275f5486bc93",
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Create a Windows vm with a patch setting patchMode of AutomaticByOS.
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2024-03-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Premium_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true,
"patchSettings": {
"patchMode": "AutomaticByOS"
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
}
}
}
from typing import Any, IO, Union
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_create_windows_vm_with_patch_setting_mode_of_automatic_by_os.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_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_D1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
"windowsConfiguration": {
"enableAutomaticUpdates": True,
"patchSettings": {"patchMode": "AutomaticByOS"},
"provisionVMAgent": True,
},
},
"storageProfile": {
"imageReference": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2016-Datacenter",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Premium_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WindowsVmWithPatchSettingModeOfAutomaticByOS.json
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/v5"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/92de53a5f1e0e03c94b40475d2135d97148ed014/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WindowsVmWithPatchSettingModeOfAutomaticByOS.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAWindowsVmWithAPatchSettingPatchModeOfAutomaticByOs() {
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.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
}},
},
OSProfile: &armcompute.OSProfile{
AdminPassword: to.Ptr("{your-password}"),
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
WindowsConfiguration: &armcompute.WindowsConfiguration{
EnableAutomaticUpdates: to.Ptr(true),
PatchSettings: &armcompute.PatchSettings{
PatchMode: to.Ptr(armcompute.WindowsVMGuestPatchModeAutomaticByOS),
},
ProvisionVMAgent: to.Ptr(true),
},
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("WindowsServer"),
Publisher: to.Ptr("MicrosoftWindowsServer"),
SKU: to.Ptr("2016-Datacenter"),
Version: to.Ptr("latest"),
},
OSDisk: &armcompute.OSDisk{
Name: to.Ptr("myVMosdisk"),
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesPremiumLRS),
},
},
},
},
}, &armcompute.VirtualMachinesClientBeginCreateOrUpdateOptions{IfMatch: nil,
IfNoneMatch: 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)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.VirtualMachine = armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// Properties: &armcompute.VirtualMachineProperties{
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardDS1V2),
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// }},
// },
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// ComputerName: to.Ptr("myVM"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// EnableAutomaticUpdates: to.Ptr(true),
// PatchSettings: &armcompute.PatchSettings{
// PatchMode: to.Ptr(armcompute.WindowsVMGuestPatchModeAutomaticByOS),
// },
// ProvisionVMAgent: to.Ptr(true),
// },
// },
// ProvisioningState: to.Ptr("Succeeded"),
// StorageProfile: &armcompute.StorageProfile{
// DataDisks: []*armcompute.DataDisk{
// },
// ImageReference: &armcompute.ImageReference{
// Offer: to.Ptr("WindowsServer"),
// Publisher: to.Ptr("MicrosoftWindowsServer"),
// SKU: to.Ptr("2016-Datacenter"),
// Version: to.Ptr("latest"),
// },
// OSDisk: &armcompute.OSDisk{
// Name: to.Ptr("myVMosdisk"),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesPremiumLRS),
// },
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// },
// },
// VMID: to.Ptr("a149cd25-409f-41af-8088-275f5486bc93"),
// },
// }
}
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");
/**
* This sample demonstrates how to The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WindowsVmWithPatchSettingModeOfAutomaticByOS.json
*/
async function createAWindowsVMWithAPatchSettingPatchModeOfAutomaticByOS() {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP"] || "myResourceGroup";
const vmName = "myVM";
const parameters = {
hardwareProfile: { vmSize: "Standard_D1_v2" },
location: "westus",
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
primary: true,
},
],
},
osProfile: {
adminPassword: "{your-password}",
adminUsername: "{your-username}",
computerName: "myVM",
windowsConfiguration: {
enableAutomaticUpdates: true,
patchSettings: { patchMode: "AutomaticByOS" },
provisionVMAgent: true,
},
},
storageProfile: {
imageReference: {
offer: "WindowsServer",
publisher: "MicrosoftWindowsServer",
sku: "2016-Datacenter",
version: "latest",
},
osDisk: {
name: "myVMosdisk",
caching: "ReadWrite",
createOption: "FromImage",
managedDisk: { storageAccountType: "Premium_LRS" },
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.beginCreateOrUpdateAndWait(
resourceGroupName,
vmName,
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
import com.azure.core.management.SubResource;
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.AdditionalCapabilities;
import com.azure.resourcemanager.compute.models.ApiEntityReference;
import com.azure.resourcemanager.compute.models.ApplicationProfile;
import com.azure.resourcemanager.compute.models.BootDiagnostics;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DataDisk;
import com.azure.resourcemanager.compute.models.DeleteOptions;
import com.azure.resourcemanager.compute.models.DiagnosticsProfile;
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.DiskControllerTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.DiskEncryptionSetParameters;
import com.azure.resourcemanager.compute.models.DomainNameLabelScopeTypes;
import com.azure.resourcemanager.compute.models.EventGridAndResourceGraph;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.LinuxConfiguration;
import com.azure.resourcemanager.compute.models.LinuxPatchAssessmentMode;
import com.azure.resourcemanager.compute.models.LinuxPatchSettings;
import com.azure.resourcemanager.compute.models.LinuxVMGuestPatchAutomaticByPlatformRebootSetting;
import com.azure.resourcemanager.compute.models.LinuxVMGuestPatchAutomaticByPlatformSettings;
import com.azure.resourcemanager.compute.models.LinuxVMGuestPatchMode;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.Mode;
import com.azure.resourcemanager.compute.models.NetworkApiVersion;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSImageNotificationProfile;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.OperatingSystemTypes;
import com.azure.resourcemanager.compute.models.PatchSettings;
import com.azure.resourcemanager.compute.models.Plan;
import com.azure.resourcemanager.compute.models.ProxyAgentSettings;
import com.azure.resourcemanager.compute.models.PublicIpAddressSku;
import com.azure.resourcemanager.compute.models.PublicIpAddressSkuName;
import com.azure.resourcemanager.compute.models.PublicIpAddressSkuTier;
import com.azure.resourcemanager.compute.models.PublicIpAllocationMethod;
import com.azure.resourcemanager.compute.models.ScheduledEventsAdditionalPublishingTargets;
import com.azure.resourcemanager.compute.models.ScheduledEventsPolicy;
import com.azure.resourcemanager.compute.models.ScheduledEventsProfile;
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.SshConfiguration;
import com.azure.resourcemanager.compute.models.SshPublicKey;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.TerminateNotificationProfile;
import com.azure.resourcemanager.compute.models.UefiSettings;
import com.azure.resourcemanager.compute.models.UserInitiatedReboot;
import com.azure.resourcemanager.compute.models.UserInitiatedRedeploy;
import com.azure.resourcemanager.compute.models.VMDiskSecurityProfile;
import com.azure.resourcemanager.compute.models.VMGalleryApplication;
import com.azure.resourcemanager.compute.models.VMSizeProperties;
import com.azure.resourcemanager.compute.models.VirtualHardDisk;
import com.azure.resourcemanager.compute.models.VirtualMachineNetworkInterfaceConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineNetworkInterfaceIpConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachinePublicIpAddressConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachinePublicIpAddressDnsSettingsConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import com.azure.resourcemanager.compute.models.WindowsConfiguration;
import com.azure.resourcemanager.compute.models.WindowsPatchAssessmentMode;
import com.azure.resourcemanager.compute.models.WindowsVMGuestPatchAutomaticByPlatformRebootSetting;
import com.azure.resourcemanager.compute.models.WindowsVMGuestPatchAutomaticByPlatformSettings;
import com.azure.resourcemanager.compute.models.WindowsVMGuestPatchMode;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WindowsVmWithPatchSettingModeOfAutomaticByOS.json
*/
/**
* Sample code: Create a Windows vm with a patch setting patchMode of AutomaticByOS.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAWindowsVmWithAPatchSettingPatchModeOfAutomaticByOS(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder")
.withWindowsConfiguration(new WindowsConfiguration().withProvisionVMAgent(true)
.withEnableAutomaticUpdates(true)
.withPatchSettings(new PatchSettings().withPatchMode(WindowsVMGuestPatchMode.AUTOMATIC_BY_OS))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_CustomImageVmFromAnUnmanagedGeneralizedOsImage.json
*/
/**
* Sample code: Create a custom-image vm from an unmanaged generalized os image.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createACustomImageVmFromAnUnmanagedGeneralizedOsImage(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines()
.createOrUpdate("myResourceGroup", "{vm-name}", new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile().withOsDisk(new OSDisk()
.withOsType(OperatingSystemTypes.WINDOWS).withName("myVMosdisk")
.withVhd(new VirtualHardDisk().withUri(
"http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk.vhd"))
.withImage(new VirtualHardDisk().withUri(
"http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/{existing-generalized-os-image-blob-name}.vhd"))
.withCaching(CachingTypes.READ_WRITE).withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithEncryptionAtHost.json
*/
/**
* Sample code: Create a vm with Host Encryption using encryptionAtHost property.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createAVmWithHostEncryptionUsingEncryptionAtHostProperty(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withPlan(new Plan().withName("windows2016").withPublisher("microsoft-ads")
.withProduct("windows-data-science-vm"))
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_DS1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("microsoft-ads")
.withOffer("windows-data-science-vm").withSku("windows2016").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withSecurityProfile(new SecurityProfile().withEncryptionAtHost(true)),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_InAnAvailabilitySet.json
*/
/**
* Sample code: Create a vm in an availability set.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmInAnAvailabilitySet(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withAvailabilitySet(new SubResource().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/availabilitySets/{existing-availability-set-name}")),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithNetworkInterfaceConfiguration.json
*/
/**
* Sample code: Create a VM with network interface configuration.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createAVMWithNetworkInterfaceConfiguration(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(new NetworkProfile()
.withNetworkApiVersion(NetworkApiVersion.TWO_ZERO_TWO_ZERO_ONE_ONE_ZERO_ONE)
.withNetworkInterfaceConfigurations(
Arrays.asList(new VirtualMachineNetworkInterfaceConfiguration().withName("{nic-config-name}")
.withPrimary(true).withDeleteOption(DeleteOptions.DELETE)
.withIpConfigurations(Arrays.asList(new VirtualMachineNetworkInterfaceIpConfiguration()
.withName("{ip-config-name}").withPrimary(true)
.withPublicIpAddressConfiguration(new VirtualMachinePublicIpAddressConfiguration()
.withName("{publicIP-config-name}")
.withSku(new PublicIpAddressSku().withName(PublicIpAddressSkuName.BASIC)
.withTier(PublicIpAddressSkuTier.GLOBAL))
.withDeleteOption(DeleteOptions.DETACH)
.withPublicIpAllocationMethod(PublicIpAllocationMethod.STATIC))))))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithADiffOsDiskUsingDiffDiskPlacementAsNvmeDisk.json
*/
/**
* Sample code: Create a vm with ephemeral os disk provisioning in Nvme disk using placement property.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithEphemeralOsDiskProvisioningInNvmeDiskUsingPlacementProperty(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withPlan(new Plan().withName("windows2016").withPublisher("microsoft-ads")
.withProduct("windows-data-science-vm"))
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_DS1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("microsoft-ads")
.withOffer("windows-data-science-vm").withSku("windows2016").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withDiffDiskSettings(new DiffDiskSettings().withOption(DiffDiskOptions.LOCAL)
.withPlacement(DiffDiskPlacement.NVME_DISK))
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_FromASpecializedSharedImage.json
*/
/**
* Sample code: Create a vm from a specialized shared image.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmFromASpecializedSharedImage(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile().withImageReference(new ImageReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/mySharedGallery/images/mySharedImage"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithPasswordAuthentication.json
*/
/**
* Sample code: Create a vm with password authentication.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithPasswordAuthentication(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithScheduledEventsProfile.json
*/
/**
* Sample code: Create a vm with Scheduled Events Profile.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithScheduledEventsProfile(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withScheduledEventsPolicy(new ScheduledEventsPolicy()
.withUserInitiatedRedeploy(new UserInitiatedRedeploy().withAutomaticallyApprove(true))
.withUserInitiatedReboot(new UserInitiatedReboot().withAutomaticallyApprove(true))
.withScheduledEventsAdditionalPublishingTargets(new ScheduledEventsAdditionalPublishingTargets()
.withEventGridAndResourceGraph(new EventGridAndResourceGraph().withEnable(true))))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics()
.withEnabled(true).withStorageUri("http://{existing-storage-account-name}.blob.core.windows.net")))
.withScheduledEventsProfile(new ScheduledEventsProfile()
.withTerminateNotificationProfile(
new TerminateNotificationProfile().withNotBeforeTimeout("PT10M").withEnable(true))
.withOsImageNotificationProfile(
new OSImageNotificationProfile().withNotBeforeTimeout("PT15M").withEnable(true))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithADiffOsDiskUsingDiffDiskPlacementAsResourceDisk.json
*/
/**
* Sample code: Create a vm with ephemeral os disk provisioning in Resource disk using placement property.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithEphemeralOsDiskProvisioningInResourceDiskUsingPlacementProperty(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withPlan(new Plan().withName("windows2016").withPublisher("microsoft-ads")
.withProduct("windows-data-science-vm"))
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_DS1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("microsoft-ads")
.withOffer("windows-data-science-vm").withSku("windows2016").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withDiffDiskSettings(new DiffDiskSettings().withOption(DiffDiskOptions.LOCAL)
.withPlacement(DiffDiskPlacement.RESOURCE_DISK))
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithADiffOsDisk.json
*/
/**
* Sample code: Create a vm with ephemeral os disk.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithEphemeralOsDisk(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withPlan(new Plan().withName("windows2016").withPublisher("microsoft-ads")
.withProduct("windows-data-science-vm"))
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_DS1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("microsoft-ads")
.withOffer("windows-data-science-vm").withSku("windows2016").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withDiffDiskSettings(new DiffDiskSettings().withOption(DiffDiskOptions.LOCAL))
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithSecurityTypeConfidentialVMWithCustomerManagedKeys.json
*/
/**
* Sample code: Create a VM with securityType ConfidentialVM with Customer Managed Keys.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMWithSecurityTypeConfidentialVMWithCustomerManagedKeys(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(
new HardwareProfile().withVmSize(VirtualMachineSizeTypes.fromString("Standard_DC2as_v5")))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("2019-datacenter-cvm").withSku("windows-cvm").withVersion("17763.2183.2109130127"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)
.withManagedDisk(new ManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.STANDARD_SSD_LRS)
.withSecurityProfile(new VMDiskSecurityProfile()
.withSecurityEncryptionType(SecurityEncryptionTypes.DISK_WITH_VMGUEST_STATE)
.withDiskEncryptionSet(new DiskEncryptionSetParameters().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"))))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withSecurityProfile(new SecurityProfile()
.withUefiSettings(new UefiSettings().withSecureBootEnabled(true).withVTpmEnabled(true))
.withSecurityType(SecurityTypes.CONFIDENTIAL_VM)),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithDiskEncryptionSetResource.json
*/
/**
* Sample code: Create a vm with DiskEncryptionSet resource id in the os disk and data disk.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithDiskEncryptionSetResourceIdInTheOsDiskAndDataDisk(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile().withImageReference(new ImageReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/{existing-custom-image-name}"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)
.withManagedDisk(new ManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.STANDARD_LRS)
.withDiskEncryptionSet(new DiskEncryptionSetParameters().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"))))
.withDataDisks(Arrays.asList(new DataDisk().withLun(0).withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.EMPTY).withDiskSizeGB(1023)
.withManagedDisk(new ManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.STANDARD_LRS)
.withDiskEncryptionSet(new DiskEncryptionSetParameters().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"))),
new DataDisk().withLun(1).withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.ATTACH).withDiskSizeGB(1023)
.withManagedDisk(new ManagedDiskParameters().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/{existing-managed-disk-name}")
.withStorageAccountType(StorageAccountTypes.STANDARD_LRS)
.withDiskEncryptionSet(new DiskEncryptionSetParameters().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"))))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithDiskControllerType.json
*/
/**
* Sample code: Create a VM with Disk Controller Type.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMWithDiskControllerType(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D4_V3))
.withScheduledEventsPolicy(new ScheduledEventsPolicy()
.withUserInitiatedRedeploy(new UserInitiatedRedeploy().withAutomaticallyApprove(true))
.withUserInitiatedReboot(new UserInitiatedReboot().withAutomaticallyApprove(true))
.withScheduledEventsAdditionalPublishingTargets(new ScheduledEventsAdditionalPublishingTargets()
.withEventGridAndResourceGraph(new EventGridAndResourceGraph().withEnable(true))))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS)))
.withDiskControllerType(DiskControllerTypes.NVME))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics()
.withEnabled(true).withStorageUri("http://{existing-storage-account-name}.blob.core.windows.net")))
.withUserData("U29tZSBDdXN0b20gRGF0YQ=="),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_FromASharedGalleryImage.json
*/
/**
* Sample code: Create a VM from a shared gallery image.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMFromASharedGalleryImage(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withSharedGalleryImageId(
"/SharedGalleries/sharedGalleryName/Images/sharedGalleryImageName/Versions/sharedGalleryImageVersionName"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithVMSizeProperties.json
*/
/**
* Sample code: Create a VM with VM Size Properties.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMWithVMSizeProperties(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D4_V3)
.withVmSizeProperties(new VMSizeProperties().withVCpusAvailable(1).withVCpusPerCore(1)))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics()
.withEnabled(true).withStorageUri("http://{existing-storage-account-name}.blob.core.windows.net")))
.withUserData("U29tZSBDdXN0b20gRGF0YQ=="),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_PlatformImageVmWithUnmanagedOsAndDataDisks.json
*/
/**
* Sample code: Create a platform-image vm with unmanaged os and data disks.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createAPlatformImageVmWithUnmanagedOsAndDataDisks(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines()
.createOrUpdate("myResourceGroup", "{vm-name}", new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withVhd(new VirtualHardDisk().withUri(
"http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk.vhd"))
.withCaching(CachingTypes.READ_WRITE).withCreateOption(DiskCreateOptionTypes.FROM_IMAGE))
.withDataDisks(Arrays.asList(new DataDisk().withLun(0).withVhd(new VirtualHardDisk().withUri(
"http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk0.vhd"))
.withCreateOption(DiskCreateOptionTypes.EMPTY).withDiskSizeGB(1023),
new DataDisk().withLun(1).withVhd(new VirtualHardDisk().withUri(
"http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk1.vhd"))
.withCreateOption(DiskCreateOptionTypes.EMPTY).withDiskSizeGB(1023))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_LinuxVmWithPatchSettingModesOfAutomaticByPlatform.json
*/
/**
* Sample code: Create a Linux vm with a patch settings patchMode and assessmentMode set to AutomaticByPlatform.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createALinuxVmWithAPatchSettingsPatchModeAndAssessmentModeSetToAutomaticByPlatform(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2S_V3))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("Canonical").withOffer("UbuntuServer")
.withSku("16.04-LTS").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder")
.withLinuxConfiguration(new LinuxConfiguration().withProvisionVMAgent(true).withPatchSettings(
new LinuxPatchSettings().withPatchMode(LinuxVMGuestPatchMode.AUTOMATIC_BY_PLATFORM)
.withAssessmentMode(LinuxPatchAssessmentMode.AUTOMATIC_BY_PLATFORM))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithSecurityTypeConfidentialVMWithNonPersistedTPM.json
*/
/**
* Sample code: Create a VM with securityType ConfidentialVM with NonPersistedTPM securityEncryptionType.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMWithSecurityTypeConfidentialVMWithNonPersistedTPMSecurityEncryptionType(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(
new HardwareProfile().withVmSize(VirtualMachineSizeTypes.fromString("Standard_DC2es_v5")))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("UbuntuServer")
.withOffer("2022-datacenter-cvm").withSku("linux-cvm").withVersion("17763.2183.2109130127"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_SSD_LRS)
.withSecurityProfile(new VMDiskSecurityProfile()
.withSecurityEncryptionType(SecurityEncryptionTypes.NON_PERSISTED_TPM)))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withSecurityProfile(new SecurityProfile()
.withUefiSettings(new UefiSettings().withSecureBootEnabled(false).withVTpmEnabled(true))
.withSecurityType(SecurityTypes.CONFIDENTIAL_VM)),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithAMarketplaceImagePlan.json
*/
/**
* Sample code: Create a vm with a marketplace image plan.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithAMarketplaceImagePlan(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withPlan(new Plan().withName("windows2016").withPublisher("microsoft-ads")
.withProduct("windows-data-science-vm"))
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("microsoft-ads")
.withOffer("windows-data-science-vm").withSku("windows2016").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WindowsVmWithPatchSettingAssessmentModeOfImageDefault.json
*/
/**
* Sample code: Create a Windows vm with a patch setting assessmentMode of ImageDefault.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAWindowsVmWithAPatchSettingAssessmentModeOfImageDefault(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder")
.withWindowsConfiguration(new WindowsConfiguration().withProvisionVMAgent(true)
.withEnableAutomaticUpdates(true).withPatchSettings(
new PatchSettings().withAssessmentMode(WindowsPatchAssessmentMode.IMAGE_DEFAULT))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/
* VirtualMachine_Create_WindowsVmWithPatchSettingModeOfAutomaticByPlatformAndEnableHotPatchingTrue.json
*/
/**
* Sample code: Create a Windows vm with a patch setting patchMode of AutomaticByPlatform and enableHotpatching set
* to true.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAWindowsVmWithAPatchSettingPatchModeOfAutomaticByPlatformAndEnableHotpatchingSetToTrue(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder")
.withWindowsConfiguration(new WindowsConfiguration().withProvisionVMAgent(true)
.withEnableAutomaticUpdates(true)
.withPatchSettings(new PatchSettings()
.withPatchMode(WindowsVMGuestPatchMode.AUTOMATIC_BY_PLATFORM).withEnableHotpatching(true))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithExtensionsTimeBudget.json
*/
/**
* Sample code: Create a vm with an extensions time budget.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithAnExtensionsTimeBudget(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics()
.withEnabled(true).withStorageUri("http://{existing-storage-account-name}.blob.core.windows.net")))
.withExtensionsTimeBudget("PT30M"),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithEmptyDataDisks.json
*/
/**
* Sample code: Create a vm with empty data disks.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithEmptyDataDisks(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS)))
.withDataDisks(Arrays.asList(
new DataDisk().withLun(0).withCreateOption(DiskCreateOptionTypes.EMPTY).withDiskSizeGB(1023),
new DataDisk().withLun(1).withCreateOption(DiskCreateOptionTypes.EMPTY).withDiskSizeGB(1023))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithSecurityTypeConfidentialVM.json
*/
/**
* Sample code: Create a VM with securityType ConfidentialVM with Platform Managed Keys.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMWithSecurityTypeConfidentialVMWithPlatformManagedKeys(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(
new HardwareProfile().withVmSize(VirtualMachineSizeTypes.fromString("Standard_DC2as_v5")))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("2019-datacenter-cvm").withSku("windows-cvm").withVersion("17763.2183.2109130127"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_SSD_LRS)
.withSecurityProfile(new VMDiskSecurityProfile()
.withSecurityEncryptionType(SecurityEncryptionTypes.DISK_WITH_VMGUEST_STATE)))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withSecurityProfile(new SecurityProfile()
.withUefiSettings(new UefiSettings().withSecureBootEnabled(true).withVTpmEnabled(true))
.withSecurityType(SecurityTypes.CONFIDENTIAL_VM)),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithDataDisksFromSourceResource.json
*/
/**
* Sample code: Create a vm with data disks using 'Copy' and 'Restore' options.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createAVmWithDataDisksUsingCopyAndRestoreOptions(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS)))
.withDataDisks(Arrays.asList(new DataDisk().withLun(0).withCreateOption(DiskCreateOptionTypes.COPY)
.withDiskSizeGB(1023)
.withSourceResource(new ApiEntityReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/{existing-snapshot-name}")),
new DataDisk().withLun(1).withCreateOption(DiskCreateOptionTypes.COPY).withDiskSizeGB(1023)
.withSourceResource(new ApiEntityReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/{existing-disk-name}")),
new DataDisk().withLun(2).withCreateOption(DiskCreateOptionTypes.RESTORE).withDiskSizeGB(1023)
.withSourceResource(new ApiEntityReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/restorePointCollections/{existing-rpc-name}/restorePoints/{existing-rp-name}/diskRestorePoints/{existing-disk-restore-point-name}")))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_FromACustomImage.json
*/
/**
* Sample code: Create a vm from a custom image.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmFromACustomImage(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile().withImageReference(new ImageReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/{existing-custom-image-name}"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithHibernationEnabled.json
*/
/**
* Sample code: Create a VM with HibernationEnabled.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMWithHibernationEnabled(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup",
"{vm-name}",
new VirtualMachineInner().withLocation("eastus2euap")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2S_V3))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2019-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("vmOSdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withAdditionalCapabilities(new AdditionalCapabilities().withHibernationEnabled(true))
.withOsProfile(new OSProfile().withComputerName("{vm-name}").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics()
.withEnabled(true).withStorageUri("http://{existing-storage-account-name}.blob.core.windows.net"))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithUefiSettings.json
*/
/**
* Sample code: Create a VM with Uefi Settings of secureBoot and vTPM.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createAVMWithUefiSettingsOfSecureBootAndVTPM(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2S_V3))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference()
.withPublisher("MicrosoftWindowsServer").withOffer("windowsserver-gen2preview-preview")
.withSku("windows10-tvm").withVersion("18363.592.2001092016"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_SSD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withSecurityProfile(new SecurityProfile()
.withUefiSettings(new UefiSettings().withSecureBootEnabled(true).withVTpmEnabled(true))
.withSecurityType(SecurityTypes.TRUSTED_LAUNCH)),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithApplicationProfile.json
*/
/**
* Sample code: Create a vm with Application Profile.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithApplicationProfile(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("{image_publisher}")
.withOffer("{image_offer}").withSku("{image_sku}").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(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(false).withEnableAutomaticUpgrade(false),
new VMGalleryApplication().withPackageReferenceId(
"/subscriptions/32c17a9e-aa7b-4ba5-a45b-e324116b6fdg/resourceGroups/myresourceGroupName3/providers/Microsoft.Compute/galleries/myGallery2/applications/MyApplication2/versions/1.1")))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithNetworkInterfaceConfigurationDnsSettings.json
*/
/**
* Sample code: Create a VM with network interface configuration with public ip address dns settings.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMWithNetworkInterfaceConfigurationWithPublicIpAddressDnsSettings(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkApiVersion(NetworkApiVersion.TWO_ZERO_TWO_ZERO_ONE_ONE_ZERO_ONE)
.withNetworkInterfaceConfigurations(
Arrays.asList(new VirtualMachineNetworkInterfaceConfiguration()
.withName("{nic-config-name}").withPrimary(true).withDeleteOption(DeleteOptions.DELETE)
.withIpConfigurations(Arrays.asList(new VirtualMachineNetworkInterfaceIpConfiguration()
.withName("{ip-config-name}").withPrimary(true)
.withPublicIpAddressConfiguration(new VirtualMachinePublicIpAddressConfiguration()
.withName("{publicIP-config-name}")
.withSku(new PublicIpAddressSku().withName(PublicIpAddressSkuName.BASIC)
.withTier(PublicIpAddressSkuTier.GLOBAL))
.withDeleteOption(DeleteOptions.DETACH)
.withDnsSettings(new VirtualMachinePublicIpAddressDnsSettingsConfiguration()
.withDomainNameLabel("aaaaa")
.withDomainNameLabelScope(DomainNameLabelScopeTypes.TENANT_REUSE))
.withPublicIpAllocationMethod(PublicIpAllocationMethod.STATIC))))))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_InAVmssWithCustomerAssignedPlatformFaultDomain.json
*/
/**
* Sample code: Create a vm in a Virtual Machine Scale Set with customer assigned platformFaultDomain.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmInAVirtualMachineScaleSetWithCustomerAssignedPlatformFaultDomain(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withVirtualMachineScaleSet(new SubResource().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{existing-flex-vmss-name-with-platformFaultDomainCount-greater-than-1}"))
.withPlatformFaultDomain(1),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithBootDiagnostics.json
*/
/**
* Sample code: Create a vm with boot diagnostics.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithBootDiagnostics(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics()
.withEnabled(true).withStorageUri("http://{existing-storage-account-name}.blob.core.windows.net"))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithSshAuthentication.json
*/
/**
* Sample code: Create a vm with ssh authentication.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithSshAuthentication(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("{image_publisher}")
.withOffer("{image_offer}").withSku("{image_sku}").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").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"))))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_FromACommunityGalleryImage.json
*/
/**
* Sample code: Create a VM from a community gallery image.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMFromACommunityGalleryImage(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withCommunityGalleryImageId(
"/CommunityGalleries/galleryPublicName/Images/communityGalleryImageName/Versions/communityGalleryImageVersionName"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithUserData.json
*/
/**
* Sample code: Create a VM with UserData.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMWithUserData(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup",
"{vm-name}",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("vmOSdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("{vm-name}").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics()
.withEnabled(true).withStorageUri("http://{existing-storage-account-name}.blob.core.windows.net")))
.withUserData("RXhhbXBsZSBVc2VyRGF0YQ=="),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_FromAGeneralizedSharedImage.json
*/
/**
* Sample code: Create a vm from a generalized shared image.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmFromAGeneralizedSharedImage(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile().withImageReference(new ImageReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/mySharedGallery/images/mySharedImage"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_LinuxVmWithAutomaticByPlatformSettings.json
*/
/**
* Sample code: Create a Linux vm with a patch setting patchMode of AutomaticByPlatform and
* AutomaticByPlatformSettings.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createALinuxVmWithAPatchSettingPatchModeOfAutomaticByPlatformAndAutomaticByPlatformSettings(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2S_V3))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("Canonical").withOffer("UbuntuServer")
.withSku("16.04-LTS").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder")
.withLinuxConfiguration(new LinuxConfiguration().withProvisionVMAgent(true).withPatchSettings(
new LinuxPatchSettings().withPatchMode(LinuxVMGuestPatchMode.AUTOMATIC_BY_PLATFORM)
.withAssessmentMode(LinuxPatchAssessmentMode.AUTOMATIC_BY_PLATFORM)
.withAutomaticByPlatformSettings(new LinuxVMGuestPatchAutomaticByPlatformSettings()
.withRebootSetting(LinuxVMGuestPatchAutomaticByPlatformRebootSetting.NEVER)
.withBypassPlatformSafetyChecksOnUserSchedule(true)))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WindowsVmWithPatchSettingModeOfManual.json
*/
/**
* Sample code: Create a Windows vm with a patch setting patchMode of Manual.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createAWindowsVmWithAPatchSettingPatchModeOfManual(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder").withWindowsConfiguration(
new WindowsConfiguration().withProvisionVMAgent(true).withEnableAutomaticUpdates(true)
.withPatchSettings(new PatchSettings().withPatchMode(WindowsVMGuestPatchMode.MANUAL))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithProxyAgentSettings.json
*/
/**
* Sample code: Create a VM with ProxyAgent Settings of enabled and mode.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createAVMWithProxyAgentSettingsOfEnabledAndMode(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2S_V3))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2019-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_SSD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withSecurityProfile(new SecurityProfile()
.withProxyAgentSettings(new ProxyAgentSettings().withEnabled(true).withMode(Mode.ENFORCE))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_LinuxVmWithPatchSettingModeOfImageDefault.json
*/
/**
* Sample code: Create a Linux vm with a patch setting patchMode of ImageDefault.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createALinuxVmWithAPatchSettingPatchModeOfImageDefault(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2S_V3))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("Canonical").withOffer("UbuntuServer")
.withSku("16.04-LTS").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder")
.withLinuxConfiguration(new LinuxConfiguration().withProvisionVMAgent(true).withPatchSettings(
new LinuxPatchSettings().withPatchMode(LinuxVMGuestPatchMode.IMAGE_DEFAULT))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithManagedBootDiagnostics.json
*/
/**
* Sample code: Create a vm with managed boot diagnostics.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithManagedBootDiagnostics(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(
new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics().withEnabled(true))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WindowsVmWithAutomaticByPlatformSettings.json
*/
/**
* Sample code: Create a Windows vm with a patch setting patchMode of AutomaticByPlatform and
* AutomaticByPlatformSettings.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAWindowsVmWithAPatchSettingPatchModeOfAutomaticByPlatformAndAutomaticByPlatformSettings(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder").withWindowsConfiguration(
new WindowsConfiguration().withProvisionVMAgent(true).withEnableAutomaticUpdates(true)
.withPatchSettings(new PatchSettings()
.withPatchMode(WindowsVMGuestPatchMode.AUTOMATIC_BY_PLATFORM)
.withAssessmentMode(WindowsPatchAssessmentMode.AUTOMATIC_BY_PLATFORM)
.withAutomaticByPlatformSettings(new WindowsVMGuestPatchAutomaticByPlatformSettings()
.withRebootSetting(WindowsVMGuestPatchAutomaticByPlatformRebootSetting.NEVER)
.withBypassPlatformSafetyChecksOnUserSchedule(false)))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
範例回覆
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true,
"patchSettings": {
"patchMode": "AutomaticByOS"
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Premium_LRS"
}
},
"dataDisks": []
},
"vmId": "a149cd25-409f-41af-8088-275f5486bc93",
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true,
"patchSettings": {
"patchMode": "AutomaticByOS"
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Premium_LRS"
}
},
"dataDisks": []
},
"vmId": "a149cd25-409f-41af-8088-275f5486bc93",
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2024-03-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Premium_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true,
"patchSettings": {
"patchMode": "AutomaticByPlatform",
"assessmentMode": "AutomaticByPlatform",
"automaticByPlatformSettings": {
"rebootSetting": "Never",
"bypassPlatformSafetyChecksOnUserSchedule": false
}
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
from typing import Any, IO, Union
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_create_windows_vm_with_automatic_by_platform_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_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_D1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
"windowsConfiguration": {
"enableAutomaticUpdates": True,
"patchSettings": {
"assessmentMode": "AutomaticByPlatform",
"automaticByPlatformSettings": {
"bypassPlatformSafetyChecksOnUserSchedule": False,
"rebootSetting": "Never",
},
"patchMode": "AutomaticByPlatform",
},
"provisionVMAgent": True,
},
},
"storageProfile": {
"imageReference": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2016-Datacenter",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Premium_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WindowsVmWithAutomaticByPlatformSettings.json
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/v5"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/92de53a5f1e0e03c94b40475d2135d97148ed014/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WindowsVmWithAutomaticByPlatformSettings.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAWindowsVmWithAPatchSettingPatchModeOfAutomaticByPlatformAndAutomaticByPlatformSettings() {
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.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
}},
},
OSProfile: &armcompute.OSProfile{
AdminPassword: to.Ptr("{your-password}"),
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
WindowsConfiguration: &armcompute.WindowsConfiguration{
EnableAutomaticUpdates: to.Ptr(true),
PatchSettings: &armcompute.PatchSettings{
AssessmentMode: to.Ptr(armcompute.WindowsPatchAssessmentModeAutomaticByPlatform),
AutomaticByPlatformSettings: &armcompute.WindowsVMGuestPatchAutomaticByPlatformSettings{
BypassPlatformSafetyChecksOnUserSchedule: to.Ptr(false),
RebootSetting: to.Ptr(armcompute.WindowsVMGuestPatchAutomaticByPlatformRebootSettingNever),
},
PatchMode: to.Ptr(armcompute.WindowsVMGuestPatchModeAutomaticByPlatform),
},
ProvisionVMAgent: to.Ptr(true),
},
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("WindowsServer"),
Publisher: to.Ptr("MicrosoftWindowsServer"),
SKU: to.Ptr("2016-Datacenter"),
Version: to.Ptr("latest"),
},
OSDisk: &armcompute.OSDisk{
Name: to.Ptr("myVMosdisk"),
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesPremiumLRS),
},
},
},
},
}, &armcompute.VirtualMachinesClientBeginCreateOrUpdateOptions{IfMatch: nil,
IfNoneMatch: 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)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.VirtualMachine = armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// Properties: &armcompute.VirtualMachineProperties{
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardDS1V2),
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// }},
// },
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// ComputerName: to.Ptr("myVM"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// EnableAutomaticUpdates: to.Ptr(true),
// PatchSettings: &armcompute.PatchSettings{
// AssessmentMode: to.Ptr(armcompute.WindowsPatchAssessmentModeAutomaticByPlatform),
// AutomaticByPlatformSettings: &armcompute.WindowsVMGuestPatchAutomaticByPlatformSettings{
// BypassPlatformSafetyChecksOnUserSchedule: to.Ptr(false),
// RebootSetting: to.Ptr(armcompute.WindowsVMGuestPatchAutomaticByPlatformRebootSettingNever),
// },
// PatchMode: to.Ptr(armcompute.WindowsVMGuestPatchModeAutomaticByPlatform),
// },
// ProvisionVMAgent: to.Ptr(true),
// },
// },
// ProvisioningState: to.Ptr("Succeeded"),
// StorageProfile: &armcompute.StorageProfile{
// DataDisks: []*armcompute.DataDisk{
// },
// ImageReference: &armcompute.ImageReference{
// Offer: to.Ptr("WindowsServer"),
// Publisher: to.Ptr("MicrosoftWindowsServer"),
// SKU: to.Ptr("2016-Datacenter"),
// Version: to.Ptr("latest"),
// },
// OSDisk: &armcompute.OSDisk{
// Name: to.Ptr("myVMosdisk"),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesPremiumLRS),
// },
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// },
// },
// VMID: to.Ptr("a149cd25-409f-41af-8088-275f5486bc93"),
// },
// }
}
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");
/**
* This sample demonstrates how to The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WindowsVmWithAutomaticByPlatformSettings.json
*/
async function createAWindowsVMWithAPatchSettingPatchModeOfAutomaticByPlatformAndAutomaticByPlatformSettings() {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP"] || "myResourceGroup";
const vmName = "myVM";
const parameters = {
hardwareProfile: { vmSize: "Standard_D1_v2" },
location: "westus",
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
osProfile: {
adminPassword: "{your-password}",
adminUsername: "{your-username}",
computerName: "myVM",
windowsConfiguration: {
enableAutomaticUpdates: true,
patchSettings: {
assessmentMode: "AutomaticByPlatform",
automaticByPlatformSettings: {
bypassPlatformSafetyChecksOnUserSchedule: false,
rebootSetting: "Never",
},
patchMode: "AutomaticByPlatform",
},
provisionVMAgent: true,
},
},
storageProfile: {
imageReference: {
offer: "WindowsServer",
publisher: "MicrosoftWindowsServer",
sku: "2016-Datacenter",
version: "latest",
},
osDisk: {
name: "myVMosdisk",
caching: "ReadWrite",
createOption: "FromImage",
managedDisk: { storageAccountType: "Premium_LRS" },
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.beginCreateOrUpdateAndWait(
resourceGroupName,
vmName,
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
範例回覆
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true,
"patchSettings": {
"patchMode": "AutomaticByPlatform",
"assessmentMode": "AutomaticByPlatform",
"automaticByPlatformSettings": {
"rebootSetting": "Never",
"bypassPlatformSafetyChecksOnUserSchedule": false
}
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Premium_LRS"
}
},
"dataDisks": []
},
"vmId": "a149cd25-409f-41af-8088-275f5486bc93",
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true,
"patchSettings": {
"patchMode": "AutomaticByPlatform",
"assessmentMode": "AutomaticByPlatform",
"automaticByPlatformSettings": {
"rebootSetting": "Never",
"bypassPlatformSafetyChecksOnUserSchedule": false
}
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Premium_LRS"
}
},
"dataDisks": []
},
"vmId": "a149cd25-409f-41af-8088-275f5486bc93",
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2024-03-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Premium_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true,
"patchSettings": {
"patchMode": "AutomaticByPlatform",
"enableHotpatching": true
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
from typing import Any, IO, Union
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_create_windows_vm_with_patch_setting_mode_of_automatic_by_platform_and_enable_hot_patching_true.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_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_D1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
"windowsConfiguration": {
"enableAutomaticUpdates": True,
"patchSettings": {"enableHotpatching": True, "patchMode": "AutomaticByPlatform"},
"provisionVMAgent": True,
},
},
"storageProfile": {
"imageReference": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2016-Datacenter",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Premium_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WindowsVmWithPatchSettingModeOfAutomaticByPlatformAndEnableHotPatchingTrue.json
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/v5"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/92de53a5f1e0e03c94b40475d2135d97148ed014/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WindowsVmWithPatchSettingModeOfAutomaticByPlatformAndEnableHotPatchingTrue.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAWindowsVmWithAPatchSettingPatchModeOfAutomaticByPlatformAndEnableHotpatchingSetToTrue() {
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.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
}},
},
OSProfile: &armcompute.OSProfile{
AdminPassword: to.Ptr("{your-password}"),
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
WindowsConfiguration: &armcompute.WindowsConfiguration{
EnableAutomaticUpdates: to.Ptr(true),
PatchSettings: &armcompute.PatchSettings{
EnableHotpatching: to.Ptr(true),
PatchMode: to.Ptr(armcompute.WindowsVMGuestPatchModeAutomaticByPlatform),
},
ProvisionVMAgent: to.Ptr(true),
},
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("WindowsServer"),
Publisher: to.Ptr("MicrosoftWindowsServer"),
SKU: to.Ptr("2016-Datacenter"),
Version: to.Ptr("latest"),
},
OSDisk: &armcompute.OSDisk{
Name: to.Ptr("myVMosdisk"),
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesPremiumLRS),
},
},
},
},
}, &armcompute.VirtualMachinesClientBeginCreateOrUpdateOptions{IfMatch: nil,
IfNoneMatch: 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)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.VirtualMachine = armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// Properties: &armcompute.VirtualMachineProperties{
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardDS1V2),
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// }},
// },
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// ComputerName: to.Ptr("myVM"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// EnableAutomaticUpdates: to.Ptr(true),
// PatchSettings: &armcompute.PatchSettings{
// EnableHotpatching: to.Ptr(true),
// PatchMode: to.Ptr(armcompute.WindowsVMGuestPatchModeAutomaticByPlatform),
// },
// ProvisionVMAgent: to.Ptr(true),
// },
// },
// ProvisioningState: to.Ptr("Succeeded"),
// StorageProfile: &armcompute.StorageProfile{
// DataDisks: []*armcompute.DataDisk{
// },
// ImageReference: &armcompute.ImageReference{
// Offer: to.Ptr("WindowsServer"),
// Publisher: to.Ptr("MicrosoftWindowsServer"),
// SKU: to.Ptr("2016-Datacenter"),
// Version: to.Ptr("latest"),
// },
// OSDisk: &armcompute.OSDisk{
// Name: to.Ptr("myVMosdisk"),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesPremiumLRS),
// },
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// },
// },
// VMID: to.Ptr("a149cd25-409f-41af-8088-275f5486bc93"),
// },
// }
}
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");
/**
* This sample demonstrates how to The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WindowsVmWithPatchSettingModeOfAutomaticByPlatformAndEnableHotPatchingTrue.json
*/
async function createAWindowsVMWithAPatchSettingPatchModeOfAutomaticByPlatformAndEnableHotpatchingSetToTrue() {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP"] || "myResourceGroup";
const vmName = "myVM";
const parameters = {
hardwareProfile: { vmSize: "Standard_D1_v2" },
location: "westus",
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
osProfile: {
adminPassword: "{your-password}",
adminUsername: "{your-username}",
computerName: "myVM",
windowsConfiguration: {
enableAutomaticUpdates: true,
patchSettings: {
enableHotpatching: true,
patchMode: "AutomaticByPlatform",
},
provisionVMAgent: true,
},
},
storageProfile: {
imageReference: {
offer: "WindowsServer",
publisher: "MicrosoftWindowsServer",
sku: "2016-Datacenter",
version: "latest",
},
osDisk: {
name: "myVMosdisk",
caching: "ReadWrite",
createOption: "FromImage",
managedDisk: { storageAccountType: "Premium_LRS" },
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.beginCreateOrUpdateAndWait(
resourceGroupName,
vmName,
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
範例回覆
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true,
"patchSettings": {
"patchMode": "AutomaticByPlatform",
"enableHotpatching": true
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Premium_LRS"
}
},
"dataDisks": []
},
"vmId": "a149cd25-409f-41af-8088-275f5486bc93",
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true,
"patchSettings": {
"patchMode": "AutomaticByPlatform",
"enableHotpatching": true
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Premium_LRS"
}
},
"dataDisks": []
},
"vmId": "a149cd25-409f-41af-8088-275f5486bc93",
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Create a Windows vm with a patch setting patchMode of Manual.
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2024-03-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Premium_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true,
"patchSettings": {
"patchMode": "Manual"
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
from typing import Any, IO, Union
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_create_windows_vm_with_patch_setting_mode_of_manual.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_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_D1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
"windowsConfiguration": {
"enableAutomaticUpdates": True,
"patchSettings": {"patchMode": "Manual"},
"provisionVMAgent": True,
},
},
"storageProfile": {
"imageReference": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2016-Datacenter",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Premium_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WindowsVmWithPatchSettingModeOfManual.json
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/v5"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/92de53a5f1e0e03c94b40475d2135d97148ed014/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WindowsVmWithPatchSettingModeOfManual.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAWindowsVmWithAPatchSettingPatchModeOfManual() {
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.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
}},
},
OSProfile: &armcompute.OSProfile{
AdminPassword: to.Ptr("{your-password}"),
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
WindowsConfiguration: &armcompute.WindowsConfiguration{
EnableAutomaticUpdates: to.Ptr(true),
PatchSettings: &armcompute.PatchSettings{
PatchMode: to.Ptr(armcompute.WindowsVMGuestPatchModeManual),
},
ProvisionVMAgent: to.Ptr(true),
},
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("WindowsServer"),
Publisher: to.Ptr("MicrosoftWindowsServer"),
SKU: to.Ptr("2016-Datacenter"),
Version: to.Ptr("latest"),
},
OSDisk: &armcompute.OSDisk{
Name: to.Ptr("myVMosdisk"),
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesPremiumLRS),
},
},
},
},
}, &armcompute.VirtualMachinesClientBeginCreateOrUpdateOptions{IfMatch: nil,
IfNoneMatch: 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)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.VirtualMachine = armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// Properties: &armcompute.VirtualMachineProperties{
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardDS1V2),
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// }},
// },
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// ComputerName: to.Ptr("myVM"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// EnableAutomaticUpdates: to.Ptr(true),
// PatchSettings: &armcompute.PatchSettings{
// PatchMode: to.Ptr(armcompute.WindowsVMGuestPatchModeManual),
// },
// ProvisionVMAgent: to.Ptr(true),
// },
// },
// ProvisioningState: to.Ptr("Succeeded"),
// StorageProfile: &armcompute.StorageProfile{
// DataDisks: []*armcompute.DataDisk{
// },
// ImageReference: &armcompute.ImageReference{
// Offer: to.Ptr("WindowsServer"),
// Publisher: to.Ptr("MicrosoftWindowsServer"),
// SKU: to.Ptr("2016-Datacenter"),
// Version: to.Ptr("latest"),
// },
// OSDisk: &armcompute.OSDisk{
// Name: to.Ptr("myVMosdisk"),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesPremiumLRS),
// },
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// },
// },
// VMID: to.Ptr("a149cd25-409f-41af-8088-275f5486bc93"),
// },
// }
}
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");
/**
* This sample demonstrates how to The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WindowsVmWithPatchSettingModeOfManual.json
*/
async function createAWindowsVMWithAPatchSettingPatchModeOfManual() {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP"] || "myResourceGroup";
const vmName = "myVM";
const parameters = {
hardwareProfile: { vmSize: "Standard_D1_v2" },
location: "westus",
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
osProfile: {
adminPassword: "{your-password}",
adminUsername: "{your-username}",
computerName: "myVM",
windowsConfiguration: {
enableAutomaticUpdates: true,
patchSettings: { patchMode: "Manual" },
provisionVMAgent: true,
},
},
storageProfile: {
imageReference: {
offer: "WindowsServer",
publisher: "MicrosoftWindowsServer",
sku: "2016-Datacenter",
version: "latest",
},
osDisk: {
name: "myVMosdisk",
caching: "ReadWrite",
createOption: "FromImage",
managedDisk: { storageAccountType: "Premium_LRS" },
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.beginCreateOrUpdateAndWait(
resourceGroupName,
vmName,
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
範例回覆
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true,
"patchSettings": {
"patchMode": "Manual"
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Premium_LRS"
}
},
"dataDisks": []
},
"vmId": "a149cd25-409f-41af-8088-275f5486bc93",
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": false,
"patchSettings": {
"patchMode": "Manual"
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Premium_LRS"
}
},
"dataDisks": []
},
"vmId": "a149cd25-409f-41af-8088-275f5486bc93",
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2024-03-01
{
"location": "westus",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_D1_v2"
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Premium_LRS"
},
"name": "myVMosdisk",
"createOption": "FromImage"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true,
"patchSettings": {
"patchMode": "AutomaticByPlatform",
"assessmentMode": "AutomaticByPlatform"
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
from typing import Any, IO, Union
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_create_windows_vm_with_patch_setting_modes_of_automatic_by_platform.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_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"properties": {
"hardwareProfile": {"vmSize": "Standard_D1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
"windowsConfiguration": {
"enableAutomaticUpdates": True,
"patchSettings": {"assessmentMode": "AutomaticByPlatform", "patchMode": "AutomaticByPlatform"},
"provisionVMAgent": True,
},
},
"storageProfile": {
"imageReference": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2016-Datacenter",
"version": "latest",
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Premium_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WindowsVmWithPatchSettingModesOfAutomaticByPlatform.json
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/v5"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/92de53a5f1e0e03c94b40475d2135d97148ed014/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WindowsVmWithPatchSettingModesOfAutomaticByPlatform.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createAWindowsVmWithPatchSettingsPatchModeAndAssessmentModeSetToAutomaticByPlatform() {
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.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
Location: to.Ptr("westus"),
Properties: &armcompute.VirtualMachineProperties{
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
}},
},
OSProfile: &armcompute.OSProfile{
AdminPassword: to.Ptr("{your-password}"),
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
WindowsConfiguration: &armcompute.WindowsConfiguration{
EnableAutomaticUpdates: to.Ptr(true),
PatchSettings: &armcompute.PatchSettings{
AssessmentMode: to.Ptr(armcompute.WindowsPatchAssessmentModeAutomaticByPlatform),
PatchMode: to.Ptr(armcompute.WindowsVMGuestPatchModeAutomaticByPlatform),
},
ProvisionVMAgent: to.Ptr(true),
},
},
StorageProfile: &armcompute.StorageProfile{
ImageReference: &armcompute.ImageReference{
Offer: to.Ptr("WindowsServer"),
Publisher: to.Ptr("MicrosoftWindowsServer"),
SKU: to.Ptr("2016-Datacenter"),
Version: to.Ptr("latest"),
},
OSDisk: &armcompute.OSDisk{
Name: to.Ptr("myVMosdisk"),
Caching: to.Ptr(armcompute.CachingTypesReadWrite),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesPremiumLRS),
},
},
},
},
}, &armcompute.VirtualMachinesClientBeginCreateOrUpdateOptions{IfMatch: nil,
IfNoneMatch: 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)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.VirtualMachine = armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// Properties: &armcompute.VirtualMachineProperties{
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardDS1V2),
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// }},
// },
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// ComputerName: to.Ptr("myVM"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// EnableAutomaticUpdates: to.Ptr(true),
// PatchSettings: &armcompute.PatchSettings{
// AssessmentMode: to.Ptr(armcompute.WindowsPatchAssessmentModeAutomaticByPlatform),
// PatchMode: to.Ptr(armcompute.WindowsVMGuestPatchModeAutomaticByPlatform),
// },
// ProvisionVMAgent: to.Ptr(true),
// },
// },
// ProvisioningState: to.Ptr("Succeeded"),
// StorageProfile: &armcompute.StorageProfile{
// DataDisks: []*armcompute.DataDisk{
// },
// ImageReference: &armcompute.ImageReference{
// Offer: to.Ptr("WindowsServer"),
// Publisher: to.Ptr("MicrosoftWindowsServer"),
// SKU: to.Ptr("2016-Datacenter"),
// Version: to.Ptr("latest"),
// },
// OSDisk: &armcompute.OSDisk{
// Name: to.Ptr("myVMosdisk"),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesPremiumLRS),
// },
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// },
// },
// VMID: to.Ptr("a149cd25-409f-41af-8088-275f5486bc93"),
// },
// }
}
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");
/**
* This sample demonstrates how to The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WindowsVmWithPatchSettingModesOfAutomaticByPlatform.json
*/
async function createAWindowsVMWithPatchSettingsPatchModeAndAssessmentModeSetToAutomaticByPlatform() {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP"] || "myResourceGroup";
const vmName = "myVM";
const parameters = {
hardwareProfile: { vmSize: "Standard_D1_v2" },
location: "westus",
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
osProfile: {
adminPassword: "{your-password}",
adminUsername: "{your-username}",
computerName: "myVM",
windowsConfiguration: {
enableAutomaticUpdates: true,
patchSettings: {
assessmentMode: "AutomaticByPlatform",
patchMode: "AutomaticByPlatform",
},
provisionVMAgent: true,
},
},
storageProfile: {
imageReference: {
offer: "WindowsServer",
publisher: "MicrosoftWindowsServer",
sku: "2016-Datacenter",
version: "latest",
},
osDisk: {
name: "myVMosdisk",
caching: "ReadWrite",
createOption: "FromImage",
managedDisk: { storageAccountType: "Premium_LRS" },
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.beginCreateOrUpdateAndWait(
resourceGroupName,
vmName,
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
import com.azure.core.management.SubResource;
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.AdditionalCapabilities;
import com.azure.resourcemanager.compute.models.ApiEntityReference;
import com.azure.resourcemanager.compute.models.ApplicationProfile;
import com.azure.resourcemanager.compute.models.BootDiagnostics;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.DataDisk;
import com.azure.resourcemanager.compute.models.DeleteOptions;
import com.azure.resourcemanager.compute.models.DiagnosticsProfile;
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.DiskControllerTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.DiskEncryptionSetParameters;
import com.azure.resourcemanager.compute.models.DomainNameLabelScopeTypes;
import com.azure.resourcemanager.compute.models.EventGridAndResourceGraph;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.LinuxConfiguration;
import com.azure.resourcemanager.compute.models.LinuxPatchAssessmentMode;
import com.azure.resourcemanager.compute.models.LinuxPatchSettings;
import com.azure.resourcemanager.compute.models.LinuxVMGuestPatchAutomaticByPlatformRebootSetting;
import com.azure.resourcemanager.compute.models.LinuxVMGuestPatchAutomaticByPlatformSettings;
import com.azure.resourcemanager.compute.models.LinuxVMGuestPatchMode;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.Mode;
import com.azure.resourcemanager.compute.models.NetworkApiVersion;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSImageNotificationProfile;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.OperatingSystemTypes;
import com.azure.resourcemanager.compute.models.PatchSettings;
import com.azure.resourcemanager.compute.models.Plan;
import com.azure.resourcemanager.compute.models.ProxyAgentSettings;
import com.azure.resourcemanager.compute.models.PublicIpAddressSku;
import com.azure.resourcemanager.compute.models.PublicIpAddressSkuName;
import com.azure.resourcemanager.compute.models.PublicIpAddressSkuTier;
import com.azure.resourcemanager.compute.models.PublicIpAllocationMethod;
import com.azure.resourcemanager.compute.models.ScheduledEventsAdditionalPublishingTargets;
import com.azure.resourcemanager.compute.models.ScheduledEventsPolicy;
import com.azure.resourcemanager.compute.models.ScheduledEventsProfile;
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.SshConfiguration;
import com.azure.resourcemanager.compute.models.SshPublicKey;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.TerminateNotificationProfile;
import com.azure.resourcemanager.compute.models.UefiSettings;
import com.azure.resourcemanager.compute.models.UserInitiatedReboot;
import com.azure.resourcemanager.compute.models.UserInitiatedRedeploy;
import com.azure.resourcemanager.compute.models.VMDiskSecurityProfile;
import com.azure.resourcemanager.compute.models.VMGalleryApplication;
import com.azure.resourcemanager.compute.models.VMSizeProperties;
import com.azure.resourcemanager.compute.models.VirtualHardDisk;
import com.azure.resourcemanager.compute.models.VirtualMachineNetworkInterfaceConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineNetworkInterfaceIpConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachinePublicIpAddressConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachinePublicIpAddressDnsSettingsConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import com.azure.resourcemanager.compute.models.WindowsConfiguration;
import com.azure.resourcemanager.compute.models.WindowsPatchAssessmentMode;
import com.azure.resourcemanager.compute.models.WindowsVMGuestPatchAutomaticByPlatformRebootSetting;
import com.azure.resourcemanager.compute.models.WindowsVMGuestPatchAutomaticByPlatformSettings;
import com.azure.resourcemanager.compute.models.WindowsVMGuestPatchMode;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WindowsVmWithPatchSettingModesOfAutomaticByPlatform.json
*/
/**
* Sample code: Create a Windows vm with patch settings patchMode and assessmentMode set to AutomaticByPlatform.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAWindowsVmWithPatchSettingsPatchModeAndAssessmentModeSetToAutomaticByPlatform(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder")
.withWindowsConfiguration(new WindowsConfiguration().withProvisionVMAgent(true)
.withEnableAutomaticUpdates(true).withPatchSettings(
new PatchSettings().withPatchMode(WindowsVMGuestPatchMode.AUTOMATIC_BY_PLATFORM)
.withAssessmentMode(WindowsPatchAssessmentMode.AUTOMATIC_BY_PLATFORM))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_CustomImageVmFromAnUnmanagedGeneralizedOsImage.json
*/
/**
* Sample code: Create a custom-image vm from an unmanaged generalized os image.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createACustomImageVmFromAnUnmanagedGeneralizedOsImage(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines()
.createOrUpdate("myResourceGroup", "{vm-name}", new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile().withOsDisk(new OSDisk()
.withOsType(OperatingSystemTypes.WINDOWS).withName("myVMosdisk")
.withVhd(new VirtualHardDisk().withUri(
"http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk.vhd"))
.withImage(new VirtualHardDisk().withUri(
"http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/{existing-generalized-os-image-blob-name}.vhd"))
.withCaching(CachingTypes.READ_WRITE).withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithEncryptionAtHost.json
*/
/**
* Sample code: Create a vm with Host Encryption using encryptionAtHost property.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createAVmWithHostEncryptionUsingEncryptionAtHostProperty(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withPlan(new Plan().withName("windows2016").withPublisher("microsoft-ads")
.withProduct("windows-data-science-vm"))
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_DS1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("microsoft-ads")
.withOffer("windows-data-science-vm").withSku("windows2016").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withSecurityProfile(new SecurityProfile().withEncryptionAtHost(true)),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_InAnAvailabilitySet.json
*/
/**
* Sample code: Create a vm in an availability set.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmInAnAvailabilitySet(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withAvailabilitySet(new SubResource().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/availabilitySets/{existing-availability-set-name}")),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithNetworkInterfaceConfiguration.json
*/
/**
* Sample code: Create a VM with network interface configuration.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createAVMWithNetworkInterfaceConfiguration(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(new NetworkProfile()
.withNetworkApiVersion(NetworkApiVersion.TWO_ZERO_TWO_ZERO_ONE_ONE_ZERO_ONE)
.withNetworkInterfaceConfigurations(
Arrays.asList(new VirtualMachineNetworkInterfaceConfiguration().withName("{nic-config-name}")
.withPrimary(true).withDeleteOption(DeleteOptions.DELETE)
.withIpConfigurations(Arrays.asList(new VirtualMachineNetworkInterfaceIpConfiguration()
.withName("{ip-config-name}").withPrimary(true)
.withPublicIpAddressConfiguration(new VirtualMachinePublicIpAddressConfiguration()
.withName("{publicIP-config-name}")
.withSku(new PublicIpAddressSku().withName(PublicIpAddressSkuName.BASIC)
.withTier(PublicIpAddressSkuTier.GLOBAL))
.withDeleteOption(DeleteOptions.DETACH)
.withPublicIpAllocationMethod(PublicIpAllocationMethod.STATIC))))))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithADiffOsDiskUsingDiffDiskPlacementAsNvmeDisk.json
*/
/**
* Sample code: Create a vm with ephemeral os disk provisioning in Nvme disk using placement property.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithEphemeralOsDiskProvisioningInNvmeDiskUsingPlacementProperty(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withPlan(new Plan().withName("windows2016").withPublisher("microsoft-ads")
.withProduct("windows-data-science-vm"))
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_DS1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("microsoft-ads")
.withOffer("windows-data-science-vm").withSku("windows2016").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withDiffDiskSettings(new DiffDiskSettings().withOption(DiffDiskOptions.LOCAL)
.withPlacement(DiffDiskPlacement.NVME_DISK))
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_FromASpecializedSharedImage.json
*/
/**
* Sample code: Create a vm from a specialized shared image.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmFromASpecializedSharedImage(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile().withImageReference(new ImageReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/mySharedGallery/images/mySharedImage"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithPasswordAuthentication.json
*/
/**
* Sample code: Create a vm with password authentication.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithPasswordAuthentication(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithScheduledEventsProfile.json
*/
/**
* Sample code: Create a vm with Scheduled Events Profile.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithScheduledEventsProfile(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withScheduledEventsPolicy(new ScheduledEventsPolicy()
.withUserInitiatedRedeploy(new UserInitiatedRedeploy().withAutomaticallyApprove(true))
.withUserInitiatedReboot(new UserInitiatedReboot().withAutomaticallyApprove(true))
.withScheduledEventsAdditionalPublishingTargets(new ScheduledEventsAdditionalPublishingTargets()
.withEventGridAndResourceGraph(new EventGridAndResourceGraph().withEnable(true))))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics()
.withEnabled(true).withStorageUri("http://{existing-storage-account-name}.blob.core.windows.net")))
.withScheduledEventsProfile(new ScheduledEventsProfile()
.withTerminateNotificationProfile(
new TerminateNotificationProfile().withNotBeforeTimeout("PT10M").withEnable(true))
.withOsImageNotificationProfile(
new OSImageNotificationProfile().withNotBeforeTimeout("PT15M").withEnable(true))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithADiffOsDiskUsingDiffDiskPlacementAsResourceDisk.json
*/
/**
* Sample code: Create a vm with ephemeral os disk provisioning in Resource disk using placement property.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithEphemeralOsDiskProvisioningInResourceDiskUsingPlacementProperty(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withPlan(new Plan().withName("windows2016").withPublisher("microsoft-ads")
.withProduct("windows-data-science-vm"))
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_DS1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("microsoft-ads")
.withOffer("windows-data-science-vm").withSku("windows2016").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withDiffDiskSettings(new DiffDiskSettings().withOption(DiffDiskOptions.LOCAL)
.withPlacement(DiffDiskPlacement.RESOURCE_DISK))
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithADiffOsDisk.json
*/
/**
* Sample code: Create a vm with ephemeral os disk.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithEphemeralOsDisk(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withPlan(new Plan().withName("windows2016").withPublisher("microsoft-ads")
.withProduct("windows-data-science-vm"))
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_DS1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("microsoft-ads")
.withOffer("windows-data-science-vm").withSku("windows2016").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withDiffDiskSettings(new DiffDiskSettings().withOption(DiffDiskOptions.LOCAL))
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithSecurityTypeConfidentialVMWithCustomerManagedKeys.json
*/
/**
* Sample code: Create a VM with securityType ConfidentialVM with Customer Managed Keys.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMWithSecurityTypeConfidentialVMWithCustomerManagedKeys(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(
new HardwareProfile().withVmSize(VirtualMachineSizeTypes.fromString("Standard_DC2as_v5")))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("2019-datacenter-cvm").withSku("windows-cvm").withVersion("17763.2183.2109130127"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)
.withManagedDisk(new ManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.STANDARD_SSD_LRS)
.withSecurityProfile(new VMDiskSecurityProfile()
.withSecurityEncryptionType(SecurityEncryptionTypes.DISK_WITH_VMGUEST_STATE)
.withDiskEncryptionSet(new DiskEncryptionSetParameters().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"))))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withSecurityProfile(new SecurityProfile()
.withUefiSettings(new UefiSettings().withSecureBootEnabled(true).withVTpmEnabled(true))
.withSecurityType(SecurityTypes.CONFIDENTIAL_VM)),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithDiskEncryptionSetResource.json
*/
/**
* Sample code: Create a vm with DiskEncryptionSet resource id in the os disk and data disk.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithDiskEncryptionSetResourceIdInTheOsDiskAndDataDisk(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile().withImageReference(new ImageReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/{existing-custom-image-name}"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)
.withManagedDisk(new ManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.STANDARD_LRS)
.withDiskEncryptionSet(new DiskEncryptionSetParameters().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"))))
.withDataDisks(Arrays.asList(new DataDisk().withLun(0).withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.EMPTY).withDiskSizeGB(1023)
.withManagedDisk(new ManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.STANDARD_LRS)
.withDiskEncryptionSet(new DiskEncryptionSetParameters().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"))),
new DataDisk().withLun(1).withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.ATTACH).withDiskSizeGB(1023)
.withManagedDisk(new ManagedDiskParameters().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/{existing-managed-disk-name}")
.withStorageAccountType(StorageAccountTypes.STANDARD_LRS)
.withDiskEncryptionSet(new DiskEncryptionSetParameters().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"))))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithDiskControllerType.json
*/
/**
* Sample code: Create a VM with Disk Controller Type.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMWithDiskControllerType(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D4_V3))
.withScheduledEventsPolicy(new ScheduledEventsPolicy()
.withUserInitiatedRedeploy(new UserInitiatedRedeploy().withAutomaticallyApprove(true))
.withUserInitiatedReboot(new UserInitiatedReboot().withAutomaticallyApprove(true))
.withScheduledEventsAdditionalPublishingTargets(new ScheduledEventsAdditionalPublishingTargets()
.withEventGridAndResourceGraph(new EventGridAndResourceGraph().withEnable(true))))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS)))
.withDiskControllerType(DiskControllerTypes.NVME))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics()
.withEnabled(true).withStorageUri("http://{existing-storage-account-name}.blob.core.windows.net")))
.withUserData("U29tZSBDdXN0b20gRGF0YQ=="),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_FromASharedGalleryImage.json
*/
/**
* Sample code: Create a VM from a shared gallery image.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMFromASharedGalleryImage(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withSharedGalleryImageId(
"/SharedGalleries/sharedGalleryName/Images/sharedGalleryImageName/Versions/sharedGalleryImageVersionName"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithVMSizeProperties.json
*/
/**
* Sample code: Create a VM with VM Size Properties.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMWithVMSizeProperties(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D4_V3)
.withVmSizeProperties(new VMSizeProperties().withVCpusAvailable(1).withVCpusPerCore(1)))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics()
.withEnabled(true).withStorageUri("http://{existing-storage-account-name}.blob.core.windows.net")))
.withUserData("U29tZSBDdXN0b20gRGF0YQ=="),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_PlatformImageVmWithUnmanagedOsAndDataDisks.json
*/
/**
* Sample code: Create a platform-image vm with unmanaged os and data disks.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createAPlatformImageVmWithUnmanagedOsAndDataDisks(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines()
.createOrUpdate("myResourceGroup", "{vm-name}", new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withVhd(new VirtualHardDisk().withUri(
"http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk.vhd"))
.withCaching(CachingTypes.READ_WRITE).withCreateOption(DiskCreateOptionTypes.FROM_IMAGE))
.withDataDisks(Arrays.asList(new DataDisk().withLun(0).withVhd(new VirtualHardDisk().withUri(
"http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk0.vhd"))
.withCreateOption(DiskCreateOptionTypes.EMPTY).withDiskSizeGB(1023),
new DataDisk().withLun(1).withVhd(new VirtualHardDisk().withUri(
"http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk1.vhd"))
.withCreateOption(DiskCreateOptionTypes.EMPTY).withDiskSizeGB(1023))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_LinuxVmWithPatchSettingModesOfAutomaticByPlatform.json
*/
/**
* Sample code: Create a Linux vm with a patch settings patchMode and assessmentMode set to AutomaticByPlatform.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createALinuxVmWithAPatchSettingsPatchModeAndAssessmentModeSetToAutomaticByPlatform(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2S_V3))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("Canonical").withOffer("UbuntuServer")
.withSku("16.04-LTS").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder")
.withLinuxConfiguration(new LinuxConfiguration().withProvisionVMAgent(true).withPatchSettings(
new LinuxPatchSettings().withPatchMode(LinuxVMGuestPatchMode.AUTOMATIC_BY_PLATFORM)
.withAssessmentMode(LinuxPatchAssessmentMode.AUTOMATIC_BY_PLATFORM))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithSecurityTypeConfidentialVMWithNonPersistedTPM.json
*/
/**
* Sample code: Create a VM with securityType ConfidentialVM with NonPersistedTPM securityEncryptionType.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMWithSecurityTypeConfidentialVMWithNonPersistedTPMSecurityEncryptionType(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(
new HardwareProfile().withVmSize(VirtualMachineSizeTypes.fromString("Standard_DC2es_v5")))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("UbuntuServer")
.withOffer("2022-datacenter-cvm").withSku("linux-cvm").withVersion("17763.2183.2109130127"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_SSD_LRS)
.withSecurityProfile(new VMDiskSecurityProfile()
.withSecurityEncryptionType(SecurityEncryptionTypes.NON_PERSISTED_TPM)))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withSecurityProfile(new SecurityProfile()
.withUefiSettings(new UefiSettings().withSecureBootEnabled(false).withVTpmEnabled(true))
.withSecurityType(SecurityTypes.CONFIDENTIAL_VM)),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithAMarketplaceImagePlan.json
*/
/**
* Sample code: Create a vm with a marketplace image plan.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithAMarketplaceImagePlan(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withPlan(new Plan().withName("windows2016").withPublisher("microsoft-ads")
.withProduct("windows-data-science-vm"))
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("microsoft-ads")
.withOffer("windows-data-science-vm").withSku("windows2016").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WindowsVmWithPatchSettingAssessmentModeOfImageDefault.json
*/
/**
* Sample code: Create a Windows vm with a patch setting assessmentMode of ImageDefault.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAWindowsVmWithAPatchSettingAssessmentModeOfImageDefault(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder")
.withWindowsConfiguration(new WindowsConfiguration().withProvisionVMAgent(true)
.withEnableAutomaticUpdates(true).withPatchSettings(
new PatchSettings().withAssessmentMode(WindowsPatchAssessmentMode.IMAGE_DEFAULT))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/
* VirtualMachine_Create_WindowsVmWithPatchSettingModeOfAutomaticByPlatformAndEnableHotPatchingTrue.json
*/
/**
* Sample code: Create a Windows vm with a patch setting patchMode of AutomaticByPlatform and enableHotpatching set
* to true.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAWindowsVmWithAPatchSettingPatchModeOfAutomaticByPlatformAndEnableHotpatchingSetToTrue(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder")
.withWindowsConfiguration(new WindowsConfiguration().withProvisionVMAgent(true)
.withEnableAutomaticUpdates(true)
.withPatchSettings(new PatchSettings()
.withPatchMode(WindowsVMGuestPatchMode.AUTOMATIC_BY_PLATFORM).withEnableHotpatching(true))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithExtensionsTimeBudget.json
*/
/**
* Sample code: Create a vm with an extensions time budget.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithAnExtensionsTimeBudget(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics()
.withEnabled(true).withStorageUri("http://{existing-storage-account-name}.blob.core.windows.net")))
.withExtensionsTimeBudget("PT30M"),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithEmptyDataDisks.json
*/
/**
* Sample code: Create a vm with empty data disks.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithEmptyDataDisks(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS)))
.withDataDisks(Arrays.asList(
new DataDisk().withLun(0).withCreateOption(DiskCreateOptionTypes.EMPTY).withDiskSizeGB(1023),
new DataDisk().withLun(1).withCreateOption(DiskCreateOptionTypes.EMPTY).withDiskSizeGB(1023))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithSecurityTypeConfidentialVM.json
*/
/**
* Sample code: Create a VM with securityType ConfidentialVM with Platform Managed Keys.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMWithSecurityTypeConfidentialVMWithPlatformManagedKeys(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(
new HardwareProfile().withVmSize(VirtualMachineSizeTypes.fromString("Standard_DC2as_v5")))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("2019-datacenter-cvm").withSku("windows-cvm").withVersion("17763.2183.2109130127"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_SSD_LRS)
.withSecurityProfile(new VMDiskSecurityProfile()
.withSecurityEncryptionType(SecurityEncryptionTypes.DISK_WITH_VMGUEST_STATE)))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withSecurityProfile(new SecurityProfile()
.withUefiSettings(new UefiSettings().withSecureBootEnabled(true).withVTpmEnabled(true))
.withSecurityType(SecurityTypes.CONFIDENTIAL_VM)),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithDataDisksFromSourceResource.json
*/
/**
* Sample code: Create a vm with data disks using 'Copy' and 'Restore' options.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createAVmWithDataDisksUsingCopyAndRestoreOptions(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS)))
.withDataDisks(Arrays.asList(new DataDisk().withLun(0).withCreateOption(DiskCreateOptionTypes.COPY)
.withDiskSizeGB(1023)
.withSourceResource(new ApiEntityReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/{existing-snapshot-name}")),
new DataDisk().withLun(1).withCreateOption(DiskCreateOptionTypes.COPY).withDiskSizeGB(1023)
.withSourceResource(new ApiEntityReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/{existing-disk-name}")),
new DataDisk().withLun(2).withCreateOption(DiskCreateOptionTypes.RESTORE).withDiskSizeGB(1023)
.withSourceResource(new ApiEntityReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/restorePointCollections/{existing-rpc-name}/restorePoints/{existing-rp-name}/diskRestorePoints/{existing-disk-restore-point-name}")))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_FromACustomImage.json
*/
/**
* Sample code: Create a vm from a custom image.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmFromACustomImage(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile().withImageReference(new ImageReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/{existing-custom-image-name}"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithHibernationEnabled.json
*/
/**
* Sample code: Create a VM with HibernationEnabled.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMWithHibernationEnabled(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup",
"{vm-name}",
new VirtualMachineInner().withLocation("eastus2euap")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2S_V3))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2019-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("vmOSdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withAdditionalCapabilities(new AdditionalCapabilities().withHibernationEnabled(true))
.withOsProfile(new OSProfile().withComputerName("{vm-name}").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics()
.withEnabled(true).withStorageUri("http://{existing-storage-account-name}.blob.core.windows.net"))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithUefiSettings.json
*/
/**
* Sample code: Create a VM with Uefi Settings of secureBoot and vTPM.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createAVMWithUefiSettingsOfSecureBootAndVTPM(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2S_V3))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference()
.withPublisher("MicrosoftWindowsServer").withOffer("windowsserver-gen2preview-preview")
.withSku("windows10-tvm").withVersion("18363.592.2001092016"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_SSD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withSecurityProfile(new SecurityProfile()
.withUefiSettings(new UefiSettings().withSecureBootEnabled(true).withVTpmEnabled(true))
.withSecurityType(SecurityTypes.TRUSTED_LAUNCH)),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithApplicationProfile.json
*/
/**
* Sample code: Create a vm with Application Profile.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithApplicationProfile(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("{image_publisher}")
.withOffer("{image_offer}").withSku("{image_sku}").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(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(false).withEnableAutomaticUpgrade(false),
new VMGalleryApplication().withPackageReferenceId(
"/subscriptions/32c17a9e-aa7b-4ba5-a45b-e324116b6fdg/resourceGroups/myresourceGroupName3/providers/Microsoft.Compute/galleries/myGallery2/applications/MyApplication2/versions/1.1")))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithNetworkInterfaceConfigurationDnsSettings.json
*/
/**
* Sample code: Create a VM with network interface configuration with public ip address dns settings.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMWithNetworkInterfaceConfigurationWithPublicIpAddressDnsSettings(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkApiVersion(NetworkApiVersion.TWO_ZERO_TWO_ZERO_ONE_ONE_ZERO_ONE)
.withNetworkInterfaceConfigurations(
Arrays.asList(new VirtualMachineNetworkInterfaceConfiguration()
.withName("{nic-config-name}").withPrimary(true).withDeleteOption(DeleteOptions.DELETE)
.withIpConfigurations(Arrays.asList(new VirtualMachineNetworkInterfaceIpConfiguration()
.withName("{ip-config-name}").withPrimary(true)
.withPublicIpAddressConfiguration(new VirtualMachinePublicIpAddressConfiguration()
.withName("{publicIP-config-name}")
.withSku(new PublicIpAddressSku().withName(PublicIpAddressSkuName.BASIC)
.withTier(PublicIpAddressSkuTier.GLOBAL))
.withDeleteOption(DeleteOptions.DETACH)
.withDnsSettings(new VirtualMachinePublicIpAddressDnsSettingsConfiguration()
.withDomainNameLabel("aaaaa")
.withDomainNameLabelScope(DomainNameLabelScopeTypes.TENANT_REUSE))
.withPublicIpAllocationMethod(PublicIpAllocationMethod.STATIC))))))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_InAVmssWithCustomerAssignedPlatformFaultDomain.json
*/
/**
* Sample code: Create a vm in a Virtual Machine Scale Set with customer assigned platformFaultDomain.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmInAVirtualMachineScaleSetWithCustomerAssignedPlatformFaultDomain(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withVirtualMachineScaleSet(new SubResource().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{existing-flex-vmss-name-with-platformFaultDomainCount-greater-than-1}"))
.withPlatformFaultDomain(1),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithBootDiagnostics.json
*/
/**
* Sample code: Create a vm with boot diagnostics.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithBootDiagnostics(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics()
.withEnabled(true).withStorageUri("http://{existing-storage-account-name}.blob.core.windows.net"))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithSshAuthentication.json
*/
/**
* Sample code: Create a vm with ssh authentication.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithSshAuthentication(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("{image_publisher}")
.withOffer("{image_offer}").withSku("{image_sku}").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").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"))))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_FromACommunityGalleryImage.json
*/
/**
* Sample code: Create a VM from a community gallery image.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMFromACommunityGalleryImage(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withCommunityGalleryImageId(
"/CommunityGalleries/galleryPublicName/Images/communityGalleryImageName/Versions/communityGalleryImageVersionName"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithUserData.json
*/
/**
* Sample code: Create a VM with UserData.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMWithUserData(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup",
"{vm-name}",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("vmOSdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("{vm-name}").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics()
.withEnabled(true).withStorageUri("http://{existing-storage-account-name}.blob.core.windows.net")))
.withUserData("RXhhbXBsZSBVc2VyRGF0YQ=="),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_FromAGeneralizedSharedImage.json
*/
/**
* Sample code: Create a vm from a generalized shared image.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmFromAGeneralizedSharedImage(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile().withImageReference(new ImageReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/mySharedGallery/images/mySharedImage"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_LinuxVmWithAutomaticByPlatformSettings.json
*/
/**
* Sample code: Create a Linux vm with a patch setting patchMode of AutomaticByPlatform and
* AutomaticByPlatformSettings.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createALinuxVmWithAPatchSettingPatchModeOfAutomaticByPlatformAndAutomaticByPlatformSettings(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2S_V3))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("Canonical").withOffer("UbuntuServer")
.withSku("16.04-LTS").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder")
.withLinuxConfiguration(new LinuxConfiguration().withProvisionVMAgent(true).withPatchSettings(
new LinuxPatchSettings().withPatchMode(LinuxVMGuestPatchMode.AUTOMATIC_BY_PLATFORM)
.withAssessmentMode(LinuxPatchAssessmentMode.AUTOMATIC_BY_PLATFORM)
.withAutomaticByPlatformSettings(new LinuxVMGuestPatchAutomaticByPlatformSettings()
.withRebootSetting(LinuxVMGuestPatchAutomaticByPlatformRebootSetting.NEVER)
.withBypassPlatformSafetyChecksOnUserSchedule(true)))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WindowsVmWithPatchSettingModeOfManual.json
*/
/**
* Sample code: Create a Windows vm with a patch setting patchMode of Manual.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createAWindowsVmWithAPatchSettingPatchModeOfManual(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder").withWindowsConfiguration(
new WindowsConfiguration().withProvisionVMAgent(true).withEnableAutomaticUpdates(true)
.withPatchSettings(new PatchSettings().withPatchMode(WindowsVMGuestPatchMode.MANUAL))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithProxyAgentSettings.json
*/
/**
* Sample code: Create a VM with ProxyAgent Settings of enabled and mode.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createAVMWithProxyAgentSettingsOfEnabledAndMode(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2S_V3))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2019-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_SSD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withSecurityProfile(new SecurityProfile()
.withProxyAgentSettings(new ProxyAgentSettings().withEnabled(true).withMode(Mode.ENFORCE))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_LinuxVmWithPatchSettingModeOfImageDefault.json
*/
/**
* Sample code: Create a Linux vm with a patch setting patchMode of ImageDefault.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createALinuxVmWithAPatchSettingPatchModeOfImageDefault(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2S_V3))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("Canonical").withOffer("UbuntuServer")
.withSku("16.04-LTS").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder")
.withLinuxConfiguration(new LinuxConfiguration().withProvisionVMAgent(true).withPatchSettings(
new LinuxPatchSettings().withPatchMode(LinuxVMGuestPatchMode.IMAGE_DEFAULT))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithManagedBootDiagnostics.json
*/
/**
* Sample code: Create a vm with managed boot diagnostics.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithManagedBootDiagnostics(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(
new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics().withEnabled(true))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WindowsVmWithAutomaticByPlatformSettings.json
*/
/**
* Sample code: Create a Windows vm with a patch setting patchMode of AutomaticByPlatform and
* AutomaticByPlatformSettings.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAWindowsVmWithAPatchSettingPatchModeOfAutomaticByPlatformAndAutomaticByPlatformSettings(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder").withWindowsConfiguration(
new WindowsConfiguration().withProvisionVMAgent(true).withEnableAutomaticUpdates(true)
.withPatchSettings(new PatchSettings()
.withPatchMode(WindowsVMGuestPatchMode.AUTOMATIC_BY_PLATFORM)
.withAssessmentMode(WindowsPatchAssessmentMode.AUTOMATIC_BY_PLATFORM)
.withAutomaticByPlatformSettings(new WindowsVMGuestPatchAutomaticByPlatformSettings()
.withRebootSetting(WindowsVMGuestPatchAutomaticByPlatformRebootSetting.NEVER)
.withBypassPlatformSafetyChecksOnUserSchedule(false)))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
範例回覆
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true,
"patchSettings": {
"patchMode": "AutomaticByPlatform",
"assessmentMode": "AutomaticByPlatform"
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Premium_LRS"
}
},
"dataDisks": []
},
"vmId": "a149cd25-409f-41af-8088-275f5486bc93",
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"type": "Microsoft.Compute/virtualMachines",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true,
"patchSettings": {
"patchMode": "AutomaticByPlatform",
"assessmentMode": "AutomaticByPlatform"
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "2016-Datacenter",
"publisher": "MicrosoftWindowsServer",
"version": "latest",
"offer": "WindowsServer"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"name": "myVMosdisk",
"managedDisk": {
"storageAccountType": "Premium_LRS"
}
},
"dataDisks": []
},
"vmId": "a149cd25-409f-41af-8088-275f5486bc93",
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"provisioningState": "Creating"
},
"name": "myVM",
"location": "westus"
}
Create or update a VM with capacity reservation
範例要求
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2024-03-01
{
"location": "westus",
"plan": {
"publisher": "microsoft-ads",
"product": "windows-data-science-vm",
"name": "windows2016"
},
"properties": {
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"storageProfile": {
"imageReference": {
"sku": "windows2016",
"publisher": "microsoft-ads",
"version": "latest",
"offer": "windows-data-science-vm"
},
"osDisk": {
"caching": "ReadOnly",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"createOption": "FromImage",
"name": "myVMosdisk"
}
},
"capacityReservation": {
"capacityReservationGroup": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/CapacityReservationGroups/{crgName}"
}
},
"osProfile": {
"adminUsername": "{your-username}",
"computerName": "myVM",
"adminPassword": "{your-password}"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {
"primary": true
}
}
]
}
}
}
from typing import Any, IO, Union
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_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_machines.begin_create_or_update(
resource_group_name="myResourceGroup",
vm_name="myVM",
parameters={
"location": "westus",
"plan": {"name": "windows2016", "product": "windows-data-science-vm", "publisher": "microsoft-ads"},
"properties": {
"capacityReservation": {
"capacityReservationGroup": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/CapacityReservationGroups/{crgName}"
}
},
"hardwareProfile": {"vmSize": "Standard_DS1_v2"},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
"properties": {"primary": True},
}
]
},
"osProfile": {
"adminPassword": "{your-password}",
"adminUsername": "{your-username}",
"computerName": "myVM",
},
"storageProfile": {
"imageReference": {
"offer": "windows-data-science-vm",
"publisher": "microsoft-ads",
"sku": "windows2016",
"version": "latest",
},
"osDisk": {
"caching": "ReadOnly",
"createOption": "FromImage",
"managedDisk": {"storageAccountType": "Standard_LRS"},
"name": "myVMosdisk",
},
},
},
},
).result()
print(response)
# x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithCapacityReservation.json
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/v5"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/92de53a5f1e0e03c94b40475d2135d97148ed014/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithCapacityReservation.json
func ExampleVirtualMachinesClient_BeginCreateOrUpdate_createOrUpdateAVmWithCapacityReservation() {
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.NewVirtualMachinesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myVM", armcompute.VirtualMachine{
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.VirtualMachineProperties{
CapacityReservation: &armcompute.CapacityReservationProfile{
CapacityReservationGroup: &armcompute.SubResource{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/CapacityReservationGroups/{crgName}"),
},
},
HardwareProfile: &armcompute.HardwareProfile{
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardDS1V2),
},
NetworkProfile: &armcompute.NetworkProfile{
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"),
Properties: &armcompute.NetworkInterfaceReferenceProperties{
Primary: to.Ptr(true),
},
}},
},
OSProfile: &armcompute.OSProfile{
AdminPassword: to.Ptr("{your-password}"),
AdminUsername: to.Ptr("{your-username}"),
ComputerName: to.Ptr("myVM"),
},
StorageProfile: &armcompute.StorageProfile{
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.OSDisk{
Name: to.Ptr("myVMosdisk"),
Caching: to.Ptr(armcompute.CachingTypesReadOnly),
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
ManagedDisk: &armcompute.ManagedDiskParameters{
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
},
},
},
},
}, &armcompute.VirtualMachinesClientBeginCreateOrUpdateOptions{IfMatch: nil,
IfNoneMatch: 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)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.VirtualMachine = armcompute.VirtualMachine{
// Name: to.Ptr("myVM"),
// Type: to.Ptr("Microsoft.Compute/virtualMachines"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// Location: to.Ptr("westus"),
// Plan: &armcompute.Plan{
// Name: to.Ptr("standard-data-science-vm"),
// Product: to.Ptr("standard-data-science-vm"),
// Publisher: to.Ptr("microsoft-ads"),
// },
// Properties: &armcompute.VirtualMachineProperties{
// CapacityReservation: &armcompute.CapacityReservationProfile{
// CapacityReservationGroup: &armcompute.SubResource{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/CapacityReservationGroups/{crgName}"),
// },
// },
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardDS1V2),
// },
// NetworkProfile: &armcompute.NetworkProfile{
// NetworkInterfaces: []*armcompute.NetworkInterfaceReference{
// {
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic"),
// Properties: &armcompute.NetworkInterfaceReferenceProperties{
// Primary: to.Ptr(true),
// },
// }},
// },
// OSProfile: &armcompute.OSProfile{
// AdminUsername: to.Ptr("{your-username}"),
// ComputerName: to.Ptr("myVM"),
// Secrets: []*armcompute.VaultSecretGroup{
// },
// WindowsConfiguration: &armcompute.WindowsConfiguration{
// EnableAutomaticUpdates: to.Ptr(true),
// ProvisionVMAgent: to.Ptr(true),
// },
// },
// ProvisioningState: to.Ptr("Succeeded"),
// StorageProfile: &armcompute.StorageProfile{
// DataDisks: []*armcompute.DataDisk{
// },
// ImageReference: &armcompute.ImageReference{
// Offer: to.Ptr("standard-data-science-vm"),
// Publisher: to.Ptr("microsoft-ads"),
// SKU: to.Ptr("standard-data-science-vm"),
// Version: to.Ptr("latest"),
// },
// OSDisk: &armcompute.OSDisk{
// Name: to.Ptr("myVMosdisk"),
// Caching: to.Ptr(armcompute.CachingTypesReadOnly),
// CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage),
// ManagedDisk: &armcompute.ManagedDiskParameters{
// StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS),
// },
// OSType: to.Ptr(armcompute.OperatingSystemTypesWindows),
// },
// },
// VMID: to.Ptr("5c0d55a7-c407-4ed6-bf7d-ddb810267c85"),
// },
// }
}
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");
/**
* This sample demonstrates how to The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
*
* @summary The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation.
* x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/virtualMachineExamples/VirtualMachine_Create_WithCapacityReservation.json
*/
async function createOrUpdateAVMWithCapacityReservation() {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP"] || "myResourceGroup";
const vmName = "myVM";
const parameters = {
capacityReservation: {
capacityReservationGroup: {
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/CapacityReservationGroups/{crgName}",
},
},
hardwareProfile: { vmSize: "Standard_DS1_v2" },
location: "westus",
networkProfile: {
networkInterfaces: [
{
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
primary: true,
},
],
},
osProfile: {
adminPassword: "{your-password}",
adminUsername: "{your-username}",
computerName: "myVM",
},
plan: {
name: "windows2016",
product: "windows-data-science-vm",
publisher: "microsoft-ads",
},
storageProfile: {
imageReference: {
offer: "windows-data-science-vm",
publisher: "microsoft-ads",
sku: "windows2016",
version: "latest",
},
osDisk: {
name: "myVMosdisk",
caching: "ReadOnly",
createOption: "FromImage",
managedDisk: { storageAccountType: "Standard_LRS" },
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.virtualMachines.beginCreateOrUpdateAndWait(
resourceGroupName,
vmName,
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
import com.azure.core.management.SubResource;
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.compute.models.AdditionalCapabilities;
import com.azure.resourcemanager.compute.models.ApiEntityReference;
import com.azure.resourcemanager.compute.models.ApplicationProfile;
import com.azure.resourcemanager.compute.models.BootDiagnostics;
import com.azure.resourcemanager.compute.models.CachingTypes;
import com.azure.resourcemanager.compute.models.CapacityReservationProfile;
import com.azure.resourcemanager.compute.models.DataDisk;
import com.azure.resourcemanager.compute.models.DeleteOptions;
import com.azure.resourcemanager.compute.models.DiagnosticsProfile;
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.DiskControllerTypes;
import com.azure.resourcemanager.compute.models.DiskCreateOptionTypes;
import com.azure.resourcemanager.compute.models.DiskEncryptionSetParameters;
import com.azure.resourcemanager.compute.models.DomainNameLabelScopeTypes;
import com.azure.resourcemanager.compute.models.EventGridAndResourceGraph;
import com.azure.resourcemanager.compute.models.HardwareProfile;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.LinuxConfiguration;
import com.azure.resourcemanager.compute.models.LinuxPatchAssessmentMode;
import com.azure.resourcemanager.compute.models.LinuxPatchSettings;
import com.azure.resourcemanager.compute.models.LinuxVMGuestPatchAutomaticByPlatformRebootSetting;
import com.azure.resourcemanager.compute.models.LinuxVMGuestPatchAutomaticByPlatformSettings;
import com.azure.resourcemanager.compute.models.LinuxVMGuestPatchMode;
import com.azure.resourcemanager.compute.models.ManagedDiskParameters;
import com.azure.resourcemanager.compute.models.Mode;
import com.azure.resourcemanager.compute.models.NetworkApiVersion;
import com.azure.resourcemanager.compute.models.NetworkInterfaceReference;
import com.azure.resourcemanager.compute.models.NetworkProfile;
import com.azure.resourcemanager.compute.models.OSDisk;
import com.azure.resourcemanager.compute.models.OSImageNotificationProfile;
import com.azure.resourcemanager.compute.models.OSProfile;
import com.azure.resourcemanager.compute.models.OperatingSystemTypes;
import com.azure.resourcemanager.compute.models.PatchSettings;
import com.azure.resourcemanager.compute.models.Plan;
import com.azure.resourcemanager.compute.models.ProxyAgentSettings;
import com.azure.resourcemanager.compute.models.PublicIpAddressSku;
import com.azure.resourcemanager.compute.models.PublicIpAddressSkuName;
import com.azure.resourcemanager.compute.models.PublicIpAddressSkuTier;
import com.azure.resourcemanager.compute.models.PublicIpAllocationMethod;
import com.azure.resourcemanager.compute.models.ScheduledEventsAdditionalPublishingTargets;
import com.azure.resourcemanager.compute.models.ScheduledEventsPolicy;
import com.azure.resourcemanager.compute.models.ScheduledEventsProfile;
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.SshConfiguration;
import com.azure.resourcemanager.compute.models.SshPublicKey;
import com.azure.resourcemanager.compute.models.StorageAccountTypes;
import com.azure.resourcemanager.compute.models.StorageProfile;
import com.azure.resourcemanager.compute.models.TerminateNotificationProfile;
import com.azure.resourcemanager.compute.models.UefiSettings;
import com.azure.resourcemanager.compute.models.UserInitiatedReboot;
import com.azure.resourcemanager.compute.models.UserInitiatedRedeploy;
import com.azure.resourcemanager.compute.models.VMDiskSecurityProfile;
import com.azure.resourcemanager.compute.models.VMGalleryApplication;
import com.azure.resourcemanager.compute.models.VMSizeProperties;
import com.azure.resourcemanager.compute.models.VirtualHardDisk;
import com.azure.resourcemanager.compute.models.VirtualMachineNetworkInterfaceConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineNetworkInterfaceIpConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachinePublicIpAddressConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachinePublicIpAddressDnsSettingsConfiguration;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import com.azure.resourcemanager.compute.models.WindowsConfiguration;
import com.azure.resourcemanager.compute.models.WindowsPatchAssessmentMode;
import com.azure.resourcemanager.compute.models.WindowsVMGuestPatchAutomaticByPlatformRebootSetting;
import com.azure.resourcemanager.compute.models.WindowsVMGuestPatchAutomaticByPlatformSettings;
import com.azure.resourcemanager.compute.models.WindowsVMGuestPatchMode;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for VirtualMachines CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithCapacityReservation.json
*/
/**
* Sample code: Create or update a VM with capacity reservation.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createOrUpdateAVMWithCapacityReservation(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withPlan(new Plan().withName("windows2016").withPublisher("microsoft-ads")
.withProduct("windows-data-science-vm"))
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_DS1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("microsoft-ads")
.withOffer("windows-data-science-vm").withSku("windows2016").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withCapacityReservation(
new CapacityReservationProfile().withCapacityReservationGroup(new SubResource().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/CapacityReservationGroups/{crgName}"))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_CustomImageVmFromAnUnmanagedGeneralizedOsImage.json
*/
/**
* Sample code: Create a custom-image vm from an unmanaged generalized os image.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createACustomImageVmFromAnUnmanagedGeneralizedOsImage(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines()
.createOrUpdate("myResourceGroup", "{vm-name}", new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile().withOsDisk(new OSDisk()
.withOsType(OperatingSystemTypes.WINDOWS).withName("myVMosdisk")
.withVhd(new VirtualHardDisk().withUri(
"http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk.vhd"))
.withImage(new VirtualHardDisk().withUri(
"http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/{existing-generalized-os-image-blob-name}.vhd"))
.withCaching(CachingTypes.READ_WRITE).withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithEncryptionAtHost.json
*/
/**
* Sample code: Create a vm with Host Encryption using encryptionAtHost property.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createAVmWithHostEncryptionUsingEncryptionAtHostProperty(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withPlan(new Plan().withName("windows2016").withPublisher("microsoft-ads")
.withProduct("windows-data-science-vm"))
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_DS1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("microsoft-ads")
.withOffer("windows-data-science-vm").withSku("windows2016").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withSecurityProfile(new SecurityProfile().withEncryptionAtHost(true)),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_InAnAvailabilitySet.json
*/
/**
* Sample code: Create a vm in an availability set.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmInAnAvailabilitySet(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withAvailabilitySet(new SubResource().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/availabilitySets/{existing-availability-set-name}")),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithNetworkInterfaceConfiguration.json
*/
/**
* Sample code: Create a VM with network interface configuration.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createAVMWithNetworkInterfaceConfiguration(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(new NetworkProfile()
.withNetworkApiVersion(NetworkApiVersion.TWO_ZERO_TWO_ZERO_ONE_ONE_ZERO_ONE)
.withNetworkInterfaceConfigurations(
Arrays.asList(new VirtualMachineNetworkInterfaceConfiguration().withName("{nic-config-name}")
.withPrimary(true).withDeleteOption(DeleteOptions.DELETE)
.withIpConfigurations(Arrays.asList(new VirtualMachineNetworkInterfaceIpConfiguration()
.withName("{ip-config-name}").withPrimary(true)
.withPublicIpAddressConfiguration(new VirtualMachinePublicIpAddressConfiguration()
.withName("{publicIP-config-name}")
.withSku(new PublicIpAddressSku().withName(PublicIpAddressSkuName.BASIC)
.withTier(PublicIpAddressSkuTier.GLOBAL))
.withDeleteOption(DeleteOptions.DETACH)
.withPublicIpAllocationMethod(PublicIpAllocationMethod.STATIC))))))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithADiffOsDiskUsingDiffDiskPlacementAsNvmeDisk.json
*/
/**
* Sample code: Create a vm with ephemeral os disk provisioning in Nvme disk using placement property.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithEphemeralOsDiskProvisioningInNvmeDiskUsingPlacementProperty(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withPlan(new Plan().withName("windows2016").withPublisher("microsoft-ads")
.withProduct("windows-data-science-vm"))
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_DS1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("microsoft-ads")
.withOffer("windows-data-science-vm").withSku("windows2016").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withDiffDiskSettings(new DiffDiskSettings().withOption(DiffDiskOptions.LOCAL)
.withPlacement(DiffDiskPlacement.NVME_DISK))
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_FromASpecializedSharedImage.json
*/
/**
* Sample code: Create a vm from a specialized shared image.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmFromASpecializedSharedImage(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile().withImageReference(new ImageReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/mySharedGallery/images/mySharedImage"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithPasswordAuthentication.json
*/
/**
* Sample code: Create a vm with password authentication.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithPasswordAuthentication(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithScheduledEventsProfile.json
*/
/**
* Sample code: Create a vm with Scheduled Events Profile.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithScheduledEventsProfile(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withScheduledEventsPolicy(new ScheduledEventsPolicy()
.withUserInitiatedRedeploy(new UserInitiatedRedeploy().withAutomaticallyApprove(true))
.withUserInitiatedReboot(new UserInitiatedReboot().withAutomaticallyApprove(true))
.withScheduledEventsAdditionalPublishingTargets(new ScheduledEventsAdditionalPublishingTargets()
.withEventGridAndResourceGraph(new EventGridAndResourceGraph().withEnable(true))))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics()
.withEnabled(true).withStorageUri("http://{existing-storage-account-name}.blob.core.windows.net")))
.withScheduledEventsProfile(new ScheduledEventsProfile()
.withTerminateNotificationProfile(
new TerminateNotificationProfile().withNotBeforeTimeout("PT10M").withEnable(true))
.withOsImageNotificationProfile(
new OSImageNotificationProfile().withNotBeforeTimeout("PT15M").withEnable(true))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithADiffOsDiskUsingDiffDiskPlacementAsResourceDisk.json
*/
/**
* Sample code: Create a vm with ephemeral os disk provisioning in Resource disk using placement property.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithEphemeralOsDiskProvisioningInResourceDiskUsingPlacementProperty(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withPlan(new Plan().withName("windows2016").withPublisher("microsoft-ads")
.withProduct("windows-data-science-vm"))
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_DS1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("microsoft-ads")
.withOffer("windows-data-science-vm").withSku("windows2016").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withDiffDiskSettings(new DiffDiskSettings().withOption(DiffDiskOptions.LOCAL)
.withPlacement(DiffDiskPlacement.RESOURCE_DISK))
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithADiffOsDisk.json
*/
/**
* Sample code: Create a vm with ephemeral os disk.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithEphemeralOsDisk(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withPlan(new Plan().withName("windows2016").withPublisher("microsoft-ads")
.withProduct("windows-data-science-vm"))
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_DS1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("microsoft-ads")
.withOffer("windows-data-science-vm").withSku("windows2016").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withDiffDiskSettings(new DiffDiskSettings().withOption(DiffDiskOptions.LOCAL))
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithSecurityTypeConfidentialVMWithCustomerManagedKeys.json
*/
/**
* Sample code: Create a VM with securityType ConfidentialVM with Customer Managed Keys.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMWithSecurityTypeConfidentialVMWithCustomerManagedKeys(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(
new HardwareProfile().withVmSize(VirtualMachineSizeTypes.fromString("Standard_DC2as_v5")))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("2019-datacenter-cvm").withSku("windows-cvm").withVersion("17763.2183.2109130127"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)
.withManagedDisk(new ManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.STANDARD_SSD_LRS)
.withSecurityProfile(new VMDiskSecurityProfile()
.withSecurityEncryptionType(SecurityEncryptionTypes.DISK_WITH_VMGUEST_STATE)
.withDiskEncryptionSet(new DiskEncryptionSetParameters().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"))))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withSecurityProfile(new SecurityProfile()
.withUefiSettings(new UefiSettings().withSecureBootEnabled(true).withVTpmEnabled(true))
.withSecurityType(SecurityTypes.CONFIDENTIAL_VM)),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithDiskEncryptionSetResource.json
*/
/**
* Sample code: Create a vm with DiskEncryptionSet resource id in the os disk and data disk.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithDiskEncryptionSetResourceIdInTheOsDiskAndDataDisk(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile().withImageReference(new ImageReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/{existing-custom-image-name}"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE)
.withManagedDisk(new ManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.STANDARD_LRS)
.withDiskEncryptionSet(new DiskEncryptionSetParameters().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"))))
.withDataDisks(Arrays.asList(new DataDisk().withLun(0).withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.EMPTY).withDiskSizeGB(1023)
.withManagedDisk(new ManagedDiskParameters()
.withStorageAccountType(StorageAccountTypes.STANDARD_LRS)
.withDiskEncryptionSet(new DiskEncryptionSetParameters().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"))),
new DataDisk().withLun(1).withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.ATTACH).withDiskSizeGB(1023)
.withManagedDisk(new ManagedDiskParameters().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/{existing-managed-disk-name}")
.withStorageAccountType(StorageAccountTypes.STANDARD_LRS)
.withDiskEncryptionSet(new DiskEncryptionSetParameters().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"))))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithDiskControllerType.json
*/
/**
* Sample code: Create a VM with Disk Controller Type.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMWithDiskControllerType(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D4_V3))
.withScheduledEventsPolicy(new ScheduledEventsPolicy()
.withUserInitiatedRedeploy(new UserInitiatedRedeploy().withAutomaticallyApprove(true))
.withUserInitiatedReboot(new UserInitiatedReboot().withAutomaticallyApprove(true))
.withScheduledEventsAdditionalPublishingTargets(new ScheduledEventsAdditionalPublishingTargets()
.withEventGridAndResourceGraph(new EventGridAndResourceGraph().withEnable(true))))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS)))
.withDiskControllerType(DiskControllerTypes.NVME))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics()
.withEnabled(true).withStorageUri("http://{existing-storage-account-name}.blob.core.windows.net")))
.withUserData("U29tZSBDdXN0b20gRGF0YQ=="),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_FromASharedGalleryImage.json
*/
/**
* Sample code: Create a VM from a shared gallery image.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMFromASharedGalleryImage(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withSharedGalleryImageId(
"/SharedGalleries/sharedGalleryName/Images/sharedGalleryImageName/Versions/sharedGalleryImageVersionName"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithVMSizeProperties.json
*/
/**
* Sample code: Create a VM with VM Size Properties.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMWithVMSizeProperties(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D4_V3)
.withVmSizeProperties(new VMSizeProperties().withVCpusAvailable(1).withVCpusPerCore(1)))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics()
.withEnabled(true).withStorageUri("http://{existing-storage-account-name}.blob.core.windows.net")))
.withUserData("U29tZSBDdXN0b20gRGF0YQ=="),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_PlatformImageVmWithUnmanagedOsAndDataDisks.json
*/
/**
* Sample code: Create a platform-image vm with unmanaged os and data disks.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createAPlatformImageVmWithUnmanagedOsAndDataDisks(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines()
.createOrUpdate("myResourceGroup", "{vm-name}", new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withVhd(new VirtualHardDisk().withUri(
"http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk.vhd"))
.withCaching(CachingTypes.READ_WRITE).withCreateOption(DiskCreateOptionTypes.FROM_IMAGE))
.withDataDisks(Arrays.asList(new DataDisk().withLun(0).withVhd(new VirtualHardDisk().withUri(
"http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk0.vhd"))
.withCreateOption(DiskCreateOptionTypes.EMPTY).withDiskSizeGB(1023),
new DataDisk().withLun(1).withVhd(new VirtualHardDisk().withUri(
"http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk1.vhd"))
.withCreateOption(DiskCreateOptionTypes.EMPTY).withDiskSizeGB(1023))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_LinuxVmWithPatchSettingModesOfAutomaticByPlatform.json
*/
/**
* Sample code: Create a Linux vm with a patch settings patchMode and assessmentMode set to AutomaticByPlatform.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createALinuxVmWithAPatchSettingsPatchModeAndAssessmentModeSetToAutomaticByPlatform(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2S_V3))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("Canonical").withOffer("UbuntuServer")
.withSku("16.04-LTS").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder")
.withLinuxConfiguration(new LinuxConfiguration().withProvisionVMAgent(true).withPatchSettings(
new LinuxPatchSettings().withPatchMode(LinuxVMGuestPatchMode.AUTOMATIC_BY_PLATFORM)
.withAssessmentMode(LinuxPatchAssessmentMode.AUTOMATIC_BY_PLATFORM))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithSecurityTypeConfidentialVMWithNonPersistedTPM.json
*/
/**
* Sample code: Create a VM with securityType ConfidentialVM with NonPersistedTPM securityEncryptionType.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMWithSecurityTypeConfidentialVMWithNonPersistedTPMSecurityEncryptionType(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(
new HardwareProfile().withVmSize(VirtualMachineSizeTypes.fromString("Standard_DC2es_v5")))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("UbuntuServer")
.withOffer("2022-datacenter-cvm").withSku("linux-cvm").withVersion("17763.2183.2109130127"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_SSD_LRS)
.withSecurityProfile(new VMDiskSecurityProfile()
.withSecurityEncryptionType(SecurityEncryptionTypes.NON_PERSISTED_TPM)))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withSecurityProfile(new SecurityProfile()
.withUefiSettings(new UefiSettings().withSecureBootEnabled(false).withVTpmEnabled(true))
.withSecurityType(SecurityTypes.CONFIDENTIAL_VM)),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithAMarketplaceImagePlan.json
*/
/**
* Sample code: Create a vm with a marketplace image plan.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithAMarketplaceImagePlan(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withPlan(new Plan().withName("windows2016").withPublisher("microsoft-ads")
.withProduct("windows-data-science-vm"))
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("microsoft-ads")
.withOffer("windows-data-science-vm").withSku("windows2016").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WindowsVmWithPatchSettingAssessmentModeOfImageDefault.json
*/
/**
* Sample code: Create a Windows vm with a patch setting assessmentMode of ImageDefault.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAWindowsVmWithAPatchSettingAssessmentModeOfImageDefault(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder")
.withWindowsConfiguration(new WindowsConfiguration().withProvisionVMAgent(true)
.withEnableAutomaticUpdates(true).withPatchSettings(
new PatchSettings().withAssessmentMode(WindowsPatchAssessmentMode.IMAGE_DEFAULT))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/
* VirtualMachine_Create_WindowsVmWithPatchSettingModeOfAutomaticByPlatformAndEnableHotPatchingTrue.json
*/
/**
* Sample code: Create a Windows vm with a patch setting patchMode of AutomaticByPlatform and enableHotpatching set
* to true.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAWindowsVmWithAPatchSettingPatchModeOfAutomaticByPlatformAndEnableHotpatchingSetToTrue(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder")
.withWindowsConfiguration(new WindowsConfiguration().withProvisionVMAgent(true)
.withEnableAutomaticUpdates(true)
.withPatchSettings(new PatchSettings()
.withPatchMode(WindowsVMGuestPatchMode.AUTOMATIC_BY_PLATFORM).withEnableHotpatching(true))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithExtensionsTimeBudget.json
*/
/**
* Sample code: Create a vm with an extensions time budget.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithAnExtensionsTimeBudget(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics()
.withEnabled(true).withStorageUri("http://{existing-storage-account-name}.blob.core.windows.net")))
.withExtensionsTimeBudget("PT30M"),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithEmptyDataDisks.json
*/
/**
* Sample code: Create a vm with empty data disks.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithEmptyDataDisks(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS)))
.withDataDisks(Arrays.asList(
new DataDisk().withLun(0).withCreateOption(DiskCreateOptionTypes.EMPTY).withDiskSizeGB(1023),
new DataDisk().withLun(1).withCreateOption(DiskCreateOptionTypes.EMPTY).withDiskSizeGB(1023))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithSecurityTypeConfidentialVM.json
*/
/**
* Sample code: Create a VM with securityType ConfidentialVM with Platform Managed Keys.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMWithSecurityTypeConfidentialVMWithPlatformManagedKeys(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(
new HardwareProfile().withVmSize(VirtualMachineSizeTypes.fromString("Standard_DC2as_v5")))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("2019-datacenter-cvm").withSku("windows-cvm").withVersion("17763.2183.2109130127"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_SSD_LRS)
.withSecurityProfile(new VMDiskSecurityProfile()
.withSecurityEncryptionType(SecurityEncryptionTypes.DISK_WITH_VMGUEST_STATE)))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withSecurityProfile(new SecurityProfile()
.withUefiSettings(new UefiSettings().withSecureBootEnabled(true).withVTpmEnabled(true))
.withSecurityType(SecurityTypes.CONFIDENTIAL_VM)),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithDataDisksFromSourceResource.json
*/
/**
* Sample code: Create a vm with data disks using 'Copy' and 'Restore' options.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createAVmWithDataDisksUsingCopyAndRestoreOptions(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS)))
.withDataDisks(Arrays.asList(new DataDisk().withLun(0).withCreateOption(DiskCreateOptionTypes.COPY)
.withDiskSizeGB(1023)
.withSourceResource(new ApiEntityReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/{existing-snapshot-name}")),
new DataDisk().withLun(1).withCreateOption(DiskCreateOptionTypes.COPY).withDiskSizeGB(1023)
.withSourceResource(new ApiEntityReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/{existing-disk-name}")),
new DataDisk().withLun(2).withCreateOption(DiskCreateOptionTypes.RESTORE).withDiskSizeGB(1023)
.withSourceResource(new ApiEntityReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/restorePointCollections/{existing-rpc-name}/restorePoints/{existing-rp-name}/diskRestorePoints/{existing-disk-restore-point-name}")))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_FromACustomImage.json
*/
/**
* Sample code: Create a vm from a custom image.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmFromACustomImage(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile().withImageReference(new ImageReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/{existing-custom-image-name}"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithHibernationEnabled.json
*/
/**
* Sample code: Create a VM with HibernationEnabled.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMWithHibernationEnabled(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup",
"{vm-name}",
new VirtualMachineInner().withLocation("eastus2euap")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2S_V3))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2019-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("vmOSdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withAdditionalCapabilities(new AdditionalCapabilities().withHibernationEnabled(true))
.withOsProfile(new OSProfile().withComputerName("{vm-name}").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics()
.withEnabled(true).withStorageUri("http://{existing-storage-account-name}.blob.core.windows.net"))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithUefiSettings.json
*/
/**
* Sample code: Create a VM with Uefi Settings of secureBoot and vTPM.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createAVMWithUefiSettingsOfSecureBootAndVTPM(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2S_V3))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference()
.withPublisher("MicrosoftWindowsServer").withOffer("windowsserver-gen2preview-preview")
.withSku("windows10-tvm").withVersion("18363.592.2001092016"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_SSD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withSecurityProfile(new SecurityProfile()
.withUefiSettings(new UefiSettings().withSecureBootEnabled(true).withVTpmEnabled(true))
.withSecurityType(SecurityTypes.TRUSTED_LAUNCH)),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithApplicationProfile.json
*/
/**
* Sample code: Create a vm with Application Profile.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithApplicationProfile(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("{image_publisher}")
.withOffer("{image_offer}").withSku("{image_sku}").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(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(false).withEnableAutomaticUpgrade(false),
new VMGalleryApplication().withPackageReferenceId(
"/subscriptions/32c17a9e-aa7b-4ba5-a45b-e324116b6fdg/resourceGroups/myresourceGroupName3/providers/Microsoft.Compute/galleries/myGallery2/applications/MyApplication2/versions/1.1")))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithNetworkInterfaceConfigurationDnsSettings.json
*/
/**
* Sample code: Create a VM with network interface configuration with public ip address dns settings.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMWithNetworkInterfaceConfigurationWithPublicIpAddressDnsSettings(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkApiVersion(NetworkApiVersion.TWO_ZERO_TWO_ZERO_ONE_ONE_ZERO_ONE)
.withNetworkInterfaceConfigurations(
Arrays.asList(new VirtualMachineNetworkInterfaceConfiguration()
.withName("{nic-config-name}").withPrimary(true).withDeleteOption(DeleteOptions.DELETE)
.withIpConfigurations(Arrays.asList(new VirtualMachineNetworkInterfaceIpConfiguration()
.withName("{ip-config-name}").withPrimary(true)
.withPublicIpAddressConfiguration(new VirtualMachinePublicIpAddressConfiguration()
.withName("{publicIP-config-name}")
.withSku(new PublicIpAddressSku().withName(PublicIpAddressSkuName.BASIC)
.withTier(PublicIpAddressSkuTier.GLOBAL))
.withDeleteOption(DeleteOptions.DETACH)
.withDnsSettings(new VirtualMachinePublicIpAddressDnsSettingsConfiguration()
.withDomainNameLabel("aaaaa")
.withDomainNameLabelScope(DomainNameLabelScopeTypes.TENANT_REUSE))
.withPublicIpAllocationMethod(PublicIpAllocationMethod.STATIC))))))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_InAVmssWithCustomerAssignedPlatformFaultDomain.json
*/
/**
* Sample code: Create a vm in a Virtual Machine Scale Set with customer assigned platformFaultDomain.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmInAVirtualMachineScaleSetWithCustomerAssignedPlatformFaultDomain(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withVirtualMachineScaleSet(new SubResource().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/{existing-flex-vmss-name-with-platformFaultDomainCount-greater-than-1}"))
.withPlatformFaultDomain(1),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithBootDiagnostics.json
*/
/**
* Sample code: Create a vm with boot diagnostics.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithBootDiagnostics(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics()
.withEnabled(true).withStorageUri("http://{existing-storage-account-name}.blob.core.windows.net"))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithSshAuthentication.json
*/
/**
* Sample code: Create a vm with ssh authentication.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithSshAuthentication(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("{image_publisher}")
.withOffer("{image_offer}").withSku("{image_sku}").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").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"))))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_FromACommunityGalleryImage.json
*/
/**
* Sample code: Create a VM from a community gallery image.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMFromACommunityGalleryImage(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withCommunityGalleryImageId(
"/CommunityGalleries/galleryPublicName/Images/communityGalleryImageName/Versions/communityGalleryImageVersionName"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithUserData.json
*/
/**
* Sample code: Create a VM with UserData.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVMWithUserData(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup",
"{vm-name}",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("vmOSdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("{vm-name}").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics()
.withEnabled(true).withStorageUri("http://{existing-storage-account-name}.blob.core.windows.net")))
.withUserData("RXhhbXBsZSBVc2VyRGF0YQ=="),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_FromAGeneralizedSharedImage.json
*/
/**
* Sample code: Create a vm from a generalized shared image.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmFromAGeneralizedSharedImage(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile().withImageReference(new ImageReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/mySharedGallery/images/mySharedImage"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_LinuxVmWithAutomaticByPlatformSettings.json
*/
/**
* Sample code: Create a Linux vm with a patch setting patchMode of AutomaticByPlatform and
* AutomaticByPlatformSettings.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createALinuxVmWithAPatchSettingPatchModeOfAutomaticByPlatformAndAutomaticByPlatformSettings(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2S_V3))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("Canonical").withOffer("UbuntuServer")
.withSku("16.04-LTS").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder")
.withLinuxConfiguration(new LinuxConfiguration().withProvisionVMAgent(true).withPatchSettings(
new LinuxPatchSettings().withPatchMode(LinuxVMGuestPatchMode.AUTOMATIC_BY_PLATFORM)
.withAssessmentMode(LinuxPatchAssessmentMode.AUTOMATIC_BY_PLATFORM)
.withAutomaticByPlatformSettings(new LinuxVMGuestPatchAutomaticByPlatformSettings()
.withRebootSetting(LinuxVMGuestPatchAutomaticByPlatformRebootSetting.NEVER)
.withBypassPlatformSafetyChecksOnUserSchedule(true)))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WindowsVmWithPatchSettingModeOfManual.json
*/
/**
* Sample code: Create a Windows vm with a patch setting patchMode of Manual.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createAWindowsVmWithAPatchSettingPatchModeOfManual(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder").withWindowsConfiguration(
new WindowsConfiguration().withProvisionVMAgent(true).withEnableAutomaticUpdates(true)
.withPatchSettings(new PatchSettings().withPatchMode(WindowsVMGuestPatchMode.MANUAL))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithProxyAgentSettings.json
*/
/**
* Sample code: Create a VM with ProxyAgent Settings of enabled and mode.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createAVMWithProxyAgentSettingsOfEnabledAndMode(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2S_V3))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2019-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_ONLY)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_SSD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withSecurityProfile(new SecurityProfile()
.withProxyAgentSettings(new ProxyAgentSettings().withEnabled(true).withMode(Mode.ENFORCE))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_LinuxVmWithPatchSettingModeOfImageDefault.json
*/
/**
* Sample code: Create a Linux vm with a patch setting patchMode of ImageDefault.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createALinuxVmWithAPatchSettingPatchModeOfImageDefault(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D2S_V3))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("Canonical").withOffer("UbuntuServer")
.withSku("16.04-LTS").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder")
.withLinuxConfiguration(new LinuxConfiguration().withProvisionVMAgent(true).withPatchSettings(
new LinuxPatchSettings().withPatchMode(LinuxVMGuestPatchMode.IMAGE_DEFAULT))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WithManagedBootDiagnostics.json
*/
/**
* Sample code: Create a vm with managed boot diagnostics.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVmWithManagedBootDiagnostics(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.STANDARD_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder"))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true))))
.withDiagnosticsProfile(
new DiagnosticsProfile().withBootDiagnostics(new BootDiagnostics().withEnabled(true))),
null, null, com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/
* virtualMachineExamples/VirtualMachine_Create_WindowsVmWithAutomaticByPlatformSettings.json
*/
/**
* Sample code: Create a Windows vm with a patch setting patchMode of AutomaticByPlatform and
* AutomaticByPlatformSettings.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAWindowsVmWithAPatchSettingPatchModeOfAutomaticByPlatformAndAutomaticByPlatformSettings(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getVirtualMachines().createOrUpdate("myResourceGroup", "myVM",
new VirtualMachineInner().withLocation("westus")
.withHardwareProfile(new HardwareProfile().withVmSize(VirtualMachineSizeTypes.STANDARD_D1_V2))
.withStorageProfile(new StorageProfile()
.withImageReference(new ImageReference().withPublisher("MicrosoftWindowsServer")
.withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest"))
.withOsDisk(new OSDisk().withName("myVMosdisk").withCaching(CachingTypes.READ_WRITE)
.withCreateOption(DiskCreateOptionTypes.FROM_IMAGE).withManagedDisk(
new ManagedDiskParameters().withStorageAccountType(StorageAccountTypes.PREMIUM_LRS))))
.withOsProfile(new OSProfile().withComputerName("myVM").withAdminUsername("{your-username}")
.withAdminPassword("fakeTokenPlaceholder").withWindowsConfiguration(
new WindowsConfiguration().withProvisionVMAgent(true).withEnableAutomaticUpdates(true)
.withPatchSettings(new PatchSettings()
.withPatchMode(WindowsVMGuestPatchMode.AUTOMATIC_BY_PLATFORM)
.withAssessmentMode(WindowsPatchAssessmentMode.AUTOMATIC_BY_PLATFORM)
.withAutomaticByPlatformSettings(new WindowsVMGuestPatchAutomaticByPlatformSettings()
.withRebootSetting(WindowsVMGuestPatchAutomaticByPlatformRebootSetting.NEVER)
.withBypassPlatformSafetyChecksOnUserSchedule(false)))))
.withNetworkProfile(
new NetworkProfile().withNetworkInterfaces(Arrays.asList(new NetworkInterfaceReference().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}")
.withPrimary(true)))),
null, null, com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
範例回覆
{
"name": "myVM",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"capacityReservation": {
"capacityReservationGroup": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/CapacityReservationGroups/{crgName}"
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "standard-data-science-vm",
"publisher": "microsoft-ads",
"version": "latest",
"offer": "standard-data-science-vm"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadOnly",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"createOption": "FromImage",
"name": "myVMosdisk"
},
"dataDisks": []
},
"vmId": "5c0d55a7-c407-4ed6-bf7d-ddb810267c85",
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"provisioningState": "Creating"
},
"plan": {
"publisher": "microsoft-ads",
"product": "standard-data-science-vm",
"name": "standard-data-science-vm"
},
"type": "Microsoft.Compute/virtualMachines",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"location": "westus"
}
{
"name": "myVM",
"properties": {
"osProfile": {
"adminUsername": "{your-username}",
"secrets": [],
"computerName": "myVM",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
}
},
"capacityReservation": {
"capacityReservationGroup": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/CapacityReservationGroups/{crgName}"
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/nsgExistingNic",
"properties": {
"primary": true
}
}
]
},
"storageProfile": {
"imageReference": {
"sku": "standard-data-science-vm",
"publisher": "microsoft-ads",
"version": "latest",
"offer": "standard-data-science-vm"
},
"osDisk": {
"osType": "Windows",
"caching": "ReadOnly",
"managedDisk": {
"storageAccountType": "Standard_LRS"
},
"createOption": "FromImage",
"name": "myVMosdisk"
},
"dataDisks": []
},
"vmId": "5c0d55a7-c407-4ed6-bf7d-ddb810267c85",
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"provisioningState": "Creating"
},
"plan": {
"publisher": "microsoft-ads",
"product": "standard-data-science-vm",
"name": "standard-data-science-vm"
},
"type": "Microsoft.Compute/virtualMachines",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"location": "westus"
}
定義
AdditionalCapabilities
指定虛擬機上啟用或停用的其他功能。
名稱 |
類型 |
Description |
hibernationEnabled
|
boolean
|
啟用或停用 VM 上休眠功能的旗標。
|
ultraSSDEnabled
|
boolean
|
旗標,可啟用或停用在 VM 或 VMSS 上具有一或多個具有 UltraSSD_LRS記憶體帳戶類型的受控數據磁碟。 只有啟用此屬性時,才能將具有記憶體帳戶類型的受控磁碟UltraSSD_LRS新增至虛擬機或虛擬機擴展集。
|
AdditionalUnattendContent
指定可併入 Unattend.xml 檔案 (由 Windows 安裝程式使用) 的額外 Base-64 編碼 XML 格式資訊。
名稱 |
類型 |
Description |
componentName
|
ComponentNames
|
元件名稱。 目前唯一允許的值是 Microsoft-Windows-Shell-Setup。
|
content
|
string
|
針對指定的路徑和元件,指定新增至 unattend.xml 檔案的 XML 格式內容。 XML 必須小於 4KB,而且必須包含要插入之設定或功能的根元素。
|
passName
|
PassNames
|
傳遞名稱。 目前唯一允許的值是 OobeSystem。
|
settingName
|
SettingNames
|
指定要套用內容之設定的名稱。 可能的值為:FirstLogonCommands 和 AutoLogon。
|
ApiEntityReference
來源資源標識碼。 它可以是建立磁碟的快照集或磁碟還原點。
名稱 |
類型 |
Description |
id
|
string
|
/subscriptions/{SubscriptionId}/resourceGroups/{ResourceGroupName}/... 形式的 ARM 資源標識符
|
ApiError
API 錯誤。
名稱 |
類型 |
Description |
code
|
string
|
錯誤碼。
|
details
|
ApiErrorBase[]
|
API 錯誤詳細數據
|
innererror
|
InnerError
|
Api 內部錯誤
|
message
|
string
|
錯誤訊息。
|
target
|
string
|
特定錯誤的目標。
|
ApiErrorBase
Api 錯誤基底。
名稱 |
類型 |
Description |
code
|
string
|
錯誤碼。
|
message
|
string
|
錯誤訊息。
|
target
|
string
|
特定錯誤的目標。
|
ApplicationProfile
指定應該提供給 VM/VMSS 的資源庫應用程式。
AvailablePatchSummary
虛擬機最新評量作業的可用修補程式摘要。
名稱 |
類型 |
Description |
assessmentActivityId
|
string
|
產生此結果之作業的活動標識碼。 它用來相互關聯CRP和延伸模組記錄。
|
criticalAndSecurityPatchCount
|
integer
|
偵測到為可用且尚未安裝的重要或安全性修補程式數目。
|
error
|
ApiError
|
執行作業期間遇到的錯誤。 詳細數據陣列包含它們的清單。
|
lastModifiedTime
|
string
|
作業開始時的 UTC 時間戳。
|
otherPatchCount
|
integer
|
排除重大和安全性的所有可用修補程式數目。
|
rebootPending
|
boolean
|
VM 的整體重新啟動狀態。 部分安裝的修補程式需要重新啟動才能完成安裝,但尚未發生重新啟動時,就會是 true。
|
startTime
|
string
|
作業開始時的 UTC 時間戳。
|
status
|
PatchOperationStatus
|
作業的整體成功或失敗狀態。 它會維持 「InProgress」,直到作業完成為止。 此時,它將會變成「未知」、「失敗」、「成功」或「CompletedWithWarnings」。
|
BillingProfile
指定 Azure Spot 虛擬機的計費相關詳細數據。 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。
|
BootDiagnostics
開機診斷是一項偵錯功能,可讓您檢視控制台輸出和螢幕快照以診斷 VM 狀態。
注意:如果要指定 storageUri,請確定記憶體帳戶位於與 VM 相同的區域和訂用帳戶中。 您可以輕鬆地檢視主控台記錄檔的輸出。 Azure 也可讓您從 Hypervisor 查看 VM 的螢幕快照。
名稱 |
類型 |
Description |
enabled
|
boolean
|
是否應在虛擬機上啟用開機診斷。
|
storageUri
|
string
|
用來放置主控台輸出和螢幕快照的記憶體帳戶 URI。 如果未在啟用開機診斷時指定 storageUri,則會使用受控記憶體。
|
BootDiagnosticsInstanceView
開機診斷是一項偵錯功能,可讓您檢視控制台輸出和螢幕快照以診斷 VM 狀態。 您可以輕鬆地檢視主控台記錄檔的輸出。 Azure 也可讓您從 Hypervisor 查看 VM 的螢幕快照。
名稱 |
類型 |
Description |
consoleScreenshotBlobUri
|
string
|
控制台螢幕快照 Blob URI。
注意: 如果目前已啟用受控記憶體的開機診斷,則 不會 設定此設定。
|
serialConsoleLogBlobUri
|
string
|
序列主控台記錄 Blob URI。
注意: 如果目前已啟用受控記憶體的開機診斷,則 不會 設定此設定。
|
status
|
InstanceViewStatus
|
VM 的開機診斷狀態資訊。
注意: 只有在啟用開機診斷時發生錯誤時,才會設定它。
|
CachingTypes
指定快取需求。 可能的值為: None、ReadOnly、ReadWrite。 默認行為為: 標準記憶體的 None。進階記憶體的 ReadOnly。
名稱 |
類型 |
Description |
None
|
string
|
|
ReadOnly
|
string
|
|
ReadWrite
|
string
|
|
CapacityReservationProfile
指定用來配置虛擬機之容量保留區的相關信息。 API 版本下限:2021-04-01。
CloudError
來自計算服務的錯誤回應。
名稱 |
類型 |
Description |
error
|
ApiError
|
API 錯誤。
|
ComponentNames
元件名稱。 目前唯一允許的值是 Microsoft-Windows-Shell-Setup。
名稱 |
類型 |
Description |
Microsoft-Windows-Shell-Setup
|
string
|
|
DataDisk
指定用來將資料磁碟加入至虛擬機器的參數。 如需磁碟的詳細資訊,請參閱 關於 Azure 虛擬機的磁碟和 VHD。
名稱 |
類型 |
Description |
caching
|
CachingTypes
|
指定快取需求。 可能的值為: None、ReadOnly、ReadWrite。 默認行為為: 標準記憶體無。進階記憶體的 ReadOnly。
|
createOption
|
DiskCreateOptionTypes
|
指定應該如何建立虛擬機磁碟。 可能的值為 Attach: 當您使用特製化磁碟來建立虛擬機時,會使用此值。
FromImage: 當您使用映像來建立虛擬機數據磁碟時,會使用此值。 如果您使用平臺映像,則也應該使用上述的 imageReference 元素。 如果您使用市集映像,您也應該使用先前所述的方案元素。
空: 建立空的數據磁碟時,會使用此值。
複製: 這個值可用來從快照集或其他磁碟建立數據磁碟。
恢復: 這個值是用來從磁碟還原點建立數據磁碟。
|
deleteOption
|
DiskDeleteOptionTypes
|
指定在 VM 刪除時應該刪除或中斷連結資料磁碟。 可能的值為: Delete。 如果使用此值,則會在刪除 VM 時刪除資料磁碟。 分離。 如果使用此值,則會在刪除 VM 之後保留資料磁碟。 默認值設定為 [卸離]。
|
detachOption
|
DiskDetachOptionTypes
|
指定要在中斷連結磁碟時使用的卸離行為,或已在從虛擬機中斷鏈接的過程中使用。 支援的值: ForceDetach。 detachOption: ForceDetach 僅適用於受控數據磁碟。 如果先前的數據磁碟斷連結嘗試因為虛擬機發生意外失敗而未完成,但磁碟仍然未釋放,請使用強制卸離作為最後一個從 VM 強制卸離磁碟的選項。 使用這個卸離行為時,所有寫入可能都尚未排清。
此功能仍在預覽模式中 ,且 VirtualMachineScaleSet 不支援此功能。 若要強制中斷數據磁碟更新至BeDetached 為 『true』,以及設定 detachOption: 'ForceDetach'。
|
diskIOPSReadWrite
|
integer
|
指定 StorageAccountType UltraSSD_LRS時,受控磁碟的 Read-Write IOPS。 僅針對 VirtualMachine ScaleSet VM 磁碟傳回。 只能透過 VirtualMachine 擴展集的更新來更新。
|
diskMBpsReadWrite
|
integer
|
指定 StorageAccountType UltraSSD_LRS時,受控磁碟每秒以 MB 為單位的頻寬。 僅針對 VirtualMachine ScaleSet VM 磁碟傳回。 只能透過 VirtualMachine 擴展集的更新來更新。
|
diskSizeGB
|
integer
|
指定以 GB 為單位的空白資料磁碟大小。 此元素可用來覆寫虛擬機映像中的磁碟大小。 屬性 'diskSizeGB' 是磁碟的位元組 x 1024^3 數目,值不能大於 1023。
|
image
|
VirtualHardDisk
|
來源使用者映像虛擬硬碟。 在連接至虛擬機之前,將會先複製虛擬硬碟。 如果提供SourceImage,目的地虛擬硬碟不得存在。
|
lun
|
integer
|
指定數據磁碟的邏輯單位編號。 此值是用來識別 VM 內的數據磁碟,因此對於連結至 VM 的每個數據磁碟而言,都必須是唯一的。
|
managedDisk
|
ManagedDiskParameters
|
受控磁碟參數。
|
name
|
string
|
磁碟名稱。
|
sourceResource
|
ApiEntityReference
|
來源資源標識碼。 它可以是建立磁碟的快照集或磁碟還原點。
|
toBeDetached
|
boolean
|
指定數據磁碟是否正在從 VirtualMachine/VirtualMachineScaleset 中斷連結
|
vhd
|
VirtualHardDisk
|
虛擬硬碟。
|
writeAcceleratorEnabled
|
boolean
|
指定是否應該在磁碟上啟用或停用 writeAccelerator。
|
DeleteOptions
指定刪除 VM 時網路介面會發生什麼事
名稱 |
類型 |
Description |
Delete
|
string
|
|
Detach
|
string
|
|
DiagnosticsProfile
指定開機診斷設定狀態。 API 版本下限:2015-06-15。
名稱 |
類型 |
Description |
bootDiagnostics
|
BootDiagnostics
|
開機診斷是一項偵錯功能,可讓您檢視控制台輸出和螢幕快照以診斷 VM 狀態。
注意:如果要指定 storageUri,請確定記憶體帳戶位於與 VM 相同的區域和訂用帳戶中。 您可以輕鬆地檢視主控台記錄檔的輸出。 Azure 也可讓您從 Hypervisor 查看 VM 的螢幕快照。
|
DiffDiskOptions
指定作業系統磁碟的暫時磁碟設定。
名稱 |
類型 |
Description |
Local
|
string
|
|
DiffDiskPlacement
指定作業系統磁碟的暫時磁碟位置。 可能的值為: CacheDisk、ResourceDisk、NvmeDisk。 默認行為為:如果已針對 VM 大小設定 快取Disk ,否則會使用 ResourceDisk 或 NvmeDisk 。 請參閱 上的 https://docs.microsoft.com/azure/virtual-machines/windows/sizes Windows VM 和 Linux VM https://docs.microsoft.com/azure/virtual-machines/linux/sizes 的 VM 大小檔,以檢查哪些 VM 大小會公開快取磁碟。 NvmeDisk 的最低 API 版本:2024-03-01。
名稱 |
類型 |
Description |
CacheDisk
|
string
|
|
NvmeDisk
|
string
|
|
ResourceDisk
|
string
|
|
DiffDiskSettings
指定虛擬機所使用作業系統磁碟的暫時磁碟設定。
DiskControllerTypes
指定為 VM 設定的磁碟控制器類型。
注意: 如果未指定,則會使用 『hyperVGeneration』 設定為 V2,根據指定之最低 API 版本之作業系統磁碟和 VM 大小的功能,將此屬性設定為預設磁碟控制器類型。 除非您更新 VM 組態中的 VM 大小,以隱含地解除分配和重新配置 VM,否則您必須在更新其磁碟控制器類型之前解除分配 VM。 API 版本下限:2022-08-01。
名稱 |
類型 |
Description |
NVMe
|
string
|
|
SCSI
|
string
|
|
DiskCreateOptionTypes
指定應如何建立虛擬機磁碟。 可能的值為 Attach: 當您使用特製化磁碟來建立虛擬機時,會使用此值。
FromImage: 當您使用映像來建立虛擬機時,會使用此值。 如果您使用平臺映像,則也應該使用上述的 imageReference 元素。 如果您使用 Marketplace 映射,則也應該使用先前所述的方案元素。
名稱 |
類型 |
Description |
Attach
|
string
|
|
Copy
|
string
|
|
Empty
|
string
|
|
FromImage
|
string
|
|
Restore
|
string
|
|
DiskDeleteOptionTypes
指定在 VM 刪除時應刪除或中斷連結 OS 磁碟。 可能的值為: Delete。 如果使用此值,則會在刪除 VM 時刪除 OS 磁碟。 分離。 如果使用此值,則會在刪除 VM 之後保留 os 磁碟。 默認值設定為 [卸離]。 若為暫時OS磁碟,預設值會設定為 Delete。 使用者無法變更暫時 OS 磁碟的刪除選項。
名稱 |
類型 |
Description |
Delete
|
string
|
|
Detach
|
string
|
|
DiskDetachOptionTypes
指定卸離磁碟時所要使用的卸離行為,或已在從虛擬機中斷鏈接的過程中使用。 支援的值: ForceDetach。 detachOption: ForceDetach 僅適用於受控數據磁碟。 如果先前的數據磁碟斷連結嘗試因為虛擬機發生非預期的失敗而未完成,但磁碟仍然未釋放,請使用強制中斷連結作為最後一個從 VM 中斷連結磁碟的最後一個選項。 使用此卸離行為時,可能不會排清所有寫入。
此功能仍處於預覽 模式,且 VirtualMachineScaleSet 不支援此功能。 若要強制中斷數據磁碟更新至BeDetached 為 『true』,以及設定 detachOption: 'ForceDetach'。
名稱 |
類型 |
Description |
ForceDetach
|
string
|
|
DiskEncryptionSetParameters
指定受控磁碟的客戶受控磁碟加密集資源標識符。
名稱 |
類型 |
Description |
id
|
string
|
資源標識碼
|
DiskEncryptionSettings
指定 OS 磁碟的加密設定。 API 版本下限:2015-06-15。
DiskInstanceView
虛擬機磁碟資訊。
DomainNameLabelScopeTypes
即將建立之 PublicIPAddress 資源的功能變數名稱標籤範圍。 產生的名稱標籤是根據功能變數名稱標籤範圍和 vm 網路配置檔唯一識別碼,與原則串連哈希功能變數名稱標籤。
名稱 |
類型 |
Description |
NoReuse
|
string
|
|
ResourceGroupReuse
|
string
|
|
SubscriptionReuse
|
string
|
|
TenantReuse
|
string
|
|
EncryptionIdentity
指定 ADE 用來取得金鑰保存庫作業存取令牌的受控識別。
名稱 |
類型 |
Description |
userAssignedIdentityResourceId
|
string
|
指定與 VM 相關聯的其中一個使用者身分識別的 ARM 資源識別碼。
|
EventGridAndResourceGraph
建立 eventGridAndResourceGraph 排程事件設定時所使用的組態參數。
名稱 |
類型 |
Description |
enable
|
boolean
|
指定是否已啟用排程事件相關組態的事件方格和資源圖表。
|
ExtendedLocation
虛擬機的擴充位置。
ExtendedLocationTypes
擴充位置的類型。
名稱 |
類型 |
Description |
EdgeZone
|
string
|
|
HardwareProfile
指定虛擬機器的硬體設定。
HyperVGenerationType
指定與資源相關聯的 HyperVGeneration 類型
名稱 |
類型 |
Description |
V1
|
string
|
|
V2
|
string
|
|
ImageReference
指定要使用之映像的相關信息。 您可以指定平臺映像、市集映像或虛擬機映像的相關信息。 當您想要使用平臺映像、市集映像或虛擬機映像,但不會用於其他建立作業時,需要此元素。
名稱 |
類型 |
Description |
communityGalleryImageId
|
string
|
指定 vm 部署的社群資源庫映像唯一標識碼。 這可以從社群資源庫映像 GET 呼叫擷取。
|
exactVersion
|
string
|
以十進位數指定,也就是用來建立虛擬機的平臺映像或市集映射版本。 這個只讀欄位與 'version' 不同,只有在 'version' 字段中指定的值是 'latest'時。
|
id
|
string
|
資源標識碼
|
offer
|
string
|
指定用來建立虛擬機的平臺映像或 Marketplace 映像供應專案。
|
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}' 字段,就不需要輸入版本。
|
InnerError
內部錯誤詳細數據。
名稱 |
類型 |
Description |
errordetail
|
string
|
內部錯誤訊息或例外狀況傾印。
|
exceptiontype
|
string
|
例外狀況型別。
|
InstanceViewStatus
實例檢視狀態。
名稱 |
類型 |
Description |
code
|
string
|
狀態碼。
|
displayStatus
|
string
|
狀態的簡短可當地語系化標籤。
|
level
|
StatusLevelTypes
|
層級程序代碼。
|
message
|
string
|
詳細的狀態消息,包括警示和錯誤訊息。
|
time
|
string
|
狀態的時間。
|
IPVersions
從 Api-Version 2019-07-01 起提供,它代表特定 ipconfiguration 是 IPv4 或 IPv6。 預設值會視為 IPv4。 可能的值為:'IPv4' 和 'IPv6'。
名稱 |
類型 |
Description |
IPv4
|
string
|
|
IPv6
|
string
|
|
KeyVaultKeyReference
指定 金鑰保存庫 中金鑰加密金鑰的位置。
名稱 |
類型 |
Description |
keyUrl
|
string
|
參考 金鑰保存庫 中金鑰加密金鑰的 URL。
|
sourceVault
|
SubResource
|
包含金鑰之 金鑰保存庫 的相對 URL。
|
KeyVaultSecretReference
以傳址方式傳遞並從金鑰保存庫取用的延伸模組受保護設定
名稱 |
類型 |
Description |
secretUrl
|
string
|
參考 金鑰保存庫 秘密的 URL。
|
sourceVault
|
SubResource
|
包含秘密之 金鑰保存庫的相對 URL。
|
LastPatchInstallationSummary
虛擬機最新安裝作業的安裝摘要。
名稱 |
類型 |
Description |
error
|
ApiError
|
執行作業期間遇到的錯誤。 詳細數據陣列包含它們的清單。
|
excludedPatchCount
|
integer
|
客戶指定排除清單相符項目明確排除的所有可用修補程式數目。
|
failedPatchCount
|
integer
|
安裝失敗的修補程式計數。
|
installationActivityId
|
string
|
產生此結果之作業的活動標識碼。 它用來相互關聯CRP和延伸模組記錄。
|
installedPatchCount
|
integer
|
已成功安裝的修補程式計數。
|
lastModifiedTime
|
string
|
作業開始時的 UTC 時間戳。
|
maintenanceWindowExceeded
|
boolean
|
描述作業是否在完成所有預定動作之前用盡時間
|
notSelectedPatchCount
|
integer
|
所有可用的修補程式數目,但不會安裝,因為它不符合分類或包含清單專案。
|
pendingPatchCount
|
integer
|
預期會在修補程式安裝作業期間安裝的所有可用修補程式數目。
|
startTime
|
string
|
作業開始時的 UTC 時間戳。
|
status
|
PatchOperationStatus
|
作業的整體成功或失敗狀態。 它會維持 「InProgress」,直到作業完成為止。 此時,它將會變成「未知」、「失敗」、「成功」或「CompletedWithWarnings」。
|
LinuxConfiguration
指定虛擬機上的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 金鑰組態。
|
LinuxPatchAssessmentMode
指定 IaaS 虛擬機的 VM 客體修補評估模式。
可能的值包括:
ImageDefault - 您可以在虛擬機上控制修補程式評估的時間。
AutomaticByPlatform - 平臺會觸發定期修補評估。 屬性 provisionVMAgent 必須是 true。
名稱 |
類型 |
Description |
AutomaticByPlatform
|
string
|
|
ImageDefault
|
string
|
|
LinuxPatchSettings
[預覽功能]指定與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 上的 VM 客體修補中指定 Patch 模式 AutomaticByPlatform 的其他設定。
LinuxVMGuestPatchMode
指定 VM 客體修補至 IaaS 虛擬機的模式,或與 OrchestraMode 為彈性的虛擬機擴展集相關聯的虛擬機。
可能的值包括:
ImageDefault - 會使用虛擬機的默認修補組態。
AutomaticByPlatform - 虛擬機將會由平台自動更新。 provisionVMAgent 屬性必須是 true
名稱 |
類型 |
Description |
AutomaticByPlatform
|
string
|
|
ImageDefault
|
string
|
|
MaintenanceOperationResultCodeTypes
上次維護作業結果碼。
名稱 |
類型 |
Description |
MaintenanceAborted
|
string
|
|
MaintenanceCompleted
|
string
|
|
None
|
string
|
|
RetryLater
|
string
|
|
MaintenanceRedeployStatus
虛擬機上的維護作業狀態。
名稱 |
類型 |
Description |
isCustomerInitiatedMaintenanceAllowed
|
boolean
|
如果允許客戶執行維護,則為 True。
|
lastOperationMessage
|
string
|
針對上次維護作業傳回的訊息。
|
lastOperationResultCode
|
MaintenanceOperationResultCodeTypes
|
上次維護作業結果碼。
|
maintenanceWindowEndTime
|
string
|
維護時段的結束時間。
|
maintenanceWindowStartTime
|
string
|
維護時段的開始時間。
|
preMaintenanceWindowEndTime
|
string
|
維護前時段的結束時間。
|
preMaintenanceWindowStartTime
|
string
|
維護前時段的開始時間。
|
ManagedDiskParameters
受控磁碟參數。
Mode
指定如果啟用此功能,ProxyAgent 將會在 上執行的模式。 ProxyAgent 會開始稽核或監視,但不會對稽核模式中的主機端點要求強制執行訪問控制,而在 [強制執行] 模式中,則會強制執行訪問控制。 默認值為 [強制] 模式。
名稱 |
類型 |
Description |
Audit
|
string
|
|
Enforce
|
string
|
|
NetworkApiVersion
會指定在網路介面組態中建立網路資源時所使用的 Microsoft.Network API 版本
名稱 |
類型 |
Description |
2020-11-01
|
string
|
|
NetworkInterfaceAuxiliaryMode
指定是否為網路介面資源啟用輔助模式。
名稱 |
類型 |
Description |
AcceleratedConnections
|
string
|
|
Floating
|
string
|
|
None
|
string
|
|
NetworkInterfaceAuxiliarySku
指定是否為網路介面資源啟用輔助 SKU。
名稱 |
類型 |
Description |
A1
|
string
|
|
A2
|
string
|
|
A4
|
string
|
|
A8
|
string
|
|
None
|
string
|
|
NetworkInterfaceReference
指定與虛擬機相關聯之網路介面的資源標識符清單。
名稱 |
類型 |
Description |
id
|
string
|
資源標識碼
|
properties.deleteOption
|
DeleteOptions
|
指定刪除 VM 時網路介面會發生什麼情況
|
properties.primary
|
boolean
|
指定虛擬機有1個以上的網路介面時的主要網路介面。
|
NetworkProfile
指定虛擬機器的網路介面。
OperatingSystemTypes
操作系統類型。
名稱 |
類型 |
Description |
Linux
|
string
|
|
Windows
|
string
|
|
OSDisk
指定虛擬機所使用的作業系統磁碟相關信息。 如需磁碟的詳細資訊,請參閱 關於 Azure 虛擬機的磁碟和 VHD。
名稱 |
類型 |
Description |
caching
|
CachingTypes
|
指定快取需求。 可能的值為: None、ReadOnly、ReadWrite。 默認行為為: 標準記憶體無。進階記憶體的 ReadOnly。
|
createOption
|
DiskCreateOptionTypes
|
指定應該如何建立虛擬機磁碟。 可能的值為 Attach: 當您使用特製化磁碟來建立虛擬機時,會使用此值。
FromImage: 當您使用映像來建立虛擬機時,會使用此值。 如果您使用平臺映像,則也應該使用上述的 imageReference 元素。 如果您使用市集映像,您也應該使用先前所述的方案元素。
|
deleteOption
|
DiskDeleteOptionTypes
|
指定在 VM 刪除時,是否應該刪除或中斷連結 OS 磁碟。 可能的值為: Delete。 如果使用此值,則會在刪除 VM 時刪除 OS 磁碟。 分離。 如果使用此值,則會在刪除 VM 之後保留 os 磁碟。 默認值設定為 [卸離]。 對於暫時 OS 磁碟,預設值會設定為 [刪除]。 使用者無法變更暫時 OS 磁碟的刪除選項。
|
diffDiskSettings
|
DiffDiskSettings
|
指定虛擬機所使用作業系統磁碟的暫時磁碟設定。
|
diskSizeGB
|
integer
|
指定以 GB 為單位的空白資料磁碟大小。 此元素可用來覆寫虛擬機映像中的磁碟大小。 屬性 'diskSizeGB' 是磁碟的位元組 x 1024^3 數目,值不能大於 1023。
|
encryptionSettings
|
DiskEncryptionSettings
|
指定 OS 磁碟的加密設定。 API 版本下限:2015-06-15。
|
image
|
VirtualHardDisk
|
來源使用者映像虛擬硬碟。 在連接至虛擬機之前,將會先複製虛擬硬碟。 如果提供SourceImage,目的地虛擬硬碟不得存在。
|
managedDisk
|
ManagedDiskParameters
|
受控磁碟參數。
|
name
|
string
|
磁碟名稱。
|
osType
|
OperatingSystemTypes
|
此屬性可讓您指定從使用者映像或特製化 VHD 建立 VM 時,磁碟包含的 OS 類型。 可能的值為: Windows、Linux。
|
vhd
|
VirtualHardDisk
|
虛擬硬碟。
|
writeAcceleratorEnabled
|
boolean
|
指定是否應該在磁碟上啟用或停用 writeAccelerator。
|
OSImageNotificationProfile
指定OS映像排程事件相關組態。
名稱 |
類型 |
Description |
enable
|
boolean
|
指定是否啟用或停用OS映像排程事件。
|
notBeforeTimeout
|
string
|
虛擬機重新映像或其操作系統升級的時間長度,在事件自動核准之前,必須先核准 OS 映射排程事件, (逾時) 。 設定是以 ISO 8601 格式指定,而且此值必須是 15 分鐘, (PT15M)
|
OSProfile
指定建立虛擬機時所使用的作業系統設定。 一旦布建 VM 之後,就無法變更部分設定。
名稱 |
類型 |
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”、“P@ssword123”、“pa$$word”、“Password!”、“Password1”、“Password22”、“P@ssword123!”
如需重設密碼,請參閱 如何在 Windows VM 中重設遠端桌面服務或其登入密碼
如需重設根密碼,請參閱 使用 VMAccess 擴充功能管理使用者、SSH 及檢查或修復 Azure Linux VM 上的磁碟
|
adminUsername
|
string
|
指定系統管理員帳戶的名稱。
建立 VM 之後,就無法更新此屬性。
僅限 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。
|
computerName
|
string
|
指定虛擬機的主機OS名稱。 建立 VM 之後,就無法更新此名稱。
Windows) 長度上限 (: 15 個字元。
Linux) 長度上限 (: 64 個字元。 如需命名慣例和限制,請參閱 Azure 基礎結構服務實作指導方針。
|
customData
|
string
|
指定自訂資料的 Base-64 編碼字串。 Base-64 編碼字串會解碼成二進位陣列而儲存為虛擬機器上的檔案。 二進位陣列的長度上限是 65535 個位元組。 注意:請勿在 customData 屬性中傳遞任何秘密或密碼。 建立 VM 之後,就無法更新此屬性。 屬性 'customData' 會傳遞至要儲存為檔案的 VM,如需詳細資訊,請參閱 Azure VM 上的自定義數據。 如需針對Linux 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 作業系統設定。
|
PassNames
傳遞名稱。 目前唯一允許的值是 OobeSystem。
名稱 |
類型 |
Description |
OobeSystem
|
string
|
|
PatchOperationStatus
作業的整體成功或失敗狀態。 它會維持 「InProgress」,直到作業完成為止。 此時,它會變成「未知」、「失敗」、「成功」或「CompletedWithWarnings」。
名稱 |
類型 |
Description |
CompletedWithWarnings
|
string
|
|
Failed
|
string
|
|
InProgress
|
string
|
|
Succeeded
|
string
|
|
Unknown
|
string
|
|
PatchSettings
[預覽功能]指定與 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
|
Plan
指定用來建立虛擬機之 Marketplace 映像的相關信息。 此元素僅用於市集映像。 您必須先啟用映像以程序設計方式使用,才能從 API 使用市集映射。 在 Azure 入口網站 中,尋找您想要使用的市集映像,然後按兩下 [想要以程序設計方式部署][開始使用] ->。 輸入任何必要資訊,然後按兩下 [ 儲存]。
名稱 |
類型 |
Description |
name
|
string
|
方案標識碼。
|
product
|
string
|
指定市集中映像的產品。 這個值與 imageReference 元素下的 Offer 相同。
|
promotionCode
|
string
|
促銷碼。
|
publisher
|
string
|
發行者標識碼。
|
ProtocolTypes
指定 WinRM 接聽程式的通訊協定。 可能的值為: HTTP、https。
名稱 |
類型 |
Description |
Http
|
string
|
|
Https
|
string
|
|
ProxyAgentSettings
指定建立虛擬機時的 ProxyAgent 設定。 API 版本下限:2024-03-01。
名稱 |
類型 |
Description |
enabled
|
boolean
|
指定是否應在虛擬機或虛擬機擴展集上啟用 ProxyAgent 功能。
|
keyIncarnationId
|
integer
|
增加此屬性的值可讓使用者重設用來保護客體與主機之間通道的密鑰。
|
mode
|
Mode
|
指定啟用此功能時,ProxyAgent 將會在 上執行的模式。 ProxyAgent 會開始稽核或監視,但不會在稽核模式中對主機端點的要求強制執行訪問控制,而在 [強制執行] 模式中,則會強制執行訪問控制。 默認值為 [強制模式]。
|
PublicIPAddressSku
描述公用IP Sku。 它只能以 OrchestrationMode 設定為彈性。
PublicIPAddressSkuName
指定公用IP SKU 名稱
名稱 |
類型 |
Description |
Basic
|
string
|
|
Standard
|
string
|
|
PublicIPAddressSkuTier
指定公用IP SKU層
名稱 |
類型 |
Description |
Global
|
string
|
|
Regional
|
string
|
|
PublicIPAllocationMethod
指定公用IP配置類型
名稱 |
類型 |
Description |
Dynamic
|
string
|
|
Static
|
string
|
|
ResourceIdentityType
用於虛擬機的身分識別類型。 「SystemAssigned、UserAssigned」類型同時包含隱含建立的身分識別,和一組使用者指派的身分識別。 類型 『None』 將會從虛擬機中移除任何身分識別。
名稱 |
類型 |
Description |
None
|
string
|
|
SystemAssigned
|
string
|
|
SystemAssigned, UserAssigned
|
string
|
|
UserAssigned
|
string
|
|
ScheduledEventsAdditionalPublishingTargets
發佈 scheduledEventsAdditionalPublishingTargets 時所使用的組態參數。
名稱 |
類型 |
Description |
eventGridAndResourceGraph
|
EventGridAndResourceGraph
|
建立 eventGridAndResourceGraph Scheduled Event 設定時所使用的組態參數。
|
ScheduledEventsPolicy
指定虛擬機的重新部署、重新啟動和 ScheduledEventsAdditionalPublishingTargets Scheduled 事件相關設定。
ScheduledEventsProfile
指定排程的事件相關組態。
securityEncryptionTypes
指定受控磁碟的 EncryptionType。 它設定為 DiskWithVMGuestState 以加密受控磁碟以及 VMGuestState Blob、VMGuestStateOnly 只加密 VMGuestState Blob,以及 NonPersistedTPM 表示未在 VMGuestState Blob 中保存韌體狀態。
注意: 它只能設定為機密 VM。
名稱 |
類型 |
Description |
DiskWithVMGuestState
|
string
|
|
NonPersistedTPM
|
string
|
|
VMGuestStateOnly
|
string
|
|
SecurityProfile
指定虛擬機的安全性相關配置檔設定。
名稱 |
類型 |
Description |
encryptionAtHost
|
boolean
|
用戶可以在要求中使用此屬性,以啟用或停用虛擬機或虛擬機擴展集的主機加密。 這會啟用所有磁碟的加密,包括主機本身的資源/暫存磁碟。 默認行為為:除非資源將此屬性設定為 true,否則將會停用主機加密。
|
encryptionIdentity
|
EncryptionIdentity
|
指定 ADE 用來取得金鑰保存庫作業存取令牌的受控識別。
|
proxyAgentSettings
|
ProxyAgentSettings
|
指定建立虛擬機時的 ProxyAgent 設定。 API 版本下限:2024-03-01。
|
securityType
|
SecurityTypes
|
指定虛擬機的 SecurityType。 它必須設定為任何指定的值,才能啟用 UefiSettings。 默認行為為:除非設定此屬性,否則不會啟用 UefiSettings。
|
uefiSettings
|
UefiSettings
|
指定安全性設定,例如建立虛擬機時所使用的安全開機和 vTPM。 API 版本下限:2020-12-01。
|
SecurityTypes
指定虛擬機的 SecurityType。 它必須設定為任何指定的值,才能啟用 UefiSettings。 默認行為為:除非設定此屬性,否則不會啟用 UefiSettings。
名稱 |
類型 |
Description |
ConfidentialVM
|
string
|
|
TrustedLaunch
|
string
|
|
SettingNames
指定要套用內容之設定的名稱。 可能的值為:FirstLogonCommands 和 AutoLogon。
名稱 |
類型 |
Description |
AutoLogon
|
string
|
|
FirstLogonCommands
|
string
|
|
SshConfiguration
指定 Linux OS 的 SSH 金鑰組態。
名稱 |
類型 |
Description |
publicKeys
|
SshPublicKey[]
|
用來向Linux型VM進行驗證的SSH公鑰清單。
|
SshPublicKey
用來向Linux型VM進行驗證的SSH公鑰清單。
名稱 |
類型 |
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
|
StatusLevelTypes
層級程序代碼。
名稱 |
類型 |
Description |
Error
|
string
|
|
Info
|
string
|
|
Warning
|
string
|
|
StorageAccountTypes
指定受控磁碟的記憶體帳戶類型。 注意: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
|
|
StorageProfile
指定虛擬機器磁碟的儲存體設定。
名稱 |
類型 |
Description |
dataDisks
|
DataDisk[]
|
指定用來將資料磁碟加入至虛擬機器的參數。 如需磁碟的詳細資訊,請參閱 關於 Azure 虛擬機的磁碟和 VHD。
|
diskControllerType
|
DiskControllerTypes
|
指定為 VM 設定的磁碟控制器類型。
注意: 如果未指定提供的虛擬機是以 『hyperVGeneration』 設定為 V2,根據指定的最小 API 版本中的作業系統磁碟和 VM 大小功能,此屬性將會設定為預設磁碟控制器類型。 除非您在 VM 組態中更新 VM 大小,以隱含解除分配並重新配置 VM,否則您必須在更新其磁碟控制器類型之前解除分配 VM。 API 版本下限:2022-08-01。
|
imageReference
|
ImageReference
|
指定要使用之映像的相關信息。 您可以指定平臺映像、市集映像或虛擬機映像的相關信息。 當您想要使用平臺映像、市集映像或虛擬機映像,但不會用於其他建立作業時,需要此元素。
|
osDisk
|
OSDisk
|
指定虛擬機所使用的作業系統磁碟相關信息。 如需磁碟的詳細資訊,請參閱 關於 Azure 虛擬機的磁碟和 VHD。
|
SubResource
包含秘密之 金鑰保存庫的相對 URL。
名稱 |
類型 |
Description |
id
|
string
|
資源標識碼
|
TerminateNotificationProfile
指定終止排程事件相關組態。
名稱 |
類型 |
Description |
enable
|
boolean
|
指定是否啟用或停用 Terminate Scheduled 事件。
|
notBeforeTimeout
|
string
|
刪除虛擬機的可設定時間長度,在自動核准事件之前,虛擬機必須核准終止排程事件, (逾時) 。 設定必須以 ISO 8601 格式指定,預設值為 5 分鐘, (PT5M)
|
UefiSettings
指定安全性設定,例如建立虛擬機時所使用的安全開機和 vTPM。 API 版本下限:2020-12-01。
名稱 |
類型 |
Description |
secureBootEnabled
|
boolean
|
指定是否應在虛擬機上啟用安全開機。 API 版本下限:2020-12-01。
|
vTpmEnabled
|
boolean
|
指定是否應在虛擬機上啟用 vTPM。 API 版本下限:2020-12-01。
|
UserAssignedIdentities
與虛擬機相關聯的使用者身分識別清單。 使用者身分識別字典索引鍵參考的格式為 ARM 資源標識符:'/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}'。
UserInitiatedReboot
建立 userInitiatedReboot 排程事件設定時所使用的組態參數。
名稱 |
類型 |
Description |
automaticallyApprove
|
boolean
|
指定重新啟動排程事件相關設定。
|
UserInitiatedRedeploy
建立 userInitiatedRedeploy 排程事件設定時所使用的組態參數。
名稱 |
類型 |
Description |
automaticallyApprove
|
boolean
|
指定重新部署排程事件相關組態。
|
VaultCertificate
SourceVault 中包含憑證的金鑰保存庫參考清單。
名稱 |
類型 |
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 金鑰保存庫 虛擬機擴充功能。
|
VaultSecretGroup
指定應該安裝到虛擬機器的憑證集。 若要在虛擬機上安裝憑證,建議使用適用於Linux的 Azure 金鑰保存庫 虛擬機擴充功能或適用於Windows的 Azure 金鑰保存庫 虛擬機擴充功能。
名稱 |
類型 |
Description |
sourceVault
|
SubResource
|
包含 VaultCertificates 中所有憑證之 金鑰保存庫 的相對 URL。
|
vaultCertificates
|
VaultCertificate[]
|
SourceVault 中包含憑證的金鑰保存庫參考清單。
|
VirtualHardDisk
虛擬硬碟。
名稱 |
類型 |
Description |
uri
|
string
|
指定虛擬硬碟的 URI。
|
VirtualMachine
描述虛擬機。
名稱 |
類型 |
Description |
etag
|
string
|
Etag 是在 VM 的建立/更新/取得回應中傳回的屬性,讓客戶可以在標頭中提供它,以確保開放式更新。
|
extendedLocation
|
ExtendedLocation
|
虛擬機的擴充位置。
|
id
|
string
|
資源標識碼
|
identity
|
VirtualMachineIdentity
|
如果已設定,則為虛擬機的身分識別。
|
location
|
string
|
資源位置
|
managedBy
|
string
|
如果 VM 是 VMSS 的一部分,ManagedBy 會設定為虛擬機擴展集 (VMSS) flex ARM resourceID。 這個屬性是由平臺用於內部資源群組刪除優化。
|
name
|
string
|
資源名稱
|
plan
|
Plan
|
指定用來建立虛擬機之 Marketplace 映像的相關信息。 此元素僅用於市集映像。 您必須先啟用映像以供程序設計使用,才能從 API 使用市集映射。 在 Azure 入口網站 中,尋找您想要使用的市集映射,然後按兩下 [想要以程序設計方式部署] [開始使用] -> 。 輸入任何必要資訊,然後按兩下 [ 儲存]。
|
properties.additionalCapabilities
|
AdditionalCapabilities
|
指定在虛擬機上啟用或停用的其他功能。
|
properties.applicationProfile
|
ApplicationProfile
|
指定應該提供給 VM/VMSS 的資源庫應用程式。
|
properties.availabilitySet
|
SubResource
|
指定虛擬機應指派給的可用性設定組相關信息。 在相同可用性設定組中指定的虛擬機器會配置到不同的節點,以便將可用性最大化。 如需可用性設定組的詳細資訊,請參閱 可用性設定組概觀。 如需 Azure 計劃性維護的詳細資訊,請參閱 Azure 中 虛擬機器 的維護和更新。 目前,VM 只能在建立時新增至可用性設定組。 要新增 VM 的可用性設定組應該位於與可用性設定組資源相同的資源群組之下。 現有的 VM 無法新增至可用性設定組。 此屬性不能與非 Null 屬性一起存在。virtualMachineScaleSet 參考。
|
properties.billingProfile
|
BillingProfile
|
指定 Azure Spot 虛擬機的計費相關詳細數據。 API 版本下限:2019-03-01。
|
properties.capacityReservation
|
CapacityReservationProfile
|
指定用來配置虛擬機之容量保留區的相關信息。 API 版本下限:2021-04-01。
|
properties.diagnosticsProfile
|
DiagnosticsProfile
|
指定開機診斷設定狀態。 API 版本下限:2015-06-15。
|
properties.evictionPolicy
|
VirtualMachineEvictionPolicyTypes
|
指定 Azure Spot 虛擬機和 Azure Spot 擴展集的收回原則。 針對 Azure Spot 虛擬機,支援「解除分配」和「刪除」,而最低 API 版本為 2019-03-01。 針對 Azure Spot 擴展集,同時支援 'Deallocate' 和 'Delete',而最低 API 版本為 2017-10-30-preview。
|
properties.extensionsTimeBudget
|
string
|
指定要啟動之所有延伸模組加上批注的時間。 持續時間應介於 15 分鐘到 120 分鐘之間, (包含) ,且應以 ISO 8601 格式指定。 預設值為90分鐘 (PT1H30M) 。 API 版本下限:2020-06-01。
|
properties.hardwareProfile
|
HardwareProfile
|
指定虛擬機器的硬體設定。
|
properties.host
|
SubResource
|
指定虛擬機所在專用主機的相關信息。 API 版本下限:2018-10-01。
|
properties.hostGroup
|
SubResource
|
指定虛擬機所在專用主機群組的相關信息。
注意: 用戶無法同時指定 host 和 hostGroup 屬性。 API 版本下限:2020-06-01。
|
properties.instanceView
|
VirtualMachineInstanceView
|
虛擬機實例檢視。
|
properties.licenseType
|
string
|
指定正在使用的映像或磁碟是在內部部署授權。
Windows Server 操作系統的可能值為:
Windows_Client
Windows_Server
Linux Server 操作系統的可能值為:
RHEL) 的RHEL_BYOS (
SUSE) 的SLES_BYOS (
如需詳細資訊,請參閱 適用於 Windows Server 的 Azure Hybrid Use Benefit
適用於Linux伺服器的 Azure Hybrid Use Benefit
最低 api-version:2015-06-15
|
properties.networkProfile
|
NetworkProfile
|
指定虛擬機器的網路介面。
|
properties.osProfile
|
OSProfile
|
指定建立虛擬機時所使用的作業系統設定。 布建 VM 之後,就無法變更部分設定。
|
properties.platformFaultDomain
|
integer
|
指定要在其中建立虛擬機的擴展集邏輯容錯網域。 根據預設,虛擬機會自動指派給容錯網域,以在可用的容錯網域之間維持平衡。 只有在設定此虛擬機的 'virtualMachineScaleSet' 屬性時,才適用這個屬性。 所參考的虛擬機擴展集必須具有大於 1 的 『platformFaultDomainCount』。 建立虛擬機之後,就無法更新此屬性。 容錯網域指派可以在虛擬機實例檢視中檢視。 最低 api-version:2020?12?01。
|
properties.priority
|
VirtualMachinePriorityTypes
|
指定虛擬機的優先順序。 最低 api-version:2019-03-01
|
properties.provisioningState
|
string
|
布建狀態,只會出現在回應中。
|
properties.proximityPlacementGroup
|
SubResource
|
指定虛擬機應指派給之鄰近放置群組的相關信息。 API 版本下限:2018-04-01。
|
properties.scheduledEventsPolicy
|
ScheduledEventsPolicy
|
指定虛擬機的重新部署、重新啟動和 ScheduledEventsAdditionalPublishingTargets Scheduled 事件相關組態。
|
properties.scheduledEventsProfile
|
ScheduledEventsProfile
|
指定排程的事件相關組態。
|
properties.securityProfile
|
SecurityProfile
|
指定虛擬機的安全性相關配置檔設定。
|
properties.storageProfile
|
StorageProfile
|
指定虛擬機器磁碟的儲存體設定。
|
properties.timeCreated
|
string
|
指定虛擬機資源建立的時間。 最低 api-version:2021-11-01。
|
properties.userData
|
string
|
VM 的 UserData,必須以 base-64 編碼。 客戶不應在此傳遞任何秘密。 最低 api-version:2021-03-01。
|
properties.virtualMachineScaleSet
|
SubResource
|
指定要指派虛擬機之虛擬機擴展集的相關信息。 相同虛擬機擴展集中指定的虛擬機會配置給不同的節點,以最大化可用性。 目前,VM 只能在建立時新增至虛擬機擴展集。 現有的 VM 無法新增至虛擬機擴展集。 這個屬性不能與非 Null properties.availabilitySet 參考一起存在。 最低 api-version:2019?03\01。
|
properties.vmId
|
string
|
指定 VM 唯一識別碼,這是編碼並儲存在所有 Azure IaaS VM SMBIOS 中的 128 位識別符,而且可以使用平臺 BIOS 命令來讀取。
|
resources
|
VirtualMachineExtension[]
|
虛擬機子擴充功能資源。
|
tags
|
object
|
資源標籤
|
type
|
string
|
資源類型
|
zones
|
string[]
|
虛擬機區域。
|
VirtualMachineAgentInstanceView
在虛擬機上執行的 VM 代理程式。
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
|
|
VirtualMachineExtension
虛擬機子擴充功能資源。
名稱 |
類型 |
Description |
id
|
string
|
資源標識碼
|
location
|
string
|
資源位置
|
name
|
string
|
資源名稱
|
properties.autoUpgradeMinorVersion
|
boolean
|
指出擴充功能是否應該在部署時間使用較新的次要版本。 不過,部署之後,除非重新部署延伸模組,否則延伸模組將不會升級次要版本,即使此屬性設定為 true 亦然。
|
properties.enableAutomaticUpgrade
|
boolean
|
指出如果有較新版本的擴充功能可用,平臺是否應該自動升級延伸模組。
|
properties.forceUpdateTag
|
string
|
延伸模組處理程式應該如何強制更新,即使延伸模組組態尚未變更也一樣。
|
properties.instanceView
|
VirtualMachineExtensionInstanceView
|
虛擬機擴充實例檢視。
|
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
|
指定文稿處理程式的版本。
|
tags
|
object
|
資源標籤
|
type
|
string
|
資源類型
|
VirtualMachineExtensionHandlerInstanceView
虛擬機擴充功能處理程序實例檢視。
名稱 |
類型 |
Description |
status
|
InstanceViewStatus
|
擴充處理程序狀態。
|
type
|
string
|
指定延伸模組的類型;範例為 「CustomScriptExtension」。。
|
typeHandlerVersion
|
string
|
指定文稿處理程式的版本。
|
VirtualMachineExtensionInstanceView
虛擬機擴充實例檢視。
名稱 |
類型 |
Description |
name
|
string
|
虛擬機擴充功能名稱。
|
statuses
|
InstanceViewStatus[]
|
資源狀態資訊。
|
substatuses
|
InstanceViewStatus[]
|
資源狀態資訊。
|
type
|
string
|
指定延伸模組的類型;例如“CustomScriptExtension”。
|
typeHandlerVersion
|
string
|
指定文稿處理程式的版本。
|
VirtualMachineHealthStatus
VM 的健康情況狀態。
VirtualMachineIdentity
如果已設定,則為虛擬機的身分識別。
名稱 |
類型 |
Description |
principalId
|
string
|
虛擬機身分識別的主體標識碼。 此屬性只會針對系統指派的身分識別提供。
|
tenantId
|
string
|
與虛擬機相關聯的租用戶標識碼。 此屬性只會針對系統指派的身分識別提供。
|
type
|
ResourceIdentityType
|
用於虛擬機的身分識別類型。 「SystemAssigned、UserAssigned」類型同時包含隱含建立的身分識別,和一組使用者指派的身分識別。 類型 『None』 會從虛擬機中移除任何身分識別。
|
userAssignedIdentities
|
UserAssignedIdentities
|
與虛擬機相關聯的使用者身分識別清單。 使用者身分識別字典索引鍵參考的格式為 ARM 資源標識符:'/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}'。
|
VirtualMachineInstanceView
虛擬機實例檢視。
VirtualMachineIpTag
與公用IP位址相關聯的IP標籤清單。
名稱 |
類型 |
Description |
ipTagType
|
string
|
IP 標籤類型。 範例:FirstPartyUsage。
|
tag
|
string
|
與公用IP相關聯的IP標籤。 範例:SQL、記憶體等。
|
VirtualMachineNetworkInterfaceConfiguration
指定將用來建立虛擬機網路資源的網路設定。
VirtualMachineNetworkInterfaceDnsSettingsConfiguration
要套用在網路介面上的 DNS 設定。
名稱 |
類型 |
Description |
dnsServers
|
string[]
|
DNS 伺服器 IP 位址清單
|
VirtualMachineNetworkInterfaceIPConfiguration
指定網路介面的IP組態。
名稱 |
類型 |
Description |
name
|
string
|
IP 組態名稱。
|
properties.applicationGatewayBackendAddressPools
|
SubResource[]
|
指定應用程式閘道後端位址池的參考數位。 虛擬機可以參考多個應用程式閘道的後端位址池。 多部虛擬機無法使用相同的應用程式閘道。
|
properties.applicationSecurityGroups
|
SubResource[]
|
指定應用程式安全組的參考陣列。
|
properties.loadBalancerBackendAddressPools
|
SubResource[]
|
指定負載平衡器後端位址池參考的陣列。 虛擬機可以參考一個公用和一個內部負載平衡器的後端位址池。 [多部虛擬機無法使用相同的基本 SKU 負載平衡器]。
|
properties.primary
|
boolean
|
指定虛擬機有1個以上的網路介面時的主要網路介面。
|
properties.privateIPAddressVersion
|
IPVersions
|
從 Api-Version 2017-03-30 起提供,它代表特定 ipconfiguration 是 IPv4 或 IPv6。 預設值會視為 IPv4。 可能的值為:'IPv4' 和 'IPv6'。
|
properties.publicIPAddressConfiguration
|
VirtualMachinePublicIPAddressConfiguration
|
publicIPAddressConfiguration。
|
properties.subnet
|
SubResource
|
指定子網的識別碼。
|
VirtualMachinePatchStatus
[預覽功能]虛擬機修補作業的狀態。
VirtualMachinePriorityTypes
指定虛擬機的優先順序。 最低 api-version:2019-03-01
名稱 |
類型 |
Description |
Low
|
string
|
|
Regular
|
string
|
|
Spot
|
string
|
|
VirtualMachinePublicIPAddressConfiguration
publicIPAddressConfiguration。
VirtualMachinePublicIPAddressDnsSettingsConfiguration
要套用在 publicIP 位址 上的 DNS 設定。
名稱 |
類型 |
Description |
domainNameLabel
|
string
|
即將建立之 PublicIPAddress 資源的功能變數名稱標籤前置詞。 產生的名稱標籤是功能變數名稱標籤和 vm 網路設定檔唯一識別碼的串連。
|
domainNameLabelScope
|
DomainNameLabelScopeTypes
|
即將建立之 PublicIPAddress 資源的功能變數名稱標籤範圍。 產生的名稱標籤是根據功能變數名稱標籤範圍和 vm 網路配置檔唯一識別碼,與原則串連哈希功能變數名稱標籤。
|
VirtualMachineSizeTypes
指定虛擬機器的大小。 列舉數據類型目前已被取代,將於 2023 年 12 月 23 日移除。 取得可用大小清單的建議方式是使用這些 API: 列出可用性設定組中的所有可用虛擬機器大小、 列出區域中所有可用的虛擬機大小、 列出所有可用的虛擬機大小以重設大小。 如需虛擬機大小的詳細資訊,請參閱 虛擬機的大小。 可用的 VM 大小取決於區域和可用性設定組。
名稱 |
類型 |
Description |
Basic_A0
|
string
|
|
Basic_A1
|
string
|
|
Basic_A2
|
string
|
|
Basic_A3
|
string
|
|
Basic_A4
|
string
|
|
Standard_A0
|
string
|
|
Standard_A1
|
string
|
|
Standard_A10
|
string
|
|
Standard_A11
|
string
|
|
Standard_A1_v2
|
string
|
|
Standard_A2
|
string
|
|
Standard_A2_v2
|
string
|
|
Standard_A2m_v2
|
string
|
|
Standard_A3
|
string
|
|
Standard_A4
|
string
|
|
Standard_A4_v2
|
string
|
|
Standard_A4m_v2
|
string
|
|
Standard_A5
|
string
|
|
Standard_A6
|
string
|
|
Standard_A7
|
string
|
|
Standard_A8
|
string
|
|
Standard_A8_v2
|
string
|
|
Standard_A8m_v2
|
string
|
|
Standard_A9
|
string
|
|
Standard_B1ms
|
string
|
|
Standard_B1s
|
string
|
|
Standard_B2ms
|
string
|
|
Standard_B2s
|
string
|
|
Standard_B4ms
|
string
|
|
Standard_B8ms
|
string
|
|
Standard_D1
|
string
|
|
Standard_D11
|
string
|
|
Standard_D11_v2
|
string
|
|
Standard_D12
|
string
|
|
Standard_D12_v2
|
string
|
|
Standard_D13
|
string
|
|
Standard_D13_v2
|
string
|
|
Standard_D14
|
string
|
|
Standard_D14_v2
|
string
|
|
Standard_D15_v2
|
string
|
|
Standard_D16_v3
|
string
|
|
Standard_D16s_v3
|
string
|
|
Standard_D1_v2
|
string
|
|
Standard_D2
|
string
|
|
Standard_D2_v2
|
string
|
|
Standard_D2_v3
|
string
|
|
Standard_D2s_v3
|
string
|
|
Standard_D3
|
string
|
|
Standard_D32_v3
|
string
|
|
Standard_D32s_v3
|
string
|
|
Standard_D3_v2
|
string
|
|
Standard_D4
|
string
|
|
Standard_D4_v2
|
string
|
|
Standard_D4_v3
|
string
|
|
Standard_D4s_v3
|
string
|
|
Standard_D5_v2
|
string
|
|
Standard_D64_v3
|
string
|
|
Standard_D64s_v3
|
string
|
|
Standard_D8_v3
|
string
|
|
Standard_D8s_v3
|
string
|
|
Standard_DS1
|
string
|
|
Standard_DS11
|
string
|
|
Standard_DS11_v2
|
string
|
|
Standard_DS12
|
string
|
|
Standard_DS12_v2
|
string
|
|
Standard_DS13
|
string
|
|
Standard_DS13-2_v2
|
string
|
|
Standard_DS13-4_v2
|
string
|
|
Standard_DS13_v2
|
string
|
|
Standard_DS14
|
string
|
|
Standard_DS14-4_v2
|
string
|
|
Standard_DS14-8_v2
|
string
|
|
Standard_DS14_v2
|
string
|
|
Standard_DS15_v2
|
string
|
|
Standard_DS1_v2
|
string
|
|
Standard_DS2
|
string
|
|
Standard_DS2_v2
|
string
|
|
Standard_DS3
|
string
|
|
Standard_DS3_v2
|
string
|
|
Standard_DS4
|
string
|
|
Standard_DS4_v2
|
string
|
|
Standard_DS5_v2
|
string
|
|
Standard_E16_v3
|
string
|
|
Standard_E16s_v3
|
string
|
|
Standard_E2_v3
|
string
|
|
Standard_E2s_v3
|
string
|
|
Standard_E32-16_v3
|
string
|
|
Standard_E32-8s_v3
|
string
|
|
Standard_E32_v3
|
string
|
|
Standard_E32s_v3
|
string
|
|
Standard_E4_v3
|
string
|
|
Standard_E4s_v3
|
string
|
|
Standard_E64-16s_v3
|
string
|
|
Standard_E64-32s_v3
|
string
|
|
Standard_E64_v3
|
string
|
|
Standard_E64s_v3
|
string
|
|
Standard_E8_v3
|
string
|
|
Standard_E8s_v3
|
string
|
|
Standard_F1
|
string
|
|
Standard_F16
|
string
|
|
Standard_F16s
|
string
|
|
Standard_F16s_v2
|
string
|
|
Standard_F1s
|
string
|
|
Standard_F2
|
string
|
|
Standard_F2s
|
string
|
|
Standard_F2s_v2
|
string
|
|
Standard_F32s_v2
|
string
|
|
Standard_F4
|
string
|
|
Standard_F4s
|
string
|
|
Standard_F4s_v2
|
string
|
|
Standard_F64s_v2
|
string
|
|
Standard_F72s_v2
|
string
|
|
Standard_F8
|
string
|
|
Standard_F8s
|
string
|
|
Standard_F8s_v2
|
string
|
|
Standard_G1
|
string
|
|
Standard_G2
|
string
|
|
Standard_G3
|
string
|
|
Standard_G4
|
string
|
|
Standard_G5
|
string
|
|
Standard_GS1
|
string
|
|
Standard_GS2
|
string
|
|
Standard_GS3
|
string
|
|
Standard_GS4
|
string
|
|
Standard_GS4-4
|
string
|
|
Standard_GS4-8
|
string
|
|
Standard_GS5
|
string
|
|
Standard_GS5-16
|
string
|
|
Standard_GS5-8
|
string
|
|
Standard_H16
|
string
|
|
Standard_H16m
|
string
|
|
Standard_H16mr
|
string
|
|
Standard_H16r
|
string
|
|
Standard_H8
|
string
|
|
Standard_H8m
|
string
|
|
Standard_L16s
|
string
|
|
Standard_L32s
|
string
|
|
Standard_L4s
|
string
|
|
Standard_L8s
|
string
|
|
Standard_M128-32ms
|
string
|
|
Standard_M128-64ms
|
string
|
|
Standard_M128ms
|
string
|
|
Standard_M128s
|
string
|
|
Standard_M64-16ms
|
string
|
|
Standard_M64-32ms
|
string
|
|
Standard_M64ms
|
string
|
|
Standard_M64s
|
string
|
|
Standard_NC12
|
string
|
|
Standard_NC12s_v2
|
string
|
|
Standard_NC12s_v3
|
string
|
|
Standard_NC24
|
string
|
|
Standard_NC24r
|
string
|
|
Standard_NC24rs_v2
|
string
|
|
Standard_NC24rs_v3
|
string
|
|
Standard_NC24s_v2
|
string
|
|
Standard_NC24s_v3
|
string
|
|
Standard_NC6
|
string
|
|
Standard_NC6s_v2
|
string
|
|
Standard_NC6s_v3
|
string
|
|
Standard_ND12s
|
string
|
|
Standard_ND24rs
|
string
|
|
Standard_ND24s
|
string
|
|
Standard_ND6s
|
string
|
|
Standard_NV12
|
string
|
|
Standard_NV24
|
string
|
|
Standard_NV6
|
string
|
|
VMDiskSecurityProfile
指定受控磁碟的安全性配置檔。
名稱 |
類型 |
Description |
diskEncryptionSet
|
DiskEncryptionSetParameters
|
針對客戶受控密鑰加密的機密VM OS 磁碟和 VMGuest Blob,指定受控磁碟的客戶受控磁碟加密集資源識別碼。
|
securityEncryptionType
|
securityEncryptionTypes
|
指定受控磁碟的 EncryptionType。 它設定為 DiskWithVMGuestState 以加密受控磁碟以及 VMGuestState Blob、VMGuestStateOnly 只加密 VMGuestState Blob,以及 NonPersistedTPM 用於不保存 VMGuestState Blob 中的韌體狀態。
注意: 它只能設定為機密 VM。
|
VMGalleryApplication
指定應該提供給 VM/VMSS 使用的資源庫應用程式
名稱 |
類型 |
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 中任何作業的任何失敗都會使部署失敗
|
VMSizeProperties
指定自定義虛擬機大小的屬性。 API 版本下限:2021-07-01。 此功能仍處於預覽模式,且 VirtualMachineScaleSet 不支援此功能。 如需詳細資訊,請遵循 VM 自定義 中的指示。
名稱 |
類型 |
Description |
vCPUsAvailable
|
integer
|
指定 VM 可用的 vCPU 數目。 在要求本文中未指定這個屬性時,預設行為是將它設定為 API 回應中公開該 VM 大小的 vCPU 值, 以列出區域中所有可用的虛擬機大小。
|
vCPUsPerCore
|
integer
|
指定 vCPU 與實體核心比率。 在要求本文中未指定這個屬性時,預設行為會針對在 API 回應中公開的 VM 大小設定為 vCPUPerCore 的值,以 列出區域中所有可用的虛擬機大小。
將此屬性設定為 1 也表示超線程已停用。
|
WindowsConfiguration
指定虛擬機器上的 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 上 VM 客體修補中的 Patch 模式 AutomaticByPlatform 的其他設定。
WindowsVMGuestPatchMode
指定 VM 客體修補至 IaaS 虛擬機的模式,或與 OrchestraMode 為彈性的虛擬機擴展集相關聯的虛擬機。
可能的值包括:
手動 - 您可以控制將修補程式應用程式套用至虛擬機。 您可以在 VM 內手動套用修補程式來執行此動作。 在此模式中,自動更新會停用;屬性 WindowsConfiguration.enableAutomaticUpdates 必須為 false
AutomaticByOS - 作業系統會自動更新虛擬機。 WindowsConfiguration.enableAutomaticUpdates 屬性必須是 true。
AutomaticByPlatform - 虛擬機將會由平台自動更新。 provisionVMAgent 和 WindowsConfiguration.enableAutomaticUpdates 屬性必須是 true
名稱 |
類型 |
Description |
AutomaticByOS
|
string
|
|
AutomaticByPlatform
|
string
|
|
Manual
|
string
|
|
WinRMConfiguration
指定 Windows 遠端管理接聽程式。 藉此將啟用遠端 Windows PowerShell。
WinRMListener
Windows 遠端管理接聽程式清單