Skip to content

Commit 625a0c0

Browse files
committed
add 2 examples to documentation
1 parent 8755f4a commit 625a0c0

5 files changed

Lines changed: 126 additions & 2 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,5 @@ dmypy.json
141141
cython_debug/
142142

143143
# python sphinx docs
144-
_build/
144+
_build/
145+
testing.py

CHANGELOG.rst

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

4+
v1.0.2 (2021-06-16)
5+
-------------------
6+
7+
* Added examples to documentation
8+
49
v1.0.1 (2021-06-16)
510
-------------------
611

datacrunch/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION = '1.0.1'
1+
VERSION = '1.0.2'
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
Instances and Volumes
2+
=====================
3+
4+
.. code-block:: python
5+
6+
import os
7+
from datacrunch import DataCrunchClient
8+
9+
# Get client secret from environment variable
10+
CLIENT_SECRET = os.environ['DATACRUNCH_CLIENT_SECRET']
11+
CLIENT_ID = 'Ibk5bdxV64lKAWOqYnvSi' # Replace with your client ID
12+
13+
# Create datcrunch client
14+
datacrunch = DataCrunchClient(CLIENT_ID, CLIENT_SECRET)
15+
16+
# Get some volume type constants
17+
NVMe = datacrunch.constants.volume_types.NVMe
18+
HDD = datacrunch.constants.volume_types.HDD
19+
20+
EXISTING_OS_VOLUME_ID = '81e45bf0-5da2-412b-97d7-c20a7564fca0'
21+
EXAMPLE_VOLUME_ID = '225dde24-ae44-4787-9224-2b9f56f44394'
22+
EXAMPLE_INSTANCE_ID = '1eeabba4-caf7-4b4a-9143-0107034cc7f5'
23+
24+
# Get all SSH keys
25+
ssh_keys = datacrunch.ssh_keys.get()
26+
27+
# Create instance with extra attached volumes
28+
instance_with_extra_volumes = datacrunch.instances.create(instance_type='1V100.6V',
29+
image='fastai',
30+
ssh_key_ids=ssh_keys[0].id,
31+
hostname='example',
32+
description='example instance',
33+
volumes=[
34+
{"type": HDD, "name": "volume-1", "size": 95},
35+
{"type": NVMe, "name": "volume-2", "size": 95}
36+
])
37+
38+
# Create instance with existing OS volume as an image
39+
instance_with_existing_os_volume = datacrunch.instances.create(instance_type='1V100.6V',
40+
image=EXISTING_OS_VOLUME_ID,
41+
ssh_key_ids=ssh_keys[0].id,
42+
hostname='example',
43+
description='example instance')
44+
45+
# Delete instance AND OS volume (the rest of the volumes would be detached)
46+
datacrunch.instances.action(instance_id=EXAMPLE_INSTANCE_ID,
47+
action=datacrunch.constants.instance_actions.DELETE)
48+
49+
# Delete instance WITHOUT deleting the OS volume (will detach all volumes of the instance)
50+
datacrunch.instances.action(instance_id=EXAMPLE_INSTANCE_ID,
51+
action=datacrunch.constants.instance_actions.DELETE,
52+
volume_ids=[])
53+
54+
55+
# Delete instance and one of it's volumes (will delete one volume, detach the rest)
56+
datacrunch.instances.action(instance_id=EXAMPLE_INSTANCE_ID,
57+
action=datacrunch.constants.instance_actions.DELETE,
58+
volume_ids=[EXAMPLE_VOLUME_ID])
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
Storage Volumes
2+
===============
3+
4+
.. code-block:: python
5+
6+
import os
7+
from datacrunch import DataCrunchClient
8+
9+
# Get client secret from environment variable
10+
CLIENT_SECRET = os.environ['DATACRUNCH_CLIENT_SECRET']
11+
CLIENT_ID = 'Ibk5bdxV64lKAWOqYnvSi' # Replace with your client ID
12+
13+
# Create datcrunch client
14+
datacrunch = DataCrunchClient(CLIENT_ID, CLIENT_SECRET)
15+
16+
# Get some volume type constants
17+
NVMe = datacrunch.constants.volume_types.NVMe
18+
HDD = datacrunch.constants.volume_types.HDD
19+
20+
# Example instance id
21+
INSTANCE_ID = '8705bb38-2574-454f-9967-d18b130bf5ee'
22+
23+
# Get all volumes
24+
all_volumes = datacrunch.volumes.get()
25+
26+
# Get all attached volumes
27+
all_attached_volumes = datacrunch.volumes.get(status=datacrunch.constants.volume_status.ATTACHED)
28+
29+
# Get volume by id
30+
random_volume = datacrunch.volumes.get_by_id("0c41e387-3dd8-495f-a285-e861527f2f3d")
31+
32+
# Create a 200 GB detached NVMe volume
33+
nvme_volume = datacrunch.volumes.create(type=NVMe,
34+
name="data-storage-1",
35+
size=200)
36+
37+
# Create a 500 GB HDD volume and attach it to an existing shutdown instance
38+
# Note: If the instance isn't shutdown an exception would be raised
39+
hdd_volume = datacrunch.volumes.create(type=HDD,
40+
name="data-storage-2",
41+
size=500,
42+
instance_id=INSTANCE_ID)
43+
44+
nvme_volume_id = nvme_volume.id
45+
hdd_volume_id = hdd_volume.id
46+
47+
# attach the nvme volume to the instance
48+
datacrunch.volumes.attach(nvme_volume_id, INSTANCE_ID)
49+
50+
# detach both volumes from the instance
51+
datacrunch.volumes.detach([nvme_volume_id, hdd_volume_id])
52+
53+
# rename volume
54+
datacrunch.volumes.rename(nvme_volume_id, "new-name")
55+
56+
# increase volume size
57+
datacrunch.volumes.increase_size(nvme_volume_id, 300)
58+
59+
# delete volumes
60+
datacrunch.volumes.delete([nvme_volume_id, hdd_volume_id])

0 commit comments

Comments
 (0)