Skip to main content
 首页 » 编程设计

python之操作系统的 Azure python sdk 列表

2024年09月03日35davidwang456

我尝试使用 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 ComputeManagementClient 但没有方法获取存储配置文件或图像引用列表, azure的官方文档很困惑。

请您参考如下方法:

我认为您想在 Azure 市场上获取 VM 镜像。为此,您可以查看 VirtualMachineImagesOperations class,使用里面的方法,就可以得到Azure marketplace上有特殊需求的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)