Создание или обновление образа.
PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/images/{imageName}?api-version=2024-03-01
Параметры URI
Имя |
В |
Обязательно |
Тип |
Описание |
imageName
|
path |
True
|
string
|
Имя изображения.
|
resourceGroupName
|
path |
True
|
string
|
Имя группы ресурсов.
|
subscriptionId
|
path |
True
|
string
|
Учетные данные подписки, которые однозначно идентифицируют подписку Microsoft Azure. Идентификатор подписки формирует часть URI для каждого вызова службы.
|
api-version
|
query |
True
|
string
|
Версия API клиента.
|
Текст запроса
Имя |
Обязательно |
Тип |
Описание |
location
|
True
|
string
|
Расположение ресурса
|
extendedLocation
|
|
ExtendedLocation
|
Расширенное расположение образа.
|
properties.hyperVGeneration
|
|
HyperVGenerationTypes
|
Указывает Тип HyperVGenerationType виртуальной машины, созданной на основе образа. Из API версии 2019-03-01, если источником образа является BLOB-объект, необходимо, чтобы пользователь указал значение. Если источником является управляемый ресурс, например диск или snapshot, может потребоваться указать свойство, если мы не можем вывести его из управляемого исходного ресурса.
|
properties.sourceVirtualMachine
|
|
SubResource
|
Исходная виртуальная машина, на основе которой создается образ.
|
properties.storageProfile
|
|
ImageStorageProfile
|
Указывает параметры хранилища дисков виртуальной машины.
|
tags
|
|
object
|
Теги ресурсов
|
Ответы
Имя |
Тип |
Описание |
200 OK
|
Image
|
ОК
|
201 Created
|
Image
|
Создание
|
Other Status Codes
|
CloudError
|
Ответ об ошибке, описывающий причину сбоя операции.
|
Безопасность
azure_auth
Поток OAuth2 в Azure Active Directory
Type:
oauth2
Flow:
implicit
Authorization URL:
https://login.microsoftonline.com/common/oauth2/authorize
Scopes
Имя |
Описание |
user_impersonation
|
олицетворения учетной записи пользователя
|
Примеры
Create a virtual machine image from a blob with DiskEncryptionSet resource.
Sample Request
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/myImage?api-version=2024-03-01
{
"location": "West US",
"properties": {
"storageProfile": {
"osDisk": {
"osType": "Linux",
"blobUri": "https://mystorageaccount.blob.core.windows.net/osimages/osimage.vhd",
"diskEncryptionSet": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"
},
"osState": "Generalized"
}
}
}
}
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 image_create_from_ablob_with_disk_encryption_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.images.begin_create_or_update(
resource_group_name="myResourceGroup",
image_name="myImage",
parameters={
"location": "West US",
"properties": {
"storageProfile": {
"osDisk": {
"blobUri": "https://mystorageaccount.blob.core.windows.net/osimages/osimage.vhd",
"diskEncryptionSet": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"
},
"osState": "Generalized",
"osType": "Linux",
}
}
},
},
).result()
print(response)
# x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/imageExamples/Image_CreateFromABlobWithDiskEncryptionSet.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/imageExamples/Image_CreateFromABlobWithDiskEncryptionSet.json
func ExampleImagesClient_BeginCreateOrUpdate_createAVirtualMachineImageFromABlobWithDiskEncryptionSetResource() {
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.NewImagesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myImage", armcompute.Image{
Location: to.Ptr("West US"),
Properties: &armcompute.ImageProperties{
StorageProfile: &armcompute.ImageStorageProfile{
OSDisk: &armcompute.ImageOSDisk{
BlobURI: to.Ptr("https://mystorageaccount.blob.core.windows.net/osimages/osimage.vhd"),
DiskEncryptionSet: &armcompute.DiskEncryptionSetParameters{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"),
},
OSState: to.Ptr(armcompute.OperatingSystemStateTypesGeneralized),
OSType: to.Ptr(armcompute.OperatingSystemTypesLinux),
},
},
},
}, 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.Image = armcompute.Image{
// Name: to.Ptr("myImage"),
// Type: to.Ptr("Microsoft.Compute/images"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/disk/providers/Microsoft.Compute/images/myImage"),
// Location: to.Ptr("westus"),
// Properties: &armcompute.ImageProperties{
// ProvisioningState: to.Ptr("Succeeded"),
// StorageProfile: &armcompute.ImageStorageProfile{
// DataDisks: []*armcompute.ImageDataDisk{
// },
// OSDisk: &armcompute.ImageOSDisk{
// BlobURI: to.Ptr("https://mystorageaccount.blob.core.windows.net/osimages/osimage.vhd"),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// DiskEncryptionSet: &armcompute.DiskEncryptionSetParameters{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"),
// },
// OSState: to.Ptr(armcompute.OperatingSystemStateTypesGeneralized),
// OSType: to.Ptr(armcompute.OperatingSystemTypesLinux),
// },
// },
// },
// }
}
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 Create or update an image.
*
* @summary Create or update an image.
* x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/imageExamples/Image_CreateFromABlobWithDiskEncryptionSet.json
*/
async function createAVirtualMachineImageFromABlobWithDiskEncryptionSetResource() {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP"] || "myResourceGroup";
const imageName = "myImage";
const parameters = {
location: "West US",
storageProfile: {
osDisk: {
blobUri: "https://mystorageaccount.blob.core.windows.net/osimages/osimage.vhd",
diskEncryptionSet: {
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}",
},
osState: "Generalized",
osType: "Linux",
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.images.beginCreateOrUpdateAndWait(
resourceGroupName,
imageName,
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
Sample Response
{
"properties": {
"storageProfile": {
"osDisk": {
"osType": "Linux",
"osState": "Generalized",
"blobUri": "https://mystorageaccount.blob.core.windows.net/osimages/osimage.vhd",
"diskEncryptionSet": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"
},
"caching": "ReadWrite"
},
"dataDisks": []
},
"provisioningState": "Creating"
},
"type": "Microsoft.Compute/images",
"location": "westus",
"id": "/subscriptions/{subscription-id}/resourceGroups/disk/providers/Microsoft.Compute/images/myImage",
"name": "myImage"
}
{
"properties": {
"storageProfile": {
"osDisk": {
"osType": "Linux",
"osState": "Generalized",
"blobUri": "https://mystorageaccount.blob.core.windows.net/osimages/osimage.vhd",
"diskEncryptionSet": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"
},
"caching": "ReadWrite"
},
"dataDisks": []
},
"provisioningState": "Creating"
},
"type": "Microsoft.Compute/images",
"location": "westus",
"id": "/subscriptions/{subscription-id}/resourceGroups/disk/providers/Microsoft.Compute/images/myImage",
"name": "myImage"
}
Create a virtual machine image from a blob.
Sample Request
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/myImage?api-version=2024-03-01
{
"location": "West US",
"properties": {
"storageProfile": {
"osDisk": {
"osType": "Linux",
"blobUri": "https://mystorageaccount.blob.core.windows.net/osimages/osimage.vhd",
"osState": "Generalized"
},
"zoneResilient": 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 image_create_from_ablob.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.images.begin_create_or_update(
resource_group_name="myResourceGroup",
image_name="myImage",
parameters={
"location": "West US",
"properties": {
"storageProfile": {
"osDisk": {
"blobUri": "https://mystorageaccount.blob.core.windows.net/osimages/osimage.vhd",
"osState": "Generalized",
"osType": "Linux",
},
"zoneResilient": True,
}
},
},
).result()
print(response)
# x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/imageExamples/Image_CreateFromABlob.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/imageExamples/Image_CreateFromABlob.json
func ExampleImagesClient_BeginCreateOrUpdate_createAVirtualMachineImageFromABlob() {
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.NewImagesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myImage", armcompute.Image{
Location: to.Ptr("West US"),
Properties: &armcompute.ImageProperties{
StorageProfile: &armcompute.ImageStorageProfile{
OSDisk: &armcompute.ImageOSDisk{
BlobURI: to.Ptr("https://mystorageaccount.blob.core.windows.net/osimages/osimage.vhd"),
OSState: to.Ptr(armcompute.OperatingSystemStateTypesGeneralized),
OSType: to.Ptr(armcompute.OperatingSystemTypesLinux),
},
ZoneResilient: to.Ptr(true),
},
},
}, 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.Image = armcompute.Image{
// Name: to.Ptr("myImage"),
// Type: to.Ptr("Microsoft.Compute/images"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/disk/providers/Microsoft.Compute/images/myImage"),
// Location: to.Ptr("westus"),
// Properties: &armcompute.ImageProperties{
// ProvisioningState: to.Ptr("Succeeded"),
// StorageProfile: &armcompute.ImageStorageProfile{
// DataDisks: []*armcompute.ImageDataDisk{
// },
// OSDisk: &armcompute.ImageOSDisk{
// BlobURI: to.Ptr("https://mystorageaccount.blob.core.windows.net/osimages/osimage.vhd"),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// OSState: to.Ptr(armcompute.OperatingSystemStateTypesGeneralized),
// OSType: to.Ptr(armcompute.OperatingSystemTypesLinux),
// },
// ZoneResilient: to.Ptr(true),
// },
// },
// }
}
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 Create or update an image.
*
* @summary Create or update an image.
* x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/imageExamples/Image_CreateFromABlob.json
*/
async function createAVirtualMachineImageFromABlob() {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP"] || "myResourceGroup";
const imageName = "myImage";
const parameters = {
location: "West US",
storageProfile: {
osDisk: {
blobUri: "https://mystorageaccount.blob.core.windows.net/osimages/osimage.vhd",
osState: "Generalized",
osType: "Linux",
},
zoneResilient: true,
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.images.beginCreateOrUpdateAndWait(
resourceGroupName,
imageName,
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
Sample Response
{
"properties": {
"storageProfile": {
"osDisk": {
"osType": "Linux",
"osState": "Generalized",
"blobUri": "https://mystorageaccount.blob.core.windows.net/osimages/osimage.vhd",
"caching": "ReadWrite"
},
"dataDisks": [],
"zoneResilient": true
},
"provisioningState": "Creating"
},
"type": "Microsoft.Compute/images",
"location": "westus",
"id": "/subscriptions/{subscription-id}/resourceGroups/disk/providers/Microsoft.Compute/images/myImage",
"name": "myImage"
}
{
"properties": {
"storageProfile": {
"osDisk": {
"osType": "Linux",
"osState": "Generalized",
"blobUri": "https://mystorageaccount.blob.core.windows.net/osimages/osimage.vhd",
"caching": "ReadWrite"
},
"dataDisks": [],
"zoneResilient": true
},
"provisioningState": "Creating"
},
"type": "Microsoft.Compute/images",
"location": "westus",
"id": "/subscriptions/{subscription-id}/resourceGroups/disk/providers/Microsoft.Compute/images/myImage",
"name": "myImage"
}
Create a virtual machine image from a managed disk with DiskEncryptionSet resource.
Sample Request
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/myImage?api-version=2024-03-01
{
"location": "West US",
"properties": {
"storageProfile": {
"osDisk": {
"osType": "Linux",
"snapshot": {
"id": "subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/mySnapshot"
},
"diskEncryptionSet": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"
},
"osState": "Generalized"
}
}
}
}
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 image_create_from_amanaged_disk_with_disk_encryption_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.images.begin_create_or_update(
resource_group_name="myResourceGroup",
image_name="myImage",
parameters={
"location": "West US",
"properties": {
"storageProfile": {
"osDisk": {
"diskEncryptionSet": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"
},
"osState": "Generalized",
"osType": "Linux",
"snapshot": {
"id": "subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/mySnapshot"
},
}
}
},
},
).result()
print(response)
# x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/imageExamples/Image_CreateFromAManagedDiskWithDiskEncryptionSet.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/imageExamples/Image_CreateFromAManagedDiskWithDiskEncryptionSet.json
func ExampleImagesClient_BeginCreateOrUpdate_createAVirtualMachineImageFromAManagedDiskWithDiskEncryptionSetResource() {
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.NewImagesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myImage", armcompute.Image{
Location: to.Ptr("West US"),
Properties: &armcompute.ImageProperties{
StorageProfile: &armcompute.ImageStorageProfile{
OSDisk: &armcompute.ImageOSDisk{
DiskEncryptionSet: &armcompute.DiskEncryptionSetParameters{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"),
},
Snapshot: &armcompute.SubResource{
ID: to.Ptr("subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/mySnapshot"),
},
OSState: to.Ptr(armcompute.OperatingSystemStateTypesGeneralized),
OSType: to.Ptr(armcompute.OperatingSystemTypesLinux),
},
},
},
}, 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.Image = armcompute.Image{
// Name: to.Ptr("myImage"),
// Type: to.Ptr("Microsoft.Compute/images"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/disk/providers/Microsoft.Compute/images/myImage"),
// Location: to.Ptr("westus"),
// Properties: &armcompute.ImageProperties{
// ProvisioningState: to.Ptr("Succeeded"),
// StorageProfile: &armcompute.ImageStorageProfile{
// DataDisks: []*armcompute.ImageDataDisk{
// },
// OSDisk: &armcompute.ImageOSDisk{
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// DiskEncryptionSet: &armcompute.DiskEncryptionSetParameters{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"),
// },
// Snapshot: &armcompute.SubResource{
// ID: to.Ptr("subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/mySnapshot"),
// },
// OSState: to.Ptr(armcompute.OperatingSystemStateTypesGeneralized),
// OSType: to.Ptr(armcompute.OperatingSystemTypesLinux),
// },
// },
// },
// }
}
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 Create or update an image.
*
* @summary Create or update an image.
* x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/imageExamples/Image_CreateFromAManagedDiskWithDiskEncryptionSet.json
*/
async function createAVirtualMachineImageFromAManagedDiskWithDiskEncryptionSetResource() {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP"] || "myResourceGroup";
const imageName = "myImage";
const parameters = {
location: "West US",
storageProfile: {
osDisk: {
diskEncryptionSet: {
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}",
},
osState: "Generalized",
osType: "Linux",
snapshot: {
id: "subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/mySnapshot",
},
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.images.beginCreateOrUpdateAndWait(
resourceGroupName,
imageName,
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
Sample Response
{
"properties": {
"storageProfile": {
"osDisk": {
"osType": "Linux",
"snapshot": {
"id": "subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/mySnapshot"
},
"diskEncryptionSet": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"
},
"osState": "Generalized",
"caching": "ReadWrite"
},
"dataDisks": []
},
"provisioningState": "Creating"
},
"type": "Microsoft.Compute/images",
"location": "westus",
"id": "/subscriptions/{subscription-id}/resourceGroups/disk/providers/Microsoft.Compute/images/myImage",
"name": "myImage"
}
{
"properties": {
"storageProfile": {
"osDisk": {
"osType": "Linux",
"snapshot": {
"id": "subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/mySnapshot"
},
"diskEncryptionSet": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"
},
"osState": "Generalized",
"caching": "ReadWrite"
},
"dataDisks": []
},
"provisioningState": "Creating"
},
"type": "Microsoft.Compute/images",
"location": "westus",
"id": "/subscriptions/{subscription-id}/resourceGroups/disk/providers/Microsoft.Compute/images/myImage",
"name": "myImage"
}
Create a virtual machine image from a managed disk.
Sample Request
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/myImage?api-version=2024-03-01
{
"location": "West US",
"properties": {
"storageProfile": {
"osDisk": {
"osType": "Linux",
"managedDisk": {
"id": "subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/myManagedDisk"
},
"osState": "Generalized"
},
"zoneResilient": 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 image_create_from_amanaged_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.images.begin_create_or_update(
resource_group_name="myResourceGroup",
image_name="myImage",
parameters={
"location": "West US",
"properties": {
"storageProfile": {
"osDisk": {
"managedDisk": {
"id": "subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/myManagedDisk"
},
"osState": "Generalized",
"osType": "Linux",
},
"zoneResilient": True,
}
},
},
).result()
print(response)
# x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/imageExamples/Image_CreateFromAManagedDisk.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/imageExamples/Image_CreateFromAManagedDisk.json
func ExampleImagesClient_BeginCreateOrUpdate_createAVirtualMachineImageFromAManagedDisk() {
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.NewImagesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myImage", armcompute.Image{
Location: to.Ptr("West US"),
Properties: &armcompute.ImageProperties{
StorageProfile: &armcompute.ImageStorageProfile{
OSDisk: &armcompute.ImageOSDisk{
ManagedDisk: &armcompute.SubResource{
ID: to.Ptr("subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/myManagedDisk"),
},
OSState: to.Ptr(armcompute.OperatingSystemStateTypesGeneralized),
OSType: to.Ptr(armcompute.OperatingSystemTypesLinux),
},
ZoneResilient: to.Ptr(true),
},
},
}, 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.Image = armcompute.Image{
// Name: to.Ptr("myImage"),
// Type: to.Ptr("Microsoft.Compute/images"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/disk/providers/Microsoft.Compute/images/myImage"),
// Location: to.Ptr("westus"),
// Properties: &armcompute.ImageProperties{
// ProvisioningState: to.Ptr("Succeeded"),
// StorageProfile: &armcompute.ImageStorageProfile{
// DataDisks: []*armcompute.ImageDataDisk{
// },
// OSDisk: &armcompute.ImageOSDisk{
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// ManagedDisk: &armcompute.SubResource{
// ID: to.Ptr("subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/myManagedDisk"),
// },
// OSState: to.Ptr(armcompute.OperatingSystemStateTypesGeneralized),
// OSType: to.Ptr(armcompute.OperatingSystemTypesLinux),
// },
// ZoneResilient: to.Ptr(true),
// },
// },
// }
}
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 Create or update an image.
*
* @summary Create or update an image.
* x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/imageExamples/Image_CreateFromAManagedDisk.json
*/
async function createAVirtualMachineImageFromAManagedDisk() {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP"] || "myResourceGroup";
const imageName = "myImage";
const parameters = {
location: "West US",
storageProfile: {
osDisk: {
managedDisk: {
id: "subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/myManagedDisk",
},
osState: "Generalized",
osType: "Linux",
},
zoneResilient: true,
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.images.beginCreateOrUpdateAndWait(
resourceGroupName,
imageName,
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
Sample Response
{
"properties": {
"storageProfile": {
"osDisk": {
"osType": "Linux",
"managedDisk": {
"id": "subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/myManagedDisk"
},
"osState": "Generalized",
"caching": "ReadWrite"
},
"dataDisks": [],
"zoneResilient": true
},
"provisioningState": "Creating"
},
"type": "Microsoft.Compute/images",
"location": "westus",
"id": "/subscriptions/{subscription-id}/resourceGroups/disk/providers/Microsoft.Compute/images/myImage",
"name": "myImage"
}
{
"properties": {
"storageProfile": {
"osDisk": {
"osType": "Linux",
"managedDisk": {
"id": "subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/myManagedDisk"
},
"osState": "Generalized",
"caching": "ReadWrite"
},
"dataDisks": [],
"zoneResilient": true
},
"provisioningState": "Creating"
},
"type": "Microsoft.Compute/images",
"location": "westus",
"id": "/subscriptions/{subscription-id}/resourceGroups/disk/providers/Microsoft.Compute/images/myImage",
"name": "myImage"
}
Create a virtual machine image from a snapshot with DiskEncryptionSet resource.
Sample Request
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/myImage?api-version=2024-03-01
{
"location": "West US",
"properties": {
"storageProfile": {
"osDisk": {
"osType": "Linux",
"managedDisk": {
"id": "subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/myManagedDisk"
},
"diskEncryptionSet": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"
},
"osState": "Generalized"
}
}
}
}
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 image_create_from_asnapshot_with_disk_encryption_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.images.begin_create_or_update(
resource_group_name="myResourceGroup",
image_name="myImage",
parameters={
"location": "West US",
"properties": {
"storageProfile": {
"osDisk": {
"diskEncryptionSet": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"
},
"managedDisk": {
"id": "subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/myManagedDisk"
},
"osState": "Generalized",
"osType": "Linux",
}
}
},
},
).result()
print(response)
# x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/imageExamples/Image_CreateFromASnapshotWithDiskEncryptionSet.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/imageExamples/Image_CreateFromASnapshotWithDiskEncryptionSet.json
func ExampleImagesClient_BeginCreateOrUpdate_createAVirtualMachineImageFromASnapshotWithDiskEncryptionSetResource() {
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.NewImagesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myImage", armcompute.Image{
Location: to.Ptr("West US"),
Properties: &armcompute.ImageProperties{
StorageProfile: &armcompute.ImageStorageProfile{
OSDisk: &armcompute.ImageOSDisk{
DiskEncryptionSet: &armcompute.DiskEncryptionSetParameters{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"),
},
ManagedDisk: &armcompute.SubResource{
ID: to.Ptr("subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/myManagedDisk"),
},
OSState: to.Ptr(armcompute.OperatingSystemStateTypesGeneralized),
OSType: to.Ptr(armcompute.OperatingSystemTypesLinux),
},
},
},
}, 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.Image = armcompute.Image{
// Name: to.Ptr("myImage"),
// Type: to.Ptr("Microsoft.Compute/images"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/disk/providers/Microsoft.Compute/images/myImage"),
// Location: to.Ptr("westus"),
// Properties: &armcompute.ImageProperties{
// ProvisioningState: to.Ptr("Succeeded"),
// StorageProfile: &armcompute.ImageStorageProfile{
// DataDisks: []*armcompute.ImageDataDisk{
// },
// OSDisk: &armcompute.ImageOSDisk{
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// DiskEncryptionSet: &armcompute.DiskEncryptionSetParameters{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"),
// },
// ManagedDisk: &armcompute.SubResource{
// ID: to.Ptr("subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/myManagedDisk"),
// },
// OSState: to.Ptr(armcompute.OperatingSystemStateTypesGeneralized),
// OSType: to.Ptr(armcompute.OperatingSystemTypesLinux),
// },
// },
// },
// }
}
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 Create or update an image.
*
* @summary Create or update an image.
* x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/imageExamples/Image_CreateFromASnapshotWithDiskEncryptionSet.json
*/
async function createAVirtualMachineImageFromASnapshotWithDiskEncryptionSetResource() {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP"] || "myResourceGroup";
const imageName = "myImage";
const parameters = {
location: "West US",
storageProfile: {
osDisk: {
diskEncryptionSet: {
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}",
},
managedDisk: {
id: "subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/myManagedDisk",
},
osState: "Generalized",
osType: "Linux",
},
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.images.beginCreateOrUpdateAndWait(
resourceGroupName,
imageName,
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
Sample Response
{
"properties": {
"storageProfile": {
"osDisk": {
"osType": "Linux",
"managedDisk": {
"id": "subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/myManagedDisk"
},
"diskEncryptionSet": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"
},
"osState": "Generalized",
"caching": "ReadWrite"
},
"dataDisks": []
},
"provisioningState": "Creating"
},
"type": "Microsoft.Compute/images",
"location": "westus",
"id": "/subscriptions/{subscription-id}/resourceGroups/disk/providers/Microsoft.Compute/images/myImage",
"name": "myImage"
}
{
"properties": {
"storageProfile": {
"osDisk": {
"osType": "Linux",
"managedDisk": {
"id": "subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/myManagedDisk"
},
"diskEncryptionSet": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"
},
"osState": "Generalized",
"caching": "ReadWrite"
},
"dataDisks": []
},
"provisioningState": "Creating"
},
"type": "Microsoft.Compute/images",
"location": "westus",
"id": "/subscriptions/{subscription-id}/resourceGroups/disk/providers/Microsoft.Compute/images/myImage",
"name": "myImage"
}
Create a virtual machine image from a snapshot.
Sample Request
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/myImage?api-version=2024-03-01
{
"location": "West US",
"properties": {
"storageProfile": {
"osDisk": {
"osType": "Linux",
"snapshot": {
"id": "subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/mySnapshot"
},
"osState": "Generalized"
},
"zoneResilient": false
}
}
}
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 image_create_from_asnapshot.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.images.begin_create_or_update(
resource_group_name="myResourceGroup",
image_name="myImage",
parameters={
"location": "West US",
"properties": {
"storageProfile": {
"osDisk": {
"osState": "Generalized",
"osType": "Linux",
"snapshot": {
"id": "subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/mySnapshot"
},
},
"zoneResilient": False,
}
},
},
).result()
print(response)
# x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/imageExamples/Image_CreateFromASnapshot.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/imageExamples/Image_CreateFromASnapshot.json
func ExampleImagesClient_BeginCreateOrUpdate_createAVirtualMachineImageFromASnapshot() {
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.NewImagesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myImage", armcompute.Image{
Location: to.Ptr("West US"),
Properties: &armcompute.ImageProperties{
StorageProfile: &armcompute.ImageStorageProfile{
OSDisk: &armcompute.ImageOSDisk{
Snapshot: &armcompute.SubResource{
ID: to.Ptr("subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/mySnapshot"),
},
OSState: to.Ptr(armcompute.OperatingSystemStateTypesGeneralized),
OSType: to.Ptr(armcompute.OperatingSystemTypesLinux),
},
ZoneResilient: to.Ptr(false),
},
},
}, 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.Image = armcompute.Image{
// Name: to.Ptr("myImage"),
// Type: to.Ptr("Microsoft.Compute/images"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/disk/providers/Microsoft.Compute/images/myImage"),
// Location: to.Ptr("westus"),
// Properties: &armcompute.ImageProperties{
// ProvisioningState: to.Ptr("Succeeded"),
// StorageProfile: &armcompute.ImageStorageProfile{
// DataDisks: []*armcompute.ImageDataDisk{
// },
// OSDisk: &armcompute.ImageOSDisk{
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// Snapshot: &armcompute.SubResource{
// ID: to.Ptr("subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/mySnapshot"),
// },
// OSState: to.Ptr(armcompute.OperatingSystemStateTypesGeneralized),
// OSType: to.Ptr(armcompute.OperatingSystemTypesLinux),
// },
// ZoneResilient: to.Ptr(false),
// },
// },
// }
}
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 Create or update an image.
*
* @summary Create or update an image.
* x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/imageExamples/Image_CreateFromASnapshot.json
*/
async function createAVirtualMachineImageFromASnapshot() {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP"] || "myResourceGroup";
const imageName = "myImage";
const parameters = {
location: "West US",
storageProfile: {
osDisk: {
osState: "Generalized",
osType: "Linux",
snapshot: {
id: "subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/mySnapshot",
},
},
zoneResilient: false,
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.images.beginCreateOrUpdateAndWait(
resourceGroupName,
imageName,
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.ImageInner;
import com.azure.resourcemanager.compute.models.DiskEncryptionSetParameters;
import com.azure.resourcemanager.compute.models.ImageDataDisk;
import com.azure.resourcemanager.compute.models.ImageOSDisk;
import com.azure.resourcemanager.compute.models.ImageStorageProfile;
import com.azure.resourcemanager.compute.models.OperatingSystemStateTypes;
import com.azure.resourcemanager.compute.models.OperatingSystemTypes;
import java.util.Arrays;
/**
* Samples for Images CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/imageExamples/
* Image_CreateFromASnapshot.json
*/
/**
* Sample code: Create a virtual machine image from a snapshot.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVirtualMachineImageFromASnapshot(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getImages().createOrUpdate("myResourceGroup", "myImage",
new ImageInner().withLocation("West US").withStorageProfile(new ImageStorageProfile()
.withOsDisk(new ImageOSDisk().withSnapshot(new SubResource().withId(
"subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/mySnapshot"))
.withOsType(OperatingSystemTypes.LINUX).withOsState(OperatingSystemStateTypes.GENERALIZED))
.withZoneResilient(false)),
com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/imageExamples/
* Image_CreateFromAManagedDisk.json
*/
/**
* Sample code: Create a virtual machine image from a managed disk.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createAVirtualMachineImageFromAManagedDisk(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getImages().createOrUpdate("myResourceGroup", "myImage",
new ImageInner().withLocation("West US").withStorageProfile(new ImageStorageProfile()
.withOsDisk(new ImageOSDisk().withManagedDisk(new SubResource().withId(
"subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/myManagedDisk"))
.withOsType(OperatingSystemTypes.LINUX).withOsState(OperatingSystemStateTypes.GENERALIZED))
.withZoneResilient(true)),
com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/imageExamples/
* Image_CreateFromABlobWithDiskEncryptionSet.json
*/
/**
* Sample code: Create a virtual machine image from a blob with DiskEncryptionSet resource.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVirtualMachineImageFromABlobWithDiskEncryptionSetResource(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getImages().createOrUpdate("myResourceGroup", "myImage",
new ImageInner().withLocation("West US")
.withStorageProfile(new ImageStorageProfile().withOsDisk(new ImageOSDisk()
.withBlobUri("https://mystorageaccount.blob.core.windows.net/osimages/osimage.vhd")
.withDiskEncryptionSet(new DiskEncryptionSetParameters().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"))
.withOsType(OperatingSystemTypes.LINUX).withOsState(OperatingSystemStateTypes.GENERALIZED))),
com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/imageExamples/
* Image_CreateFromAManagedDiskWithDiskEncryptionSet.json
*/
/**
* Sample code: Create a virtual machine image from a managed disk with DiskEncryptionSet resource.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVirtualMachineImageFromAManagedDiskWithDiskEncryptionSetResource(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getImages().createOrUpdate("myResourceGroup", "myImage",
new ImageInner().withLocation("West US").withStorageProfile(
new ImageStorageProfile().withOsDisk(new ImageOSDisk().withSnapshot(new SubResource().withId(
"subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/mySnapshot"))
.withDiskEncryptionSet(new DiskEncryptionSetParameters().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"))
.withOsType(OperatingSystemTypes.LINUX).withOsState(OperatingSystemStateTypes.GENERALIZED))),
com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/imageExamples/
* Image_Create_DataDiskFromABlobIncluded.json
*/
/**
* Sample code: Create a virtual machine image that includes a data disk from a blob.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createAVirtualMachineImageThatIncludesADataDiskFromABlob(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getImages().createOrUpdate("myResourceGroup", "myImage",
new ImageInner().withLocation("West US").withStorageProfile(new ImageStorageProfile()
.withOsDisk(
new ImageOSDisk().withBlobUri("https://mystorageaccount.blob.core.windows.net/osimages/osimage.vhd")
.withOsType(OperatingSystemTypes.LINUX).withOsState(OperatingSystemStateTypes.GENERALIZED))
.withDataDisks(Arrays.asList(new ImageDataDisk()
.withBlobUri("https://mystorageaccount.blob.core.windows.net/dataimages/dataimage.vhd").withLun(1)))
.withZoneResilient(false)),
com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/imageExamples/
* Image_CreateFromASnapshotWithDiskEncryptionSet.json
*/
/**
* Sample code: Create a virtual machine image from a snapshot with DiskEncryptionSet resource.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVirtualMachineImageFromASnapshotWithDiskEncryptionSetResource(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getImages().createOrUpdate("myResourceGroup", "myImage",
new ImageInner().withLocation("West US").withStorageProfile(
new ImageStorageProfile().withOsDisk(new ImageOSDisk().withManagedDisk(new SubResource().withId(
"subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/myManagedDisk"))
.withDiskEncryptionSet(new DiskEncryptionSetParameters().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"))
.withOsType(OperatingSystemTypes.LINUX).withOsState(OperatingSystemStateTypes.GENERALIZED))),
com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/imageExamples/
* Image_Create_DataDiskFromASnapshotIncluded.json
*/
/**
* Sample code: Create a virtual machine image that includes a data disk from a snapshot.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVirtualMachineImageThatIncludesADataDiskFromASnapshot(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getImages().createOrUpdate("myResourceGroup", "myImage",
new ImageInner().withLocation("West US").withStorageProfile(new ImageStorageProfile()
.withOsDisk(new ImageOSDisk().withSnapshot(new SubResource().withId(
"subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/mySnapshot"))
.withOsType(OperatingSystemTypes.LINUX).withOsState(OperatingSystemStateTypes.GENERALIZED))
.withDataDisks(Arrays.asList(new ImageDataDisk().withSnapshot(new SubResource().withId(
"subscriptions/{subscriptionId}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/mySnapshot2"))
.withLun(1)))
.withZoneResilient(true)),
com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/imageExamples/
* Image_CreateFromABlob.json
*/
/**
* Sample code: Create a virtual machine image from a blob.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVirtualMachineImageFromABlob(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getImages().createOrUpdate("myResourceGroup", "myImage",
new ImageInner().withLocation("West US").withStorageProfile(new ImageStorageProfile()
.withOsDisk(
new ImageOSDisk().withBlobUri("https://mystorageaccount.blob.core.windows.net/osimages/osimage.vhd")
.withOsType(OperatingSystemTypes.LINUX).withOsState(OperatingSystemStateTypes.GENERALIZED))
.withZoneResilient(true)),
com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/imageExamples/
* Image_CreateFromAVM.json
*/
/**
* Sample code: Create a virtual machine image from an existing virtual machine.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createAVirtualMachineImageFromAnExistingVirtualMachine(com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getImages().createOrUpdate("myResourceGroup", "myImage",
new ImageInner().withLocation("West US").withSourceVirtualMachine(new SubResource().withId(
"/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM")),
com.azure.core.util.Context.NONE);
}
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/imageExamples/
* Image_Create_DataDiskFromAManagedDiskIncluded.json
*/
/**
* Sample code: Create a virtual machine image that includes a data disk from a managed disk.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createAVirtualMachineImageThatIncludesADataDiskFromAManagedDisk(
com.azure.resourcemanager.AzureResourceManager azure) {
azure.virtualMachines().manager().serviceClient().getImages().createOrUpdate("myResourceGroup", "myImage",
new ImageInner().withLocation("West US").withStorageProfile(new ImageStorageProfile()
.withOsDisk(new ImageOSDisk().withManagedDisk(new SubResource().withId(
"subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/myManagedDisk"))
.withOsType(OperatingSystemTypes.LINUX).withOsState(OperatingSystemStateTypes.GENERALIZED))
.withDataDisks(Arrays.asList(new ImageDataDisk().withManagedDisk(new SubResource().withId(
"subscriptions/{subscriptionId}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/myManagedDisk2"))
.withLun(1)))
.withZoneResilient(false)),
com.azure.core.util.Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Sample Response
{
"properties": {
"storageProfile": {
"osDisk": {
"osType": "Linux",
"snapshot": {
"id": "subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/mySnapshot"
},
"osState": "Generalized",
"caching": "ReadWrite"
},
"dataDisks": [],
"zoneResilient": false
},
"provisioningState": "Creating"
},
"type": "Microsoft.Compute/images",
"location": "westus",
"id": "/subscriptions/{subscription-id}/resourceGroups/disk/providers/Microsoft.Compute/images/myImage",
"name": "myImage"
}
{
"properties": {
"storageProfile": {
"osDisk": {
"osType": "Linux",
"snapshot": {
"id": "subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/mySnapshot"
},
"osState": "Generalized",
"caching": "ReadWrite"
},
"dataDisks": [],
"zoneResilient": false
},
"provisioningState": "Creating"
},
"type": "Microsoft.Compute/images",
"location": "westus",
"id": "/subscriptions/{subscription-id}/resourceGroups/disk/providers/Microsoft.Compute/images/myImage",
"name": "myImage"
}
Create a virtual machine image from an existing virtual machine.
Sample Request
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/myImage?api-version=2024-03-01
{
"location": "West US",
"properties": {
"sourceVirtualMachine": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"
}
}
}
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 image_create_from_avm.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.images.begin_create_or_update(
resource_group_name="myResourceGroup",
image_name="myImage",
parameters={
"location": "West US",
"properties": {
"sourceVirtualMachine": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"
}
},
},
).result()
print(response)
# x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/imageExamples/Image_CreateFromAVM.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/imageExamples/Image_CreateFromAVM.json
func ExampleImagesClient_BeginCreateOrUpdate_createAVirtualMachineImageFromAnExistingVirtualMachine() {
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.NewImagesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myImage", armcompute.Image{
Location: to.Ptr("West US"),
Properties: &armcompute.ImageProperties{
SourceVirtualMachine: &armcompute.SubResource{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
},
},
}, 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.Image = armcompute.Image{
// Name: to.Ptr("myImage"),
// Type: to.Ptr("Microsoft.Compute/images"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/disk/providers/Microsoft.Compute/images/myImage"),
// Location: to.Ptr("westus"),
// Properties: &armcompute.ImageProperties{
// ProvisioningState: to.Ptr("Succeeded"),
// SourceVirtualMachine: &armcompute.SubResource{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
// },
// StorageProfile: &armcompute.ImageStorageProfile{
// DataDisks: []*armcompute.ImageDataDisk{
// },
// OSDisk: &armcompute.ImageOSDisk{
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// ManagedDisk: &armcompute.SubResource{
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/myVM_OsDisk_1_6dc293b7d811433196903acf92665022"),
// },
// OSState: to.Ptr(armcompute.OperatingSystemStateTypesGeneralized),
// OSType: to.Ptr(armcompute.OperatingSystemTypesLinux),
// },
// ZoneResilient: to.Ptr(false),
// },
// },
// }
}
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 Create or update an image.
*
* @summary Create or update an image.
* x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/imageExamples/Image_CreateFromAVM.json
*/
async function createAVirtualMachineImageFromAnExistingVirtualMachine() {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP"] || "myResourceGroup";
const imageName = "myImage";
const parameters = {
location: "West US",
sourceVirtualMachine: {
id: "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.images.beginCreateOrUpdateAndWait(
resourceGroupName,
imageName,
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
Sample Response
{
"properties": {
"sourceVirtualMachine": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"
},
"storageProfile": {
"osDisk": {
"osType": "Linux",
"osState": "Generalized",
"managedDisk": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/myVM_OsDisk_1_6dc293b7d811433196903acf92665022"
},
"caching": "ReadWrite"
},
"dataDisks": [],
"zoneResilient": false
},
"provisioningState": "Creating"
},
"type": "Microsoft.Compute/images",
"location": "westus",
"id": "/subscriptions/{subscription-id}/resourceGroups/disk/providers/Microsoft.Compute/images/myImage",
"name": "myImage"
}
{
"properties": {
"sourceVirtualMachine": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"
},
"storageProfile": {
"osDisk": {
"osType": "Linux",
"osState": "Generalized",
"managedDisk": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/myVM_OsDisk_1_6dc293b7d811433196903acf92665022"
},
"caching": "ReadWrite"
},
"dataDisks": [],
"zoneResilient": false
},
"provisioningState": "Creating"
},
"type": "Microsoft.Compute/images",
"location": "westus",
"id": "/subscriptions/{subscription-id}/resourceGroups/disk/providers/Microsoft.Compute/images/myImage",
"name": "myImage"
}
Create a virtual machine image that includes a data disk from a blob.
Sample Request
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/myImage?api-version=2024-03-01
{
"location": "West US",
"properties": {
"storageProfile": {
"osDisk": {
"osType": "Linux",
"blobUri": "https://mystorageaccount.blob.core.windows.net/osimages/osimage.vhd",
"osState": "Generalized"
},
"dataDisks": [
{
"lun": 1,
"blobUri": "https://mystorageaccount.blob.core.windows.net/dataimages/dataimage.vhd"
}
],
"zoneResilient": false
}
}
}
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 image_create_data_disk_from_ablob_included.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.images.begin_create_or_update(
resource_group_name="myResourceGroup",
image_name="myImage",
parameters={
"location": "West US",
"properties": {
"storageProfile": {
"dataDisks": [
{"blobUri": "https://mystorageaccount.blob.core.windows.net/dataimages/dataimage.vhd", "lun": 1}
],
"osDisk": {
"blobUri": "https://mystorageaccount.blob.core.windows.net/osimages/osimage.vhd",
"osState": "Generalized",
"osType": "Linux",
},
"zoneResilient": False,
}
},
},
).result()
print(response)
# x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/imageExamples/Image_Create_DataDiskFromABlobIncluded.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/imageExamples/Image_Create_DataDiskFromABlobIncluded.json
func ExampleImagesClient_BeginCreateOrUpdate_createAVirtualMachineImageThatIncludesADataDiskFromABlob() {
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.NewImagesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myImage", armcompute.Image{
Location: to.Ptr("West US"),
Properties: &armcompute.ImageProperties{
StorageProfile: &armcompute.ImageStorageProfile{
DataDisks: []*armcompute.ImageDataDisk{
{
BlobURI: to.Ptr("https://mystorageaccount.blob.core.windows.net/dataimages/dataimage.vhd"),
Lun: to.Ptr[int32](1),
}},
OSDisk: &armcompute.ImageOSDisk{
BlobURI: to.Ptr("https://mystorageaccount.blob.core.windows.net/osimages/osimage.vhd"),
OSState: to.Ptr(armcompute.OperatingSystemStateTypesGeneralized),
OSType: to.Ptr(armcompute.OperatingSystemTypesLinux),
},
ZoneResilient: to.Ptr(false),
},
},
}, 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.Image = armcompute.Image{
// Name: to.Ptr("myImage"),
// Type: to.Ptr("Microsoft.Compute/images"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/disk/providers/Microsoft.Compute/images/myImage"),
// Location: to.Ptr("westus"),
// Properties: &armcompute.ImageProperties{
// ProvisioningState: to.Ptr("Succeeded"),
// StorageProfile: &armcompute.ImageStorageProfile{
// DataDisks: []*armcompute.ImageDataDisk{
// {
// BlobURI: to.Ptr("https://mystorageaccount.blob.core.windows.net/dataimages/dataimage.vhd"),
// Lun: to.Ptr[int32](1),
// }},
// OSDisk: &armcompute.ImageOSDisk{
// BlobURI: to.Ptr("https://mystorageaccount.blob.core.windows.net/osimages/osimage.vhd"),
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// OSState: to.Ptr(armcompute.OperatingSystemStateTypesGeneralized),
// OSType: to.Ptr(armcompute.OperatingSystemTypesLinux),
// },
// ZoneResilient: to.Ptr(false),
// },
// },
// }
}
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 Create or update an image.
*
* @summary Create or update an image.
* x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/imageExamples/Image_Create_DataDiskFromABlobIncluded.json
*/
async function createAVirtualMachineImageThatIncludesADataDiskFromABlob() {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP"] || "myResourceGroup";
const imageName = "myImage";
const parameters = {
location: "West US",
storageProfile: {
dataDisks: [
{
blobUri: "https://mystorageaccount.blob.core.windows.net/dataimages/dataimage.vhd",
lun: 1,
},
],
osDisk: {
blobUri: "https://mystorageaccount.blob.core.windows.net/osimages/osimage.vhd",
osState: "Generalized",
osType: "Linux",
},
zoneResilient: false,
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.images.beginCreateOrUpdateAndWait(
resourceGroupName,
imageName,
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
Sample Response
{
"properties": {
"storageProfile": {
"osDisk": {
"osType": "Linux",
"osState": "Generalized",
"blobUri": "https://mystorageaccount.blob.core.windows.net/osimages/osimage.vhd",
"caching": "ReadWrite"
},
"dataDisks": [
{
"lun": 1,
"blobUri": "https://mystorageaccount.blob.core.windows.net/dataimages/dataimage.vhd"
}
],
"zoneResilient": false
},
"provisioningState": "Creating"
},
"type": "Microsoft.Compute/images",
"location": "westus",
"id": "/subscriptions/{subscription-id}/resourceGroups/disk/providers/Microsoft.Compute/images/myImage",
"name": "myImage"
}
{
"properties": {
"storageProfile": {
"osDisk": {
"osType": "Linux",
"osState": "Generalized",
"blobUri": "https://mystorageaccount.blob.core.windows.net/osimages/osimage.vhd",
"caching": "ReadWrite"
},
"dataDisks": [
{
"lun": 1,
"blobUri": "https://mystorageaccount.blob.core.windows.net/dataimages/dataimage.vhd"
}
],
"zoneResilient": false
},
"provisioningState": "Creating"
},
"type": "Microsoft.Compute/images",
"location": "westus",
"id": "/subscriptions/{subscription-id}/resourceGroups/disk/providers/Microsoft.Compute/images/myImage",
"name": "myImage"
}
Create a virtual machine image that includes a data disk from a managed disk.
Sample Request
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/myImage?api-version=2024-03-01
{
"location": "West US",
"properties": {
"storageProfile": {
"osDisk": {
"osType": "Linux",
"managedDisk": {
"id": "subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/myManagedDisk"
},
"osState": "Generalized"
},
"dataDisks": [
{
"lun": 1,
"managedDisk": {
"id": "subscriptions/{subscriptionId}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/myManagedDisk2"
}
}
],
"zoneResilient": false
}
}
}
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 image_create_data_disk_from_amanaged_disk_included.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.images.begin_create_or_update(
resource_group_name="myResourceGroup",
image_name="myImage",
parameters={
"location": "West US",
"properties": {
"storageProfile": {
"dataDisks": [
{
"lun": 1,
"managedDisk": {
"id": "subscriptions/{subscriptionId}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/myManagedDisk2"
},
}
],
"osDisk": {
"managedDisk": {
"id": "subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/myManagedDisk"
},
"osState": "Generalized",
"osType": "Linux",
},
"zoneResilient": False,
}
},
},
).result()
print(response)
# x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/imageExamples/Image_Create_DataDiskFromAManagedDiskIncluded.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/imageExamples/Image_Create_DataDiskFromAManagedDiskIncluded.json
func ExampleImagesClient_BeginCreateOrUpdate_createAVirtualMachineImageThatIncludesADataDiskFromAManagedDisk() {
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.NewImagesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myImage", armcompute.Image{
Location: to.Ptr("West US"),
Properties: &armcompute.ImageProperties{
StorageProfile: &armcompute.ImageStorageProfile{
DataDisks: []*armcompute.ImageDataDisk{
{
ManagedDisk: &armcompute.SubResource{
ID: to.Ptr("subscriptions/{subscriptionId}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/myManagedDisk2"),
},
Lun: to.Ptr[int32](1),
}},
OSDisk: &armcompute.ImageOSDisk{
ManagedDisk: &armcompute.SubResource{
ID: to.Ptr("subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/myManagedDisk"),
},
OSState: to.Ptr(armcompute.OperatingSystemStateTypesGeneralized),
OSType: to.Ptr(armcompute.OperatingSystemTypesLinux),
},
ZoneResilient: to.Ptr(false),
},
},
}, 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.Image = armcompute.Image{
// Name: to.Ptr("myImage"),
// Type: to.Ptr("Microsoft.Compute/images"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/disk/providers/Microsoft.Compute/images/myImage"),
// Location: to.Ptr("westus"),
// Properties: &armcompute.ImageProperties{
// ProvisioningState: to.Ptr("Succeeded"),
// StorageProfile: &armcompute.ImageStorageProfile{
// DataDisks: []*armcompute.ImageDataDisk{
// {
// ManagedDisk: &armcompute.SubResource{
// ID: to.Ptr("subscriptions/{subscriptionId}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/myManagedDisk2"),
// },
// Lun: to.Ptr[int32](1),
// }},
// OSDisk: &armcompute.ImageOSDisk{
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// ManagedDisk: &armcompute.SubResource{
// ID: to.Ptr("subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/myManagedDisk"),
// },
// OSState: to.Ptr(armcompute.OperatingSystemStateTypesGeneralized),
// OSType: to.Ptr(armcompute.OperatingSystemTypesLinux),
// },
// ZoneResilient: to.Ptr(false),
// },
// },
// }
}
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 Create or update an image.
*
* @summary Create or update an image.
* x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/imageExamples/Image_Create_DataDiskFromAManagedDiskIncluded.json
*/
async function createAVirtualMachineImageThatIncludesADataDiskFromAManagedDisk() {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP"] || "myResourceGroup";
const imageName = "myImage";
const parameters = {
location: "West US",
storageProfile: {
dataDisks: [
{
lun: 1,
managedDisk: {
id: "subscriptions/{subscriptionId}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/myManagedDisk2",
},
},
],
osDisk: {
managedDisk: {
id: "subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/myManagedDisk",
},
osState: "Generalized",
osType: "Linux",
},
zoneResilient: false,
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.images.beginCreateOrUpdateAndWait(
resourceGroupName,
imageName,
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
Sample Response
{
"properties": {
"storageProfile": {
"osDisk": {
"osType": "Linux",
"managedDisk": {
"id": "subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/myManagedDisk"
},
"osState": "Generalized",
"caching": "ReadWrite"
},
"dataDisks": [
{
"lun": 1,
"managedDisk": {
"id": "subscriptions/{subscriptionId}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/myManagedDisk2"
}
}
],
"zoneResilient": false
},
"provisioningState": "Creating"
},
"type": "Microsoft.Compute/images",
"location": "westus",
"id": "/subscriptions/{subscription-id}/resourceGroups/disk/providers/Microsoft.Compute/images/myImage",
"name": "myImage"
}
{
"properties": {
"storageProfile": {
"osDisk": {
"osType": "Linux",
"managedDisk": {
"id": "subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/myManagedDisk"
},
"osState": "Generalized",
"caching": "ReadWrite"
},
"dataDisks": [
{
"lun": 1,
"managedDisk": {
"id": "subscriptions/{subscriptionId}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/myManagedDisk2"
}
}
],
"zoneResilient": false
},
"provisioningState": "Creating"
},
"type": "Microsoft.Compute/images",
"location": "westus",
"id": "/subscriptions/{subscription-id}/resourceGroups/disk/providers/Microsoft.Compute/images/myImage",
"name": "myImage"
}
Create a virtual machine image that includes a data disk from a snapshot.
Sample Request
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/myImage?api-version=2024-03-01
{
"location": "West US",
"properties": {
"storageProfile": {
"osDisk": {
"osType": "Linux",
"snapshot": {
"id": "subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/mySnapshot"
},
"osState": "Generalized"
},
"dataDisks": [
{
"lun": 1,
"snapshot": {
"id": "subscriptions/{subscriptionId}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/mySnapshot2"
}
}
],
"zoneResilient": 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 image_create_data_disk_from_asnapshot_included.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.images.begin_create_or_update(
resource_group_name="myResourceGroup",
image_name="myImage",
parameters={
"location": "West US",
"properties": {
"storageProfile": {
"dataDisks": [
{
"lun": 1,
"snapshot": {
"id": "subscriptions/{subscriptionId}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/mySnapshot2"
},
}
],
"osDisk": {
"osState": "Generalized",
"osType": "Linux",
"snapshot": {
"id": "subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/mySnapshot"
},
},
"zoneResilient": True,
}
},
},
).result()
print(response)
# x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/imageExamples/Image_Create_DataDiskFromASnapshotIncluded.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/imageExamples/Image_Create_DataDiskFromASnapshotIncluded.json
func ExampleImagesClient_BeginCreateOrUpdate_createAVirtualMachineImageThatIncludesADataDiskFromASnapshot() {
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.NewImagesClient().BeginCreateOrUpdate(ctx, "myResourceGroup", "myImage", armcompute.Image{
Location: to.Ptr("West US"),
Properties: &armcompute.ImageProperties{
StorageProfile: &armcompute.ImageStorageProfile{
DataDisks: []*armcompute.ImageDataDisk{
{
Snapshot: &armcompute.SubResource{
ID: to.Ptr("subscriptions/{subscriptionId}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/mySnapshot2"),
},
Lun: to.Ptr[int32](1),
}},
OSDisk: &armcompute.ImageOSDisk{
Snapshot: &armcompute.SubResource{
ID: to.Ptr("subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/mySnapshot"),
},
OSState: to.Ptr(armcompute.OperatingSystemStateTypesGeneralized),
OSType: to.Ptr(armcompute.OperatingSystemTypesLinux),
},
ZoneResilient: to.Ptr(true),
},
},
}, 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.Image = armcompute.Image{
// Name: to.Ptr("myImage"),
// Type: to.Ptr("Microsoft.Compute/images"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/disk/providers/Microsoft.Compute/images/myImage"),
// Location: to.Ptr("westus"),
// Properties: &armcompute.ImageProperties{
// ProvisioningState: to.Ptr("Succeeded"),
// StorageProfile: &armcompute.ImageStorageProfile{
// DataDisks: []*armcompute.ImageDataDisk{
// {
// Snapshot: &armcompute.SubResource{
// ID: to.Ptr("subscriptions/{subscriptionId}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/mySnapshot2"),
// },
// Lun: to.Ptr[int32](1),
// }},
// OSDisk: &armcompute.ImageOSDisk{
// Caching: to.Ptr(armcompute.CachingTypesReadWrite),
// Snapshot: &armcompute.SubResource{
// ID: to.Ptr("subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/mySnapshot"),
// },
// OSState: to.Ptr(armcompute.OperatingSystemStateTypesGeneralized),
// OSType: to.Ptr(armcompute.OperatingSystemTypesLinux),
// },
// ZoneResilient: to.Ptr(true),
// },
// },
// }
}
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 Create or update an image.
*
* @summary Create or update an image.
* x-ms-original-file: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/examples/imageExamples/Image_Create_DataDiskFromASnapshotIncluded.json
*/
async function createAVirtualMachineImageThatIncludesADataDiskFromASnapshot() {
const subscriptionId = process.env["COMPUTE_SUBSCRIPTION_ID"] || "{subscription-id}";
const resourceGroupName = process.env["COMPUTE_RESOURCE_GROUP"] || "myResourceGroup";
const imageName = "myImage";
const parameters = {
location: "West US",
storageProfile: {
dataDisks: [
{
lun: 1,
snapshot: {
id: "subscriptions/{subscriptionId}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/mySnapshot2",
},
},
],
osDisk: {
osState: "Generalized",
osType: "Linux",
snapshot: {
id: "subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/mySnapshot",
},
},
zoneResilient: true,
},
};
const credential = new DefaultAzureCredential();
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.images.beginCreateOrUpdateAndWait(
resourceGroupName,
imageName,
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
Sample Response
{
"properties": {
"storageProfile": {
"osDisk": {
"osType": "Linux",
"snapshot": {
"id": "subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/mySnapshot"
},
"osState": "Generalized",
"caching": "ReadWrite"
},
"dataDisks": [
{
"lun": 1,
"snapshot": {
"id": "subscriptions/{subscriptionId}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/mySnapshot2"
}
}
],
"zoneResilient": true
},
"provisioningState": "Creating"
},
"type": "Microsoft.Compute/images",
"location": "westus",
"id": "/subscriptions/{subscription-id}/resourceGroups/disk/providers/Microsoft.Compute/images/myImage",
"name": "myImage"
}
{
"properties": {
"storageProfile": {
"osDisk": {
"osType": "Linux",
"snapshot": {
"id": "subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/mySnapshot"
},
"osState": "Generalized",
"caching": "ReadWrite"
},
"dataDisks": [
{
"lun": 1,
"snapshot": {
"id": "subscriptions/{subscriptionId}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/mySnapshot2"
}
}
],
"zoneResilient": true
},
"provisioningState": "Creating"
},
"type": "Microsoft.Compute/images",
"location": "westus",
"id": "/subscriptions/{subscription-id}/resourceGroups/disk/providers/Microsoft.Compute/images/myImage",
"name": "myImage"
}
Определения
Имя |
Описание |
ApiError
|
Ошибка API.
|
ApiErrorBase
|
База ошибок API.
|
CachingTypes
|
Указывает требования к кэшированию. Возможные значения: None,ReadOnly,ReadWrite. Значения по умолчанию: None для хранилища уровня "Стандартный". ReadOnly для хранилища класса Premium.
|
CloudError
|
Ответ об ошибке от службы вычислений.
|
DiskEncryptionSetParameters
|
Описывает параметр управляемого клиентом идентификатора ресурса набора шифрования дисков, который можно указать для диска. Примечание: Идентификатор ресурса набора шифрования дисков можно указать только для управляемого диска. Дополнительные сведения см. в этой статье https://aka.ms/mdssewithcmkoverview .
|
ExtendedLocation
|
Сложный тип расширенного расположения.
|
ExtendedLocationTypes
|
Тип расширенного расположения.
|
HyperVGenerationTypes
|
Указывает Тип HyperVGenerationType виртуальной машины, созданной на основе образа. Из API версии 2019-03-01, если источником образа является BLOB-объект, необходимо, чтобы пользователь указал значение. Если источником является управляемый ресурс, например диск или snapshot, может потребоваться указать свойство, если мы не можем вывести его из управляемого исходного ресурса.
|
Image
|
Виртуальный жесткий диск исходного образа пользователя. Виртуальный жесткий диск будет скопирован перед подключением к виртуальной машине. Если указан параметр SourceImage, целевой виртуальный жесткий диск не должен существовать.
|
ImageDataDisk
|
Описывает диск данных.
|
ImageOSDisk
|
Описывает диск операционной системы.
|
ImageStorageProfile
|
Описывает профиль хранилища.
|
InnerError
|
Сведения о внутренней ошибке.
|
OperatingSystemStateTypes
|
Состояние ОС. Для управляемых образов используйте generalized.
|
OperatingSystemTypes
|
Это свойство позволяет указать тип ОПЕРАЦИОННОй системы, которая включена в диск при создании виртуальной машины из пользовательского образа. Возможные значения: Windows,Linux.
|
StorageAccountTypes
|
Указывает тип учетной записи хранения для управляемого диска. ПРИМЕЧАНИЕ. UltraSSD_LRS можно использовать только с дисками данных, его нельзя использовать с диском ОС.
|
SubResource
|
|
ApiError
Ошибка API.
Имя |
Тип |
Описание |
code
|
string
|
Код ошибки.
|
details
|
ApiErrorBase[]
|
Сведения об ошибке API
|
innererror
|
InnerError
|
Внутренняя ошибка API
|
message
|
string
|
Сообщение об ошибке.
|
target
|
string
|
Целевой объект конкретной ошибки.
|
ApiErrorBase
База ошибок API.
Имя |
Тип |
Описание |
code
|
string
|
Код ошибки.
|
message
|
string
|
Сообщение об ошибке.
|
target
|
string
|
Целевой объект конкретной ошибки.
|
CachingTypes
Указывает требования к кэшированию. Возможные значения: None,ReadOnly,ReadWrite. Значения по умолчанию: None для хранилища уровня "Стандартный". ReadOnly для хранилища класса Premium.
Имя |
Тип |
Описание |
None
|
string
|
|
ReadOnly
|
string
|
|
ReadWrite
|
string
|
|
CloudError
Ответ об ошибке от службы вычислений.
Имя |
Тип |
Описание |
error
|
ApiError
|
Ошибка API.
|
DiskEncryptionSetParameters
Описывает параметр управляемого клиентом идентификатора ресурса набора шифрования дисков, который можно указать для диска. Примечание: Идентификатор ресурса набора шифрования дисков можно указать только для управляемого диска. Дополнительные сведения см. в этой статье https://aka.ms/mdssewithcmkoverview .
Имя |
Тип |
Описание |
id
|
string
|
Идентификатор ресурса
|
ExtendedLocation
Сложный тип расширенного расположения.
Имя |
Тип |
Описание |
name
|
string
|
Имя расширенного расположения.
|
type
|
ExtendedLocationTypes
|
Тип расширенного расположения.
|
ExtendedLocationTypes
Тип расширенного расположения.
Имя |
Тип |
Описание |
EdgeZone
|
string
|
|
HyperVGenerationTypes
Указывает Тип HyperVGenerationType виртуальной машины, созданной на основе образа. Из API версии 2019-03-01, если источником образа является BLOB-объект, необходимо, чтобы пользователь указал значение. Если источником является управляемый ресурс, например диск или snapshot, может потребоваться указать свойство, если мы не можем вывести его из управляемого исходного ресурса.
Имя |
Тип |
Описание |
V1
|
string
|
|
V2
|
string
|
|
Image
Виртуальный жесткий диск исходного образа пользователя. Виртуальный жесткий диск будет скопирован перед подключением к виртуальной машине. Если указан параметр SourceImage, целевой виртуальный жесткий диск не должен существовать.
Имя |
Тип |
Описание |
extendedLocation
|
ExtendedLocation
|
Расширенное расположение образа.
|
id
|
string
|
Идентификатор ресурса
|
location
|
string
|
Расположение ресурса
|
name
|
string
|
Имя ресурса
|
properties.hyperVGeneration
|
HyperVGenerationTypes
|
Указывает Тип HyperVGenerationType виртуальной машины, созданной на основе образа. Из API версии 2019-03-01, если источником образа является BLOB-объект, необходимо, чтобы пользователь указал значение. Если источником является управляемый ресурс, например диск или snapshot, может потребоваться указать свойство, если мы не можем вывести его из управляемого исходного ресурса.
|
properties.provisioningState
|
string
|
Состояние подготовки.
|
properties.sourceVirtualMachine
|
SubResource
|
Исходная виртуальная машина, на основе которой создается образ.
|
properties.storageProfile
|
ImageStorageProfile
|
Указывает параметры хранилища дисков виртуальной машины.
|
tags
|
object
|
Теги ресурсов
|
type
|
string
|
Тип ресурса
|
ImageDataDisk
Описывает диск данных.
Имя |
Тип |
Описание |
blobUri
|
string
|
Виртуальный жесткий диск.
|
caching
|
CachingTypes
|
Указывает требования к кэшированию. Возможные значения: None,ReadOnly,ReadWrite. Значения по умолчанию: None для хранилища уровня "Стандартный". ReadOnly для хранилища класса Premium.
|
diskEncryptionSet
|
DiskEncryptionSetParameters
|
Указывает идентификатор ресурса набора шифрования управляемых пользователем дисков для диска управляемого образа.
|
diskSizeGB
|
integer
|
Указывает размер пустых дисков данных в гигабайтах. Этот элемент можно использовать для перезаписи имени диска в образе виртуальной машины. Это значение не может превышать 1023 ГБ.
|
lun
|
integer
|
Указывает номер логической единицы диска данных. Это значение используется для идентификации дисков данных в виртуальной машине и поэтому должно быть уникальным для каждого диска данных, подключенного к виртуальной машине.
|
managedDisk
|
SubResource
|
ManagedDisk.
|
snapshot
|
SubResource
|
Snapshot.
|
storageAccountType
|
StorageAccountTypes
|
Указывает тип учетной записи хранения для управляемого диска. ПРИМЕЧАНИЕ. UltraSSD_LRS можно использовать только с дисками данных, его нельзя использовать с диском ОС.
|
ImageOSDisk
Описывает диск операционной системы.
Имя |
Тип |
Описание |
blobUri
|
string
|
Виртуальный жесткий диск.
|
caching
|
CachingTypes
|
Указывает требования к кэшированию. Возможные значения: None,ReadOnly,ReadWrite. Значения по умолчанию: None для хранилища уровня "Стандартный". ReadOnly для хранилища класса Premium.
|
diskEncryptionSet
|
DiskEncryptionSetParameters
|
Указывает идентификатор ресурса набора шифрования управляемых пользователем дисков для диска управляемого образа.
|
diskSizeGB
|
integer
|
Указывает размер пустых дисков данных в гигабайтах. Этот элемент можно использовать для перезаписи имени диска в образе виртуальной машины. Это значение не может превышать 1023 ГБ.
|
managedDisk
|
SubResource
|
ManagedDisk.
|
osState
|
OperatingSystemStateTypes
|
Состояние ОС. Для управляемых образов используйте generalized.
|
osType
|
OperatingSystemTypes
|
Это свойство позволяет указать тип ОПЕРАЦИОННОй системы, которая включена в диск при создании виртуальной машины из пользовательского образа. Возможные значения: Windows,Linux.
|
snapshot
|
SubResource
|
Snapshot.
|
storageAccountType
|
StorageAccountTypes
|
Указывает тип учетной записи хранения для управляемого диска. ПРИМЕЧАНИЕ. UltraSSD_LRS можно использовать только с дисками данных, его нельзя использовать с диском ОС.
|
ImageStorageProfile
Описывает профиль хранилища.
InnerError
Сведения о внутренней ошибке.
Имя |
Тип |
Описание |
errordetail
|
string
|
Внутреннее сообщение об ошибке или дамп исключений.
|
exceptiontype
|
string
|
Тип исключения.
|
OperatingSystemStateTypes
Состояние ОС. Для управляемых образов используйте generalized.
Имя |
Тип |
Описание |
Generalized
|
string
|
Обобщенное изображение. Необходимо подготовить во время развертывания.
|
Specialized
|
string
|
Специализированное изображение. Содержит уже подготовленный диск ОС.
|
OperatingSystemTypes
Это свойство позволяет указать тип ОПЕРАЦИОННОй системы, которая включена в диск при создании виртуальной машины из пользовательского образа. Возможные значения: Windows,Linux.
Имя |
Тип |
Описание |
Linux
|
string
|
|
Windows
|
string
|
|
StorageAccountTypes
Указывает тип учетной записи хранения для управляемого диска. ПРИМЕЧАНИЕ. UltraSSD_LRS можно использовать только с дисками данных, его нельзя использовать с диском ОС.
Имя |
Тип |
Описание |
PremiumV2_LRS
|
string
|
|
Premium_LRS
|
string
|
|
Premium_ZRS
|
string
|
|
StandardSSD_LRS
|
string
|
|
StandardSSD_ZRS
|
string
|
|
Standard_LRS
|
string
|
|
UltraSSD_LRS
|
string
|
|
SubResource
Имя |
Тип |
Описание |
id
|
string
|
Идентификатор ресурса
|