Azure 虛擬機器程式庫Azure virtual machine libraries

概觀Overview

執行 Linux 或 Windows 並可視需要擴充的計算資源。On-demand, scalable computing resources running Linux or Windows.

若要開始使用 Azure 虛擬機器,請參閱使用 Azure 入口網站建立 Linux 虛擬機器To get started with Azure Virtual Machines, see Create a Linux virtual machine with the Azure portal.

管理 APIManagement API

從程式碼使用管理 API 在 Azure 中建立、設定、管理及調整 Windows 和 Linux 虛擬機器。Create, configure, manage and scale Windows and Linux virtual machines in Azure from your code with the management API.

透過 pip 安裝程式庫。Install the library via pip.

pip install azure-mgmt-compute

範例Example

在現有的 Azure 資源群組中,使用受控服務身分識別 (MSI) 驗證建立新的 Linux 虛擬機器。Create a new Linux virtual machine in an existing Azure resource group with Managed Service Identity(MSI) authentication.

VM_PARAMETERS={
        'location': 'LOCATION',
        'os_profile': {
            'computer_name': 'VM_NAME',
            'admin_username': 'USERNAME',
            'admin_password': 'PASSWORD'
        },
        'hardware_profile': {
            'vm_size': 'Standard_DS1_v2'
        },
        'storage_profile': {
            'image_reference': {
                'publisher': 'Canonical',
                'offer': 'UbuntuServer',
                'sku': '16.04.0-LTS',
                'version': 'latest'
            },
        },
        'network_profile': {
            'network_interfaces': [{
                'id': 'NIC_ID',
            }]
        },
    }

def create_vm()
    compute_client.virtual_machines.create_or_update(
        'RESOURCE_GROUP_NAME', 'VM_NAME', VM_PARAMETERS)

範例Samples

檢視虛擬機器範本的完整清單View the complete list of virtual machine samples.