I’m attempting to reboot/restart an Azure virtual machine through the REST interface.
I created a virtual machine through the Azure portal and it appears as running under the Virtual Machines tab on the left.
The url I am using for this operation is as follows:
https://management.core.windows.net/{my-subscription-guid}/services/hostedservices/cloudvm-test/deployments/cloudvm-test/roles/cloudvm-test/Operations
You can see “cloudvm-test” repeated as the hosted service name, the deployment name and the role name because that’s how it appears in the xml you get back from calling Get Hosted Service Properties. Even though a Virtual Machine is not a classic hosted service, it appears in this xml and so I just use the values I find there. One of the concerns I have is whether I’m building the URL correctly.
Anyway, using the above URL, I build my request as expected, and POST a body of:
<RestartRoleOperation xmlns="http://schemas.microsoft.com/windowsazure" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<OperationType>RestartRoleOperation</OperationType></RestartRoleOperation>
The error I receive is a 404, stating that “The resource service name hostedservices is not supported”.
Not that it really matters, but I’m writing in Objective C. If you have an example in C# I can deal with it fine.
Instead of
.../roles/roleName/...you have to use.../roleInstances/roleName ....(replace roles with roleInstances in the Uri path).The VM related documentation is full of such small mistakes.
By the way, in order to have a Virtual Machine you need to have a “Hosted Service”. So if you try the REST API to create a VM, you will discover that you have to specify an existing hosted service. So you first have to create the Hosted service, and then deploy a Virtual Machine to it. It is a little confusing, because the portal hides that little detail from us. But if you go to the old portal you will see that there is actually a hosted service behind each Virtual VM you created. That hosted service does not appear in the new portal as “Cloud Service” until you delete all the VMs in it…