Windows azure rest api - creating a virtual machine

I am learning how to use the Windows Azure REST API to create virtual machines in a Windows Azure environment. Looking at the Windows Azure REST API link, I see that the URL to which the POST request should be made is as follows:

https://management.core.windows.net/<subscription-id>/services/hostedservices/<cloudservice-name>/deployments/<deployment-name>/roles 

My confusion here is related to the need for <cloudservice-name> and <deployment-name> . In fact, if I sign up directly to my Windows Azure subscription portal and go through the menu to create a virtual machine, I DO NOT have to provide a cloud name or deployment name. All I do is select the image (centos, ubuntu, windows, etc.) for the virtual machine, select the taste (xsmall, small, large, etc.) for the virtual machine and click "Create", and a virtual machine will be created in a few minutes,

Given that I could create a virtual machine this way, I donโ€™t understand why I need to pass the <cloudservice-name> and <deployment-name> parameters in the curl REST API call and what values โ€‹โ€‹to pass to these parameters. In fact, I do not have a deployment in my subscription, and I do not intend to have it. All I want to do is just create a virtual machine that I could use.

Is it possible for me to skip these options and still be able to create a virtual machine in my Azure subscription? those. only by skipping <subscription-id> ?

Can someone who has used the Windows Azure REST API before or someone who has experience with Windows Azure shed some light on this and helps clarify?

Update Wed, 07/31/2013: Thanks again for the feedback on my question. I would like to update that I managed to get to the point where I was finally able to create a virtual machine using a REST API call. But it is strange that the creation of a virtual machine only worked successfully once. Subsequently, when I tried to create a virtual machine with a different name, it threw an error, for example, "Deployment Lock". So for the sake of sanity, I went ahead and deleted the existing virtual machine and did some cleaning up the account. I tried the POST operation to create the virtual machine again, and now it happens that the POST response is returned with the message 202 Accepted, but despite this, I DO NOT see the virtual machine created in my Azure account. I donโ€™t know where and how to even start fixing this problem, given that I am not getting an error, and a virtual machine is being created.

I am placed below the whole body of the XML request that I submit to create the virtual machine:

 <Deployment xmlns="http://schemas.microsoft.com/windowsazure" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> <Name>Staging</Name> <DeploymentSlot>Staging</DeploymentSlot> <Label>stk_curl_label_1</Label> <RoleList> <Role> <RoleName>stk_curl_role_1</RoleName> <RoleType>PersistentVMRole</RoleType> <ConfigurationSets> <ConfigurationSet> <ConfigurationSetType>WindowsProvisioningConfiguration</ConfigurationSetType> <ComputerName>stkVm1</ComputerName> <AdminPassword>Password123</AdminPassword> <EnableAutomaticUpdates>false</EnableAutomaticUpdates> </ConfigurationSet> </ConfigurationSets> <OSVirtualHardDisk> <HostCaching>ReadWrite</HostCaching> <DiskLabel>Visual studio ultimate</DiskLabel> <DiskName>stk_disk_1</DiskName> <MediaLink>http://stk11.blob.core.windows.net/communityimages/visual_studio_ultimate.vhd</MediaLink> <SourceImageName>03f55de797f546a1b29d1b8d66be687a__Visual-Studio-2013-Preview-Ultimate-12.0.20617.1</SourceImageName> </OSVirtualHardDisk> <RoleSize>ExtraSmall</RoleSize> </Role> </RoleList> </Deployment> 

And I insert below the tail of the response that I get to call curl:

 > User-Agent: curl/7.15.5 (x86_64-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5 > Host: management.core.windows.net > Accept: */* > x-ms-version: 2012-03-01 > Content-Type: application/xml > Content-Length: 1236 > Expect: 100-continue > * SSLv3, TLS handshake, Hello request (0): SSLv3, TLS handshake, Client hello (1): SSLv3, TLS handshake, Server hello (2): SSLv3, TLS handshake, CERT (11): SSLv3, TLS handshake, Request CERT (13): SSLv3, TLS handshake, Server finished (14): SSLv3, TLS handshake, CERT (11): SSLv3, TLS handshake, Client key exchange (16): SSLv3, TLS handshake, CERT verify (15): SSLv3, TLS change cipher, Client hello (1): SSLv3, TLS handshake, Finished (20): SSLv3, TLS change cipher, Client hello (1): SSLv3, TLS handshake, Finished (20): HTTP/1.1 100 Continue HTTP/1.1 202 Accepted < Cache-Control: no-cache < Content-Length: 0 < Server: 33.0.6198.68 (rd_rdfe_stable.130710-0833) Microsoft-HTTPAPI/2.0 < x-ms-servedbyregion: ussouth < x-ms-request-id: b2f3dd01319049a5a6728bbdbcde6c4a < Date: Wed, 31 Jul 2013 17:26:54 GMT * Connection #0 to host management.core.windows.net left intact * Closing connection #0 * SSLv3, TLS alert, Client hello (1): 

As you can clearly see, this is the answer "202 accepted." But, as I mentioned earlier, despite this, when I check my Azure account, I do not see the creation of a virtual machine.

Would thank any expert information / ideas on how to decide why it is not working properly?

+4
source share
3 answers

What you see is little magic behind the scenes of the portal. When you deploy a virtual machine, it really ends up in the cloud service container. This has recently been changed to be more obvious on the portal, and before they hid it from you. When people deleted a virtual machine or added other virtual machines to the same group (previously called something like โ€œattach toโ€), a cloud service appeared on the portal. People were confused about what it was, and it raised more questions than was worth it.

The portal now offers you a cloud service. If you quickly create when it asks for the DNS name (and shows .cloudapp.net next to it) that you provide the name of the cloud service. When you make a creation through the Gallery, this is even more obvious in step 3, where you are asked to create a new cloud service or select one that already exists.

To do what you want using the REST API, you need to create a cloud service ahead of time or as a call before creating it for the virtual machine. In addition, the link you provided is intended to add the role of a cloud service, and not to create a virtual machine. For this REST API Call you want to use this: http://msdn.microsoft.com/en-us/library/windowsazure/jj157194.aspx It still requires a cloud service, but not a deployment name.

+5
source

There are two different APIs: one for creating a deployment and a virtual machine under a cloud service, and the other for adding roles to the deployment that you created earlier.

These are two APIs.

For VM Deployment

 http://msdn.microsoft.com/en-us/library/azure/jj157194.aspx 

For deployment roles

 http://msdn.microsoft.com/en-us/library/azure/jj157186.aspx 

What you use is the second, you first need to create a virtual machine deployment using the first API, and then use the second to add more roles to the same cloud service.

+1
source

I had the same problem with the add role, which returned me 202 but the VM was not created. After many hours, trying to find out what was wrong, I found out that on the management portal they have these service management logs โ†’ where it shows you the log of all API calls.

It was here that my API with the added role told me that this was the 404th invalid request instead of the accepted 202 code, and it also showed me a specific error.

Management Services -> Operation Logs are very useful when you are stuck in an API.

+1
source

Source: https://habr.com/ru/post/1494327/


All Articles