Skip to content

Commit 41c8d44

Browse files
authored
feat: expose network policy interfaces (#28)
Signed-off-by: vsoch <vsoch@users.noreply.github.com> Co-authored-by: vsoch <vsoch@users.noreply.github.com>
1 parent d5de5a1 commit 41c8d44

3 files changed

Lines changed: 75 additions & 30 deletions

File tree

docs/further.md

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -65,33 +65,6 @@ the ratelimit is hit very easily. We are currently assessing strategies to deliv
6565
without hitting issues with this rate limit. It looks possible to create "[sinks](https://cloud.google.com/logging/docs/routing/overview#sinks)" using
6666
Pub Sub, however this would be adding an extra API dependency (and cost).
6767

68-
### Arguments
69-
70-
And custom arguments can be any of the following, either on the command line or provided in the environment.
71-
72-
| Name | Description | Flag | Type | Environment Variable | Required | Default |
73-
|------|-------------|------|------|----------------------|----------|---------|
74-
| project | The name of the Google Project | `--googlebatch-project` | str | `SNAKEMAKE_GOOGLEBATCH_PROJECT` | True | unset |
75-
| region | The name of the Google Project region (e.g., us-central1) | str | `--googlebatch-region` |`SNAKEMAKE_GOOGLEBATCH_REGION` | True | unset |
76-
| machine_type | Google Cloud machine type or VM (mpitune configurations are on c2 and c2d family) | str | `--googlebatch-machine-type` | | False | c2-standard-4 |
77-
| image_family | Google Cloud image family (defaults to hpc-centos-7) | `--googlebatch-image-family` | str | | False | hpc-centos-7 |
78-
| image_project | The project the selected image belongs to (defaults to cloud-hpc-image-public) | `--googlebatch-image-project` | str | | False | cloud-hpc-image-public |
79-
| bucket | A bucket to mount with snakemake data | `--googlebatch-bucket` | str | `SNAKEMAKE_GOOGLEBATCH_BUCKET` | True | unset |
80-
| mount_path | The mount path for a bucket (if provided) | `--googlebatch-mount-path` | str | | False | /mnt/share |
81-
| work_tasks | The default number of work tasks (these are NOT MPI ranks) | `--googlebatch-work-tasks` | int | | False | 1 |
82-
| cpu_milli | Milliseconds per cpu-second | `--googlebatch-cpu-milli` | int | | False | 1000 |
83-
| work_tasks_per_node | The default number of work tasks per node (Google Batch calls these tasks) | `--googlebatch-work-tasks-per-node` | int | | False | 1 |
84-
| memory | Memory in MiB | `--googlebatch-memory` | int | | False | 1000 |
85-
| retry_count | Retry count (default to 1) | `--googlebatch-retry-count` | int | | False | 1 |
86-
| max_run_duration | Maximum run duration, string (e.g., 3600s) | `--googlebatch-max-run-duration` | str | | False | "3600s" |
87-
| labels | Comma separated key value pairs to label job (e.g., model=a3,stage=test) |`--googlebatch-labels` | str | | False | unset|
88-
| container | Container to use (only when image_family is batch-cos*) [see here](https://cloud.google.com/batch/docs/vm-os-environment-overview#supported_vm_os_images) for families/projects | `--googlebatch-container` | str | | False | unset|
89-
| keep_source_cache | Cache workflows in your Google Cloud Storage Bucket | `--googlebatch-keep-source-cache` | bool | | False | False |
90-
| snippet | A comma separated list of one or more snippets to add to your setup | `--googelbatch-snippets` | str | | False | unset |
91-
92-
For machine type, note that for MPI workloads, mpitune configurations are validated on c2 and c2d instances only.
93-
Also note that you can customize the machine type on the level of the step (see [Step Options](#step-options) below).
94-
9568
#### Choosing an Image
9669

9770
You can read about how to choose an image [here](https://cloud.google.com/batch/docs/view-os-images). Note that
@@ -152,6 +125,9 @@ rule hello_world:
152125
"..."
153126
```
154127

128+
Note that for MPI workloads, mpitune configurations are validated on c2 and c2d instances only.
129+
130+
155131
#### googlebatch_image_family
156132

157133
This will define the image family for a particular step, overriding the default from the command line.
@@ -225,6 +201,34 @@ rule hello_world:
225201
"..."
226202
```
227203

204+
#### googlebatch_network
205+
206+
The URL of an existing network resource (e.g., `projects/{project}/global/networks/{network}`)
207+
208+
```console
209+
rule hello_world:
210+
output:
211+
"...",
212+
resources:
213+
googlebatch_network="projects/{project}/global/networks/{network}"
214+
shell:
215+
"..."
216+
```
217+
218+
#### googlebatch_subnetwork
219+
220+
The URL of an existing subnetwork resource (e.g., `projects/{project}/regions/{region}/subnetworks/{subnetwork}`)
221+
222+
```console
223+
rule hello_world:
224+
output:
225+
"...",
226+
resources:
227+
googlebatch_subnetwork="projects/{project}/regions/{region}/subnetworks/{subnetwork}"
228+
shell:
229+
"..."
230+
```
231+
228232
#### googlebatch_cpu_milli
229233

230234
This will define the milliseconds per cpu-second for a particular step, overriding the default from the command line.

snakemake_executor_plugin_googlebatch/__init__.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,24 @@ class ExecutorSettings(ExecutorSettingsBase):
110110
},
111111
)
112112

113+
network: Optional[str] = field(
114+
default=None,
115+
metadata={
116+
"help": "The URL of an existing network resource",
117+
"env_var": False,
118+
"required": False,
119+
},
120+
)
121+
122+
subnetwork: Optional[str] = field(
123+
default=None,
124+
metadata={
125+
"help": "The URL of an existing subnetwork resource",
126+
"env_var": False,
127+
"required": False,
128+
},
129+
)
130+
113131
# local SSD uses type "local-ssd".
114132
# Also "pd-balanced", "pd-extreme", "pd-ssd", "pd-standard"
115133
boot_disk_type: Optional[str] = field(

snakemake_executor_plugin_googlebatch/executor.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,16 +306,39 @@ def get_allocation_policy(self, job):
306306

307307
instances.policy = policy
308308
allocation_policy.instances = [instances]
309+
310+
# Add custom network interfaces
311+
network_policy = self.get_network_policy(job)
312+
if network_policy is not None:
313+
allocation_policy.network = network_policy
309314
return allocation_policy
310315

316+
def get_network_policy(self, job):
317+
"""
318+
Given a job request, get the network policy
319+
"""
320+
network = self.get_param(job, "network")
321+
subnetwork = self.get_param(job, "subnetwork")
322+
if all(x is None for x in [network, subnetwork]):
323+
return
324+
325+
policy = batch_v1.AllocationPolicy.NetworkPolicy()
326+
interface = batch_v1.AllocationPolicy.NetworkInterface()
327+
if network is not None:
328+
interface.network = network
329+
if subnetwork is not None:
330+
interface.subnetwork = subnetwork
331+
policy.network_interfaces = [interface]
332+
return policy
333+
311334
def get_boot_disk(self, job):
312335
"""
313336
Given a job request, add a customized boot disk.
314337
"""
315338
# Reference disk, boot disk type, and size
316-
image = job.resources.get("googlebatch_boot_disk_image")
317-
size = job.resources.get("googlebatch_boot_disk_gb")
318-
typ = job.resources.get("googlebatch_boot_disk_type")
339+
image = self.get_param(job, "boot_disk_image")
340+
size = self.get_param(job, "boot_disk_gb")
341+
typ = self.get_param(job, "boot_disk_type")
319342

320343
# Cut out early if no customization
321344
if all(x is None for x in [image, size, typ]):

0 commit comments

Comments
 (0)