Microsoft Azure Batch Client Library for Python providing comprehensive APIs for managing batch computing workloads in Azure cloud
91
Pool management capabilities including creation, deletion, scaling, and monitoring of compute node pools that execute batch workloads. Pools define the virtual machines and configuration that will run your batch jobs and tasks.
Create, retrieve, update, and delete pools with comprehensive configuration options.
def add(pool, pool_add_options=None, custom_headers=None, raw=False, **operation_config):
"""
Add a pool to the specified account.
Args:
pool: The pool to add (PoolSpecification)
pool_add_options: Additional options for the operation
custom_headers: Custom headers to include in request
raw: Return raw response if True
Returns:
None
"""
def list(pool_list_options=None, custom_headers=None, raw=False, **operation_config):
"""
List all pools in the account.
Args:
pool_list_options: Additional options for listing
Returns:
ItemPaged[CloudPool]: Paginated list of pools
"""
def get(pool_id, pool_get_options=None, custom_headers=None, raw=False, **operation_config):
"""
Get information about the specified pool.
Args:
pool_id: ID of the pool to retrieve
pool_get_options: Additional options for the operation
Returns:
CloudPool: Pool information
"""
def delete(pool_id, pool_delete_options=None, custom_headers=None, raw=False, **operation_config):
"""
Delete the specified pool.
Args:
pool_id: ID of the pool to delete
pool_delete_options: Additional options for deletion
Returns:
None
"""
def exists(pool_id, pool_exists_options=None, custom_headers=None, raw=False, **operation_config):
"""
Check if a pool exists.
Args:
pool_id: ID of the pool to check
Returns:
bool: True if pool exists, False otherwise
"""Update pool properties and configuration after creation.
def patch(pool_id, pool_patch_parameter, pool_patch_options=None, custom_headers=None, raw=False, **operation_config):
"""
Update properties of the specified pool.
Args:
pool_id: ID of the pool to update
pool_patch_parameter: Properties to update
pool_patch_options: Additional options
Returns:
None
"""
def update_properties(pool_id, pool_update_properties_parameter, pool_update_properties_options=None, custom_headers=None, raw=False, **operation_config):
"""
Update the properties of the specified pool.
Args:
pool_id: ID of the pool to update
pool_update_properties_parameter: Properties to update
Returns:
None
"""Manage pool scaling through manual resize operations and automatic scaling with formulas.
def resize(pool_id, pool_resize_parameter, pool_resize_options=None, custom_headers=None, raw=False, **operation_config):
"""
Change the number of compute nodes in the pool.
Args:
pool_id: ID of the pool to resize
pool_resize_parameter: Resize parameters including target node counts
Returns:
None
"""
def stop_resize(pool_id, pool_stop_resize_options=None, custom_headers=None, raw=False, **operation_config):
"""
Stop an ongoing resize operation on the pool.
Args:
pool_id: ID of the pool
Returns:
None
"""
def enable_auto_scale(pool_id, auto_scale_formula, pool_enable_auto_scale_options=None, custom_headers=None, raw=False, **operation_config):
"""
Enable automatic scaling on the pool.
Args:
pool_id: ID of the pool
auto_scale_formula: Formula for automatic scaling
pool_enable_auto_scale_options: Additional options
Returns:
None
"""
def disable_auto_scale(pool_id, pool_disable_auto_scale_options=None, custom_headers=None, raw=False, **operation_config):
"""
Disable automatic scaling on the pool.
Args:
pool_id: ID of the pool
Returns:
None
"""
def evaluate_auto_scale(pool_id, auto_scale_formula, pool_evaluate_auto_scale_options=None, custom_headers=None, raw=False, **operation_config):
"""
Evaluate an autoscale formula without applying it.
Args:
pool_id: ID of the pool
auto_scale_formula: Formula to evaluate
Returns:
AutoScaleRun: Results of the formula evaluation
"""Manage individual compute nodes within pools.
def remove_nodes(pool_id, node_remove_parameter, pool_remove_nodes_options=None, custom_headers=None, raw=False, **operation_config):
"""
Remove compute nodes from the specified pool.
Args:
pool_id: ID of the pool
node_remove_parameter: Parameters for node removal including node list
Returns:
None
"""
def list_usage_metrics(pool_list_usage_metrics_options=None, custom_headers=None, raw=False, **operation_config):
"""
List usage metrics for pools in the account.
Args:
pool_list_usage_metrics_options: Options for metrics listing
Returns:
ItemPaged[PoolUsageMetrics]: Pool usage metrics
"""from azure.batch.models import (
PoolSpecification, CloudServiceConfiguration,
StartTask, UserIdentity, AutoUserSpecification
)
# Define pool specification
pool_spec = PoolSpecification(
id="windows-pool",
vm_size="Standard_D2s_v3",
cloud_service_configuration=CloudServiceConfiguration(
os_family="6", # Windows Server 2019
target_os_version="*"
),
target_dedicated_nodes=3,
target_low_priority_nodes=0,
enable_auto_scale=False,
start_task=StartTask(
command_line="cmd /c echo Pool initialized",
user_identity=UserIdentity(
auto_user=AutoUserSpecification(
scope="pool",
elevation_level="admin"
)
),
wait_for_success=True
)
)
# Create the pool
client.pool.add(pool_spec)from azure.batch.models import (
PoolSpecification, VirtualMachineConfiguration,
ImageReference, NodeAgentSkuId
)
pool_spec = PoolSpecification(
id="linux-pool",
vm_size="Standard_D2s_v3",
virtual_machine_configuration=VirtualMachineConfiguration(
image_reference=ImageReference(
publisher="Canonical",
offer="UbuntuServer",
sku="18.04-LTS",
version="latest"
),
node_agent_sku_id="batch.node.ubuntu 18.04"
),
target_dedicated_nodes=2,
target_low_priority_nodes=5,
enable_auto_scale=False
)
client.pool.add(pool_spec)# Create pool with auto-scaling enabled
auto_scale_formula = """
// Get pending tasks for the past 15 minutes
$samples = $ActiveTasks.GetSamplePercent(TimeInterval_Minute * 15);
// If we have less than 70% data, use last sample
$tasks = $samples < 70 ? max(0,$ActiveTasks.GetSample(1)) : max(0, avg($ActiveTasks.GetSample(TimeInterval_Minute * 15)));
// Scale up if there are more tasks than nodes, scale down if few tasks
$targetVMs = $tasks > 0 ? $tasks + 1 : max(0, $TargetDedicatedNodes - 1);
// Limit between 0 and 10 nodes
$TargetDedicatedNodes = max(0, min($targetVMs, 10));
"""
pool_spec = PoolSpecification(
id="autoscale-pool",
vm_size="Standard_D2s_v3",
cloud_service_configuration=CloudServiceConfiguration(
os_family="6"
),
enable_auto_scale=True,
auto_scale_formula=auto_scale_formula,
auto_scale_evaluation_interval=datetime.timedelta(minutes=15)
)
client.pool.add(pool_spec)
# Test the formula before applying
result = client.pool.evaluate_auto_scale("autoscale-pool", auto_scale_formula)
print(f"Formula result: {result.results}")# Check if pool exists
if client.pool.exists("my-pool"):
# Get pool details
pool = client.pool.get("my-pool")
print(f"Pool {pool.id} has {pool.current_dedicated_nodes} nodes")
# Resize pool
from azure.batch.models import PoolResizeParameter
resize_params = PoolResizeParameter(
target_dedicated_nodes=5,
target_low_priority_nodes=10
)
client.pool.resize("my-pool", resize_params)
# Later, delete the pool
client.pool.delete("my-pool")class PoolSpecification:
"""Pool creation specification."""
def __init__(self):
self.id: str
self.display_name: str
self.vm_size: str
self.cloud_service_configuration: CloudServiceConfiguration
self.virtual_machine_configuration: VirtualMachineConfiguration
self.target_dedicated_nodes: int
self.target_low_priority_nodes: int
self.enable_auto_scale: bool
self.auto_scale_formula: str
self.auto_scale_evaluation_interval: datetime.timedelta
self.start_task: StartTask
self.certificates: List[CertificateReference]
self.application_packages: List[ApplicationPackageReference]
self.max_tasks_per_node: int
self.task_scheduling_policy: TaskSchedulingPolicy
self.user_accounts: List[UserAccount]
self.metadata: List[MetadataItem]
class CloudServiceConfiguration:
"""Windows cloud service configuration."""
def __init__(self):
self.os_family: str # "4", "5", "6" for different Windows versions
self.target_os_version: str # "*" for latest
class VirtualMachineConfiguration:
"""Linux/Windows VM configuration."""
def __init__(self):
self.image_reference: ImageReference
self.node_agent_sku_id: str
self.windows_configuration: WindowsConfiguration
self.data_disks: List[DataDisk]
self.license_type: str
self.container_configuration: ContainerConfiguration
class ImageReference:
"""Reference to VM image."""
def __init__(self):
self.publisher: str
self.offer: str
self.sku: str
self.version: str
self.virtual_machine_image_id: str # Custom image IDclass CloudPool:
"""Pool information and state."""
def __init__(self):
self.id: str
self.display_name: str
self.state: str # active, deleting, etc.
self.state_transition_time: datetime.datetime
self.allocation_state: str # steady, resizing, stopping
self.allocation_state_transition_time: datetime.datetime
self.vm_size: str
self.current_dedicated_nodes: int
self.current_low_priority_nodes: int
self.target_dedicated_nodes: int
self.target_low_priority_nodes: int
self.enable_auto_scale: bool
self.auto_scale_formula: str
self.auto_scale_run: AutoScaleRun
self.creation_time: datetime.datetime
self.last_modified: datetime.datetime
self.stats: PoolStatistics
class PoolResizeParameter:
"""Pool resize parameters."""
def __init__(self):
self.target_dedicated_nodes: int
self.target_low_priority_nodes: int
self.resize_timeout: datetime.timedelta
self.node_deallocation_option: str # requeue, terminate, taskcompletion, retainondata
class AutoScaleRun:
"""Auto-scale evaluation results."""
def __init__(self):
self.timestamp: datetime.datetime
self.results: str
self.error: AutoScaleRunErrorInstall with Tessl CLI
npx tessl i tessl/pypi-azure-batchdocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10