Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Using Availability Zones for Pools #156

Merged
merged 3 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ For example, if we would like to persist stdout and stderr to the blob container
client.add_job("persisting_test", save_logs_to_blob = "input-test")
```

**Availability Zones**
To make use of Azure's availability zone functionality there is a parameter available in the `set_pool_info()` method called `availability_zones`. To use availability zones when building a pool, set this parameter to True. If you want to stick with the default Regional configuration, this parameter can be left out or set to False. Turn availability zone on like the following:
```
client.set_pool_info(
...
availability_zones = True,
...
)
```


### Functions
- create_pool: creates a new Azure batch pool using default autoscale mode
Example:
Expand Down
7 changes: 5 additions & 2 deletions cfa_azure/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ def set_pool_info(
dedicated_nodes=0,
low_priority_nodes=1,
cache_blobfuse: bool = True,
task_slots_per_node: int = 1
task_slots_per_node: int = 1,
availability_zones = False
) -> None:
"""Sets the scaling mode of the client, either "fixed" or "autoscale".
If "fixed" is selected, debug must be turned off.
Expand All @@ -126,6 +127,7 @@ def set_pool_info(
low_priority_nodes (int, optional): number of low priority nodes for the pool. Defaults to 0.
cache_blobfuse (bool): True to use blobfuse caching, False to download data from blobfuse every time. Defaults to True.
task_slots_per_node (int): number of task slots per node. Default 1.
availability_zones (bool): whether to use availability zones for the pool. True to use Availability Zones. False to stay Regional. Default False.
"""
# check if debug and scaling mode match, otherwise alert the user
if self.debug is True and mode == "autoscale":
Expand Down Expand Up @@ -179,7 +181,8 @@ def set_pool_info(
low_priority_nodes=low_priority_nodes,
use_default_autoscale_formula=use_default_autoscale_formula,
max_autoscale_nodes=max_autoscale_nodes,
task_slots_per_node= task_slots_per_node
task_slots_per_node= task_slots_per_node,
availability_zones = availability_zones
)
logger.debug("pool parameters generated")
else:
Expand Down
14 changes: 13 additions & 1 deletion cfa_azure/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,7 @@ def get_deployment_config(
container_registry_url: str,
container_registry_server: str,
config: str,
availability_zones: bool = False
):
"""gets the deployment config based on the config information

Expand All @@ -1157,6 +1158,12 @@ def get_deployment_config(
Returns:
dict: dictionary containing info for container deployment. Uses ubuntu server with info obtained from config file.
"""
logger.debug("setting availability zone info")
if availability_zones:
policy = "Zonal"
else:
policy = "Regional"

logger.debug("Getting deployment config.")
deployment_config = {
"virtualMachineConfiguration": {
Expand All @@ -1166,6 +1173,9 @@ def get_deployment_config(
"sku": "20-04-lts",
"version": "latest",
},
"nodePlacementConfiguration": {
"policy": policy
},
"nodeAgentSkuId": "batch.node.ubuntu 20.04",
"containerConfiguration": {
"type": "dockercompatible",
Expand Down Expand Up @@ -1262,7 +1272,8 @@ def get_pool_parameters(
low_priority_nodes: int = 1,
use_default_autoscale_formula: bool = False,
max_autoscale_nodes: int = 3,
task_slots_per_node: int = 1
task_slots_per_node: int = 1,
availability_zones: bool = False
):
"""creates a pool parameter dictionary to be used with pool creation.

Expand Down Expand Up @@ -1334,6 +1345,7 @@ def get_pool_parameters(
container_registry_url,
container_registry_server,
config,
availability_zones
),
"networkConfiguration": get_network_config(config),
"scaleSettings": scale_settings,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "cfa_azure"
version = "1.0.6"
version = "1.0.7"
description = "module for use with Azure and Azure Batch"
authors = ["Ryan Raasch <[email protected]>"]
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="cfa_azure",
version="1.0.6",
version="1.0.7",
description="module for use with Azure and Azure Batch",
packages=find_packages(exclude=["tests", "venv"]),
author="Ryan Raasch",
Expand Down