0
votes

I used azure-storage-java to upload a vhd page blob to my storage account from a java application. But to create a virtual machine out of it using ARM template, the vhd should either be registered as an image or a disk, so that it shows up in image gallery while creating a vm. Is there any example of creating an image from a blob, programmatically using azure-sdk-for-java?

2
@J.Chomel, let me rephrase my question a bit, if i was not clear. I want my uploaded vhd to show up in image gallery, when i try to create a vm out of it. So, i want to 'register that vhd blob as an image' programmatically, using azure-sdk-for-javaharshitha bt
OK, my bad. removed.J. Chomel

2 Answers

0
votes

There is an example for creating VM using Azure SDK for Java, please see https://github.com/Azure/azure-sdk-for-java/blob/0.9/azure-mgmt-samples/src/main/java/com/microsoft/azure/samples/compute/CreateVMExample.java.

To understanding the example, you can refer to the section Create a Virtual Machine of the offical article "Azure Resource Manager SDK for Java".

As references, you can refer to these source codes on GitHub for understanding the help classes in the example code, such as ComputerHelper & ResourceContext.

0
votes

@harshitha, AFAIK,Currently Azure doesn't have the SDK/API to convert VHD as Image in ARM.We can operate it on Azure Portal or using Powershell. Another approach is that we can use Create VM Image REST API to create a VM Image in the image repository that is associated with the specified subscription using a specified set of virtual hard disks(https://msdn.microsoft.com/en-us/library/azure/dn775054.aspx ). You could call this REST API with Java code in your project. And then use the Peter pan's code sample to create your VM. Hope it helps.