1

I'm accessing a VM through an application I've created in the Active Directory. This application has full access to all the resources I'm trying to reach.

The problem is that the VM cannot be found. I'm able to access the VM's resource group, but Azure is reporting there are no VMs inside. Any idea why this might be happening?

My code:

ApplicationTokenCredentials credentials = new ApplicationTokenCredentials(client, tenant, key, AzureEnvironment.AZURE);
Azure azure = Azure.configure()
    .withLogLevel(LogLevel.NONE)
    .authenticate(credentials)
    .withSubscription(subscription);

VirtualMachine vm = azure.virtualMachines().getByResourceGroup(resourceGroup, vmName);
vm.start();
MultiplyByZer0
  • 6,302
  • 3
  • 32
  • 48
Praveen
  • 85
  • 7

1 Answers1

0

Do you ensure your subscription is right? I suggest you could print your subscription and check it. The following code works for me.

ApplicationTokenCredentials credentials = new ApplicationTokenCredentials(client, tenant, key, AzureEnvironment.AZURE);
Azure.Authenticated azureAuth = Azure.authenticate(credentials);
Azure azure = azureAuth.withSubscription(subscriptionid);
System.out.println("Selected subscription: " + azure.subscriptionId());

VirtualMachine vm = azure.virtualMachines().getByResourceGroup(resourceGroup, vmName);
System.out.println("Now VM is"+vm);
vm.start();

Update:

Please ensure your VM is a ARM mode VM, the code could not list classic VM.

Shui shengbao
  • 18,746
  • 3
  • 27
  • 45
  • The vm is in the correct resource group. I discovered the issue was because the vm was created in ASM and the SDK I am using only works with ARM vms. – Praveen Aug 09 '17 at 17:35