Python용 Azure DNS 라이브러리

개요

Azure DNS는 Azure 인프라를 통해 DNS 확인을 제공하는 DNS 도메인에 대한 호스팅 서비스입니다.

Azure DNS를 시작하려면 Azure Portal을 사용하여 Azure DNS 시작을 참조하세요.

관리 API

pip install azure-mgmt-dns

관리 클라이언트 만들기

다음 코드는 관리 클라이언트의 인스턴스를 만듭니다.

구독 목록에서 검색할 수 있는 를 제공해야 subscription_id 합니다.

Python SDK를 사용하여 Azure Active Directory 인증을 처리하고 Credentials 인스턴스를 만드는 방법에 대한 자세한 내용은 리소스 관리 인증을 참조하세요.

from azure.mgmt.dns import DnsManagementClient
from azure.common.credentials import UserPassCredentials

# Replace this with your subscription id
subscription_id = '33333333-3333-3333-3333-333333333333'

# See above for details on creating different types of AAD credentials
credentials = UserPassCredentials(
	'user@domain.com',  # Your user
	'my_password',      # Your password
)

dns_client = DnsManagementClient(
	credentials,
	subscription_id
)

DNS 영역 만들기

# The only valid value is 'global', otherwise you will get a:
# The subscription is not registered for the resource type 'dnszones' in the location 'westus'.
zone = dns_client.zones.create_or_update(
	'MyResourceGroup',
	'pydns.com',
	{
	        'zone_type': 'Public', # or Private
		'location': 'global'
	}
)

레코드 집합 만들기

record_set = dns_client.record_sets.create_or_update(
	'MyResourceGroup',
	'pydns.com',
	'MyRecordSet',
	'A',
	{
			"ttl": 300,
			"arecords": [
				{
				"ipv4_address": "1.2.3.4"
				},
				{
				"ipv4_address": "1.2.3.5"
				}
			]
	}
)