Code to create Azure VM using Azure Java SDK

956 Views Asked by At

I need to create a Azure Virtual Machine using Azure Java SDK. I wants either code of some guideline for creating VM step by step.

1

There are 1 best solutions below

0
On

As I known, there are two ways for creating VM using Azure Java SDK. You can refer to their different REST APIs and authenticating request to know them.

  1. Create VM using Azure Resource Management (VM REST API require Authenticating Resource Manager Requests)
  2. Create VM (classic) using Azure Service Management (VM classic REST API require Authenticating Service Management Requests)

I recommend the first one to create an Azure VM. There is a offical sample code on GitHub, please see https://github.com/Azure/azure-sdk-for-java/blob/master/azure-mgmt-samples/src/main/java/com/microsoft/azure/samples/compute/CreateVMExample.java.

As reference, the steps are as below.

  1. Create a Configuration, please see https://github.com/Azure/azure-sdk-for-java/blob/master/azure-mgmt-samples/src/main/java/com/microsoft/azure/samples/authentication/ServicePrincipalExample.java to know more details.
  2. Create these client like ResourceManagementClient, StorageManagementClient, ComputeManagementClient & NetworkResourceProviderClient using the Configuration.
  3. Create the ResourceContent using ResouceGroupName & Region.
  4. Create a VM via the function createVM of the Helper ComputeHelper.

You also can refer to the javadocs of the package com.microsoft.azure.management for Azure Java SDK at http://azure.github.io/azure-sdk-for-java/.