java - 如何使用最新的 SDK 启动 Azure VM 异步

标签 java azure sdk virtual-machine

使用最新的azure java sdk -

<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure</artifactId>
<version>1.0.0-beta4</version>

<小时/>
  1. 如何同步创建虚拟机并监控进度?

  2. ComputeManagementClient 不支持 clientId、租户类型身份验证。它使用证书和所有内容。

  3. 互联网上没有任何示例。 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/

相关文章:

java - 防止使用共享内存

java - 单击单选按钮时如何显示微调器

java 。扩展 Object 的类中的 super 调用

azure - azure 数据工厂中的长时间重试

c++ - vs2015中的intel实感sdk编程

java - 如何统计Stream已处理的元素数量?

wcf - 如何让网站 Ping ARR 服务器并说我要宕机了?

caching - Windows Azure 是否具有 Web 缓存功能?

unity3d - 如何在Unity应用中设置和使用Kin区 block 链-逐步

android - Facebook SDK Android 不断加载