【发布时间】:2016-11-11 17:10:18
【问题描述】:
String cloudServiceDeployment = "imagevmtest";
url = String.format("https://management.core.windows.net/%s/services/hostedservices/%s/deployments", subscriptionId, cloudServiceDeployment);
String requestBody2 = "<?xml version=\"1.0\" encoding=\"utf-8\"?><Deployment xmlns=\"http://schemas.microsoft.com/windowsazure\"><Name>190bed4a</Name><DeploymentSlot>Production</DeploymentSlot><Label>190bed4a</Label><RoleList><Role><RoleName>SuseOpenVm_rolec8fc</RoleName><RoleType>PersistentVMRole</RoleType><ConfigurationSets><ConfigurationSet><ConfigurationSetType>LinuxProvisioningConfiguration</ConfigurationSetType><HostName>SuseOpenVm_rolec8fc</HostName><UserName>anandsrinivasan</UserName><UserPassword>Cloud360</UserPassword><DisableSshPasswordAuthentication>false</DisableSshPasswordAuthentication></ConfigurationSet><ConfigurationSet><ConfigurationSetType>NetworkConfiguration</ConfigurationSetType><DisableSshPasswordAuthentication>false</DisableSshPasswordAuthentication><InputEndpoints><InputEndpoint><LocalPort>22</LocalPort><Name>SSH</Name><Port>22</Port><Protocol>TCP</Protocol></InputEndpoint></InputEndpoints></ConfigurationSet></ConfigurationSets><OSVirtualHardDisk><MediaLink>https://2xportalvhds7jsf9ncknn4s.blob.core.windows.net/vhds/imagevmtest-imagevmtest-2016-11-10.vhd</MediaLink><SourceImageName>imagevmtest-imagevmtest-2016-11-10.vhd</SourceImageName></OSVirtualHardDisk><RoleSize>Small</RoleSize></Role></RoleList><VirtualNetworkName>anand360NW</VirtualNetworkName></Deployment>";
int deployResponseCode = processPostRequest(new URL(url),requestBody2.getBytes(), "application/xml", keyStorePath, keyStorePassword);
System.out.println(deployResponseCode);
我正在使用上面的代码并尝试在我的 Azure 中创建一个虚拟机。但仍然出现错误 400。你们能指导我如何通过 REST API 在我的 Azure 帐户中创建一个 vm 吗?
【问题讨论】:
-
我想问你尝试使用原始REST API创建Azure资源的目的是什么?您是否尝试过一些替代方案?
-
@MilanNankov 我正在计划让用户在我的网站下创建帐户后自动在 Azure 上创建虚拟机。有哪些替代方案?你能提供一些步骤吗?谢谢