-
Notifications
You must be signed in to change notification settings - Fork 12
feat: on_spot_discontinue on os_volume and delete_permanently on instance action #74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
db27741
feat: add on_spot_discontinue on os_volume and delete_permanently on …
f2f2aad
fix: tests
f7d676d
fix: reformat
dea5950
fix: formatting
9340b4d
fix: add test for spot
726cc85
fix: format
f71b67d
fix: copilot review fixes
da11d9d
fix: fix
8c6d8e0
fix: simpler check
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import logging | ||
| import os | ||
| import time | ||
|
|
||
| import pytest | ||
|
|
||
| from verda import VerdaClient | ||
| from verda.constants import Locations | ||
| from verda.instances import OSVolume | ||
|
|
||
| IN_GITHUB_ACTIONS = os.getenv('GITHUB_ACTIONS') == 'true' | ||
|
|
||
| logging.basicConfig(level=logging.DEBUG) | ||
| logger = logging.getLogger() | ||
|
|
||
|
|
||
| @pytest.mark.skipif(IN_GITHUB_ACTIONS, reason="Test doesn't work in Github Actions.") | ||
| @pytest.mark.withoutresponses | ||
| class TestInstances: | ||
| def test_create_spot(self, verda_client: VerdaClient): | ||
| # get ssh key | ||
| ssh_key = verda_client.ssh_keys.get()[0] | ||
|
|
||
| # create instance | ||
| instance = verda_client.instances.create( | ||
| hostname='test-instance', | ||
| location=Locations.FIN_03, | ||
| instance_type='CPU.4V.16G', | ||
| description='test cpu instance', | ||
| image='ubuntu-22.04', | ||
| is_spot=True, | ||
| ssh_key_ids=[ssh_key.id], | ||
| os_volume=OSVolume(name='test-os-volume-spot', size=56, on_spot_discontinue='delete_permanently'), | ||
| ) | ||
|
|
||
| # assert instance is created | ||
| assert instance.id is not None | ||
| assert instance.status == verda_client.constants.instance_status.PROVISIONING | ||
|
|
||
| while instance.status != verda_client.constants.instance_status.RUNNING: | ||
| time.sleep(2) | ||
| logger.debug('Waiting for instance to be running... %s', instance.status) | ||
| instance = verda_client.instances.get_by_id(instance.id) | ||
|
|
||
| logger.debug('Instance is running... %s', instance.status) | ||
| logger.debug('Instance ID: %s', instance.id) | ||
| logger.debug('Instance OS Volume ID: %s', instance.os_volume_id) | ||
| logger.debug('Instance IP: %s', instance.ip) | ||
|
|
||
| # assert os volume is created | ||
| assert instance.os_volume_id is not None | ||
|
|
||
| # get os volume | ||
| os_volume = verda_client.volumes.get_by_id(instance.os_volume_id) | ||
| assert os_volume.id is not None | ||
| assert os_volume.name == 'test-os-volume-spot' | ||
| assert os_volume.size == 56 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,8 @@ | ||
| from ._instances import Contract, Instance, InstancesService, Pricing | ||
| from ._instances import ( | ||
| Contract, | ||
| Instance, | ||
| InstancesService, | ||
| OnSpotDiscontinue, | ||
| OSVolume, | ||
| Pricing, | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.