-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathinstances_and_volumes.py
More file actions
71 lines (59 loc) · 2.13 KB
/
instances_and_volumes.py
File metadata and controls
71 lines (59 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import os
from verda import VerdaClient
from verda.constants import Actions, VolumeTypes
# Get client secret and id from environment variables
CLIENT_ID = os.environ.get('VERDA_CLIENT_ID')
CLIENT_SECRET = os.environ.get('VERDA_CLIENT_SECRET')
# Create datcrunch client
verda = VerdaClient(CLIENT_ID, CLIENT_SECRET)
# Get some volume type constants
NVMe = VolumeTypes.NVMe
HDD = VolumeTypes.HDD
EXISTING_OS_VOLUME_ID = '81e45bf0-5da2-412b-97d7-c20a7564fca0'
EXAMPLE_VOLUME_ID = '225dde24-ae44-4787-9224-2b9f56f44394'
EXAMPLE_INSTANCE_ID = '1eeabba4-caf7-4b4a-9143-0107034cc7f5'
# Get all SSH keys
ssh_keys = verda.ssh_keys.get()
# Create instance with extra attached volumes
instance_with_extra_volumes = verda.instances.create(
instance_type='1V100.6V',
image='ubuntu-22.04-cuda-12.0-docker',
ssh_key_ids=ssh_keys,
hostname='example',
description='example instance',
volumes=[
{'type': HDD, 'name': 'volume-1', 'size': 95},
{'type': NVMe, 'name': 'volume-2', 'size': 95},
],
)
# Create instance with custom OS volume size and name
instance_with_custom_os_volume = verda.instances.create(
instance_type='1V100.6V',
image='ubuntu-22.04-cuda-12.0-docker',
ssh_key_ids=ssh_keys,
hostname='example',
description='example instance',
os_volume={'name': 'OS volume', 'size': 95},
)
# Create instance with existing OS volume as an image
instance_with_existing_os_volume = verda.instances.create(
instance_type='1V100.6V',
image=EXISTING_OS_VOLUME_ID,
ssh_key_ids=ssh_keys,
hostname='example',
description='example instance',
)
# Delete instance AND OS volume (the rest of the volumes would be detached)
verda.instances.action(instance_id=EXAMPLE_INSTANCE_ID, action=Actions.DELETE)
# Delete instance WITHOUT deleting the OS volume (will detach all volumes of the instance)
verda.instances.action(
instance_id=EXAMPLE_INSTANCE_ID,
action=Actions.DELETE,
volume_ids=[],
)
# Delete instance and one of it's volumes (will delete one volume, detach the rest)
verda.instances.action(
instance_id=EXAMPLE_INSTANCE_ID,
action=Actions.DELETE,
volume_ids=[EXAMPLE_VOLUME_ID],
)