繁体   English   中英

创建虚拟机部署Azure REST API

[英]Create Virtual Machine Deployment Azure REST API

        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帐户中创建虚拟机吗?

现在,这直接回答了您的问题,但我将提供一些可能更适合您的情况的替代方法。

必须处理生成整个XML是非常困难且容易出错的。 REST API与在Azure上一样低。 我的建议是尝试一些在REST API之上构建的API /工具,例如PowerShellAzure CLI

如果使用的是.NET,最好的选择是使用.NET的管理库 原始的管理库使用起来有点麻烦,但是使用流畅的API的作品中有一个新的和改进的版本,并且到目前为止,我发现它很棒! 这是介绍性博客文章-https: //azure.microsoft.com/zh-cn/blog/simpler-azure-management-libraries-for-net/

总而言之,我认为最好是可以避免使用原始REST API的麻烦,而改用一些包装器。

让我知道你的想法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM