# 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)