You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by to...@apache.org on 2021/11/07 18:24:38 UTC
[libcloud] 03/06: Change delete_key_pair arg to KeyPair
This is an automated email from the ASF dual-hosted git repository.
tomaz pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/libcloud.git
commit 35f4499f8da89940b953e12dbdea659dac3cc3e8
Author: Dimitris Galanis <di...@gmail.com>
AuthorDate: Sun Nov 7 18:14:34 2021 +0200
Change delete_key_pair arg to KeyPair
---
libcloud/compute/drivers/vultr.py | 11 ++++++-----
libcloud/test/compute/fixtures/vultr_v2/list_key_pairs.json | 2 +-
libcloud/test/compute/test_vultr_v2.py | 7 ++++---
3 files changed, 11 insertions(+), 9 deletions(-)
diff --git a/libcloud/compute/drivers/vultr.py b/libcloud/compute/drivers/vultr.py
index 2d189d0..d164b6b 100644
--- a/libcloud/compute/drivers/vultr.py
+++ b/libcloud/compute/drivers/vultr.py
@@ -1471,17 +1471,18 @@ class VultrNodeDriverV2(VultrNodeDriver):
method='POST')
return self._to_key_pair(resp.object['ssh_key'])
- def delete_key_pair(self, key_id):
+ def delete_key_pair(self, key_pair):
"""Delete existing key pair.
- :param key_id: ID of the key pair to delete.
- :type key_id: ``str``
+ :param key_pair: The key pair object to delete.
+ :type key_pair: :class:`.KeyPair`
:rtype: ``bool``
"""
- resp = self.connection.request('/v2/ssh-keys/%s' % key_id,
- method='DELETE')
+ resp = self.connection.request(
+ '/v2/ssh-keys/%s' % key_pair.extra['id'],
+ method='DELETE')
return resp.success()
diff --git a/libcloud/test/compute/fixtures/vultr_v2/list_key_pairs.json b/libcloud/test/compute/fixtures/vultr_v2/list_key_pairs.json
index f4414b8..b4e4218 100644
--- a/libcloud/test/compute/fixtures/vultr_v2/list_key_pairs.json
+++ b/libcloud/test/compute/fixtures/vultr_v2/list_key_pairs.json
@@ -1,7 +1,7 @@
{
"ssh_keys": [
{
- "id": "6d2a787f-4dc5-434e-9ae2-8f54ec5ea5b6",
+ "id": "123",
"date_created": "2019-09-20T11:14:26+00:00",
"name": "tester",
"ssh_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCwRaxNA9gsFPVAIq4rkBjTtBAsofSJ0lJS3hPFHiwABpiihu45dcJtcmIqUO2jooVsKCfPJ/KrZ5DqhgPWbHJ/C+ZtHDhZ19jq022nfb+tfqCgwolKd8POlmivtpQdl3AaG4hm/Uh0VICAsrgp1o6EEzRLJE6vWrz4XaIUKYI1idzv/1kF2R9LBb60HXsQaIeV5z0036uy9d55wG+DtwUIpBBfyxevISS9n1kEI+MHi+Ci4D9dmE3SGm+9gDAZ2ZwPjWcAiUnf8SJ5CyA3MwUCa8czPgVMtpt5qZNYxilrGJEpPhnCHwT3YvUbh69F24kMDj2IX9LYjcvUsgIjXuxb"
diff --git a/libcloud/test/compute/test_vultr_v2.py b/libcloud/test/compute/test_vultr_v2.py
index 5ef16ce..f9da81c 100644
--- a/libcloud/test/compute/test_vultr_v2.py
+++ b/libcloud/test/compute/test_vultr_v2.py
@@ -170,7 +170,7 @@ class VultrTestsV2(unittest.TestCase):
self.assertEqual(key.name, 'tester')
self.assertIsNone(key.private_key)
self.assertEqual(key.extra['id'],
- '6d2a787f-4dc5-434e-9ae2-8f54ec5ea5b6')
+ '123')
def test_list_key_pairs_UNAUTHORIZED(self):
VultrMockHttpV2.type = 'UNAUTHORIZED'
@@ -193,8 +193,9 @@ class VultrTestsV2(unittest.TestCase):
self.assertIsNone(key.private_key)
def test_delete_key_pair(self):
- key_id = '123'
- response = self.driver.delete_key_pair(key_id)
+ keys = self.driver.list_key_pairs()
+ key = keys[0]
+ response = self.driver.delete_key_pair(key)
self.assertTrue(response)
def test_list_volumes(self):