# List available resource providers with RegistrationState "Registered" and select ProviderNamespace and RegistrationState
providers = resource_management_client.providers.list()
registered_providers = [provider for provider in providers if provider.registration_state == "Registered"]
# Sort by ProviderNamespace
sorted_registered_providers = sorted(registered_providers, key=lambda x: x.namespace)
for provider in sorted_registered_providers:
print(f"ProviderNamespace: {provider.namespace}, RegistrationState: {provider.registration_state}")
import os
from azure.identity import DefaultAzureCredential
from azure.mgmt.resource import ResourceManagementClient
# Authentication
credential = DefaultAzureCredential()
subscription_id = os.environ["AZURE_SUBSCRIPTION_ID"]
# Initialize Resource Management client
resource_management_client = ResourceManagementClient(credential, subscription_id)
# Get resource provider by ProviderNamespace
provider_namespace = "Microsoft.Batch"
provider = resource_management_client.providers.get(provider_namespace)
print(f"ProviderNamespace: {provider.namespace}, RegistrationState: {provider.registration_state}\n")
# Add resource types, locations, and API versions with new lines to separate results for resource_type in provider.resource_types:
print(f"ResourceType: {resource_type.resource_type}\nLocations: {', '.join(resource_type.locations)}\nAPIVersions: {', '.join(resource_type.api_versions)}\n")
该命令返回:
输出
ProviderNamespace: Microsoft.Batch, RegistrationState: Registered
ResourceType: batchAccounts
Locations: West Europe, East US, East US 2, West US, North Central US, Brazil South, North Europe, Central US, East Asia, Japan East, Australia Southeast, Japan West, Korea South, Korea Central, Southeast Asia, South Central US, Australia East, Jio India West, South India, Central India, West India, Canada Central, Canada East, UK South, UK West, West Central US, West US 2, France Central, South Africa North, UAE North, Australia Central, Germany West Central, Switzerland North, Norway East, Brazil Southeast, West US 3, Sweden Central, Qatar Central, Poland Central, East US 2 EUAP, Central US EUAP
APIVersions: 2023-05-01, 2022-10-01, 2022-06-01, 2022-01-01, 2021-06-01, 2021-01-01, 2020-09-01, 2020-05-01, 2020-03-01-preview, 2020-03-01, 2019-08-01, 2019-04-01, 2018-12-01, 2017-09-01, 2017-05-01, 2017-01-01, 2015-12-01, 2015-09-01, 2015-07-01, 2014-05-01-privatepreview
...
若要查看资源提供程序的资源类型,请使用:
Python
# Get resource provider by ProviderNamespace
provider_namespace = "Microsoft.Batch"
provider = resource_management_client.providers.get(provider_namespace)
# Get ResourceTypeName of the resource types
resource_type_names = [resource_type.resource_type for resource_type in provider.resource_types]
for resource_type_name in resource_type_names:
print(resource_type_name)
API 版本对应于资源提供程序的 REST API 操作的版本。 资源提供程序启用新功能时,会发布 REST API 的新版本。
若要获取资源类型可用的 API 版本,请使用:
Python
# Get resource provider by ProviderNamespace
provider_namespace = "Microsoft.Batch"
provider = resource_management_client.providers.get(provider_namespace)
# Filter resource type by ResourceTypeName and get its ApiVersions
resource_type_name = "batchAccounts"
api_versions = [
resource_type.api_versions
for resource_type in provider.resource_types
if resource_type.resource_type == resource_type_name
]
for api_version in api_versions[0]:
print(api_version)
# Get resource provider by ProviderNamespace
provider_namespace = "Microsoft.Batch"
provider = resource_management_client.providers.get(provider_namespace)
# Filter resource type by ResourceTypeName and get its Locations
resource_type_name = "batchAccounts"
locations = [
resource_type.locations
for resource_type in provider.resource_types
if resource_type.resource_type == resource_type_name
]
for location in locations[0]:
print(location)