簡體   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