編輯

共用方式為


適用於 Python 的 Azure 網路程式庫Azure Network libraries for python

概觀Overview

Azure 虛擬網路可讓您連線 Azure 資源,還能將它們連線至內部部署網路。Azure Virtual Network allows you to connect Azure resources, and also connect them to your on-premises network.

若要開始使用 Azure 虛擬網路,請參閱建立您的第一個虛擬網路To get started with Azure Virtual Network, see Create your first virtual network.

管理 APIManagement APIs

使用管理 API 來檢查、管理及設定 Azure 虛擬網路。Inspect, manage, and configure Azure virtual networks with the management APIs.

不同於其他 Azure Python API,網路 API 會明確地建立版本以分成個別套件。Unlike other Azure python APIs, the networking APIs are explicitly versioned into separage packages. 您不需要將它們個別匯入,因為套件資訊會在用戶端建構函式中加以指定。You do not need to import them individually since the package information is specified in the client constructor.

使用 pip 安裝管理套件。Install the management package with pip.

pip install azure-mgmt-network

範例Example

建立虛擬網路和相關聯的子網路。Create a virtual network and an associated subnet.

from azure.mgmt.network import NetworkManagementClient

GROUP_NAME = 'resource-group'
VNET_NAME = 'your-vnet-identifier'
LOCATION = 'region'
SUBNET_NAME = 'your-subnet-identifier'

network_client = NetworkManagementClient(credentials, 'your-subscription-id')

async_vnet_creation = network_client.virtual_networks.create_or_update(
    GROUP_NAME,
    VNET_NAME,
    {
        'location': LOCATION,
        'address_space': {
            'address_prefixes': ['10.0.0.0/16']
        }
    }
)
async_vnet_creation.wait()

# Create Subnet
async_subnet_creation = network_client.subnets.create_or_update(
    GROUP_NAME,
    VNET_NAME,
    SUBNET_NAME,
    {'address_prefix': '10.0.0.0/24'}
)
subnet_info = async_subnet_creation.result()

範例Samples

檢視 Azure 虛擬網路範例的完整清單View the complete list of Azure Virtual Network samples.