3

Launching a VM using a marketplace image in Azure is pretty straight forward.

here is the relevant piece of code.

def create_vm(network_client, compute_client):

vm_parameters = {
    'storage_profile': {
        'image_reference': {
            'publisher': 'MicrosoftWindowsServer',
            'offer': 'WindowsServer',
            'sku': '2012-R2-Datacenter',
            'version': 'latest'
        }
    },

vm = compute_client.virtual_machines.create_or_update(
    GROUP_NAME, 
    VM_NAME, 
    vm_parameters
)

(Clearly there is more in the actual code, this is the part that I think is most relevant)

So in this case the image reference points to the marketplace.

I used the following doc to create a custom image.

https://learn.microsoft.com/en-us/azure/virtual-machines/windows/create-vm-generalized-managed?toc=%2fazure%2fvirtual-machines%2fwindows%2ftoc.json

I would like to create a VM based on the new custom image that I created. It is my perception that image_reference should point to something else but it isn't clear to me what it should be. Can anybody help here?

Thanks!

0

1 Answer 1

3

In fact, Azure Python SDK uses Azure Rest API. You could check this example.

So, you could modify your script like below:

vm_parameters = {
    'storage_profile': {
        'image_reference': {
            'id' : '/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/{existing-custom-image-name}'
        }
    },
Sign up to request clarification or add additional context in comments.

3 Comments

That did it! Is this documented somewhere? I wasn't able to find it in the documentation.
You could check this document learn.microsoft.com/en-us/python/api/…
In fact, the parameters is a json file. Azure rest api body also requires a json file. When you don't know how to structure parameters, you could check Azure rest api. learn.microsoft.com/en-us/rest/api

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.