Skip to content

Commit

Permalink
Allow multiple GCP image formats (#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtomlinson committed Nov 16, 2020
1 parent 5b5cc32 commit 546be3d
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion dask_cloudprovider/gcp/instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ def __init__(

self.machine_type = machine_type or self.config.get("machine_type")

self.source_image = source_image or self.config.get("source_image")
self.source_image = self.expand_source_image(
source_image or self.config.get("source_image")
)
self.docker_image = docker_image or self.config.get("docker_image")
self.env_vars = env_vars
self.filesystem_size = filesystem_size or self.config.get("filesystem_size")
Expand Down Expand Up @@ -233,6 +235,13 @@ def update_status(self):

return d["items"][0]["status"]

def expand_source_image(self, source_image):
if "/" not in source_image:
return f"projects/{self.projectid}/global/images/{source_image}"
if source_image.startswith("https://www.googleapis.com/compute/v1/"):
return source_image.replace("https://www.googleapis.com/compute/v1/", "")
return source_image

async def close(self):
self.cluster._log(f"Closing Instance: {self.name}")
self.cluster.compute.instances().delete(
Expand Down Expand Up @@ -346,7 +355,14 @@ class GCPCluster(VMCluster):
source_image: str
The OS image to use for the VM. Dask Cloudprovider will boostrap Ubuntu based images automatically.
Other images require Docker and for GPUs the NVIDIA Drivers and NVIDIA Docker.
A list of available images can be found with ``gcloud compute images list``
Valid values are:
- The short image name provided it is in ``projectid``.
- The full image name ``projects/<projectid>/global/images/<source_image>``.
- The full image URI such as those listed in ``gcloud compute images list --uri``.
The default is ``projects/ubuntu-os-cloud/global/images/ubuntu-minimal-1804-bionic-v20201014``.
docker_image: string (optional)
The Docker image to run on all instances.
Expand Down

0 comments on commit 546be3d

Please sign in to comment.