|
8 | 8 | # Create datcrunch client |
9 | 9 | datacrunch = DataCrunchClient(CLIENT_ID, CLIENT_SECRET) |
10 | 10 |
|
11 | | -# Create instance with extra volumes |
12 | | -# TODO: |
| 11 | +# Get some volume type constants |
| 12 | +NVMe = datacrunch.constants.volume_types.NVMe |
| 13 | +HDD = datacrunch.constants.volume_types.HDD |
| 14 | + |
| 15 | +EXISTING_OS_VOLUME_ID = '81e45bf0-5da2-412b-97d7-c20a7564fca0' |
| 16 | +EXAMPLE_VOLUME_ID = '225dde24-ae44-4787-9224-2b9f56f44394' |
| 17 | +EXAMPLE_INSTANCE_ID = '1eeabba4-caf7-4b4a-9143-0107034cc7f5' |
| 18 | + |
| 19 | +# Get all SSH keys |
| 20 | +ssh_keys = datacrunch.ssh_keys.get() |
| 21 | + |
| 22 | +# Create instance with extra attached volumes |
| 23 | +instance_with_extra_volumes = datacrunch.instances.create(instance_type='1V100.6V', |
| 24 | + image='fastai', |
| 25 | + ssh_key_ids=ssh_keys[0].id, |
| 26 | + hostname='example', |
| 27 | + description='example instance', |
| 28 | + volumes=[ |
| 29 | + {"type": HDD, "name": "volume-1", "size": 95}, |
| 30 | + {"type": NVMe, "name": "volume-2", "size": 95} |
| 31 | + ]) |
13 | 32 |
|
14 | 33 | # Create instance with existing OS volume as an image |
15 | | -# TODO: |
| 34 | +instance_with_existing_os_volume = datacrunch.instances.create(instance_type='1V100.6V', |
| 35 | + image=EXISTING_OS_VOLUME_ID, |
| 36 | + ssh_key_ids=ssh_keys[0].id, |
| 37 | + hostname='example', |
| 38 | + description='example instance') |
| 39 | + |
| 40 | +# Delete instance AND OS volume (the rest of the volumes would be detached) |
| 41 | +datacrunch.instances.action(instance_id=EXAMPLE_INSTANCE_ID, |
| 42 | + action=datacrunch.constants.instance_actions.DELETE) |
16 | 43 |
|
17 | | -# Delete instance without deleting the OS volume |
18 | | -# TODO: |
| 44 | +# Delete instance WITHOUT deleting the OS volume (will detach all volumes of the instance) |
| 45 | +datacrunch.instances.action(instance_id=EXAMPLE_INSTANCE_ID, |
| 46 | + action=datacrunch.constants.instance_actions.DELETE, |
| 47 | + volume_ids=[]) |
19 | 48 |
|
20 | | -# Delete instance and one of it's volumes |
21 | | -# TODO: |
22 | 49 |
|
| 50 | +# Delete instance and one of it's volumes (will delete one volume, detach the rest) |
| 51 | +datacrunch.instances.action(instance_id=EXAMPLE_INSTANCE_ID, |
| 52 | + action=datacrunch.constants.instance_actions.DELETE, |
| 53 | + volume_ids=[EXAMPLE_VOLUME_ID]) |
0 commit comments