Skip to content

Commit

Permalink
Add debug flag to VMCluster (#271)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtomlinson committed Mar 26, 2021
1 parent c8a7be0 commit 620a94d
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 6 deletions.
6 changes: 5 additions & 1 deletion dask_cloudprovider/aws/ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@ class EC2Cluster(VMCluster):
Configures communication security in this cluster. Can be a security
object, or True. If True, temporary self-signed credentials will
be created automatically. Default is ``True``.
debug: bool, optional
More information will be printed when constructing clusters to enable debugging.
Notes
-----
Expand Down Expand Up @@ -402,6 +404,7 @@ def __init__(
key_name=None,
iam_instance_profile=None,
docker_image=None,
debug=False,
**kwargs,
):
self.boto_session = aiobotocore.get_session()
Expand Down Expand Up @@ -452,6 +455,7 @@ def __init__(
if iam_instance_profile is not None
else self.config.get("iam_instance_profile")
)
self.debug = debug
self.options = {
"cluster": self,
"config": self.config,
Expand All @@ -471,4 +475,4 @@ def __init__(
}
self.scheduler_options = {**self.options}
self.worker_options = {**self.options}
super().__init__(**kwargs)
super().__init__(debug=debug, **kwargs)
6 changes: 5 additions & 1 deletion dask_cloudprovider/azure/azurevm.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ class AzureVMCluster(VMCluster):
Configures communication security in this cluster. Can be a security
object, or True. If True, temporary self-signed credentials will
be created automatically. Default is ``True``.
debug: bool, optional
More information will be printed when constructing clusters to enable debugging.
Examples
--------
Expand Down Expand Up @@ -412,6 +414,7 @@ def __init__(
bootstrap: bool = None,
auto_shutdown: bool = None,
docker_image=None,
debug: bool = False,
**kwargs,
):
self.config = dask.config.get("cloudprovider.azure.azurevm", {})
Expand Down Expand Up @@ -478,6 +481,7 @@ def __init__(
else self.config.get("auto_shutdown")
)
self.docker_image = docker_image or self.config.get("docker_image")
self.debug = debug
self.options = {
"cluster": self,
"config": self.config,
Expand All @@ -495,4 +499,4 @@ def __init__(
**self.options,
}
self.worker_options = {"vm_size": self.vm_size, **self.options}
super().__init__(**kwargs)
super().__init__(debug=debug, **kwargs)
6 changes: 5 additions & 1 deletion dask_cloudprovider/digitalocean/droplet.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ class DropletCluster(VMCluster):
Configures communication security in this cluster. Can be a security
object, or True. If True, temporary self-signed credentials will
be created automatically. Default is ``True``.
debug: bool, optional
More information will be printed when constructing clusters to enable debugging.
Examples
--------
Expand Down Expand Up @@ -193,11 +195,13 @@ def __init__(
region: str = None,
size: str = None,
image: str = None,
debug: bool = False,
**kwargs,
):
self.config = dask.config.get("cloudprovider.digitalocean", {})
self.scheduler_class = DropletScheduler
self.worker_class = DropletWorker
self.debug = debug
self.options = {
"cluster": self,
"config": self.config,
Expand All @@ -207,4 +211,4 @@ def __init__(
}
self.scheduler_options = {**self.options}
self.worker_options = {**self.options}
super().__init__(**kwargs)
super().__init__(debug=debug, **kwargs)
6 changes: 5 additions & 1 deletion dask_cloudprovider/gcp/instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,8 @@ class GCPCluster(VMCluster):
be created automatically. Default is ``True``.
preemptible: bool (optional)
Whether to use preemptible instances for workers in this cluster. Defaults to ``False``.
debug: bool, optional
More information will be printed when constructing clusters to enable debugging.
Examples
--------
Expand Down Expand Up @@ -553,6 +555,7 @@ def __init__(
auto_shutdown=None,
bootstrap=True,
preemptible=None,
debug=False,
**kwargs,
):

Expand All @@ -571,6 +574,7 @@ def __init__(
)
self.machine_type = machine_type or self.config.get("machine_type")
self.gpu_instance = "gpu" in self.machine_type or bool(ngpus)
self.debug = debug
self.options = {
"cluster": self,
"config": self.config,
Expand All @@ -596,7 +600,7 @@ def __init__(
self.scheduler_options = {**self.options}
self.worker_options = {**self.options}

super().__init__(**kwargs)
super().__init__(debug=debug, **kwargs)


class GCPCompute:
Expand Down
13 changes: 11 additions & 2 deletions dask_cloudprovider/generic/vmcluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,12 @@ class VMCluster(SpecCluster):
asynchronous: bool
If this is intended to be used directly within an event loop with
async/await
security : Security or bool, optional
security: Security or bool, optional
Configures communication security in this cluster. Can be a security
object, or True. If True, temporary self-signed credentials will
be created automatically. Default is ``True``.
debug: bool, optional
More information will be printed when constructing clusters to enable debugging.
"""

Expand All @@ -224,6 +226,7 @@ def __init__(
env_vars: dict = {},
security: bool = True,
protocol: str = None,
debug: bool = False,
**kwargs,
):
if self.scheduler_class is None or self.worker_class is None:
Expand All @@ -250,6 +253,8 @@ def __init__(
else:
self.protocol = protocol

self.debug = debug

if self.security and self.security.require_encryption:
dask.config.set(
{
Expand Down Expand Up @@ -338,7 +343,11 @@ def render_cloud_init(self, *args, **kwargs):
loader = FileSystemLoader([os.path.dirname(os.path.abspath(__file__))])
environment = Environment(loader=loader)
template = environment.get_template("cloud-init.yaml.j2")
return template.render(**kwargs)
cloud_init = template.render(**kwargs)
if self.debug:
print("\nCloud init\n==========\n\n")
print(cloud_init)
return cloud_init

@classmethod
def get_cloud_init(cls, *args, **kwargs):
Expand Down

0 comments on commit 620a94d

Please sign in to comment.