使用最新的azure java sdk -
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure</artifactId>
<version>1.0.0-beta4</version>
<小时/>
如何同步创建虚拟机并监控进度?
ComputeManagementClient 不支持 clientId、租户类型身份验证。它使用证书和所有内容。
互联网上没有任何示例。 github页面上只有同步示例:https://github.com/Azure-Samples/compute-java-manage-vm
请回复此内容。我发现即使在 Microsoft 论坛上,他们的响应也不是很灵敏。
最佳答案
这是我的代码示例,供您引用。
import com.microsoft.azure.AzureEnvironment;
import com.microsoft.azure.CloudException;
import com.microsoft.azure.credentials.ApplicationTokenCredentials;
import com.microsoft.azure.credentials.AzureTokenCredentials;
import com.microsoft.azure.management.Azure;
import com.microsoft.azure.management.compute.PowerState;
import com.microsoft.azure.management.compute.VirtualMachine;
import okhttp3.logging.HttpLoggingInterceptor;
String clientId = "xxxxx";
String domain = "xxxxx";
String secret = "xxxxx";
AzureEnvironment environment = AzureEnvironment.AZURE;
/*
* Or you can use the code `new AzureEnvironment(String authenticationEndpoint, String managementEndpoint, String resourceManagerEndpoint, String graphEndpoint)`,
* please see http://azure.github.io/azure-sdk-for-java/com/microsoft/azure/AzureEnvironment.html
*/
AzureTokenCredentials credentials = new ApplicationTokenCredentials(clientId, domain, secret, environment);
Azure azure = Azure.configure().withLogLevel(HttpLoggingInterceptor.Level.BASIC).authenticate(credentials).withDefaultSubscription();
// Get VM instance
String resourceGroup = "xxxx";
String vmName = "xxxx";
VirtualMachine vm = azure.virtualMachines().getByGroup(resourceGroup, vmName);
// Start the VM instance async
vm.start();
// Get the power status of the VM instance by polling
PowerState powerState = vm.powerState();
System.out.println(powerState);
上面代码中使用的API请引用javadocs http://azure.github.io/azure-sdk-for-java/ .
希望有帮助。
关于java - 如何使用最新的 SDK 启动 Azure VM 异步,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41353576/