问题描述

Azure 门户创建 ARM 虚拟机时,我们直接可以选择虚拟机的磁盘类型,但是在 Azure Management Libraries for Java 的 API 中我们无法找到直接设置磁盘类型的 API.默认创建的磁盘类型是 HDD,如何通过 API 设置磁盘类型?

问题分析

系统磁盘或数据磁盘的类型取决于使用的存储账户类型,如果是基于普通存储账户创建的磁盘,则磁盘类型为 HDD;如果是基于高级存储创建的磁盘,则磁盘类型为 SDD。更多信息参考:

解决方法

认证凭据

在使用 Azure Management Libraries for Java 时,我们需要通过 AD Application 进行授权认证。建议使用最新版 Powershell 按以下脚本操作:

 
# 1.在 PowerShell 中,登录 Azure 账户
Login-AzureRmAccount -EnvironmentName AzureChinaCloud # 2.选择当前订阅 ID
Set-AzureRmContext -SubscriptionId "订阅 ID" # 3.创建 AD Application
$azureAdApplication = New-AzureRmADApplication -DisplayName "georgeapp" -HomePage "https://www.georgeapp.org" -IdentifierUris "https://www.georgeapp.org/example" -Password "1QAZxsw2"
$azureAdApplication # 4.为你的 AD 应用创建服务凭证
New-AzureRmADServicePrincipal -ApplicationId $azureAdApplication.ApplicationId # 5.为服务凭证授权。如果想了解更多内容,请参考:https://azure.microsoft.com/en-us/documentation/articles/role-based-access-control-what-is/
New-AzureRmRoleAssignment -RoleDefinitionName Contributor -ServicePrincipalName $azureAdApplication.ApplicationId

执行上述操作后,就可以获取可用的认证凭据信息:

  • tentant-id:第二步执行完成后返回
  • application-id:第三步执行完成后返回
  • application-password:第三步中设置的 Password

代码实现

 
public void createWindows(
String resourceGroupName,
String vmName,
String vmStorageAccountName,
String vmUserName,
String vmPassword,
KnownWindowsVirtualMachineImage vmImage,
Region vmRegion,
VirtualMachineSizeTypes vmSize) throws Exception { if (azure == null) {
return;
} StorageAccount storageAccount =azure
.storageAccounts()
.getByGroup(resourceGroupName, vmStorageAccountName);
VirtualMachine windowsVM = azure
.virtualMachines()
.define(vmName)
.withRegion(vmRegion)
.withNewResourceGroup(resourceGroupName)
.withNewPrimaryNetwork("10.0.0.0/28")
.withPrimaryPrivateIpAddressDynamic()
.withoutPrimaryPublicIpAddress()
.withPopularWindowsImage(vmImage)
.withAdminUserName(vmUserName)
.withPassword(vmPassword)
.withNewDataDisk(10)
.withExistingStorageAccount(storageAccount)
.withSize(vmSize).create();
} @org.junit.Test
public void test() throws Exception {
VmOperation vmOp = new VmOperation(
"tentant-id",
"application-id",
"application-password",
"subId"); vmOp.createWindows(
"资源组",
"虚拟机名称",
"存储账户名称",
"虚拟机 RDP 用户名",
"虚拟机 RDP 密码",
"虚拟机 Image",
"虚拟机 Region",
"虚拟机 Size");

测试结果

  • 设定为普通存储账户

  • 设定为高级存储账户

                                                                                                                                               立即访问http://market.azure.cn

最新文章

  1. LVS集群之DR模式 实现
  2. 基于对话框的MFC应用程序基本结构
  3. 谁可以说出HashMap和HashSet的相同点和不同点。
  4. bzoj1079: [SCOI2008]着色方案
  5. GCC生成的汇编代码
  6. python - XML文件及其操作
  7. WebBrowser中取对应的图片资源
  8. highcharts分段显示不同颜色
  9. 在Android Studio上测试运行,Unity发布成Android包的环境搭建步骤
  10. spring-boot学习笔记之Conditional
  11. Windows远程桌面卡的解决办法
  12. zeros()和ones()和eye()
  13. AX_xSession
  14. Go语言中的struct tag
  15. BlackHat Arsenal USA 2018 ToolsWatch黑客工具库
  16. Django model 字段类型及选项解析
  17. vue-cli快速原型开发
  18. malloc用法整理
  19. Cracking The Coding Interview 3.5
  20. Java性能分析之线程栈详解与性能分析

热门文章

  1. MySql 碎片
  2. mutillidae之注册页面的Insert型报错注入
  3. 剑指offer——面试题15:二进制中 1的个数
  4. linux中终端字体样式显示不正常
  5. spring初始化bean的目的
  6. python 学习笔记一——Python安装和IDLE使用
  7. Oracle RAC集群删除节点
  8. shell 进阶变量的指定 declare
  9. Nginx设置日志分割方法
  10. Tor网络介绍