Create or update an image.
PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/images/{imageName}?api-version=2024-07-01
URI Parameters
Name |
In |
Required |
Type |
Description |
imageName
|
path |
True
|
string
|
The name of the image.
|
resourceGroupName
|
path |
True
|
string
|
The name of the resource group.
|
subscriptionId
|
path |
True
|
string
|
Subscription credentials which uniquely identify Microsoft Azure subscription. The subscription ID forms part of the URI for every service call.
|
api-version
|
query |
True
|
string
|
Client Api Version.
|
Request Body
Name |
Required |
Type |
Description |
location
|
True
|
string
|
Resource location
|
extendedLocation
|
|
ExtendedLocation
|
The extended location of the Image.
|
properties.hyperVGeneration
|
|
HyperVGenerationTypes
|
Specifies the HyperVGenerationType of the VirtualMachine created from the image. From API Version 2019-03-01 if the image source is a blob, then we need the user to specify the value, if the source is managed resource like disk or snapshot, we may require the user to specify the property if we cannot deduce it from the source managed resource.
|
properties.sourceVirtualMachine
|
|
SubResource
|
The source virtual machine from which Image is created.
|
properties.storageProfile
|
|
ImageStorageProfile
|
Specifies the storage settings for the virtual machine disks.
|
tags
|
|
object
|
Resource tags
|
Responses
Name |
Type |
Description |
200 OK
|
Image
|
OK
|
201 Created
|
Image
|
Created
|
Other Status Codes
|
CloudError
|
Error response describing why the operation failed.
|
Security
azure_auth
Azure Active Directory OAuth2 Flow
Type:
oauth2
Flow:
implicit
Authorization URL:
https://login.microsoftonline.com/common/oauth2/authorize
Scopes
Name |
Description |
user_impersonation
|
impersonate your user account
|
Examples
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-07-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"
}
}
}
}
import com.azure.resourcemanager.compute.fluent.models.ImageInner;
import com.azure.resourcemanager.compute.models.DiskEncryptionSetParameters;
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;
/**
* Samples for Images CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-07-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);
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
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-07-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/v6"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/c7b98b36e4023331545051284d8500adf98f02fe/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-07-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-07-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
using Azure;
using Azure.ResourceManager;
using System;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager.Compute.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Compute;
// Generated from example definition: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-07-01/examples/imageExamples/Image_CreateFromABlobWithDiskEncryptionSet.json
// this example is just showing the usage of "Images_CreateOrUpdate" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this ResourceGroupResource created on azure
// for more information of creating ResourceGroupResource, please refer to the document of ResourceGroupResource
string subscriptionId = "{subscription-id}";
string resourceGroupName = "myResourceGroup";
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
// get the collection of this DiskImageResource
DiskImageCollection collection = resourceGroupResource.GetDiskImages();
// invoke the operation
string imageName = "myImage";
DiskImageData data = new DiskImageData(new AzureLocation("West US"))
{
StorageProfile = new ImageStorageProfile()
{
OSDisk = new ImageOSDisk(SupportedOperatingSystemType.Linux, OperatingSystemStateType.Generalized)
{
BlobUri = new Uri("https://mystorageaccount.blob.core.windows.net/osimages/osimage.vhd"),
DiskEncryptionSetId = new ResourceIdentifier("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"),
},
},
};
ArmOperation<DiskImageResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, imageName, data);
DiskImageResource result = lro.Value;
// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
DiskImageData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
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-07-01
{
"location": "West US",
"properties": {
"storageProfile": {
"osDisk": {
"osType": "Linux",
"blobUri": "https://mystorageaccount.blob.core.windows.net/osimages/osimage.vhd",
"osState": "Generalized"
},
"zoneResilient": true
}
}
}
import com.azure.resourcemanager.compute.fluent.models.ImageInner;
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;
/**
* Samples for Images CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-07-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);
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
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-07-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/v6"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/c7b98b36e4023331545051284d8500adf98f02fe/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-07-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-07-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
using Azure;
using Azure.ResourceManager;
using System;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager.Compute.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Compute;
// Generated from example definition: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-07-01/examples/imageExamples/Image_CreateFromABlob.json
// this example is just showing the usage of "Images_CreateOrUpdate" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this ResourceGroupResource created on azure
// for more information of creating ResourceGroupResource, please refer to the document of ResourceGroupResource
string subscriptionId = "{subscription-id}";
string resourceGroupName = "myResourceGroup";
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
// get the collection of this DiskImageResource
DiskImageCollection collection = resourceGroupResource.GetDiskImages();
// invoke the operation
string imageName = "myImage";
DiskImageData data = new DiskImageData(new AzureLocation("West US"))
{
StorageProfile = new ImageStorageProfile()
{
OSDisk = new ImageOSDisk(SupportedOperatingSystemType.Linux, OperatingSystemStateType.Generalized)
{
BlobUri = new Uri("https://mystorageaccount.blob.core.windows.net/osimages/osimage.vhd"),
},
ZoneResilient = true,
},
};
ArmOperation<DiskImageResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, imageName, data);
DiskImageResource result = lro.Value;
// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
DiskImageData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
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-07-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"
}
}
}
}
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.ImageOSDisk;
import com.azure.resourcemanager.compute.models.ImageStorageProfile;
import com.azure.resourcemanager.compute.models.OperatingSystemStateTypes;
import com.azure.resourcemanager.compute.models.OperatingSystemTypes;
/**
* Samples for Images CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-07-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);
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
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-07-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/v6"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/c7b98b36e4023331545051284d8500adf98f02fe/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-07-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-07-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
using Azure;
using Azure.ResourceManager;
using System;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager.Compute.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Compute;
// Generated from example definition: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-07-01/examples/imageExamples/Image_CreateFromAManagedDiskWithDiskEncryptionSet.json
// this example is just showing the usage of "Images_CreateOrUpdate" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this ResourceGroupResource created on azure
// for more information of creating ResourceGroupResource, please refer to the document of ResourceGroupResource
string subscriptionId = "{subscription-id}";
string resourceGroupName = "myResourceGroup";
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
// get the collection of this DiskImageResource
DiskImageCollection collection = resourceGroupResource.GetDiskImages();
// invoke the operation
string imageName = "myImage";
DiskImageData data = new DiskImageData(new AzureLocation("West US"))
{
StorageProfile = new ImageStorageProfile()
{
OSDisk = new ImageOSDisk(SupportedOperatingSystemType.Linux, OperatingSystemStateType.Generalized)
{
SnapshotId = new ResourceIdentifier("subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/mySnapshot"),
DiskEncryptionSetId = new ResourceIdentifier("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"),
},
},
};
ArmOperation<DiskImageResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, imageName, data);
DiskImageResource result = lro.Value;
// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
DiskImageData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
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-07-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
}
}
}
import com.azure.core.management.SubResource;
import com.azure.resourcemanager.compute.fluent.models.ImageInner;
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;
/**
* Samples for Images CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-07-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);
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
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-07-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/v6"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/c7b98b36e4023331545051284d8500adf98f02fe/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-07-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-07-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
using Azure;
using Azure.ResourceManager;
using System;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager.Compute.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Compute;
// Generated from example definition: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-07-01/examples/imageExamples/Image_CreateFromAManagedDisk.json
// this example is just showing the usage of "Images_CreateOrUpdate" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this ResourceGroupResource created on azure
// for more information of creating ResourceGroupResource, please refer to the document of ResourceGroupResource
string subscriptionId = "{subscription-id}";
string resourceGroupName = "myResourceGroup";
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
// get the collection of this DiskImageResource
DiskImageCollection collection = resourceGroupResource.GetDiskImages();
// invoke the operation
string imageName = "myImage";
DiskImageData data = new DiskImageData(new AzureLocation("West US"))
{
StorageProfile = new ImageStorageProfile()
{
OSDisk = new ImageOSDisk(SupportedOperatingSystemType.Linux, OperatingSystemStateType.Generalized)
{
ManagedDiskId = new ResourceIdentifier("subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/myManagedDisk"),
},
ZoneResilient = true,
},
};
ArmOperation<DiskImageResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, imageName, data);
DiskImageResource result = lro.Value;
// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
DiskImageData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
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-07-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"
}
}
}
}
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.ImageOSDisk;
import com.azure.resourcemanager.compute.models.ImageStorageProfile;
import com.azure.resourcemanager.compute.models.OperatingSystemStateTypes;
import com.azure.resourcemanager.compute.models.OperatingSystemTypes;
/**
* Samples for Images CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-07-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);
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
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-07-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/v6"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/c7b98b36e4023331545051284d8500adf98f02fe/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-07-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-07-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
using Azure;
using Azure.ResourceManager;
using System;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager.Compute.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Compute;
// Generated from example definition: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-07-01/examples/imageExamples/Image_CreateFromASnapshotWithDiskEncryptionSet.json
// this example is just showing the usage of "Images_CreateOrUpdate" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this ResourceGroupResource created on azure
// for more information of creating ResourceGroupResource, please refer to the document of ResourceGroupResource
string subscriptionId = "{subscription-id}";
string resourceGroupName = "myResourceGroup";
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
// get the collection of this DiskImageResource
DiskImageCollection collection = resourceGroupResource.GetDiskImages();
// invoke the operation
string imageName = "myImage";
DiskImageData data = new DiskImageData(new AzureLocation("West US"))
{
StorageProfile = new ImageStorageProfile()
{
OSDisk = new ImageOSDisk(SupportedOperatingSystemType.Linux, OperatingSystemStateType.Generalized)
{
ManagedDiskId = new ResourceIdentifier("subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/myManagedDisk"),
DiskEncryptionSetId = new ResourceIdentifier("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/diskEncryptionSets/{existing-diskEncryptionSet-name}"),
},
},
};
ArmOperation<DiskImageResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, imageName, data);
DiskImageResource result = lro.Value;
// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
DiskImageData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
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-07-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
}
}
}
import com.azure.core.management.SubResource;
import com.azure.resourcemanager.compute.fluent.models.ImageInner;
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;
/**
* Samples for Images CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-07-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);
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
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-07-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/v6"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/c7b98b36e4023331545051284d8500adf98f02fe/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-07-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-07-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
using Azure;
using Azure.ResourceManager;
using System;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager.Compute.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Compute;
// Generated from example definition: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-07-01/examples/imageExamples/Image_CreateFromASnapshot.json
// this example is just showing the usage of "Images_CreateOrUpdate" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this ResourceGroupResource created on azure
// for more information of creating ResourceGroupResource, please refer to the document of ResourceGroupResource
string subscriptionId = "{subscription-id}";
string resourceGroupName = "myResourceGroup";
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
// get the collection of this DiskImageResource
DiskImageCollection collection = resourceGroupResource.GetDiskImages();
// invoke the operation
string imageName = "myImage";
DiskImageData data = new DiskImageData(new AzureLocation("West US"))
{
StorageProfile = new ImageStorageProfile()
{
OSDisk = new ImageOSDisk(SupportedOperatingSystemType.Linux, OperatingSystemStateType.Generalized)
{
SnapshotId = new ResourceIdentifier("subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/mySnapshot"),
},
ZoneResilient = false,
},
};
ArmOperation<DiskImageResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, imageName, data);
DiskImageResource result = lro.Value;
// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
DiskImageData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
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-07-01
{
"location": "West US",
"properties": {
"sourceVirtualMachine": {
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"
}
}
}
import com.azure.core.management.SubResource;
import com.azure.resourcemanager.compute.fluent.models.ImageInner;
/**
* Samples for Images CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file:
* specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-07-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);
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
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-07-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/v6"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/c7b98b36e4023331545051284d8500adf98f02fe/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-07-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-07-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
using Azure;
using Azure.ResourceManager;
using System;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager.Compute.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Compute;
// Generated from example definition: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-07-01/examples/imageExamples/Image_CreateFromAVM.json
// this example is just showing the usage of "Images_CreateOrUpdate" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this ResourceGroupResource created on azure
// for more information of creating ResourceGroupResource, please refer to the document of ResourceGroupResource
string subscriptionId = "{subscription-id}";
string resourceGroupName = "myResourceGroup";
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
// get the collection of this DiskImageResource
DiskImageCollection collection = resourceGroupResource.GetDiskImages();
// invoke the operation
string imageName = "myImage";
DiskImageData data = new DiskImageData(new AzureLocation("West US"))
{
SourceVirtualMachineId = new ResourceIdentifier("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM"),
};
ArmOperation<DiskImageResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, imageName, data);
DiskImageResource result = lro.Value;
// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
DiskImageData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
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-07-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
}
}
}
import com.azure.resourcemanager.compute.fluent.models.ImageInner;
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-07-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);
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
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-07-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/v6"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/c7b98b36e4023331545051284d8500adf98f02fe/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-07-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-07-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
using Azure;
using Azure.ResourceManager;
using System;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager.Compute.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Compute;
// Generated from example definition: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-07-01/examples/imageExamples/Image_Create_DataDiskFromABlobIncluded.json
// this example is just showing the usage of "Images_CreateOrUpdate" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this ResourceGroupResource created on azure
// for more information of creating ResourceGroupResource, please refer to the document of ResourceGroupResource
string subscriptionId = "{subscription-id}";
string resourceGroupName = "myResourceGroup";
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
// get the collection of this DiskImageResource
DiskImageCollection collection = resourceGroupResource.GetDiskImages();
// invoke the operation
string imageName = "myImage";
DiskImageData data = new DiskImageData(new AzureLocation("West US"))
{
StorageProfile = new ImageStorageProfile()
{
OSDisk = new ImageOSDisk(SupportedOperatingSystemType.Linux, OperatingSystemStateType.Generalized)
{
BlobUri = new Uri("https://mystorageaccount.blob.core.windows.net/osimages/osimage.vhd"),
},
DataDisks =
{
new ImageDataDisk(1)
{
BlobUri = new Uri("https://mystorageaccount.blob.core.windows.net/dataimages/dataimage.vhd"),
}
},
ZoneResilient = false,
},
};
ArmOperation<DiskImageResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, imageName, data);
DiskImageResource result = lro.Value;
// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
DiskImageData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
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-07-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
}
}
}
import com.azure.core.management.SubResource;
import com.azure.resourcemanager.compute.fluent.models.ImageInner;
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-07-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
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-07-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/v6"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/c7b98b36e4023331545051284d8500adf98f02fe/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-07-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-07-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
using Azure;
using Azure.ResourceManager;
using System;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager.Compute.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Compute;
// Generated from example definition: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-07-01/examples/imageExamples/Image_Create_DataDiskFromAManagedDiskIncluded.json
// this example is just showing the usage of "Images_CreateOrUpdate" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this ResourceGroupResource created on azure
// for more information of creating ResourceGroupResource, please refer to the document of ResourceGroupResource
string subscriptionId = "{subscription-id}";
string resourceGroupName = "myResourceGroup";
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
// get the collection of this DiskImageResource
DiskImageCollection collection = resourceGroupResource.GetDiskImages();
// invoke the operation
string imageName = "myImage";
DiskImageData data = new DiskImageData(new AzureLocation("West US"))
{
StorageProfile = new ImageStorageProfile()
{
OSDisk = new ImageOSDisk(SupportedOperatingSystemType.Linux, OperatingSystemStateType.Generalized)
{
ManagedDiskId = new ResourceIdentifier("subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/myManagedDisk"),
},
DataDisks =
{
new ImageDataDisk(1)
{
ManagedDiskId = new ResourceIdentifier("subscriptions/{subscriptionId}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/myManagedDisk2"),
}
},
ZoneResilient = false,
},
};
ArmOperation<DiskImageResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, imageName, data);
DiskImageResource result = lro.Value;
// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
DiskImageData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
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-07-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
}
}
}
import com.azure.core.management.SubResource;
import com.azure.resourcemanager.compute.fluent.models.ImageInner;
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-07-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);
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
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-07-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/v6"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/c7b98b36e4023331545051284d8500adf98f02fe/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-07-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-07-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
using Azure;
using Azure.ResourceManager;
using System;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager.Compute.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Compute;
// Generated from example definition: specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-07-01/examples/imageExamples/Image_Create_DataDiskFromASnapshotIncluded.json
// this example is just showing the usage of "Images_CreateOrUpdate" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this ResourceGroupResource created on azure
// for more information of creating ResourceGroupResource, please refer to the document of ResourceGroupResource
string subscriptionId = "{subscription-id}";
string resourceGroupName = "myResourceGroup";
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
// get the collection of this DiskImageResource
DiskImageCollection collection = resourceGroupResource.GetDiskImages();
// invoke the operation
string imageName = "myImage";
DiskImageData data = new DiskImageData(new AzureLocation("West US"))
{
StorageProfile = new ImageStorageProfile()
{
OSDisk = new ImageOSDisk(SupportedOperatingSystemType.Linux, OperatingSystemStateType.Generalized)
{
SnapshotId = new ResourceIdentifier("subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/mySnapshot"),
},
DataDisks =
{
new ImageDataDisk(1)
{
SnapshotId = new ResourceIdentifier("subscriptions/{subscriptionId}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/snapshots/mySnapshot2"),
}
},
ZoneResilient = true,
},
};
ArmOperation<DiskImageResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, imageName, data);
DiskImageResource result = lro.Value;
// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
DiskImageData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
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"
}
Definitions
Name |
Description |
ApiError
|
Api error.
|
ApiErrorBase
|
Api error base.
|
CachingTypes
|
Specifies the caching requirements. Possible values are: None, ReadOnly, ReadWrite. The default values are: None for Standard storage. ReadOnly for Premium storage.
|
CloudError
|
An error response from the Compute service.
|
DiskEncryptionSetParameters
|
Describes the parameter of customer managed disk encryption set resource id that can be specified for disk. Note: The disk encryption set resource id can only be specified for managed disk. Please refer https://aka.ms/mdssewithcmkoverview for more details.
|
ExtendedLocation
|
The complex type of the extended location.
|
ExtendedLocationTypes
|
The type of the extended location.
|
HyperVGenerationTypes
|
Specifies the HyperVGenerationType of the VirtualMachine created from the image. From API Version 2019-03-01 if the image source is a blob, then we need the user to specify the value, if the source is managed resource like disk or snapshot, we may require the user to specify the property if we cannot deduce it from the source managed resource.
|
Image
|
The source user image virtual hard disk. The virtual hard disk will be copied before being attached to the virtual machine. If SourceImage is provided, the destination virtual hard drive must not exist.
|
ImageDataDisk
|
Describes a data disk.
|
ImageOSDisk
|
Describes an Operating System disk.
|
ImageStorageProfile
|
Describes a storage profile.
|
InnerError
|
Inner error details.
|
OperatingSystemStateTypes
|
The OS State. For managed images, use Generalized.
|
OperatingSystemTypes
|
This property allows you to specify the type of the OS that is included in the disk if creating a VM from a custom image. Possible values are: Windows, Linux.
|
StorageAccountTypes
|
Specifies the storage account type for the managed disk. NOTE: UltraSSD_LRS can only be used with data disks, it cannot be used with OS Disk.
|
SubResource
|
|
ApiError
Api error.
Name |
Type |
Description |
code
|
string
|
The error code.
|
details
|
ApiErrorBase[]
|
The Api error details
|
innererror
|
InnerError
|
The Api inner error
|
message
|
string
|
The error message.
|
target
|
string
|
The target of the particular error.
|
ApiErrorBase
Api error base.
Name |
Type |
Description |
code
|
string
|
The error code.
|
message
|
string
|
The error message.
|
target
|
string
|
The target of the particular error.
|
CachingTypes
Specifies the caching requirements. Possible values are: None, ReadOnly, ReadWrite. The default values are: None for Standard storage. ReadOnly for Premium storage.
Name |
Type |
Description |
None
|
string
|
|
ReadOnly
|
string
|
|
ReadWrite
|
string
|
|
CloudError
An error response from the Compute service.
Name |
Type |
Description |
error
|
ApiError
|
Api error.
|
DiskEncryptionSetParameters
Describes the parameter of customer managed disk encryption set resource id that can be specified for disk. Note: The disk encryption set resource id can only be specified for managed disk. Please refer https://aka.ms/mdssewithcmkoverview for more details.
Name |
Type |
Description |
id
|
string
|
Resource Id
|
ExtendedLocation
The complex type of the extended location.
Name |
Type |
Description |
name
|
string
|
The name of the extended location.
|
type
|
ExtendedLocationTypes
|
The type of the extended location.
|
ExtendedLocationTypes
The type of the extended location.
Name |
Type |
Description |
EdgeZone
|
string
|
|
HyperVGenerationTypes
Specifies the HyperVGenerationType of the VirtualMachine created from the image. From API Version 2019-03-01 if the image source is a blob, then we need the user to specify the value, if the source is managed resource like disk or snapshot, we may require the user to specify the property if we cannot deduce it from the source managed resource.
Name |
Type |
Description |
V1
|
string
|
|
V2
|
string
|
|
Image
The source user image virtual hard disk. The virtual hard disk will be copied before being attached to the virtual machine. If SourceImage is provided, the destination virtual hard drive must not exist.
Name |
Type |
Description |
extendedLocation
|
ExtendedLocation
|
The extended location of the Image.
|
id
|
string
|
Resource Id
|
location
|
string
|
Resource location
|
name
|
string
|
Resource name
|
properties.hyperVGeneration
|
HyperVGenerationTypes
|
Specifies the HyperVGenerationType of the VirtualMachine created from the image. From API Version 2019-03-01 if the image source is a blob, then we need the user to specify the value, if the source is managed resource like disk or snapshot, we may require the user to specify the property if we cannot deduce it from the source managed resource.
|
properties.provisioningState
|
string
|
The provisioning state.
|
properties.sourceVirtualMachine
|
SubResource
|
The source virtual machine from which Image is created.
|
properties.storageProfile
|
ImageStorageProfile
|
Specifies the storage settings for the virtual machine disks.
|
tags
|
object
|
Resource tags
|
type
|
string
|
Resource type
|
ImageDataDisk
Describes a data disk.
Name |
Type |
Description |
blobUri
|
string
|
The Virtual Hard Disk.
|
caching
|
CachingTypes
|
Specifies the caching requirements. Possible values are: None, ReadOnly, ReadWrite. The default values are: None for Standard storage. ReadOnly for Premium storage.
|
diskEncryptionSet
|
DiskEncryptionSetParameters
|
Specifies the customer managed disk encryption set resource id for the managed image disk.
|
diskSizeGB
|
integer
|
Specifies the size of empty data disks in gigabytes. This element can be used to overwrite the name of the disk in a virtual machine image. This value cannot be larger than 1023 GB.
|
lun
|
integer
|
Specifies the logical unit number of the data disk. This value is used to identify data disks within the VM and therefore must be unique for each data disk attached to a VM.
|
managedDisk
|
SubResource
|
The managedDisk.
|
snapshot
|
SubResource
|
The snapshot.
|
storageAccountType
|
StorageAccountTypes
|
Specifies the storage account type for the managed disk. NOTE: UltraSSD_LRS can only be used with data disks, it cannot be used with OS Disk.
|
ImageOSDisk
Describes an Operating System disk.
Name |
Type |
Description |
blobUri
|
string
|
The Virtual Hard Disk.
|
caching
|
CachingTypes
|
Specifies the caching requirements. Possible values are: None, ReadOnly, ReadWrite. The default values are: None for Standard storage. ReadOnly for Premium storage.
|
diskEncryptionSet
|
DiskEncryptionSetParameters
|
Specifies the customer managed disk encryption set resource id for the managed image disk.
|
diskSizeGB
|
integer
|
Specifies the size of empty data disks in gigabytes. This element can be used to overwrite the name of the disk in a virtual machine image. This value cannot be larger than 1023 GB.
|
managedDisk
|
SubResource
|
The managedDisk.
|
osState
|
OperatingSystemStateTypes
|
The OS State. For managed images, use Generalized.
|
osType
|
OperatingSystemTypes
|
This property allows you to specify the type of the OS that is included in the disk if creating a VM from a custom image. Possible values are: Windows, Linux.
|
snapshot
|
SubResource
|
The snapshot.
|
storageAccountType
|
StorageAccountTypes
|
Specifies the storage account type for the managed disk. NOTE: UltraSSD_LRS can only be used with data disks, it cannot be used with OS Disk.
|
ImageStorageProfile
Describes a storage profile.
Name |
Type |
Description |
dataDisks
|
ImageDataDisk[]
|
Specifies the parameters that are used to add a data disk to a virtual machine.
For more information about disks, see About disks and VHDs for Azure virtual machines.
|
osDisk
|
ImageOSDisk
|
Specifies information about the operating system disk used by the virtual machine.
For more information about disks, see About disks and VHDs for Azure virtual machines.
|
zoneResilient
|
boolean
|
Specifies whether an image is zone resilient or not. Default is false. Zone resilient images can be created only in regions that provide Zone Redundant Storage (ZRS).
|
InnerError
Inner error details.
Name |
Type |
Description |
errordetail
|
string
|
The internal error message or exception dump.
|
exceptiontype
|
string
|
The exception type.
|
OperatingSystemStateTypes
The OS State. For managed images, use Generalized.
Name |
Type |
Description |
Generalized
|
string
|
Generalized image. Needs to be provisioned during deployment time.
|
Specialized
|
string
|
Specialized image. Contains already provisioned OS Disk.
|
OperatingSystemTypes
This property allows you to specify the type of the OS that is included in the disk if creating a VM from a custom image. Possible values are: Windows, Linux.
Name |
Type |
Description |
Linux
|
string
|
|
Windows
|
string
|
|
StorageAccountTypes
Specifies the storage account type for the managed disk. NOTE: UltraSSD_LRS can only be used with data disks, it cannot be used with OS Disk.
Name |
Type |
Description |
PremiumV2_LRS
|
string
|
|
Premium_LRS
|
string
|
|
Premium_ZRS
|
string
|
|
StandardSSD_LRS
|
string
|
|
StandardSSD_ZRS
|
string
|
|
Standard_LRS
|
string
|
|
UltraSSD_LRS
|
string
|
|
SubResource
Name |
Type |
Description |
id
|
string
|
Resource Id
|