【发布时间】:2018-04-23 08:59:03
【问题描述】:
我已经编写了 python 代码来使用 azure-python sdk 获取订阅的 azure 资源, 列出资源组内所有资源的功能不起作用,这在一周前工作正常,可能是微软更改了他们的 api? 我收到一个属性错误, AttributeError:“ResourceGroupsOperations”对象没有属性“list_resources”
请在下面找到代码,
from azure.common.credentials import ServicePrincipalCredentials
from azure.mgmt.resource.resources import ResourceManagementClient
from azure.mgmt.compute import ComputeManagementClient
from azure.mgmt.network import NetworkManagementClient
subscription_id = ''
credentials = ServicePrincipalCredentials(
client_id = '',
secret = '',
tenant = '',
)
resource_client = ResourceManagementClient(credentials,subscription_id)
resource_client.providers.register('Microsoft.Batch')
def get_resources():
for rg in resource_client.resource_groups.list():
for item in resource_client.resource_groups.list_resources(rg.name):
print "%s,%s,%s,%s,"%(item.name,item.type,item.location,rg.name)
get_resources()
请帮忙解决这个问题!提前致谢!
【问题讨论】: