Criar ou atualizar uma imagem.
PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/images/{imageName}?api-version=2024-03-01
Parâmetros de URI
Nome |
Em |
Obrigatório |
Tipo |
Description |
imageName
|
path |
True
|
string
|
O nome da imagem.
|
resourceGroupName
|
path |
True
|
string
|
O nome do grupo de recursos.
|
subscriptionId
|
path |
True
|
string
|
Credenciais de assinatura que identificam exclusivamente a assinatura do Microsoft Azure. A ID da assinatura faz parte do URI para cada chamada de serviço.
|
api-version
|
query |
True
|
string
|
Versão da API do cliente.
|
Corpo da solicitação
Nome |
Obrigatório |
Tipo |
Description |
location
|
True
|
string
|
Localização do recurso
|
extendedLocation
|
|
ExtendedLocation
|
O local estendido da Imagem.
|
properties.hyperVGeneration
|
|
HyperVGenerationTypes
|
Especifica o HyperVGenerationType do VirtualMachine criado a partir da imagem. Na API versão 2019-03-01 se a origem da imagem for um blob, precisamos que o usuário especifique o valor, se a origem for gerenciada, como disco ou instantâneo, poderemos exigir que o usuário especifique a propriedade se não pudermos deduzê-la do recurso gerenciado de origem.
|
properties.sourceVirtualMachine
|
|
SubResource
|
A máquina virtual de origem da qual a Imagem é criada.
|
properties.storageProfile
|
|
ImageStorageProfile
|
Especifica as configurações de armazenamento dos discos da máquina virtual.
|
tags
|
|
object
|
Marcações de recursos
|
Respostas
Nome |
Tipo |
Description |
200 OK
|
Image
|
OK
|
201 Created
|
Image
|
Criado
|
Other Status Codes
|
CloudError
|
Resposta de erro que descreve por que a operação falhou.
|
Segurança
azure_auth
Fluxo do OAuth2 do Azure Active Directory
Type:
oauth2
Flow:
implicit
Authorization URL:
https://login.microsoftonline.com/common/oauth2/authorize
Scopes
Nome |
Description |
user_impersonation
|
representar sua conta de usuário
|
Exemplos
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"
}
Definições
Nome |
Description |
ApiError
|
Erro de API.
|
ApiErrorBase
|
Base de erros de API.
|
CachingTypes
|
Especifica os requisitos de cache. Os valores possíveis são: None,ReadOnly,ReadWrite. Os valores padrão são: Nenhum para armazenamento Standard. ReadOnly para armazenamento Premium.
|
CloudError
|
Uma resposta de erro do serviço de computação.
|
DiskEncryptionSetParameters
|
Descreve o parâmetro da ID do recurso do conjunto de criptografia de disco gerenciado pelo cliente que pode ser especificada para disco. Nota: A ID do recurso do conjunto de criptografia de disco só pode ser especificada para o disco gerenciado. https://aka.ms/mdssewithcmkoverview Consulte para obter mais detalhes.
|
ExtendedLocation
|
O tipo complexo do local estendido.
|
ExtendedLocationTypes
|
O tipo do local estendido.
|
HyperVGenerationTypes
|
Especifica o HyperVGenerationType do VirtualMachine criado a partir da imagem. Na API versão 2019-03-01 se a origem da imagem for um blob, precisamos que o usuário especifique o valor, se a origem for gerenciada, como disco ou instantâneo, poderemos exigir que o usuário especifique a propriedade se não pudermos deduzê-la do recurso gerenciado de origem.
|
Image
|
O disco rígido virtual da imagem do usuário de origem. O disco rígido virtual será copiado antes de ser anexado à máquina virtual. Se SourceImage for fornecido, o disco rígido virtual de destino não deverá existir.
|
ImageDataDisk
|
Descreve um disco de dados.
|
ImageOSDisk
|
Descreve um disco do sistema operacional.
|
ImageStorageProfile
|
Descreve um perfil de armazenamento.
|
InnerError
|
Detalhes do erro interno.
|
OperatingSystemStateTypes
|
O estado do sistema operacional. Para imagens gerenciadas, use Generalizado.
|
OperatingSystemTypes
|
Essa propriedade permite que você especifique o tipo do sistema operacional incluído no disco se estiver criando uma VM de uma imagem personalizada. Os valores possíveis são: Windows,Linux.
|
StorageAccountTypes
|
Especifica o tipo de conta de armazenamento para o disco gerenciado. OBSERVAÇÃO: UltraSSD_LRS só pode ser usado com discos de dados, ele não pode ser usado com disco do sistema operacional.
|
SubResource
|
|
ApiError
Erro de API.
Nome |
Tipo |
Description |
code
|
string
|
O código de erro.
|
details
|
ApiErrorBase[]
|
Os detalhes do erro da API
|
innererror
|
InnerError
|
O erro interno da API
|
message
|
string
|
A mensagem de erro.
|
target
|
string
|
O destino do erro específico.
|
ApiErrorBase
Base de erros de API.
Nome |
Tipo |
Description |
code
|
string
|
O código de erro.
|
message
|
string
|
A mensagem de erro.
|
target
|
string
|
O destino do erro específico.
|
CachingTypes
Especifica os requisitos de cache. Os valores possíveis são: None,ReadOnly,ReadWrite. Os valores padrão são: Nenhum para armazenamento Standard. ReadOnly para armazenamento Premium.
Nome |
Tipo |
Description |
None
|
string
|
|
ReadOnly
|
string
|
|
ReadWrite
|
string
|
|
CloudError
Uma resposta de erro do serviço de computação.
Nome |
Tipo |
Description |
error
|
ApiError
|
Erro de API.
|
DiskEncryptionSetParameters
Descreve o parâmetro da ID do recurso do conjunto de criptografia de disco gerenciado pelo cliente que pode ser especificada para disco. Nota: A ID do recurso do conjunto de criptografia de disco só pode ser especificada para o disco gerenciado. https://aka.ms/mdssewithcmkoverview Consulte para obter mais detalhes.
Nome |
Tipo |
Description |
id
|
string
|
ID do recurso
|
ExtendedLocation
O tipo complexo do local estendido.
Nome |
Tipo |
Description |
name
|
string
|
O nome do local estendido.
|
type
|
ExtendedLocationTypes
|
O tipo do local estendido.
|
ExtendedLocationTypes
O tipo do local estendido.
Nome |
Tipo |
Description |
EdgeZone
|
string
|
|
HyperVGenerationTypes
Especifica o HyperVGenerationType do VirtualMachine criado a partir da imagem. Na API versão 2019-03-01 se a origem da imagem for um blob, precisamos que o usuário especifique o valor, se a origem for gerenciada, como disco ou instantâneo, poderemos exigir que o usuário especifique a propriedade se não pudermos deduzê-la do recurso gerenciado de origem.
Nome |
Tipo |
Description |
V1
|
string
|
|
V2
|
string
|
|
Image
O disco rígido virtual da imagem do usuário de origem. O disco rígido virtual será copiado antes de ser anexado à máquina virtual. Se SourceImage for fornecido, o disco rígido virtual de destino não deverá existir.
Nome |
Tipo |
Description |
extendedLocation
|
ExtendedLocation
|
O local estendido da Imagem.
|
id
|
string
|
ID do recurso
|
location
|
string
|
Localização do recurso
|
name
|
string
|
Nome do recurso
|
properties.hyperVGeneration
|
HyperVGenerationTypes
|
Especifica o HyperVGenerationType do VirtualMachine criado a partir da imagem. Na API versão 2019-03-01 se a origem da imagem for um blob, precisamos que o usuário especifique o valor, se a origem for gerenciada, como disco ou instantâneo, poderemos exigir que o usuário especifique a propriedade se não pudermos deduzê-la do recurso gerenciado de origem.
|
properties.provisioningState
|
string
|
O estado de provisionamento.
|
properties.sourceVirtualMachine
|
SubResource
|
A máquina virtual de origem da qual a Imagem é criada.
|
properties.storageProfile
|
ImageStorageProfile
|
Especifica as configurações de armazenamento dos discos da máquina virtual.
|
tags
|
object
|
Marcações de recursos
|
type
|
string
|
Tipo de recurso
|
ImageDataDisk
Descreve um disco de dados.
Nome |
Tipo |
Description |
blobUri
|
string
|
O Disco Rígido Virtual.
|
caching
|
CachingTypes
|
Especifica os requisitos de cache. Os valores possíveis são: None,ReadOnly,ReadWrite. Os valores padrão são: Nenhum para armazenamento Standard. ReadOnly para armazenamento Premium.
|
diskEncryptionSet
|
DiskEncryptionSetParameters
|
Especifica a ID do recurso do conjunto de criptografia de disco gerenciado pelo cliente para o disco de imagem gerenciada.
|
diskSizeGB
|
integer
|
Especifica o tamanho de discos de dados vazios em gigabytes. Esse elemento pode ser usado para substituir o nome do disco em uma imagem de máquina virtual. Esse valor não pode ser maior que 1023 GB.
|
lun
|
integer
|
Especifica o número da unidade lógica do disco de dados. Esse valor é usado para identificar discos de dados dentro da VM e, portanto, deve ser exclusivo para cada disco de dados anexado a uma VM.
|
managedDisk
|
SubResource
|
O managedDisk.
|
snapshot
|
SubResource
|
O instantâneo.
|
storageAccountType
|
StorageAccountTypes
|
Especifica o tipo de conta de armazenamento para o disco gerenciado. OBSERVAÇÃO: UltraSSD_LRS só pode ser usado com discos de dados, ele não pode ser usado com disco do sistema operacional.
|
ImageOSDisk
Descreve um disco do sistema operacional.
Nome |
Tipo |
Description |
blobUri
|
string
|
O Disco Rígido Virtual.
|
caching
|
CachingTypes
|
Especifica os requisitos de cache. Os valores possíveis são: None,ReadOnly,ReadWrite. Os valores padrão são: Nenhum para armazenamento Standard. ReadOnly para armazenamento Premium.
|
diskEncryptionSet
|
DiskEncryptionSetParameters
|
Especifica a ID do recurso do conjunto de criptografia de disco gerenciado pelo cliente para o disco de imagem gerenciada.
|
diskSizeGB
|
integer
|
Especifica o tamanho de discos de dados vazios em gigabytes. Esse elemento pode ser usado para substituir o nome do disco em uma imagem de máquina virtual. Esse valor não pode ser maior que 1023 GB.
|
managedDisk
|
SubResource
|
O managedDisk.
|
osState
|
OperatingSystemStateTypes
|
O estado do sistema operacional. Para imagens gerenciadas, use Generalizado.
|
osType
|
OperatingSystemTypes
|
Essa propriedade permite que você especifique o tipo do sistema operacional incluído no disco se estiver criando uma VM de uma imagem personalizada. Os valores possíveis são: Windows,Linux.
|
snapshot
|
SubResource
|
O instantâneo.
|
storageAccountType
|
StorageAccountTypes
|
Especifica o tipo de conta de armazenamento para o disco gerenciado. OBSERVAÇÃO: UltraSSD_LRS só pode ser usado com discos de dados, ele não pode ser usado com disco do sistema operacional.
|
ImageStorageProfile
Descreve um perfil de armazenamento.
Nome |
Tipo |
Description |
dataDisks
|
ImageDataDisk[]
|
Especifica os parâmetros que são usados para adicionar um disco de dados a uma máquina virtual.
Para obter mais informações sobre discos, consulte Sobre discos e VHDs para máquinas virtuais do Azure.
|
osDisk
|
ImageOSDisk
|
Especifica informações sobre o disco do sistema operacional usado pela máquina virtual.
Para obter mais informações sobre discos, consulte Sobre discos e VHDs para máquinas virtuais do Azure.
|
zoneResilient
|
boolean
|
Especifica se uma imagem é resiliente à zona ou não. O padrão é false. As imagens resilientes à zona só podem ser criadas em regiões que fornecem ZRS (Armazenamento com Redundância de Zona).
|
InnerError
Detalhes do erro interno.
Nome |
Tipo |
Description |
errordetail
|
string
|
A mensagem de erro interna ou despejo de exceção.
|
exceptiontype
|
string
|
O tipo de exceção.
|
OperatingSystemStateTypes
O estado do sistema operacional. Para imagens gerenciadas, use Generalizado.
Nome |
Tipo |
Description |
Generalized
|
string
|
Imagem generalizada. Precisa ser provisionado durante o tempo de implantação.
|
Specialized
|
string
|
Imagem especializada. Contém disco do sistema operacional já provisionado.
|
OperatingSystemTypes
Essa propriedade permite que você especifique o tipo do sistema operacional incluído no disco se estiver criando uma VM de uma imagem personalizada. Os valores possíveis são: Windows,Linux.
Nome |
Tipo |
Description |
Linux
|
string
|
|
Windows
|
string
|
|
StorageAccountTypes
Especifica o tipo de conta de armazenamento para o disco gerenciado. OBSERVAÇÃO: UltraSSD_LRS só pode ser usado com discos de dados, ele não pode ser usado com disco do sistema operacional.
Nome |
Tipo |
Description |
PremiumV2_LRS
|
string
|
|
Premium_LRS
|
string
|
|
Premium_ZRS
|
string
|
|
StandardSSD_LRS
|
string
|
|
StandardSSD_ZRS
|
string
|
|
Standard_LRS
|
string
|
|
UltraSSD_LRS
|
string
|
|
SubResource
Nome |
Tipo |
Description |
id
|
string
|
ID do recurso
|