Microsoft Azure Batch Client Library for Python providing comprehensive APIs for managing batch computing workloads in Azure cloud
91
Compute node management capabilities for managing individual virtual machines within pools, including user management, remote access, and node maintenance operations. Compute nodes are the actual virtual machines that execute batch tasks.
Retrieve information about compute nodes within pools.
def list(pool_id, compute_node_list_options=None, custom_headers=None, raw=False, **operation_config):
"""
List compute nodes in the specified pool.
Args:
pool_id: ID of the pool containing the nodes
compute_node_list_options: Additional options for listing
Returns:
ItemPaged[ComputeNode]: Paginated list of compute nodes
"""
def get(pool_id, node_id, compute_node_get_options=None, custom_headers=None, raw=False, **operation_config):
"""
Get information about the specified compute node.
Args:
pool_id: ID of the pool containing the node
node_id: ID of the compute node to retrieve
compute_node_get_options: Additional options for the operation
Returns:
ComputeNode: Compute node information
"""Manage user accounts on compute nodes for remote access and task execution.
def add_user(pool_id, node_id, user, compute_node_add_user_options=None, custom_headers=None, raw=False, **operation_config):
"""
Add a user account to the specified compute node.
Args:
pool_id: ID of the pool containing the node
node_id: ID of the compute node
user: User account to add (ComputeNodeUser)
compute_node_add_user_options: Additional options
Returns:
None
"""
def delete_user(pool_id, node_id, user_name, compute_node_delete_user_options=None, custom_headers=None, raw=False, **operation_config):
"""
Delete a user account from the specified compute node.
Args:
pool_id: ID of the pool containing the node
node_id: ID of the compute node
user_name: Name of the user account to delete
compute_node_delete_user_options: Additional options
Returns:
None
"""
def update_user(pool_id, node_id, user_name, node_update_user_parameter, compute_node_update_user_options=None, custom_headers=None, raw=False, **operation_config):
"""
Update properties of a user account on the specified compute node.
Args:
pool_id: ID of the pool containing the node
node_id: ID of the compute node
user_name: Name of the user account to update
node_update_user_parameter: Properties to update
compute_node_update_user_options: Additional options
Returns:
None
"""Perform maintenance operations on compute nodes including reboot and reimage.
def reboot(pool_id, node_id, node_reboot_parameter=None, compute_node_reboot_options=None, custom_headers=None, raw=False, **operation_config):
"""
Restart the specified compute node.
Args:
pool_id: ID of the pool containing the node
node_id: ID of the compute node to reboot
node_reboot_parameter: Reboot parameters including reboot type
compute_node_reboot_options: Additional options
Returns:
None
"""
def reimage(pool_id, node_id, node_reimage_parameter=None, compute_node_reimage_options=None, custom_headers=None, raw=False, **operation_config):
"""
Reinstall the operating system on the specified compute node.
Args:
pool_id: ID of the pool containing the node
node_id: ID of the compute node to reimage
node_reimage_parameter: Reimage parameters including reimage type
compute_node_reimage_options: Additional options
Returns:
None
"""Control task scheduling on compute nodes.
def disable_scheduling(pool_id, node_id, node_disable_scheduling_parameter=None, compute_node_disable_scheduling_options=None, custom_headers=None, raw=False, **operation_config):
"""
Disable task scheduling on the specified compute node.
Args:
pool_id: ID of the pool containing the node
node_id: ID of the compute node
node_disable_scheduling_parameter: Parameters for disabling scheduling
compute_node_disable_scheduling_options: Additional options
Returns:
None
"""
def enable_scheduling(pool_id, node_id, compute_node_enable_scheduling_options=None, custom_headers=None, raw=False, **operation_config):
"""
Enable task scheduling on the specified compute node.
Args:
pool_id: ID of the pool containing the node
node_id: ID of the compute node
compute_node_enable_scheduling_options: Additional options
Returns:
None
"""Get remote access information for compute nodes.
def get_remote_login_settings(pool_id, node_id, compute_node_get_remote_login_settings_options=None, custom_headers=None, raw=False, **operation_config):
"""
Get remote login settings for the specified compute node.
Args:
pool_id: ID of the pool containing the node
node_id: ID of the compute node
compute_node_get_remote_login_settings_options: Additional options
Returns:
ComputeNodeGetRemoteLoginSettingsResult: Remote login settings
"""
def get_remote_desktop(pool_id, node_id, compute_node_get_remote_desktop_options=None, custom_headers=None, raw=False, **operation_config):
"""
Get Remote Desktop Protocol file for the specified compute node.
Args:
pool_id: ID of the pool containing the node
node_id: ID of the compute node
compute_node_get_remote_desktop_options: Additional options
Returns:
Stream: RDP file content
"""Upload batch service logs from compute nodes.
def upload_batch_service_logs(pool_id, node_id, upload_batch_service_logs_configuration, compute_node_upload_batch_service_logs_options=None, custom_headers=None, raw=False, **operation_config):
"""
Upload Azure Batch service log files from the specified compute node.
Args:
pool_id: ID of the pool containing the node
node_id: ID of the compute node
upload_batch_service_logs_configuration: Configuration for log upload
compute_node_upload_batch_service_logs_options: Additional options
Returns:
UploadBatchServiceLogsResult: Upload results
"""# List all nodes in a pool
nodes = client.compute_node.list("my-pool")
for node in nodes:
print(f"Node {node.id}: {node.state} (IP: {node.ip_address})")
print(f" VM Size: {node.vm_size}")
print(f" Running tasks: {node.running_tasks_count}")
print(f" Total tasks run: {node.total_tasks_run}")
# Get detailed information about a specific node
node = client.compute_node.get("my-pool", "tvm-123456789")
print(f"Node state: {node.state}")
print(f"Node agent version: {node.node_agent_info.version}")
if node.recent_tasks:
print("Recent tasks:")
for task_info in node.recent_tasks:
print(f" {task_info.task_id}: {task_info.task_state}")from azure.batch.models import ComputeNodeUser
# Add a user for remote access
user = ComputeNodeUser(
name="batchuser",
password="SecurePassword123!",
is_admin=False, # Non-admin user
expiry_time=datetime.datetime.utcnow() + datetime.timedelta(days=7)
)
client.compute_node.add_user("my-pool", "tvm-123456789", user)
# Update user password
from azure.batch.models import NodeUpdateUserParameter
update_params = NodeUpdateUserParameter(
password="NewSecurePassword456!",
expiry_time=datetime.datetime.utcnow() + datetime.timedelta(days=14)
)
client.compute_node.update_user("my-pool", "tvm-123456789", "batchuser", update_params)
# Delete user when no longer needed
client.compute_node.delete_user("my-pool", "tvm-123456789", "batchuser")from azure.batch.models import NodeRebootParameter, NodeReimageParameter
# Reboot a node (wait for running tasks to complete)
reboot_params = NodeRebootParameter(node_reboot_option="taskcompletion")
client.compute_node.reboot("my-pool", "tvm-123456789", reboot_params)
# Reboot immediately (terminate running tasks)
reboot_params = NodeRebootParameter(node_reboot_option="terminate")
client.compute_node.reboot("my-pool", "tvm-123456789", reboot_params)
# Reimage a node (reinstall OS, wait for tasks to complete)
reimage_params = NodeReimageParameter(node_reimage_option="taskcompletion")
client.compute_node.reimage("my-pool", "tvm-123456789", reimage_params)
# Reimage immediately
reimage_params = NodeReimageParameter(node_reimage_option="terminate")
client.compute_node.reimage("my-pool", "tvm-123456789", reimage_params)from azure.batch.models import NodeDisableSchedulingParameter
# Disable scheduling on a node (complete running tasks)
disable_params = NodeDisableSchedulingParameter(
node_disable_scheduling_option="taskcompletion"
)
client.compute_node.disable_scheduling("my-pool", "tvm-123456789", disable_params)
# Check node state after disabling scheduling
node = client.compute_node.get("my-pool", "tvm-123456789")
print(f"Scheduling state: {node.scheduling_state}") # Should be "disabled"
# Re-enable scheduling
client.compute_node.enable_scheduling("my-pool", "tvm-123456789")# Get remote login settings (SSH for Linux, RDP for Windows)
login_settings = client.compute_node.get_remote_login_settings("my-pool", "tvm-123456789")
print(f"Remote login IP: {login_settings.remote_login_ip_address}")
print(f"Remote login port: {login_settings.remote_login_port}")
# For Windows nodes, get RDP file
rdp_file = client.compute_node.get_remote_desktop("my-pool", "tvm-123456789")
with open("node_rdp.rdp", "wb") as f:
for chunk in rdp_file:
f.write(chunk)from azure.batch.models import UploadBatchServiceLogsConfiguration
# Upload batch service logs for debugging
log_config = UploadBatchServiceLogsConfiguration(
container_url="https://mystorageaccount.blob.core.windows.net/logs?sas_token",
start_time=datetime.datetime.utcnow() - datetime.timedelta(hours=24) # Last 24 hours
)
result = client.compute_node.upload_batch_service_logs("my-pool", "tvm-123456789", log_config)
print(f"Uploaded {result.number_of_files_uploaded} log files")
print(f"Virtual directory: {result.virtual_directory_name}")class ComputeNode:
"""Compute node information and state."""
def __init__(self):
self.id: str
self.url: str
self.state: str # idle, running, starttaskfailed, etc.
self.scheduling_state: str # enabled, disabled
self.state_transition_time: datetime.datetime
self.last_boot_time: datetime.datetime
self.allocation_time: datetime.datetime
self.ip_address: str
self.affinity_id: str
self.vm_size: str
self.total_tasks_run: int
self.running_tasks_count: int
self.running_task_slots_count: int
self.total_tasks_succeeded: int
self.recent_tasks: List[TaskInformation]
self.start_task: StartTask
self.start_task_info: StartTaskInformation
self.certificate_references: List[CertificateReference]
self.errors: List[ComputeNodeError]
self.is_dedicated: bool
self.endpoint_configuration: ComputeNodeEndpointConfiguration
self.node_agent_info: NodeAgentInformation
self.virtual_machine_info: VirtualMachineInfo
class ComputeNodeUser:
"""User account for compute node."""
def __init__(self):
self.name: str
self.is_admin: bool
self.expiry_time: datetime.datetime
self.password: str
self.ssh_public_key: str
class ComputeNodeGetRemoteLoginSettingsResult:
"""Remote login settings for compute node."""
def __init__(self):
self.remote_login_ip_address: str
self.remote_login_port: int
class NodeAgentInformation:
"""Node agent information."""
def __init__(self):
self.version: str
self.last_update_time: datetime.datetime
class TaskInformation:
"""Information about a task that ran on the node."""
def __init__(self):
self.task_url: str
self.job_id: str
self.task_id: str
self.subtask_id: int
self.task_state: str
self.execution_info: TaskExecutionInformationclass NodeRebootParameter:
"""Parameters for rebooting a compute node."""
def __init__(self):
self.node_reboot_option: str # requeue, terminate, taskcompletion, retaineddata
class NodeReimageParameter:
"""Parameters for reimaging a compute node."""
def __init__(self):
self.node_reimage_option: str # requeue, terminate, taskcompletion, retaineddata
class NodeDisableSchedulingParameter:
"""Parameters for disabling scheduling on a compute node."""
def __init__(self):
self.node_disable_scheduling_option: str # requeue, terminate, taskcompletion
class NodeUpdateUserParameter:
"""Parameters for updating a user on a compute node."""
def __init__(self):
self.password: str
self.expiry_time: datetime.datetime
self.ssh_public_key: str
class UploadBatchServiceLogsConfiguration:
"""Configuration for uploading batch service logs."""
def __init__(self):
self.container_url: str
self.start_time: datetime.datetime
self.end_time: datetime.datetime
class UploadBatchServiceLogsResult:
"""Result of uploading batch service logs."""
def __init__(self):
self.virtual_directory_name: str
self.number_of_files_uploaded: intInstall 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