Skip to content

Commit a6c8ef5

Browse files
committed
Merge branch 'master' into refactor/use-dataclasses
2 parents 53256cb + 93c94d0 commit a6c8ef5

23 files changed

+166
-150
lines changed

CHANGELOG.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
Changelog
22
=========
33

4+
* Added environment variables to container deployment example
5+
* Updated examples image from 'fastai' to 'ubuntu-24.04-cuda-12.8-open-docker'
6+
* Consistent naming and load of credentials from env variables in examples
7+
48
v1.8.4 (2025-03-25)
59
-------------------
610

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ DataCrunch's Public API documentation [is available here](https://api.datacrunch
5454

5555
# Create a new instance
5656
instance = datacrunch.instances.create(instance_type='1V100.6V',
57-
image='fastai',
57+
image='ubuntu-24.04-cuda-12.8-open-docker',
5858
ssh_key_ids=ssh_keys,
5959
hostname='example',
6060
description='example instance')

datacrunch/datacrunch.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ def __init__(self, client_id: str, client_secret: str, base_url: str = "https://
2828
:type base_url: str, optional
2929
"""
3030

31+
# Validate that client_id and client_secret are not empty
32+
if not client_id or not client_secret:
33+
raise ValueError(
34+
"client_id and client_secret must be provided")
35+
3136
# Constants
3237
self.constants: Constants = Constants(base_url, VERSION)
3338
"""Constants"""

docs/source/examples/advanced_create_instance.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Advanced Create Instance
5656
if price_per_hour * DURATION < balance.amount:
5757
# Deploy a new 8V instance
5858
instance = datacrunch.instances.create(instance_type=INSTANCE_TYPE_8V,
59-
image='fastai',
59+
image='ubuntu-24.04-cuda-12.8-open-docker',
6060
ssh_key_ids=ssh_keys_ids,
6161
hostname='example',
6262
description='large instance'
@@ -67,7 +67,7 @@ Advanced Create Instance
6767
else:
6868
# Deploy a new 4V instance
6969
instance = datacrunch.instances.create(instance_type=INSTANCE_TYPE_4V,
70-
image='fastai',
70+
image='ubuntu-24.04-cuda-12.8-open-docker',
7171
ssh_key_ids=ssh_keys_ids,
7272
hostname='example',
7373
description='medium instance')

docs/source/examples/instance_actions.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Instance Actions
2222
2323
# Create a new 1V100.6V instance
2424
instance = datacrunch.instances.create(instance_type='1V100.6V',
25-
image='fastai',
25+
image='ubuntu-24.04-cuda-12.8-open-docker',
2626
ssh_key_ids=ssh_keys_ids,
2727
hostname='example',
2828
description='example instance')

docs/source/examples/instances_and_volumes.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Instances and Volumes
2727
2828
# Create instance with extra attached volumes
2929
instance_with_extra_volumes = datacrunch.instances.create(instance_type='1V100.6V',
30-
image='fastai',
30+
image='ubuntu-24.04-cuda-12.8-open-docker',
3131
ssh_key_ids=ssh_keys,
3232
hostname='example',
3333
description='example instance',
@@ -38,7 +38,7 @@ Instances and Volumes
3838
3939
# Create instance with custom OS volume size and name
4040
instance_with_custom_os_volume = datacrunch.instances.create(instance_type='1V100.6V',
41-
image='fastai',
41+
image='ubuntu-24.04-cuda-12.8-open-docker',
4242
ssh_key_ids=ssh_keys,
4343
hostname='example',
4444
description='example instance',

docs/source/examples/simple_create_instance.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Simple Create Instance
1919
2020
# Create a new instance
2121
instance = datacrunch.instances.create(instance_type='1V100.6V',
22-
image='fastai',
22+
image='ubuntu-24.04-cuda-12.8-open-docker',
2323
ssh_key_ids=ssh_keys_ids,
2424
hostname='example',
2525
description='example instance')

docs/source/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Deploy a new instance:
3737
3838
# Create a new instance
3939
instance = datacrunch.instances.create(instance_type='1V100.6V',
40-
image='fastai',
40+
image='ubuntu-24.04-cuda-12.8-open-docker',
4141
ssh_key_ids=ssh_keys_ids,
4242
hostname='example',
4343
description='example instance')

examples/advanced_create_instance.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@
2020
# Arbitrary duration for the example
2121
DURATION = 24 * 7 # one week
2222

23-
# Get client secret from environment variable
24-
CLIENT_SECRET = os.environ['DATACRUNCH_CLIENT_SECRET']
25-
CLIENT_ID = 'Ibk5bdxV64lKAWOqYnvSi' # Replace with your client ID
23+
# Get client secret and id from environment variables
24+
DATACRUNCH_CLIENT_ID = os.environ.get('DATACRUNCH_CLIENT_ID')
25+
DATACRUNCH_CLIENT_SECRET = os.environ.get('DATACRUNCH_CLIENT_SECRET')
2626

2727
try:
2828
# Create datcrunch client
29-
datacrunch = DataCrunchClient(CLIENT_ID, CLIENT_SECRET)
29+
datacrunch = DataCrunchClient(
30+
DATACRUNCH_CLIENT_ID, DATACRUNCH_CLIENT_SECRET)
3031

3132
# Create new SSH key
3233
public_key = 'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI0qq2Qjt5GPi7DKdcnBHOkvk8xNsG9dA607tnWagOkHC test_key'
@@ -51,18 +52,18 @@
5152
if price_per_hour * DURATION < balance.amount:
5253
# Deploy a new 8V instance
5354
instance = datacrunch.instances.create(instance_type=INSTANCE_TYPE_8V,
54-
image='fastai',
55+
image='ubuntu-24.04-cuda-12.8-open-docker',
5556
ssh_key_ids=ssh_keys_ids,
5657
hostname='example',
5758
description='large instance',
5859
os_volume={
59-
"name": "Large OS volume",
60-
"size": 95
61-
})
60+
"name": "Large OS volume",
61+
"size": 95
62+
})
6263
else:
6364
# Deploy a new 4V instance
6465
instance = datacrunch.instances.create(instance_type=INSTANCE_TYPE_4V,
65-
image='fastai',
66+
image='ubuntu-24.04-cuda-12.8-open-docker',
6667
ssh_key_ids=ssh_keys_ids,
6768
hostname='example',
6869
description='medium instance')

examples/containers/compute_resources_example.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
import os
12
from datacrunch import DataCrunchClient
23
from typing import List
34
from datacrunch.containers.containers import ComputeResource
45

6+
# Get client secret and id from environment variables
7+
DATACRUNCH_CLIENT_ID = os.environ.get('DATACRUNCH_CLIENT_ID')
8+
DATACRUNCH_CLIENT_SECRET = os.environ.get('DATACRUNCH_CLIENT_SECRET')
9+
510

611
def list_all_compute_resources(client: DataCrunchClient) -> List[ComputeResource]:
712
"""List all available compute resources.
@@ -44,27 +49,25 @@ def list_compute_resources_by_size(client: DataCrunchClient, size: int) -> List[
4449

4550
def main():
4651
# Initialize the client with your credentials
47-
client = DataCrunchClient(
48-
client_id="your_client_id",
49-
client_secret="your_client_secret"
50-
)
52+
datacrunch = DataCrunchClient(
53+
DATACRUNCH_CLIENT_ID, DATACRUNCH_CLIENT_SECRET)
5154

5255
# Example 1: List all compute resources
53-
print("\nAll compute resources:")
54-
all_resources = list_all_compute_resources(client)
56+
print("All compute resources:")
57+
all_resources = list_all_compute_resources(datacrunch)
5558
for resource in all_resources:
5659
print(
5760
f"Name: {resource.name}, Size: {resource.size}, Available: {resource.is_available}")
5861

5962
# Example 2: List available compute resources
60-
print("\nAvailable compute resources:")
61-
available_resources = list_available_compute_resources(client)
63+
print("Available compute resources:")
64+
available_resources = list_available_compute_resources(datacrunch)
6265
for resource in available_resources:
6366
print(f"Name: {resource.name}, Size: {resource.size}")
6467

6568
# Example 3: List compute resources of size 8
66-
print("\nCompute resources with size 8:")
67-
size_8_resources = list_compute_resources_by_size(client, 8)
69+
print("Compute resources with size 8:")
70+
size_8_resources = list_compute_resources_by_size(datacrunch, 8)
6871
for resource in size_8_resources:
6972
print(f"Name: {resource.name}, Available: {resource.is_available}")
7073

0 commit comments

Comments
 (0)