我正在尝试将Python SDK用于Service Fabric,以便从群集中获取应用程序类型的列表。
群集未启用Azure AD,因此在Powershell中我使用证书连接到该群集。
我不确定如何使用python。
我对订阅拥有所有者权限,并且我正在使用正确的SPN帐户来获取信息,资源组或群集对象上的其他python操作将返回我的输出。
from azure.common.credentials import ServicePrincipalCredentials
from azure.mgmt.servicefabric import ServiceFabricManagementClient
tenant_id = os.environ['AZURE_TENANT']
spn_client_id = os.environ['AZURE_CLIENT']
spn_secret = os.environ['AZURE_SECRET']
sub_id = 'some-subscription-id'
credentials = ServicePrincipalCredentials(
client_id = spn_client_id,
secret = spn_secret,
tenant = tenant_id
)
sf_client = ServiceFabricManagementClient(credentials, sub_id)
sf_api_client = ServiceFabricClientAPIs(credentials, sub_id)
此代码有效:
sf_client.clusters.get('some-rg-name', 'some-cluster-name')
因为我具有订阅的权限,所以Azure Api返回值。
检查集群上的应用程序是另一回事,我无法使用以下代码枚举应用程序类型:
sf_client.application_type.list('some-rg-name', 'some-cluster-name')
与许可无关,Owner
角色就足够。
您的代码有错误,应该是sf_client.application_types.list
,而不是sf_client.application_type.list
,它在我这边起作用。
apptype = sf_client.application_types.list('some-rg-name', 'some-cluster-name')
print(apptype)
Besides,如果您得到结果中的'value': []
,这也意味着成功,因为您的集群中没有application type
资源。您可以先通过此REST API Application Types - List
检查结果。