Python için Azure Batch kitaplıkları

Genel Bakış

Azure Batch ile büyük ölçekli paralel ve yüksek performanslı bilgi işlem uygulamalarını bulutta verimli bir şekilde çalıştırın.

Azure Batch kullanmaya başlamak için bkz. Azure portal ile Batch hesabı oluşturma.

Kitaplıkları yükleme

İstemci kitaplığı

Azure Batch istemci kitaplıkları işlem düğümlerini ve havuzlarını yapılandırmanıza, görevleri tanımlamanıza ve bunları işlerde çalışacak şekilde yapılandırmanıza ve iş yürütmeyi denetlemek ve izlemek için bir iş yöneticisi ayarlamanıza olanak tanır. Büyük ölçekli paralel işlem çözümlerini çalıştırmak için bu nesneleri kullanma hakkında daha fazla bilgi edinin.

pip install azure-batch

Örnek

Bir toplu iş hesabında Linux işlem düğümleri havuzu ayarlayın:

import azure.batch
from azure.batch import batch_auth, BatchServiceClient, models

# create the batch client for an account using its URI and keys
creds = batch_auth.SharedKeyCredentials(account, key)
client = BatchServiceClient(creds, batch_url)

# Create the VirtualMachineConfiguration, specifying
# the VM image reference and the Batch node agent to
# be installed on the node.
vmc = models.VirtualMachineConfiguration(
    image_reference = models.ImageReference(
        publisher='Canonical',
        offer='UbuntuServer',
        sku='18.04-LTS'
        ),
    node_agent_sku_id = "batch.node.ubuntu 18.04")

# Assign the virtual machine configuration to the pool
new_pool = models.PoolAddParameter(
    id = 'new_pool',
    vm_size='standard_d2_v2',
    virtual_machine_configuration = vmc
)

# Create pool in the Batch service
client.pool.add(new_pool)

Yönetim API'si

Batch hesapları oluşturmak ve silmek, batch hesabı anahtarlarını okumak ve yeniden oluşturmak ve batch hesabı depolama alanını yönetmek için Azure Batch yönetim kitaplıklarını kullanın.

pip install azure-mgmt-batch

Örnek

bir Azure Batch hesabı oluşturun ve bunun için yeni bir uygulama ve Azure depolama hesabı yapılandırın.

from azure.mgmt.batch import BatchManagementClient
from azure.mgmt.resource import ResourceManagementClient
from azure.mgmt.storage import StorageManagementClient

LOCATION ='eastus'
GROUP_NAME ='batchresourcegroup'
STORAGE_ACCOUNT_NAME ='batchstorageaccount'

# Create Resource group
print('Create Resource Group')
resource_client.resource_groups.create_or_update(GROUP_NAME, {'location': LOCATION})

# Create a storage account
storage_async_operation = storage_client.storage_accounts.create(
    GROUP_NAME,
    STORAGE_ACCOUNT_NAME,
    StorageAccountCreateParameters(
        sku=Sku(SkuName.standard_ragrs),
        kind=Kind.storage,
        location=LOCATION
    )
)
storage_account = storage_async_operation.result()

# Create a Batch Account, specifying the storage account we want to link
storage_resource = storage_account.id
batch_account_parameters = azure.mgmt.batch.models.BatchAccountCreateParameters(
    location=LOCATION,
    auto_storage=azure.mgmt.batch.models.AutoStorageBaseProperties(storage_resource)
)
creating = batch_client.batch_account.begin_create('MyBatchResourceGroup', 'MyBatchAccount', batch_account_parameters)
creating.wait()