or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

dns-record-sets.mddns-resource-references.mddns-zones.mdindex.md

index.mddocs/

0

# Azure DNS Management Client

1

2

A comprehensive Python client library for managing Azure DNS resources through the Azure Resource Manager API. Enables programmatic creation, configuration, and management of DNS zones, record sets, and various DNS record types within Azure's cloud DNS service.

3

4

## Package Information

5

6

- **Package Name**: azure-mgmt-dns

7

- **Language**: Python

8

- **Installation**: `pip install azure-mgmt-dns`

9

- **Dependencies**: `azure-common>=1.1`, `azure-mgmt-core>=1.5.0`, `isodate>=0.6.1`, `typing-extensions>=4.6.0`

10

- **Python Version**: 3.9+

11

12

## Core Imports

13

14

```python

15

from azure.mgmt.dns import DnsManagementClient

16

from azure.mgmt.dns.models import Zone, RecordSet, RecordType, ZoneType

17

```

18

19

For specific DNS record types:

20

21

```python

22

from azure.mgmt.dns.models import (

23

ARecord, AaaaRecord, CaaRecord, CnameRecord, MxRecord,

24

NsRecord, PtrRecord, SoaRecord, SrvRecord, TxtRecord

25

)

26

```

27

28

For resource reference operations:

29

30

```python

31

from azure.mgmt.dns.models import (

32

DnsResourceReferenceRequest, DnsResourceReferenceResult,

33

DnsResourceReference, SubResource

34

)

35

```

36

37

For error handling and pagination:

38

39

```python

40

from azure.mgmt.dns.models import (

41

CloudErrorBody, Resource,

42

ZoneListResult, RecordSetListResult,

43

ZoneUpdate

44

)

45

from azure.core.paging import ItemPaged

46

from azure.core.polling import LROPoller

47

```

48

49

For async operations:

50

51

```python

52

from azure.mgmt.dns.aio import DnsManagementClient

53

from azure.identity.aio import DefaultAzureCredential # Async credential

54

```

55

56

## Basic Usage

57

58

```python

59

from azure.core.credentials import DefaultAzureCredential

60

from azure.mgmt.dns import DnsManagementClient

61

from azure.mgmt.dns.models import Zone, RecordSet, ARecord, RecordType

62

63

# Initialize the client

64

credential = DefaultAzureCredential()

65

subscription_id = "your-subscription-id"

66

dns_client = DnsManagementClient(credential, subscription_id)

67

68

# Create a DNS zone

69

zone_params = Zone(location="global")

70

zone = dns_client.zones.create_or_update(

71

resource_group_name="myResourceGroup",

72

zone_name="example.com",

73

parameters=zone_params

74

)

75

76

# Create an A record

77

record_set = RecordSet(

78

ttl=300,

79

a_records=[ARecord(ipv4_address="1.2.3.4")]

80

)

81

dns_client.record_sets.create_or_update(

82

resource_group_name="myResourceGroup",

83

zone_name="example.com",

84

relative_record_set_name="www",

85

record_type=RecordType.A,

86

parameters=record_set

87

)

88

89

# List all zones in a resource group

90

zones = dns_client.zones.list_by_resource_group("myResourceGroup")

91

for zone in zones:

92

print(f"Zone: {zone.name}")

93

```

94

95

## Architecture

96

97

The Azure DNS Management Client follows the Azure SDK design patterns:

98

99

- **DnsManagementClient**: Main client providing access to all DNS operations

100

- **Operations Classes**: Specialized classes for different resource types (zones, record sets, references)

101

- **Model Classes**: Data structures representing DNS resources and configuration

102

- **Azure Core Integration**: Built on Azure Core for authentication, error handling, and HTTP pipeline management

103

104

## Capabilities

105

106

### DNS Zone Management

107

108

Comprehensive management of DNS zones including creation, deletion, updating, and listing operations. Supports both public and private zones with virtual network associations.

109

110

```python { .api }

111

class ZonesOperations:

112

def create_or_update(

113

self,

114

resource_group_name: str,

115

zone_name: str,

116

parameters: Union[Zone, IO[bytes]],

117

if_match: Optional[str] = None,

118

if_none_match: Optional[str] = None,

119

**kwargs: Any

120

) -> Zone: ...

121

122

def begin_delete(

123

self,

124

resource_group_name: str,

125

zone_name: str,

126

if_match: Optional[str] = None,

127

**kwargs: Any

128

) -> LROPoller[None]: ...

129

130

def get(

131

self,

132

resource_group_name: str,

133

zone_name: str,

134

**kwargs: Any

135

) -> Zone: ...

136

137

def list_by_resource_group(

138

self,

139

resource_group_name: str,

140

top: Optional[int] = None,

141

**kwargs: Any

142

) -> ItemPaged[Zone]: ...

143

```

144

145

[DNS Zone Management](./dns-zones.md)

146

147

### DNS Record Set Management

148

149

Complete CRUD operations for DNS record sets supporting all major DNS record types (A, AAAA, CAA, CNAME, MX, NS, PTR, SOA, SRV, TXT) with conditional updates and batch operations.

150

151

```python { .api }

152

class RecordSetsOperations:

153

def create_or_update(

154

self,

155

resource_group_name: str,

156

zone_name: str,

157

relative_record_set_name: str,

158

record_type: Union[str, RecordType],

159

parameters: Union[RecordSet, IO[bytes]],

160

if_match: Optional[str] = None,

161

if_none_match: Optional[str] = None,

162

**kwargs: Any

163

) -> RecordSet: ...

164

165

def update(

166

self,

167

resource_group_name: str,

168

zone_name: str,

169

relative_record_set_name: str,

170

record_type: Union[str, RecordType],

171

parameters: Union[RecordSet, IO[bytes]],

172

if_match: Optional[str] = None,

173

**kwargs: Any

174

) -> RecordSet: ...

175

176

def delete(

177

self,

178

resource_group_name: str,

179

zone_name: str,

180

relative_record_set_name: str,

181

record_type: Union[str, RecordType],

182

if_match: Optional[str] = None,

183

**kwargs: Any

184

) -> None: ...

185

186

def get(

187

self,

188

resource_group_name: str,

189

zone_name: str,

190

relative_record_set_name: str,

191

record_type: Union[str, RecordType],

192

**kwargs: Any

193

) -> RecordSet: ...

194

195

def list_by_dns_zone(

196

self,

197

resource_group_name: str,

198

zone_name: str,

199

top: Optional[int] = None,

200

recordsetnamesuffix: Optional[str] = None,

201

**kwargs: Any

202

) -> ItemPaged[RecordSet]: ...

203

204

def list_by_type(

205

self,

206

resource_group_name: str,

207

zone_name: str,

208

record_type: Union[str, RecordType],

209

top: Optional[int] = None,

210

recordsetnamesuffix: Optional[str] = None,

211

**kwargs: Any

212

) -> ItemPaged[RecordSet]: ...

213

214

def list_all_by_dns_zone(

215

self,

216

resource_group_name: str,

217

zone_name: str,

218

top: Optional[int] = None,

219

record_set_name_suffix: Optional[str] = None,

220

**kwargs: Any

221

) -> ItemPaged[RecordSet]: ...

222

```

223

224

[DNS Record Set Management](./dns-record-sets.md)

225

226

### DNS Resource References

227

228

Lookup functionality for DNS records by Azure resource IDs, enabling discovery of DNS records that reference specific Azure resources.

229

230

```python { .api }

231

class DnsResourceReferenceOperations:

232

def get_by_target_resources(

233

self,

234

parameters: Union[DnsResourceReferenceRequest, IO[bytes]],

235

**kwargs: Any

236

) -> DnsResourceReferenceResult: ...

237

```

238

239

[DNS Resource References](./dns-resource-references.md)

240

241

## Common Types

242

243

### Core DNS Models

244

245

```python { .api }

246

class Zone:

247

"""Represents a DNS zone resource."""

248

id: str # Resource ID (read-only)

249

name: str # Resource name (read-only)

250

type: str # Resource type (read-only)

251

location: str # Resource location (required)

252

tags: Dict[str, str] # Resource tags

253

etag: str # ETag for concurrency control

254

max_number_of_record_sets: int # Maximum record sets allowed (read-only)

255

number_of_record_sets: int # Current number of record sets (read-only)

256

name_servers: List[str] # Name servers for the zone (read-only)

257

zone_type: ZoneType # Public or Private zone type

258

registration_virtual_networks: List[SubResource] # VNets for hostname registration

259

resolution_virtual_networks: List[SubResource] # VNets for record resolution

260

261

class RecordSet:

262

"""Represents a DNS record set within a zone."""

263

id: str # Record set ID (read-only)

264

name: str # Record set name (read-only)

265

type: str # Record set type (read-only)

266

etag: str # ETag for concurrency control

267

metadata: Dict[str, str] # Metadata key-value pairs

268

ttl: int # Time-to-live in seconds

269

fqdn: str # Fully qualified domain name (read-only)

270

target_resource: SubResource # Reference to Azure resource

271

# Record type specific arrays:

272

a_records: List[ARecord]

273

aaaa_records: List[AaaaRecord]

274

caa_records: List[CaaRecord]

275

cname_record: CnameRecord

276

mx_records: List[MxRecord]

277

ns_records: List[NsRecord]

278

ptr_records: List[PtrRecord]

279

soa_record: SoaRecord

280

srv_records: List[SrvRecord]

281

txt_records: List[TxtRecord]

282

283

class RecordType(str, Enum):

284

"""Supported DNS record types."""

285

A = "A"

286

AAAA = "AAAA"

287

CAA = "CAA"

288

CNAME = "CNAME"

289

MX = "MX"

290

NS = "NS"

291

PTR = "PTR"

292

SOA = "SOA"

293

SRV = "SRV"

294

TXT = "TXT"

295

296

class ZoneType(str, Enum):

297

"""DNS zone types."""

298

PUBLIC = "Public"

299

PRIVATE = "Private"

300

```

301

302

### Authentication and Configuration

303

304

The client requires Azure Active Directory authentication and subscription configuration:

305

306

```python { .api }

307

class DnsManagementClient:

308

"""Main client for Azure DNS management operations."""

309

def __init__(

310

self,

311

credential: TokenCredential,

312

subscription_id: str,

313

base_url: Optional[str] = None,

314

**kwargs: Any

315

) -> None: ...

316

317

# Operation properties

318

record_sets: RecordSetsOperations

319

zones: ZonesOperations

320

dns_resource_reference: DnsResourceReferenceOperations

321

322

def close(self) -> None: ...

323

def __enter__(self) -> Self: ...

324

def __exit__(self, *exc_details: Any) -> None: ...

325

```

326

327

### Supporting Models

328

329

```python { .api }

330

class Resource:

331

"""Base Azure resource model."""

332

id: str # Azure resource ID (read-only)

333

name: str # Resource name (read-only)

334

type: str # Resource type (read-only)

335

location: str # Resource location

336

tags: Dict[str, str] # Resource tags

337

338

class SubResource:

339

"""Reference to another Azure resource."""

340

id: str # Full Azure resource ID

341

342

class CloudErrorBody:

343

"""Azure REST API error response structure."""

344

code: str # Error code

345

message: str # Error message

346

target: Optional[str] # Error target

347

details: List[CloudErrorBody] # Nested error details

348

additional_info: List[Dict] # Additional error information

349

350

class ZoneListResult:

351

"""Paginated result for zone list operations."""

352

value: List[Zone] # List of zones in current page

353

next_link: Optional[str] # URL for next page of results

354

355

class RecordSetListResult:

356

"""Paginated result for record set list operations."""

357

value: List[RecordSet] # List of record sets in current page

358

next_link: Optional[str] # URL for next page of results

359

360

class ZoneUpdate:

361

"""Parameters for updating DNS zone properties."""

362

tags: Dict[str, str] # Updated resource tags

363

```

364

365

## Async Support

366

367

The Azure DNS Management Client provides full async support through the `azure.mgmt.dns.aio` module:

368

369

```python { .api }

370

from azure.mgmt.dns.aio import DnsManagementClient

371

372

class DnsManagementClient:

373

"""Async version of the DNS management client."""

374

def __init__(

375

self,

376

credential: AsyncTokenCredential,

377

subscription_id: str,

378

base_url: Optional[str] = None,

379

**kwargs: Any

380

) -> None: ...

381

382

# Async operation properties (same methods as sync, but async)

383

record_sets: RecordSetsOperations

384

zones: ZonesOperations

385

dns_resource_reference: DnsResourceReferenceOperations

386

387

async def close(self) -> None: ...

388

async def __aenter__(self) -> Self: ...

389

async def __aexit__(self, *exc_details: Any) -> None: ...

390

```

391

392

**Async Usage Example:**

393

394

```python

395

import asyncio

396

from azure.identity.aio import DefaultAzureCredential

397

from azure.mgmt.dns.aio import DnsManagementClient

398

from azure.mgmt.dns.models import Zone

399

400

async def manage_dns_async():

401

credential = DefaultAzureCredential()

402

async with DnsManagementClient(credential, "subscription-id") as dns_client:

403

# Create zone asynchronously

404

zone_params = Zone(location="global")

405

zone = await dns_client.zones.create_or_update(

406

resource_group_name="my-rg",

407

zone_name="example.com",

408

parameters=zone_params

409

)

410

411

# List zones asynchronously

412

zones = dns_client.zones.list_by_resource_group("my-rg")

413

async for zone in zones:

414

print(f"Zone: {zone.name}")

415

416

# Run async function

417

asyncio.run(manage_dns_async())

418

```