python azure sdk -克隆服务器



我正在编写python脚本来克隆Azure中的服务器。我在获取APP磁盘信息时遇到问题

  1. 下面的代码只捕获应用程序磁盘的名称。我需要他们的LUN号,缓存信息,id。

  2. 信息收集完成后如何创建目标磁盘

computeClient = ComputeManagementClient(secretCredential,subscriptionid) 
detailsOfVM = computeClient.virtual_machines.get("AKS-CLUSTER-RG", "DOCKER", expand='instanceView')
dictOfOSDisk=dict()
if detailsOfVM.storage_profile.image_reference:
dictOfOSDisk["publisher"] = detailsOfVM.storage_profile.image_reference.publisher
dictOfOSDisk["offer"] = detailsOfVM.storage_profile.image_reference.offer
dictOfOSDisk["sku"] = detailsOfVM.storage_profile.image_reference.sku
dictOfOSDisk["version"] = detailsOfVM.storage_profile.image_reference.version
dictOfOSDisk["osType"] = detailsOfVM.storage_profile.os_disk.os_type
dictOfOSDisk["name"] = detailsOfVM.storage_profile.os_disk.name
dictOfOSDisk["createOption"] = detailsOfVM.storage_profile.os_disk.create_option)
dictOfOSDisk["caching"]= detailsOfVM.storage_profile.os_disk.caching
print(dictOfOSDisk)

allDiskOfVmList = [disk.name for disk in detailsOfVM.instance_view.disks]
print(allDiskOfVmList)

根据您提供的代码,它只会返回磁盘的实例视图。不包含Azure虚拟机数据磁盘的LUN号。详情请参阅此处。如果您想获取Azure虚拟机数据磁盘的LUN号,请参考以下代码

compute_client = ComputeManagementClient(credential, Subscription_Id)
vm = compute_client.virtual_machines.get(vmGroup, vmName)
dataDisks = vm.storage_profile.data_disks
for disk in dataDisks:
print(disk.lun)

详情请参阅此处

相关内容

  • 没有找到相关文章

最新更新