1

I want to create a virtual machine that anyone can launch using the ARM REST API.

How do I do that? I cannot find instructions.

juvchan
  • 6,113
  • 2
  • 22
  • 35
Duke Dougal
  • 24,359
  • 31
  • 91
  • 123
  • What do you mean by a virtual machine that anyone can launch? Can you specify whether you are looking to do this via Azure portal, C# or PowerShell? That are a few options which can create a Azure VM using the ARM REST API. – juvchan Feb 22 '16 at 11:16
  • This is a very vague question and I suspect you are missing a point somewhere, but it is difficult to say what that is since the required information isn't there. – Michael B Feb 22 '16 at 13:34
  • @Duke Dougal Did you find a way to achieve this? – Boomerang Jun 15 '16 at 12:12
  • @webfort it got so hard I gave up and took another approach to solving my problem. – Duke Dougal Jun 15 '16 at 21:30

3 Answers3

1

Apparently it is possible to create public virtual machine images here: https://vmdepot.msopentech.com/help/contribute/vhd.html/

Duke Dougal
  • 24,359
  • 31
  • 91
  • 123
  • vmdepot is simply a repository for storing virtual machine images, vmdepot does not have any capacity to run those images, you would need to launch them in a cloud provider. – Michael B Feb 22 '16 at 13:32
0

There are a couple of ways you could do this. Presuming you have got a website / application etc at the frontend, and it is simply the backend communication you're looking for.

Prerequisites

The option here presumes that you have an active Microsoft Azure account, and are able to create a VM there via the portal. Once you are at a stage that you can do that, you can use the REST API to create a machine instead.

Option 1

You can either use the REST API to directly create a VM by PUTing a request to this URI -

https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}/providers/Microsoft.Compute/virtualMachines/{vm-name}?validating={true|false}&api-version={api-version}

You would need to attach a JSON document to that request that would define the machine you are creating.

{  
  "id":"/subscriptions/{subscription-id}/resourceGroups/myresourcegroup1/providers/Microsoft.Compute/virtualMachines/myvm1",
  "name":"myvm1", 
  "type":"Microsoft.Compute/virtualMachines",
  "location":"westus",
  "tags": {  
    "department":"finance"
  },
  "properties": {  
    "availabilitySet": {  
      "id":"/subscriptions/{subscription-id}/resourceGroups/myresourcegroup1/providers/Microsoft.Compute/availabilitySets/myav1"
    },
    "hardwareProfile": {  
      "vmSize":"Standard_A0"
    },
    "storageProfile": {  
      "imageReference": {  
        "publisher":"MicrosoftWindowsServerEssentials",
        "offer":"WindowsServerEssentials",
        "sku":"WindowsServerEssentials",
        "version":"latest"
      },
      "osDisk": {  
        "name":"myosdisk1",
        "vhd": {  
          "uri":"http://mystorage1.blob.core.windows.net/vhds/myosdisk1.vhd"
        },
        "caching":"ReadWrite",
        "createOption":"FromImage"
      },
      "dataDisks": [ { 
         "name":"mydatadisk1", 
         "diskSizeGB":"1", 
         "lun": 0, 
         "vhd": { 
           "uri" : "http://mystorage1.blob.core.windows.net/vhds/mydatadisk1.vhd" 
         }, 
         "createOption":"Empty" 
       } ]
    },
    "osProfile": {  
      "computerName":"myvm1",
      "adminUsername":"username",
      "adminPassword":"password",
      "customData":"",
      "windowsConfiguration": {  
        "provisionVMAgent":true,
        "winRM": {
          "listeners": [ {
            "protocol": "https",
            "certificateUrl": "url-to-certificate"
          } ]
        },
        "additionalUnattendContent": {  
          "pass":"oobesystem",
          "component":"Microsoft-Windows-Shell-Setup",
          "settingName":"FirstLogonCommands|AutoLogon",
          "content":"<XML unattend content>"
        }  
        "enableAutomaticUpdates":true
      },
      "secrets":[ { 
         "sourceVault": { 
           "id": "/subscriptions/{subscription-id}/resourceGroups/myresourcegroup1/providers/Microsoft.KeyVault/vaults/myvault1" 
         }, 
         "vaultCertificates": [ { 
           "certificateUrl": "https://myvault1.vault.azure.net/secrets/{secretName}/{secretVersion}" 
           "certificateStore": "{certificateStoreName}" 
         } ] 
       } ]
    },
    "networkProfile": {  
      "networkInterfaces": [ {  
        "id":"/subscriptions/{subscription-id}/resourceGroups/myresourceGroup1/providers /Microsoft.Network/networkInterfaces/mynic1"
      } ]
    }
  }
}

More details about the authentication and parameters can be found at the Azure Virtual Machine Rest documentation - Create or update a virtual machine

Option 2

Alternatively you can create an Azure Resource Manager Template, such as 101-vm-simple-linux on Azure's Github template repository

Once you have a template defined for the VM you want to deploy you can PUT another request to this URI

https://management.azure.com/subscriptions/{subscription-id}/resourcegroups/{resource-group-name}/providers/microsoft.resources/deployments/{deployment-name}?api-version={api-version}

If you copy that template file to an Azure blob, along with another file specifying any parameters it needs, and send this JSON document with the PUT request

{
  "properties": {
    "templateLink": {
      "uri": "http://mystorageaccount.blob.core.windows.net/templates/template.json",
      "contentVersion": "1.0.0.0",
    },
    "mode": "Incremental",
    "parametersLink": {
      "uri": "http://mystorageaccount.blob.core.windows.net/templates/parameters.json",
      "contentVersion": "1.0.0.0",      
    }
  }
}

You can find the documentation for this at - Create a template deployment

Michael B
  • 11,887
  • 6
  • 38
  • 74
  • There's a big part missing to the equation though - how do I identify the public VM that will be run? The VM depot does not seem to provide the information I need to plug in to the data structure you have provided above. https://vmdepot.msopentech.com nor does the Azure Marketplace appear to provide a way to connect a public virtual machine to the data structure you specify above. – Duke Dougal Feb 22 '16 at 13:25
  • @DukeDougal I have edited the answer a little - However it does depend on what you mean by a 'public' VM, considering you are using Azure tags this answer makes the assumption that you are looking to deploy via Azure, in this case you will need to have an active account and at some point be paying for the resources you are using. – Michael B Feb 22 '16 at 13:30
0

This is to elaborate on @Michael B's answer: To discover what images are available, you can use the VMDepot -- of course -- or you can query for all the marketplace images. Look at the publishers list first, and then from there you can decide which images you would like.

The URN value you discover will be the one you want to use in your REST call. Hope this helps...

squillace
  • 41
  • 1