From 9c98d973f69338876b45f8e60e547a5a8782b2c6 Mon Sep 17 00:00:00 2001 From: Ruslan Gainutdinov Date: Mon, 8 Dec 2025 13:11:36 +0200 Subject: [PATCH 1/3] fix: examples after name change and refactoring --- README.md | 11 ++++++----- docs/source/examples/instances_and_volumes.rst | 11 ++++++----- docs/source/examples/simple_create_instance.rst | 4 ++-- examples/instance_actions.py | 11 ++++++----- examples/instances_and_volumes.py | 11 ++++++----- examples/simple_create_instance.py | 4 ++-- 6 files changed, 28 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 1fdba1f..34092bc 100644 --- a/README.md +++ b/README.md @@ -58,10 +58,11 @@ This package was originally published under `datacrunch` name, see [MIGRATION.md ```python import os from verda import VerdaClient + from verda.constants import Actions - # Get credentials from environment variables + # Get credentials from the environment variables CLIENT_ID = os.environ.get('VERDA_CLIENT_ID') - CLIENT_SECRET = os.environ['VERDA_CLIENT_SECRET'] + CLIENT_SECRET = os.environ.get('VERDA_CLIENT_SECRET') # Create client verda = VerdaClient(CLIENT_ID, CLIENT_SECRET) @@ -71,13 +72,13 @@ This package was originally published under `datacrunch` name, see [MIGRATION.md # Create a new instance instance = verda.instances.create(instance_type='1V100.6V', - image='ubuntu-24.04-cuda-12.8-open-docker', + image='ubuntu-24.04-cuda-12.6-docker', ssh_key_ids=ssh_keys, hostname='example', description='example instance') # Delete instance - verda.instances.action(instance.id, verda.constants.instance_actions.DELETE) + verda.instances.action(instance.id, Actions.DELETE) ``` More examples can be found in the `/examples` folder or in the [documentation](https://datacrunch-python.readthedocs.io/en/latest/). @@ -122,7 +123,7 @@ CLIENT_SECRET = 'secret' CLIENT_ID = 'your-id' # Create client -verda = VerdaClient(CLIENT_ID, CLIENT_SECRET, base_url='http://localhost:3001/v1') +verda = VerdaClient(CLIENT_ID, CLIENT_SECRET) ``` Run it: diff --git a/docs/source/examples/instances_and_volumes.rst b/docs/source/examples/instances_and_volumes.rst index c8886a6..f0e243a 100644 --- a/docs/source/examples/instances_and_volumes.rst +++ b/docs/source/examples/instances_and_volumes.rst @@ -5,6 +5,7 @@ Instances and Volumes import os from verda import VerdaClient + from verda.constants import Actions, VolumeTypes # Get client secret from environment variable CLIENT_SECRET = os.environ['VERDA_CLIENT_SECRET'] @@ -14,8 +15,8 @@ Instances and Volumes verda = VerdaClient(CLIENT_ID, CLIENT_SECRET) # Get some volume type constants - NVMe = verda.constants.volume_types.NVMe - HDD = verda.constants.volume_types.HDD + NVMe = VolumeTypes.NVMe + HDD = VolumeTypes.HDD EXISTING_OS_VOLUME_ID = '81e45bf0-5da2-412b-97d7-c20a7564fca0' EXAMPLE_VOLUME_ID = '225dde24-ae44-4787-9224-2b9f56f44394' @@ -56,15 +57,15 @@ Instances and Volumes # Delete instance AND OS volume (the rest of the volumes would be detached) verda.instances.action(instance_id=EXAMPLE_INSTANCE_ID, - action=verda.constants.instance_actions.DELETE) + 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=verda.constants.instance_actions.DELETE, + 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=verda.constants.instance_actions.DELETE, + action=Actions.DELETE, volume_ids=[EXAMPLE_VOLUME_ID]) diff --git a/docs/source/examples/simple_create_instance.rst b/docs/source/examples/simple_create_instance.rst index 4ef52ac..79fefb7 100644 --- a/docs/source/examples/simple_create_instance.rst +++ b/docs/source/examples/simple_create_instance.rst @@ -7,8 +7,8 @@ Simple Create Instance from verda import VerdaClient # Get client secret from environment variable - CLIENT_SECRET = os.environ['VERDA_CLIENT_SECRET'] - CLIENT_ID = 'Ibk5bdxV64lKAWOqYnvSi' # Replace with your client ID + CLIENT_SECRET = os.environ.get('VERDA_CLIENT_SECRET') + CLIENT_ID = os.environ.get('VERDA_CLIENT_ID') # Create datcrunch client verda = VerdaClient(CLIENT_ID, CLIENT_SECRET) diff --git a/examples/instance_actions.py b/examples/instance_actions.py index 9a63550..effbe78 100644 --- a/examples/instance_actions.py +++ b/examples/instance_actions.py @@ -2,6 +2,7 @@ import time from verda import VerdaClient +from verda.constants import Actions, InstanceStatus from verda.exceptions import APIException # Get client secret and id from environment variables @@ -29,28 +30,28 @@ # Try to shutdown instance right away, # encounter an error (because it's still provisioning) try: - verda.instances.action(instance.id, verda.constants.instance_actions.SHUTDOWN) + verda.instances.action(instance.id, Actions.SHUTDOWN) except APIException as exception: print(exception) # we were too eager... # Wait until instance is running (check every 30sec), only then shut it down -while instance.status != verda.constants.instance_status.RUNNING: +while instance.status != InstanceStatus.RUNNING: time.sleep(30) instance = verda.instances.get_by_id(instance.id) # Shutdown! try: - verda.instances.action(instance.id, verda.constants.instance_actions.SHUTDOWN) + verda.instances.action(instance.id, Actions.SHUTDOWN) except APIException as exception: print(exception) # no exception this time # Wait until instance is offline (check every 30sec), only then hibernate -while instance.status != verda.constants.instance_status.OFFLINE: +while instance.status != InstanceStatus.OFFLINE: time.sleep(30) instance = verda.instances.get_by_id(instance.id) # Hibernate the instance try: - verda.instances.action(instance.id, verda.constants.instance_actions.HIBERNATE) + verda.instances.action(instance.id, Actions.HIBERNATE) except APIException as exception: print(exception) diff --git a/examples/instances_and_volumes.py b/examples/instances_and_volumes.py index a8ec020..f4eed52 100644 --- a/examples/instances_and_volumes.py +++ b/examples/instances_and_volumes.py @@ -1,6 +1,7 @@ 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') @@ -10,8 +11,8 @@ verda = VerdaClient(CLIENT_ID, CLIENT_SECRET) # Get some volume type constants -NVMe = verda.constants.volume_types.NVMe -HDD = verda.constants.volume_types.HDD +NVMe = VolumeTypes.NVMe +HDD = VolumeTypes.HDD EXISTING_OS_VOLUME_ID = '81e45bf0-5da2-412b-97d7-c20a7564fca0' EXAMPLE_VOLUME_ID = '225dde24-ae44-4787-9224-2b9f56f44394' @@ -54,19 +55,19 @@ # Delete instance AND OS volume (the rest of the volumes would be detached) verda.instances.action( - instance_id=EXAMPLE_INSTANCE_ID, action=verda.constants.instance_actions.DELETE + 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=verda.constants.instance_actions.DELETE, + 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=verda.constants.instance_actions.DELETE, + action=Actions.DELETE, volume_ids=[EXAMPLE_VOLUME_ID], ) diff --git a/examples/simple_create_instance.py b/examples/simple_create_instance.py index df4b1b0..9387ac6 100644 --- a/examples/simple_create_instance.py +++ b/examples/simple_create_instance.py @@ -2,7 +2,7 @@ import time from verda import VerdaClient -from verda.constants import InstanceStatus, Locations +from verda.constants import Actions, InstanceStatus, Locations # Get client secret and id from environment variables CLIENT_ID = os.environ.get('VERDA_CLIENT_ID') @@ -33,4 +33,4 @@ print(instance) # Delete instance -verda.instances.action(instance.id, verda.constants.instance_actions.DELETE) +verda.instances.action(instance.id, Actions.DELETE) From a181b5db5bc61bfc10e3fc87e41ccd04881991df Mon Sep 17 00:00:00 2001 From: Ruslan Gainutdinov Date: Mon, 8 Dec 2025 13:13:16 +0200 Subject: [PATCH 2/3] fix: polishing --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 34092bc..a68d441 100644 --- a/README.md +++ b/README.md @@ -60,9 +60,9 @@ This package was originally published under `datacrunch` name, see [MIGRATION.md from verda import VerdaClient from verda.constants import Actions - # Get credentials from the environment variables - CLIENT_ID = os.environ.get('VERDA_CLIENT_ID') - CLIENT_SECRET = os.environ.get('VERDA_CLIENT_SECRET') + # Get credentials from environment variables + CLIENT_ID = os.environ['VERDA_CLIENT_ID'] + CLIENT_SECRET = os.environ['VERDA_CLIENT_SECRET'] # Create client verda = VerdaClient(CLIENT_ID, CLIENT_SECRET) @@ -72,7 +72,7 @@ This package was originally published under `datacrunch` name, see [MIGRATION.md # Create a new instance instance = verda.instances.create(instance_type='1V100.6V', - image='ubuntu-24.04-cuda-12.6-docker', + image='ubuntu-24.04-cuda-12.8-open-docker', ssh_key_ids=ssh_keys, hostname='example', description='example instance') From aa065075fb6b9e91257321be11c5f2927c0d31f4 Mon Sep 17 00:00:00 2001 From: Ruslan Gainutdinov Date: Mon, 8 Dec 2025 13:14:45 +0200 Subject: [PATCH 3/3] fix: format --- examples/instances_and_volumes.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/examples/instances_and_volumes.py b/examples/instances_and_volumes.py index f4eed52..818b244 100644 --- a/examples/instances_and_volumes.py +++ b/examples/instances_and_volumes.py @@ -54,9 +54,7 @@ ) # Delete instance AND OS volume (the rest of the volumes would be detached) -verda.instances.action( - instance_id=EXAMPLE_INSTANCE_ID, action=Actions.DELETE -) +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(