如何使用azure-sdk-for-python创建具有自定义映像的VM?

我正在使用 python的“新”azure sdk:

https://github.com/Azure/azure-sdk-for-python

Linked是一个用作文档的用法示例:
https://azure-sdk-for-python.readthedocs.org/en/latest/resourcemanagementcomputenetwork.html

在此示例中,他们从公共图像创建实例,提供图像发布者,商品,SKU和版本.
我想从自定义图像创建一个实例(存在于天蓝色门户网站上的“我的图像”中),我只有一个图像名称,没有发布者或SKU.

这支持吗?我该怎么办?

注意:如果可能的话,我想避免使用azure CLI命令,只依赖于python库.

谢谢!

最佳答案 如果其他人遇到此问题,SourceImage实际上是旧方法(ASM).对于ARM,以下内容将初始化StorageProfile以提供对自定义映像的引用:

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),
        ),
    ),
)

上面两个非常重要的事情是’operating_system_type’以及创建source_image的方式.

点赞