Azure python sdk list of OS



我尝试使用 python SDK 获取 azure 中所有或最流行的操作系统(如 ubuntu、centos、Windows 等(的列表,所有这些都是为了创建一个新的虚拟机,在这个例子中: https://learn.microsoft.com/en-us/python/api/overview/azure/virtualmachines?view=azure-python 要创建新虚拟机,您需要一个storage_profile:

'storage_profile': {
            'image_reference': {
                'publisher': 'Canonical',
                'offer': 'UbuntuServer',
                'sku': '16.04.0-LTS',
                'version': 'latest'
            },
        },

如何在 python azure sdk 中获取此存储配置文件或映像引用的列表? 我尝试使用 azure.mgmt.compute 计算管理客户端,但没有方法来获取存储配置文件或映像引用的列表,Azure的官方文档非常令人困惑。

我认为你想要在 Azure 市场中获取 VM 映像。为此,可以查看 VirtualMachineImagesOperations 类,使用其中的方法,然后获取 Azure 市场中具有特殊要求的 VM 映像。

更新:

下面是在 Azure 市场中获取映像的示例:

from azure.mgmt.compute import ComputeManagementClient
from azure.common.credentials import ServicePrincipalCredentials
Subscription_Id = "xxxxxx"
Tenant_Id = "xxxxxx"
Client_Id = "xxxxxx"
Secret = "xxxxxx"
credential = ServicePrincipalCredentials(
        client_id=Client_Id,
        secret=Secret,
        tenant=Tenant_Id
        )
compute_client = ComputeManagementClient(credential, Subscription_Id)
images = compute_client.virtual_machine_images.list_offers('eastus', 'Canonical')
for image in images:
    print(image.name)

最新更新