or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

index.mdload-balancers.mdnetwork-interfaces.mdnetwork-security.mdvirtual-networks.md

virtual-networks.mddocs/

0

# Virtual Networks and Subnets

1

2

Azure Virtual Networks (VNets) provide isolated network environments in the cloud. This module provides comprehensive management of virtual networks, subnets, address spaces, network peering, and related networking components.

3

4

## Capabilities

5

6

### Virtual Network Management

7

8

Create, configure, and manage Azure virtual networks including address spaces, DNS settings, DDoS protection, and service endpoints.

9

10

```python { .api }

11

class VirtualNetworksOperations:

12

def begin_create_or_update(self, resource_group_name: str, virtual_network_name: str, parameters: VirtualNetwork, **kwargs) -> LROPoller[VirtualNetwork]:

13

"""

14

Creates or updates a virtual network in the specified resource group.

15

16

Args:

17

resource_group_name (str): The name of the resource group

18

virtual_network_name (str): The name of the virtual network

19

parameters (VirtualNetwork): Parameters supplied to create or update virtual network

20

21

Returns:

22

LROPoller[VirtualNetwork]: A poller object for the long-running operation

23

"""

24

25

def get(self, resource_group_name: str, virtual_network_name: str, *, expand: Optional[str] = None, **kwargs) -> VirtualNetwork:

26

"""

27

Gets the specified virtual network by resource group.

28

29

Args:

30

resource_group_name (str): The name of the resource group

31

virtual_network_name (str): The name of the virtual network

32

expand (str, optional): Expands referenced resources

33

34

Returns:

35

VirtualNetwork: The virtual network resource

36

"""

37

38

def begin_delete(self, resource_group_name: str, virtual_network_name: str, **kwargs) -> LROPoller[None]:

39

"""

40

Deletes the specified virtual network.

41

42

Args:

43

resource_group_name (str): The name of the resource group

44

virtual_network_name (str): The name of the virtual network

45

46

Returns:

47

LROPoller[None]: A poller object for the long-running operation

48

"""

49

50

def list(self, resource_group_name: str, **kwargs) -> Iterable[VirtualNetwork]:

51

"""

52

Gets all virtual networks in a resource group.

53

54

Args:

55

resource_group_name (str): The name of the resource group

56

57

Returns:

58

Iterable[VirtualNetwork]: Iterator of virtual networks

59

"""

60

61

def list_all(self, **kwargs) -> Iterable[VirtualNetwork]:

62

"""

63

Gets all virtual networks in a subscription.

64

65

Returns:

66

Iterable[VirtualNetwork]: Iterator of virtual networks

67

"""

68

69

def check_ip_address_availability(self, resource_group_name: str, virtual_network_name: str, ip_address: str, **kwargs) -> IPAddressAvailabilityResult:

70

"""

71

Checks whether a private IP address is available for use.

72

73

Args:

74

resource_group_name (str): The name of the resource group

75

virtual_network_name (str): The name of the virtual network

76

ip_address (str): The private IP address to be verified

77

78

Returns:

79

IPAddressAvailabilityResult: IP address availability result

80

"""

81

82

def list_usage(self, resource_group_name: str, virtual_network_name: str, **kwargs) -> Iterable[VirtualNetworkUsage]:

83

"""

84

Lists usage stats for the virtual network.

85

86

Args:

87

resource_group_name (str): The name of the resource group

88

virtual_network_name (str): The name of the virtual network

89

90

Returns:

91

Iterable[VirtualNetworkUsage]: Iterator of usage stats

92

"""

93

94

def update_tags(self, resource_group_name: str, virtual_network_name: str, parameters: TagsObject, **kwargs) -> VirtualNetwork:

95

"""

96

Updates virtual network tags.

97

98

Args:

99

resource_group_name (str): The name of the resource group

100

virtual_network_name (str): The name of the virtual network

101

parameters (TagsObject): Parameters supplied to update virtual network tags

102

103

Returns:

104

VirtualNetwork: The updated virtual network

105

"""

106

107

def begin_list_ddos_protection_status(self, resource_group_name: str, virtual_network_name: str, *, top: Optional[int] = None, skip_token: Optional[str] = None, **kwargs) -> LROPoller[Iterable[PublicIpDdosProtectionStatusResult]]:

108

"""

109

Gets the DDoS Protection Status of all IP Addresses under the Virtual Network.

110

111

Args:

112

resource_group_name (str): The name of the resource group

113

virtual_network_name (str): The name of the virtual network

114

top (int, optional): An optional query parameter for the maximum number of results to return

115

skip_token (str, optional): SkipToken is only used if a previous operation returned a partial result

116

117

Returns:

118

LROPoller[Iterable[PublicIpDdosProtectionStatusResult]]: A poller object for the long-running operation

119

"""

120

```

121

122

### Subnet Management

123

124

Manage subnets within virtual networks including address prefixes, network security groups, route tables, and service endpoints.

125

126

```python { .api }

127

class SubnetsOperations:

128

def begin_create_or_update(self, resource_group_name: str, virtual_network_name: str, subnet_name: str, subnet_parameters: Subnet, **kwargs) -> LROPoller[Subnet]:

129

"""

130

Creates or updates a subnet in the specified virtual network.

131

132

Args:

133

resource_group_name (str): The name of the resource group

134

virtual_network_name (str): The name of the virtual network

135

subnet_name (str): The name of the subnet

136

subnet_parameters (Subnet): Parameters supplied to create or update subnet

137

138

Returns:

139

LROPoller[Subnet]: A poller object for the long-running operation

140

"""

141

142

def get(self, resource_group_name: str, virtual_network_name: str, subnet_name: str, *, expand: Optional[str] = None, **kwargs) -> Subnet:

143

"""

144

Gets the specified subnet by virtual network and resource group.

145

146

Args:

147

resource_group_name (str): The name of the resource group

148

virtual_network_name (str): The name of the virtual network

149

subnet_name (str): The name of the subnet

150

expand (str, optional): Expands referenced resources

151

152

Returns:

153

Subnet: The subnet resource

154

"""

155

156

def begin_delete(self, resource_group_name: str, virtual_network_name: str, subnet_name: str, **kwargs) -> LROPoller[None]:

157

"""

158

Deletes the specified subnet.

159

160

Args:

161

resource_group_name (str): The name of the resource group

162

virtual_network_name (str): The name of the virtual network

163

subnet_name (str): The name of the subnet

164

165

Returns:

166

LROPoller[None]: A poller object for the long-running operation

167

"""

168

169

def list(self, resource_group_name: str, virtual_network_name: str, **kwargs) -> Iterable[Subnet]:

170

"""

171

Gets all subnets in a virtual network.

172

173

Args:

174

resource_group_name (str): The name of the resource group

175

virtual_network_name (str): The name of the virtual network

176

177

Returns:

178

Iterable[Subnet]: Iterator of subnets

179

"""

180

181

def begin_prepare_network_policies(self, resource_group_name: str, virtual_network_name: str, subnet_name: str, prepare_network_policies_request_parameters: PrepareNetworkPoliciesRequest, **kwargs) -> LROPoller[None]:

182

"""

183

Prepares a subnet by applying network intent policies.

184

185

Args:

186

resource_group_name (str): The name of the resource group

187

virtual_network_name (str): The name of the virtual network

188

subnet_name (str): The name of the subnet

189

prepare_network_policies_request_parameters (PrepareNetworkPoliciesRequest): Parameters supplied to prepare subnet

190

191

Returns:

192

LROPoller[None]: A poller object for the long-running operation

193

"""

194

195

def begin_unprepare_network_policies(self, resource_group_name: str, virtual_network_name: str, subnet_name: str, unprepare_network_policies_request_parameters: UnprepareNetworkPoliciesRequest, **kwargs) -> LROPoller[None]:

196

"""

197

Unprepares a subnet by removing network intent policies.

198

199

Args:

200

resource_group_name (str): The name of the resource group

201

virtual_network_name (str): The name of the virtual network

202

subnet_name (str): The name of the subnet

203

unprepare_network_policies_request_parameters (UnprepareNetworkPoliciesRequest): Parameters supplied to unprepare subnet

204

205

Returns:

206

LROPoller[None]: A poller object for the long-running operation

207

"""

208

```

209

210

### Virtual Network Peering

211

212

Manage virtual network peering connections to enable communication between virtual networks.

213

214

```python { .api }

215

class VirtualNetworkPeeringsOperations:

216

def begin_create_or_update(self, resource_group_name: str, virtual_network_name: str, virtual_network_peering_name: str, virtual_network_peering_parameters: VirtualNetworkPeering, **kwargs) -> LROPoller[VirtualNetworkPeering]:

217

"""

218

Creates or updates a peering in the specified virtual network.

219

220

Args:

221

resource_group_name (str): The name of the resource group

222

virtual_network_name (str): The name of the virtual network

223

virtual_network_peering_name (str): The name of the peering

224

virtual_network_peering_parameters (VirtualNetworkPeering): Parameters supplied to create or update virtual network peering

225

226

Returns:

227

LROPoller[VirtualNetworkPeering]: A poller object for the long-running operation

228

"""

229

230

def get(self, resource_group_name: str, virtual_network_name: str, virtual_network_peering_name: str, **kwargs) -> VirtualNetworkPeering:

231

"""

232

Gets the specified virtual network peering.

233

234

Args:

235

resource_group_name (str): The name of the resource group

236

virtual_network_name (str): The name of the virtual network

237

virtual_network_peering_name (str): The name of the virtual network peering

238

239

Returns:

240

VirtualNetworkPeering: The virtual network peering resource

241

"""

242

243

def begin_delete(self, resource_group_name: str, virtual_network_name: str, virtual_network_peering_name: str, **kwargs) -> LROPoller[None]:

244

"""

245

Deletes the specified virtual network peering.

246

247

Args:

248

resource_group_name (str): The name of the resource group

249

virtual_network_name (str): The name of the virtual network

250

virtual_network_peering_name (str): The name of the virtual network peering

251

252

Returns:

253

LROPoller[None]: A poller object for the long-running operation

254

"""

255

256

def list(self, resource_group_name: str, virtual_network_name: str, **kwargs) -> Iterable[VirtualNetworkPeering]:

257

"""

258

Gets all virtual network peerings in a virtual network.

259

260

Args:

261

resource_group_name (str): The name of the resource group

262

virtual_network_name (str): The name of the virtual network

263

264

Returns:

265

Iterable[VirtualNetworkPeering]: Iterator of virtual network peerings

266

"""

267

```

268

269

## Usage Examples

270

271

### Creating a Virtual Network with Subnets

272

273

```python

274

from azure.mgmt.network.models import (

275

VirtualNetwork, AddressSpace, Subnet, DhcpOptions

276

)

277

278

# Define virtual network parameters

279

vnet_params = VirtualNetwork(

280

location="East US",

281

address_space=AddressSpace(

282

address_prefixes=["10.0.0.0/16"]

283

),

284

dhcp_options=DhcpOptions(

285

dns_servers=["8.8.8.8", "8.8.4.4"]

286

),

287

subnets=[

288

Subnet(

289

name="default",

290

address_prefix="10.0.1.0/24"

291

),

292

Subnet(

293

name="web-tier",

294

address_prefix="10.0.2.0/24"

295

),

296

Subnet(

297

name="app-tier",

298

address_prefix="10.0.3.0/24"

299

)

300

],

301

tags={"Environment": "Production", "Team": "Networking"}

302

)

303

304

# Create virtual network

305

operation = client.virtual_networks.begin_create_or_update(

306

resource_group_name="my-resource-group",

307

virtual_network_name="my-vnet",

308

parameters=vnet_params

309

)

310

vnet = operation.result()

311

312

print(f"Created VNet: {vnet.name} with {len(vnet.subnets)} subnets")

313

```

314

315

### Setting up Virtual Network Peering

316

317

```python

318

from azure.mgmt.network.models import VirtualNetworkPeering

319

320

# Create peering from VNet1 to VNet2

321

peering_params = VirtualNetworkPeering(

322

allow_virtual_network_access=True,

323

allow_forwarded_traffic=False,

324

allow_gateway_transit=False,

325

use_remote_gateways=False,

326

remote_virtual_network={

327

"id": "/subscriptions/{subscription-id}/resourceGroups/rg2/providers/Microsoft.Network/virtualNetworks/vnet2"

328

}

329

)

330

331

# Create the peering

332

peering_operation = client.virtual_network_peerings.begin_create_or_update(

333

resource_group_name="rg1",

334

virtual_network_name="vnet1",

335

virtual_network_peering_name="vnet1-to-vnet2",

336

virtual_network_peering_parameters=peering_params

337

)

338

peering = peering_operation.result()

339

340

print(f"Created peering: {peering.name}")

341

```

342

343

## Types

344

345

```python { .api }

346

class VirtualNetwork(Resource):

347

def __init__(self, **kwargs): ...

348

address_space: Optional[AddressSpace]

349

dhcp_options: Optional[DhcpOptions]

350

subnets: Optional[List[Subnet]]

351

virtual_network_peerings: Optional[List[VirtualNetworkPeering]]

352

resource_guid: Optional[str] # Read-only

353

provisioning_state: Optional[ProvisioningState] # Read-only

354

enable_ddos_protection: Optional[bool]

355

enable_vm_protection: Optional[bool]

356

ddos_protection_plan: Optional[SubResource]

357

bgp_communities: Optional[VirtualNetworkBgpCommunities]

358

ip_allocations: Optional[List[SubResource]]

359

flow_timeout_in_minutes: Optional[int]

360

361

class Subnet(SubResource):

362

def __init__(self, **kwargs): ...

363

address_prefix: Optional[str]

364

address_prefixes: Optional[List[str]]

365

network_security_group: Optional[NetworkSecurityGroup]

366

route_table: Optional[RouteTable]

367

nat_gateway: Optional[SubResource]

368

service_endpoints: Optional[List[ServiceEndpointPropertiesFormat]]

369

service_endpoint_policies: Optional[List[ServiceEndpointPolicy]]

370

private_endpoints: Optional[List[PrivateEndpoint]] # Read-only

371

ip_configurations: Optional[List[IPConfiguration]] # Read-only

372

resource_navigation_links: Optional[List[ResourceNavigationLink]] # Read-only

373

service_association_links: Optional[List[ServiceAssociationLink]] # Read-only

374

delegations: Optional[List[Delegation]]

375

purpose: Optional[str] # Read-only

376

provisioning_state: Optional[ProvisioningState] # Read-only

377

private_endpoint_network_policies: Optional[VirtualNetworkPrivateEndpointNetworkPolicies]

378

private_link_service_network_policies: Optional[VirtualNetworkPrivateLinkServiceNetworkPolicies]

379

application_gateway_ip_configurations: Optional[List[ApplicationGatewayIPConfiguration]] # Read-only

380

381

class VirtualNetworkPeering(SubResource):

382

def __init__(self, **kwargs): ...

383

allow_virtual_network_access: Optional[bool]

384

allow_forwarded_traffic: Optional[bool]

385

allow_gateway_transit: Optional[bool]

386

use_remote_gateways: Optional[bool]

387

remote_virtual_network: Optional[SubResource]

388

remote_address_space: Optional[AddressSpace] # Read-only

389

remote_bgp_communities: Optional[VirtualNetworkBgpCommunities] # Read-only

390

peering_state: Optional[VirtualNetworkPeeringState] # Read-only

391

peering_sync_level: Optional[VirtualNetworkPeeringLevel] # Read-only

392

provisioning_state: Optional[ProvisioningState] # Read-only

393

do_not_verify_remote_gateways: Optional[bool]

394

395

class AddressSpace:

396

def __init__(self, **kwargs): ...

397

address_prefixes: Optional[List[str]]

398

399

class DhcpOptions:

400

def __init__(self, **kwargs): ...

401

dns_servers: Optional[List[str]]

402

403

# Enumerations

404

class VirtualNetworkPeeringState(str, Enum):

405

INITIATED = "Initiated"

406

CONNECTED = "Connected"

407

DISCONNECTED = "Disconnected"

408

409

class VirtualNetworkPeeringLevel(str, Enum):

410

FULLY_IN_SYNC = "FullyInSync"

411

REMOTE_NOT_IN_SYNC = "RemoteNotInSync"

412

LOCAL_NOT_IN_SYNC = "LocalNotInSync"

413

LOCAL_AND_REMOTE_NOT_IN_SYNC = "LocalAndRemoteNotInSync"

414

415

class VirtualNetworkPrivateEndpointNetworkPolicies(str, Enum):

416

ENABLED = "Enabled"

417

DISABLED = "Disabled"

418

419

class VirtualNetworkPrivateLinkServiceNetworkPolicies(str, Enum):

420

ENABLED = "Enabled"

421

DISABLED = "Disabled"

422

423

class TagsObject:

424

def __init__(self, **kwargs): ...

425

tags: Optional[Dict[str, str]]

426

427

class IPAddressAvailabilityResult:

428

def __init__(self, **kwargs): ...

429

available: Optional[bool] # Read-only

430

available_ip_addresses: Optional[List[str]] # Read-only

431

is_platform_reserved: Optional[bool] # Read-only

432

433

class VirtualNetworkUsage:

434

def __init__(self, **kwargs): ...

435

current_value: Optional[float] # Read-only

436

id: Optional[str] # Read-only

437

limit: Optional[float] # Read-only

438

name: Optional[VirtualNetworkUsageName] # Read-only

439

unit: Optional[str] # Read-only

440

441

class VirtualNetworkUsageName:

442

def __init__(self, **kwargs): ...

443

localized_value: Optional[str] # Read-only

444

value: Optional[str] # Read-only

445

446

class PublicIpDdosProtectionStatusResult:

447

def __init__(self, **kwargs): ...

448

ddos_protection_plan_id: Optional[str] # Read-only

449

is_workload_protected: Optional[PublicIpDdosProtectionStatusType] # Read-only

450

public_ip_address: Optional[str] # Read-only

451

public_ip_address_id: Optional[str] # Read-only

452

453

class PublicIpDdosProtectionStatusType(str, Enum):

454

PROTECTED = "Protected"

455

UNPROTECTED = "Unprotected"

456

NOT_COVERED = "NotCovered"

457

```