如何解决Azure Python SDK 无法使用 azure-mgmt-compute==20.0.0 使用 list_of_vms 的输出
我使用 azure python sdk 进行资源管理。 以下代码段与 Azure 一起使用 -> azure-mgmt-compute==12.0.0 升级到 azure-mgmt-compute==20.0.0 后,以下代码段不起作用
creds = ServicePrincipalCredentials(client_id=client_id,secret=secret,tenant=tenant_id,**kwargs)
compute_client = ComputeManagementClient(creds,subscription_id,base_url='https://management.azure.com')
paged_iter = compute_client.virtual_machines.list_all(raw=True)
output = []
paged_iter.get(paged_iter.next_link)
while True:
chunk = json.loads(paged_iter.raw.response.content)
if 'nextLink' in chunk:
paged_iter.get(chunk['nextLink'])
else:
break
resp = {'value': output}
print(resp)
升级后报错
AttributeError: 'ItemPaged' object has no attribute 'get'
请帮助理解如何消耗 compute_client.virtual_machines.list_all(raw=True)
解决方法
试试这个:
from azure.mgmt.compute import ComputeManagementClient
from azure.identity import ClientSecretCredential
credentials = ClientSecretCredential(
client_id='',client_secret='',tenant_id=''
)
subID= ''
computer_client = ComputeManagementClient(credentials,subID)
vms = computer_client.virtual_machines.list_all()
for vm in vms:
print( vm.name )
结果:
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。