0
# Pool Operations
1
2
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.
3
4
## Capabilities
5
6
### Pool Lifecycle Management
7
8
Create, retrieve, update, and delete pools with comprehensive configuration options.
9
10
```python { .api }
11
def add(pool, pool_add_options=None, custom_headers=None, raw=False, **operation_config):
12
"""
13
Add a pool to the specified account.
14
15
Args:
16
pool: The pool to add (PoolSpecification)
17
pool_add_options: Additional options for the operation
18
custom_headers: Custom headers to include in request
19
raw: Return raw response if True
20
21
Returns:
22
None
23
"""
24
25
def list(pool_list_options=None, custom_headers=None, raw=False, **operation_config):
26
"""
27
List all pools in the account.
28
29
Args:
30
pool_list_options: Additional options for listing
31
32
Returns:
33
ItemPaged[CloudPool]: Paginated list of pools
34
"""
35
36
def get(pool_id, pool_get_options=None, custom_headers=None, raw=False, **operation_config):
37
"""
38
Get information about the specified pool.
39
40
Args:
41
pool_id: ID of the pool to retrieve
42
pool_get_options: Additional options for the operation
43
44
Returns:
45
CloudPool: Pool information
46
"""
47
48
def delete(pool_id, pool_delete_options=None, custom_headers=None, raw=False, **operation_config):
49
"""
50
Delete the specified pool.
51
52
Args:
53
pool_id: ID of the pool to delete
54
pool_delete_options: Additional options for deletion
55
56
Returns:
57
None
58
"""
59
60
def exists(pool_id, pool_exists_options=None, custom_headers=None, raw=False, **operation_config):
61
"""
62
Check if a pool exists.
63
64
Args:
65
pool_id: ID of the pool to check
66
67
Returns:
68
bool: True if pool exists, False otherwise
69
"""
70
```
71
72
### Pool Configuration Updates
73
74
Update pool properties and configuration after creation.
75
76
```python { .api }
77
def patch(pool_id, pool_patch_parameter, pool_patch_options=None, custom_headers=None, raw=False, **operation_config):
78
"""
79
Update properties of the specified pool.
80
81
Args:
82
pool_id: ID of the pool to update
83
pool_patch_parameter: Properties to update
84
pool_patch_options: Additional options
85
86
Returns:
87
None
88
"""
89
90
def update_properties(pool_id, pool_update_properties_parameter, pool_update_properties_options=None, custom_headers=None, raw=False, **operation_config):
91
"""
92
Update the properties of the specified pool.
93
94
Args:
95
pool_id: ID of the pool to update
96
pool_update_properties_parameter: Properties to update
97
98
Returns:
99
None
100
"""
101
```
102
103
### Pool Scaling Operations
104
105
Manage pool scaling through manual resize operations and automatic scaling with formulas.
106
107
```python { .api }
108
def resize(pool_id, pool_resize_parameter, pool_resize_options=None, custom_headers=None, raw=False, **operation_config):
109
"""
110
Change the number of compute nodes in the pool.
111
112
Args:
113
pool_id: ID of the pool to resize
114
pool_resize_parameter: Resize parameters including target node counts
115
116
Returns:
117
None
118
"""
119
120
def stop_resize(pool_id, pool_stop_resize_options=None, custom_headers=None, raw=False, **operation_config):
121
"""
122
Stop an ongoing resize operation on the pool.
123
124
Args:
125
pool_id: ID of the pool
126
127
Returns:
128
None
129
"""
130
131
def enable_auto_scale(pool_id, auto_scale_formula, pool_enable_auto_scale_options=None, custom_headers=None, raw=False, **operation_config):
132
"""
133
Enable automatic scaling on the pool.
134
135
Args:
136
pool_id: ID of the pool
137
auto_scale_formula: Formula for automatic scaling
138
pool_enable_auto_scale_options: Additional options
139
140
Returns:
141
None
142
"""
143
144
def disable_auto_scale(pool_id, pool_disable_auto_scale_options=None, custom_headers=None, raw=False, **operation_config):
145
"""
146
Disable automatic scaling on the pool.
147
148
Args:
149
pool_id: ID of the pool
150
151
Returns:
152
None
153
"""
154
155
def evaluate_auto_scale(pool_id, auto_scale_formula, pool_evaluate_auto_scale_options=None, custom_headers=None, raw=False, **operation_config):
156
"""
157
Evaluate an autoscale formula without applying it.
158
159
Args:
160
pool_id: ID of the pool
161
auto_scale_formula: Formula to evaluate
162
163
Returns:
164
AutoScaleRun: Results of the formula evaluation
165
"""
166
```
167
168
### Node Management
169
170
Manage individual compute nodes within pools.
171
172
```python { .api }
173
def remove_nodes(pool_id, node_remove_parameter, pool_remove_nodes_options=None, custom_headers=None, raw=False, **operation_config):
174
"""
175
Remove compute nodes from the specified pool.
176
177
Args:
178
pool_id: ID of the pool
179
node_remove_parameter: Parameters for node removal including node list
180
181
Returns:
182
None
183
"""
184
185
def list_usage_metrics(pool_list_usage_metrics_options=None, custom_headers=None, raw=False, **operation_config):
186
"""
187
List usage metrics for pools in the account.
188
189
Args:
190
pool_list_usage_metrics_options: Options for metrics listing
191
192
Returns:
193
ItemPaged[PoolUsageMetrics]: Pool usage metrics
194
"""
195
```
196
197
## Usage Examples
198
199
### Creating a Windows Pool
200
201
```python
202
from azure.batch.models import (
203
PoolSpecification, CloudServiceConfiguration,
204
StartTask, UserIdentity, AutoUserSpecification
205
)
206
207
# Define pool specification
208
pool_spec = PoolSpecification(
209
id="windows-pool",
210
vm_size="Standard_D2s_v3",
211
cloud_service_configuration=CloudServiceConfiguration(
212
os_family="6", # Windows Server 2019
213
target_os_version="*"
214
),
215
target_dedicated_nodes=3,
216
target_low_priority_nodes=0,
217
enable_auto_scale=False,
218
start_task=StartTask(
219
command_line="cmd /c echo Pool initialized",
220
user_identity=UserIdentity(
221
auto_user=AutoUserSpecification(
222
scope="pool",
223
elevation_level="admin"
224
)
225
),
226
wait_for_success=True
227
)
228
)
229
230
# Create the pool
231
client.pool.add(pool_spec)
232
```
233
234
### Creating a Linux Pool with Custom Image
235
236
```python
237
from azure.batch.models import (
238
PoolSpecification, VirtualMachineConfiguration,
239
ImageReference, NodeAgentSkuId
240
)
241
242
pool_spec = PoolSpecification(
243
id="linux-pool",
244
vm_size="Standard_D2s_v3",
245
virtual_machine_configuration=VirtualMachineConfiguration(
246
image_reference=ImageReference(
247
publisher="Canonical",
248
offer="UbuntuServer",
249
sku="18.04-LTS",
250
version="latest"
251
),
252
node_agent_sku_id="batch.node.ubuntu 18.04"
253
),
254
target_dedicated_nodes=2,
255
target_low_priority_nodes=5,
256
enable_auto_scale=False
257
)
258
259
client.pool.add(pool_spec)
260
```
261
262
### Auto-scaling Pool
263
264
```python
265
# Create pool with auto-scaling enabled
266
auto_scale_formula = """
267
// Get pending tasks for the past 15 minutes
268
$samples = $ActiveTasks.GetSamplePercent(TimeInterval_Minute * 15);
269
// If we have less than 70% data, use last sample
270
$tasks = $samples < 70 ? max(0,$ActiveTasks.GetSample(1)) : max(0, avg($ActiveTasks.GetSample(TimeInterval_Minute * 15)));
271
// Scale up if there are more tasks than nodes, scale down if few tasks
272
$targetVMs = $tasks > 0 ? $tasks + 1 : max(0, $TargetDedicatedNodes - 1);
273
// Limit between 0 and 10 nodes
274
$TargetDedicatedNodes = max(0, min($targetVMs, 10));
275
"""
276
277
pool_spec = PoolSpecification(
278
id="autoscale-pool",
279
vm_size="Standard_D2s_v3",
280
cloud_service_configuration=CloudServiceConfiguration(
281
os_family="6"
282
),
283
enable_auto_scale=True,
284
auto_scale_formula=auto_scale_formula,
285
auto_scale_evaluation_interval=datetime.timedelta(minutes=15)
286
)
287
288
client.pool.add(pool_spec)
289
290
# Test the formula before applying
291
result = client.pool.evaluate_auto_scale("autoscale-pool", auto_scale_formula)
292
print(f"Formula result: {result.results}")
293
```
294
295
### Managing Pool Lifecycle
296
297
```python
298
# Check if pool exists
299
if client.pool.exists("my-pool"):
300
# Get pool details
301
pool = client.pool.get("my-pool")
302
print(f"Pool {pool.id} has {pool.current_dedicated_nodes} nodes")
303
304
# Resize pool
305
from azure.batch.models import PoolResizeParameter
306
resize_params = PoolResizeParameter(
307
target_dedicated_nodes=5,
308
target_low_priority_nodes=10
309
)
310
client.pool.resize("my-pool", resize_params)
311
312
# Later, delete the pool
313
client.pool.delete("my-pool")
314
```
315
316
## Types
317
318
### Pool Configuration Types
319
320
```python { .api }
321
class PoolSpecification:
322
"""Pool creation specification."""
323
def __init__(self):
324
self.id: str
325
self.display_name: str
326
self.vm_size: str
327
self.cloud_service_configuration: CloudServiceConfiguration
328
self.virtual_machine_configuration: VirtualMachineConfiguration
329
self.target_dedicated_nodes: int
330
self.target_low_priority_nodes: int
331
self.enable_auto_scale: bool
332
self.auto_scale_formula: str
333
self.auto_scale_evaluation_interval: datetime.timedelta
334
self.start_task: StartTask
335
self.certificates: List[CertificateReference]
336
self.application_packages: List[ApplicationPackageReference]
337
self.max_tasks_per_node: int
338
self.task_scheduling_policy: TaskSchedulingPolicy
339
self.user_accounts: List[UserAccount]
340
self.metadata: List[MetadataItem]
341
342
class CloudServiceConfiguration:
343
"""Windows cloud service configuration."""
344
def __init__(self):
345
self.os_family: str # "4", "5", "6" for different Windows versions
346
self.target_os_version: str # "*" for latest
347
348
class VirtualMachineConfiguration:
349
"""Linux/Windows VM configuration."""
350
def __init__(self):
351
self.image_reference: ImageReference
352
self.node_agent_sku_id: str
353
self.windows_configuration: WindowsConfiguration
354
self.data_disks: List[DataDisk]
355
self.license_type: str
356
self.container_configuration: ContainerConfiguration
357
358
class ImageReference:
359
"""Reference to VM image."""
360
def __init__(self):
361
self.publisher: str
362
self.offer: str
363
self.sku: str
364
self.version: str
365
self.virtual_machine_image_id: str # Custom image ID
366
```
367
368
### Pool State Types
369
370
```python { .api }
371
class CloudPool:
372
"""Pool information and state."""
373
def __init__(self):
374
self.id: str
375
self.display_name: str
376
self.state: str # active, deleting, etc.
377
self.state_transition_time: datetime.datetime
378
self.allocation_state: str # steady, resizing, stopping
379
self.allocation_state_transition_time: datetime.datetime
380
self.vm_size: str
381
self.current_dedicated_nodes: int
382
self.current_low_priority_nodes: int
383
self.target_dedicated_nodes: int
384
self.target_low_priority_nodes: int
385
self.enable_auto_scale: bool
386
self.auto_scale_formula: str
387
self.auto_scale_run: AutoScaleRun
388
self.creation_time: datetime.datetime
389
self.last_modified: datetime.datetime
390
self.stats: PoolStatistics
391
392
class PoolResizeParameter:
393
"""Pool resize parameters."""
394
def __init__(self):
395
self.target_dedicated_nodes: int
396
self.target_low_priority_nodes: int
397
self.resize_timeout: datetime.timedelta
398
self.node_deallocation_option: str # requeue, terminate, taskcompletion, retainondata
399
400
class AutoScaleRun:
401
"""Auto-scale evaluation results."""
402
def __init__(self):
403
self.timestamp: datetime.datetime
404
self.results: str
405
self.error: AutoScaleRunError
406
```