Microsoft Azure Batch Management Client Library for Python
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Creation and management of compute pools for batch workloads, including virtual machine configuration, scaling policies, network settings, and monitoring capabilities.
Creates compute pools with specified virtual machine configurations, scaling policies, and network settings.
def create(
resource_group_name: str,
account_name: str,
pool_name: str,
parameters: Pool,
if_match: str = None,
if_none_match: str = None,
**kwargs: Any
) -> LROPoller[Pool]:
"""
Creates a new pool inside the specified account.
Args:
resource_group_name (str): The name of the resource group
account_name (str): The name of the Batch account
pool_name (str): The pool name
parameters (Pool): Pool configuration parameters
if_match (str, optional): ETag value for conditional operations
if_none_match (str, optional): ETag value for conditional operations
Returns:
LROPoller[Pool]: Long-running operation poller for the created pool
"""Retrieves detailed information about an existing pool including current state and node counts.
def get(
resource_group_name: str,
account_name: str,
pool_name: str,
**kwargs: Any
) -> Pool:
"""
Gets information about the specified pool.
Args:
resource_group_name (str): The name of the resource group
account_name (str): The name of the Batch account
pool_name (str): The pool name
Returns:
Pool: The pool details
"""Updates pool properties including scaling settings, application packages, and metadata.
def update(
resource_group_name: str,
account_name: str,
pool_name: str,
parameters: Pool,
if_match: str = None,
**kwargs: Any
) -> Pool:
"""
Updates the properties of the specified pool.
Args:
resource_group_name (str): The name of the resource group
account_name (str): The name of the Batch account
pool_name (str): The pool name
parameters (Pool): Pool update parameters
if_match (str, optional): ETag value for conditional operations
Returns:
Pool: The updated pool
"""Deletes a pool and terminates all compute nodes.
def delete(
resource_group_name: str,
account_name: str,
pool_name: str,
**kwargs: Any
) -> LROPoller[None]:
"""
Deletes the specified pool.
Args:
resource_group_name (str): The name of the resource group
account_name (str): The name of the Batch account
pool_name (str): The pool name
Returns:
LROPoller[None]: Long-running operation poller for the deletion
"""Lists pools within a Batch account with optional filtering.
def list_by_batch_account(
resource_group_name: str,
account_name: str,
maxresults: int = None,
select: str = None,
filter: str = None,
**kwargs: Any
) -> ItemPaged[Pool]:
"""
Lists all pools in the specified account.
Args:
resource_group_name (str): The name of the resource group
account_name (str): The name of the Batch account
maxresults (int, optional): Maximum number of results to return
select (str, optional): OData select clause
filter (str, optional): OData filter clause
Returns:
ItemPaged[Pool]: Paginated list of pools
"""Stops any ongoing resize operation on a pool.
def stop_resize(
resource_group_name: str,
account_name: str,
pool_name: str,
**kwargs: Any
) -> Pool:
"""
Stops an ongoing resize operation on the pool.
Args:
resource_group_name (str): The name of the resource group
account_name (str): The name of the Batch account
pool_name (str): The pool name
Returns:
Pool: The updated pool
"""Disables automatic scaling on a pool.
def disable_auto_scale(
resource_group_name: str,
account_name: str,
pool_name: str,
**kwargs: Any
) -> Pool:
"""
Disables automatic scaling on the specified pool.
Args:
resource_group_name (str): The name of the resource group
account_name (str): The name of the Batch account
pool_name (str): The pool name
Returns:
Pool: The updated pool
"""class Pool:
id: str
name: str
type: str
etag: str
identity: BatchPoolIdentity
display_name: str
last_modified: datetime
creation_time: datetime
provisioning_state: PoolProvisioningState
provisioning_state_transition_time: datetime
allocation_state: AllocationState
allocation_state_transition_time: datetime
vm_size: str
inter_node_communication: InterNodeCommunicationState
max_tasks_per_node: int
task_scheduling_policy: TaskSchedulingPolicy
deployment_configuration: DeploymentConfiguration
scale_settings: ScaleSettings
start_task: StartTask
certificates: list
application_packages: list
application_licenses: list
user_accounts: list
metadata: list
mount_configuration: list
target_node_communication_mode: NodeCommunicationMode
current_node_communication_mode: NodeCommunicationMode
network_configuration: NetworkConfiguration
current_dedicated_nodes: int
current_low_priority_nodes: int
target_dedicated_nodes: int
target_low_priority_nodes: int
resize_timeout: timedelta
resize_errors: list
upgrade_policy: UpgradePolicy
class DeploymentConfiguration:
virtual_machine_configuration: VirtualMachineConfiguration
class VirtualMachineConfiguration:
image_reference: ImageReference
node_agent_sku_id: str
windows_configuration: WindowsConfiguration
data_disks: list
license_type: str
container_configuration: ContainerConfiguration
disk_encryption_configuration: DiskEncryptionConfiguration
node_placement_configuration: NodePlacementConfiguration
extensions: list
os_disk: OSDisk
security_profile: SecurityProfile
class ScaleSettings:
fixed_scale: FixedScaleSettings
auto_scale: AutoScaleSettings
class NetworkConfiguration:
subnet_id: str
dynamic_v_net_assignment_scope: DynamicVNetAssignmentScope
endpoint_configuration: PoolEndpointConfiguration
public_ip_address_configuration: PublicIPAddressConfiguration
enable_accelerated_networking: bool
class BatchPoolIdentity:
type: PoolIdentityType
user_assigned_identities: dictclass ImageReference:
publisher: str
offer: str
sku: str
version: str
id: str
shared_image_gallery_image_id: str
class WindowsConfiguration:
enable_automatic_updates: bool
class ContainerConfiguration:
type: ContainerType
container_image_names: list
container_registries: list
class SecurityProfile:
uefi_settings: UefiSettings
encryption_at_host: bool
security_type: SecurityTypes
class StartTask:
command_line: str
container_settings: TaskContainerSettings
resource_files: list
environment_settings: list
user_identity: UserIdentity
max_task_retry_count: int
wait_for_success: boolclass FixedScaleSettings:
target_dedicated_nodes: int
target_low_priority_nodes: int
resize_timeout: timedelta
node_deallocation_option: ComputeNodeDeallocationOption
class AutoScaleSettings:
formula: str
evaluation_interval: timedelta
class AutoScaleRun:
timestamp: datetime
results: str
error: AutoScaleRunErrorfrom azure.mgmt.batch.models import (
Pool, VirtualMachineConfiguration, ImageReference,
DeploymentConfiguration, FixedScaleSettings, ScaleSettings
)
# Configure VM image
image_ref = ImageReference(
publisher="Canonical",
offer="0001-com-ubuntu-server-focal",
sku="20_04-lts-gen2",
version="latest"
)
# Configure VM settings
vm_config = VirtualMachineConfiguration(
image_reference=image_ref,
node_agent_sku_id="batch.node.ubuntu 20.04"
)
deployment_config = DeploymentConfiguration(
virtual_machine_configuration=vm_config
)
# Configure scaling
fixed_scale = FixedScaleSettings(
target_dedicated_nodes=2,
target_low_priority_nodes=0
)
scale_settings = ScaleSettings(fixed_scale=fixed_scale)
# Create pool
pool = Pool(
vm_size="Standard_D2s_v3",
deployment_configuration=deployment_config,
scale_settings=scale_settings
)
operation = client.pool.create("my-resource-group", "my-batch-account", "my-pool", pool)
created_pool = operation.result()
print(f"Created pool: {created_pool.name}")from azure.mgmt.batch.models import AutoScaleSettings
from datetime import timedelta
# Configure auto-scaling formula
auto_scale = AutoScaleSettings(
formula="""
startingNumberOfVMs = 1;
maxNumberofVMs = 25;
pendingTaskSamplePercent = $PendingTasks.GetSamplePercent(180 * TimeInterval_Second);
pendingTaskSamples = pendingTaskSamplePercent < 70 ? startingNumberOfVMs : avg($PendingTasks.GetSample(180 * TimeInterval_Second));
$TargetDedicatedNodes = min(maxNumberofVMs, pendingTaskSamples);
""",
evaluation_interval=timedelta(minutes=15)
)
scale_settings = ScaleSettings(auto_scale=auto_scale)
pool = Pool(
vm_size="Standard_D2s_v3",
deployment_configuration=deployment_config,
scale_settings=scale_settings
)
operation = client.pool.create("my-resource-group", "my-batch-account", "auto-pool", pool)
auto_pool = operation.result()# Get pool details and current state
pool = client.pool.get("my-resource-group", "my-batch-account", "my-pool")
print(f"Pool: {pool.name}")
print(f"VM Size: {pool.vm_size}")
print(f"Provisioning State: {pool.provisioning_state}")
print(f"Allocation State: {pool.allocation_state}")
print(f"Current Nodes: {pool.current_dedicated_nodes}")
print(f"Target Nodes: {pool.target_dedicated_nodes}")
if pool.resize_errors:
print("Resize Errors:")
for error in pool.resize_errors:
print(f" - {error.code}: {error.message}")Install with Tessl CLI
npx tessl i tessl/pypi-azure-mgmt-batch