Earlier I was using Python 3.8 and azure-batch
version 8.0.0
. The following setting worked for me using Python 3.7.0 and azure-batch
version 10.0.0
.
Programmatically set task slots per node in Azure Batch Python SDK
Hi Azure Batch Team,
I am setting up container tasks on Azure Batch using Python SDK client. I borrowed a small snippet from the GitHub, as shared here and modified it slightly to run for container tasks.
def create_pool(batch_service_client, pool_id):
print('Creating pool [{}]...'.format(pool_id))
# Azure Batch Pool Image Reference
image_ref_to_use = batch.models.ImageReference(
publisher='microsoft-azure-batch',
offer='ubuntu-server-container',
sku='16-04-lts',
version='latest')
# VM configuration
vm_config_to_use=batch.models.VirtualMachineConfiguration(
image_reference=image_ref_to_use,
container_configuration=container_conf,
node_agent_sku_id='batch.node.ubuntu 16.04')
# Define Pool config
new_pool = batch.models.PoolAddParameter(
id=pool_id,
virtual_machine_configuration=vm_config_to_use,
vm_size='STANDARD_D1_V2',
target_low_priority_nodes=1,
task_slots_per_node=4)
batch_service_client.pool.add(new_pool)
For the above snippet, I get a warning during pool creation that, task_slots_per_node
is not a valid property of PoolAddParameter
class:
task_slots_per_node is not a known attribute of class <class 'azure.batch.models._models_py3.PoolAddParameter'> and will be ignored
However, I had setup that parameter using constructor definition as suggested here. Although, the pool gets created and configuration shows task slots per node equal to 1
.
So, I tried another workaround to resolve the error by setting the property after the object is created, i.e. as follows:
new_pool.task_slots_per_node=4
In this case, no warning is displayed in console. However, the task slots per node in the configuration (obtained from portal view) still shows the value equal to 1
.
I would like to understand the programmatic of achieving this in Python SDK.
Regards,
Chintan Rajvir
-
Chintan Rajvir 426 Reputation points Microsoft Employee
2021-01-25T12:21:49.567+00:00