Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ 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
CLIENT_ID = os.environ.get('VERDA_CLIENT_ID')
CLIENT_ID = os.environ['VERDA_CLIENT_ID']
CLIENT_SECRET = os.environ['VERDA_CLIENT_SECRET']

# Create client
Expand All @@ -77,7 +78,7 @@ This package was originally published under `datacrunch` name, see [MIGRATION.md
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/).
Expand Down Expand Up @@ -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:
Expand Down
11 changes: 6 additions & 5 deletions docs/source/examples/instances_and_volumes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand All @@ -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'
Expand Down Expand Up @@ -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])
4 changes: 2 additions & 2 deletions docs/source/examples/simple_create_instance.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 6 additions & 5 deletions examples/instance_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
13 changes: 6 additions & 7 deletions examples/instances_and_volumes.py
Original file line number Diff line number Diff line change
@@ -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')
Expand All @@ -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'
Expand Down Expand Up @@ -53,20 +54,18 @@
)

# 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
)
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=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],
)
4 changes: 2 additions & 2 deletions examples/simple_create_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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)