Azure Python SDK 无法使用 azure-mgmt-compute==20.0.0 使用 list_of_vms 的输出
Azure Python SDK not able to consume output of list_of_vms with azure-mgmt-compute==20.0.0
我正在使用 azure python sdk 进行资源管理。
下面的代码片段在升级到 azure-mgmt-compute==20.0.0 后与 Azure 一起工作 -> azure-mgmt-compute==12.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 )
结果:
我正在使用 azure python sdk 进行资源管理。 下面的代码片段在升级到 azure-mgmt-compute==20.0.0 后与 Azure 一起工作 -> azure-mgmt-compute==12.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 )
结果: