我写了这段代码来列出Azure虚拟机。现在我想打印与OS
disks
相关的所有详细信息,如操作系统、disk
size
、encryption
settings
,以及与Azure虚拟机相关的其他详细信息
from azure.mgmt.resource import ResourceManagementClient
from azure.identity import ClientSecretCredential
Subscription_Id = "XXXX"
Tenant_Id = "XXXX"
Client_Id = "XXXX"
Secret = "XXXX"
credential = ClientSecretCredential(
client_id=Client_Id,
client_secret=Secret,
tenant_id=Tenant_Id
)
resource_client = ResourceManagementClient(
credential=credential, subscription_id=Subscription_Id)
resource_list = resource_client.resources.list()
for item in resource_list:
if(item.type == 'Microsoft.Compute/virtualMachines'):
print(item.name)
要获得storage_profile
,可以使用以下带有list all
的代码示例:
vm_list = compute_client.virtual_machines.list_all()
filtered = [vm for vm in vm_list if vm.name == "MY_VM_NAME"]
vm = filtered[0] #First VM
print("nstorageProfile")
print(" imageReference")
print(" publisher: ", vm.storage_profile.image_reference.publisher)
print(" offer: ", vm.storage_profile.image_reference.offer)
print(" sku: ", vm.storage_profile.image_reference.sku)
print(" version: ", vm.storage_profile.image_reference.version)
print(" osDisk")
print(" osType: ", vm.storage_profile.os_disk.os_type.value)
print(" name: ", vm.storage_profile.os_disk.name)
print(" createOption: ", vm.storage_profile.os_disk.create_option.value)
print(" caching: ", vm.storage_profile.os_disk.caching.value)
有关完整设置,请参阅MICROSOFT文档:使用Python在Azure中创建和管理Windows虚拟机
有关更多信息,请参阅SO THREAD:如何使用Python仅列出1台Azure虚拟机的详细信息