How to create a VM with a custom image using azure-sdk-for-python?
Question: I'm using the "new" azure sdk for python: <https://github.com/Azure/azure-sdk-
for-python>

Linked is a usage example to serve as documentation: <https://azure-sdk-for-
python.readthedocs.org/en/latest/resourcemanagementcomputenetwork.html>

In this example, they create an instance from a public image, providing an
image publisher, offer, SKU and version. I'd like to create an instance from a
custom image (present in "My Images" on the azure portal), for which I only
have an image name, no publisher or SKU.

Is this supported? How should I proceed?

Note: I'd like to avoid using the azure CLI command if possible, only relying
on the python library.

Thanks!


Answer: In case anyone else runs into this issue, the SourceImage is actually for the
older method (ASM). For ARM, the following will initialize the StorageProfile
to provide a reference to a custom image:

    
    
    storage_profile = azure.mgmt.compute.StorageProfile(
        os_disk=azure.mgmt.compute.OSDisk(
            caching=azure.mgmt.compute.CachingTypes.none,
            create_option=azure.mgmt.compute.DiskCreateOptionTypes.from_image,
            name=OS_DISK_NAME,
            virtual_hard_disk=azure.mgmt.compute.VirtualHardDisk(
                uri='https://{0}.blob.core.windows.net/vhds/{1}.vhd'.
                format(STORAGE_NAME, OS_DISK_NAME),
            ),
            operating_system_type='Linux',
            source_image=azure.mgmt.compute.VirtualHardDisk(
                uri='https://{0}.blob.core.windows.net/{1}/{2}'.format(
                    STORAGE_NAME, CUSTOM_IMAGE_PATH, CUSTOM_IMAGE_VHD),
            ),
        ),
    )
    

The two very important things above are 'operating_system_type' and the way
the source_image is created.

