diff --git a/shade/_tasks.py b/shade/_tasks.py index 4bb761676..1449ac021 100644 --- a/shade/_tasks.py +++ b/shade/_tasks.py @@ -107,21 +107,6 @@ class AggregateSetMetadata(task_manager.Task): return client.nova_client.aggregates.set_metadata(**self.args) -class KeypairList(task_manager.Task): - def main(self, client): - return client.nova_client.keypairs.list() - - -class KeypairCreate(task_manager.Task): - def main(self, client): - return client.nova_client.keypairs.create(**self.args) - - -class KeypairDelete(task_manager.Task): - def main(self, client): - return client.nova_client.keypairs.delete(**self.args) - - class MachineCreate(task_manager.Task): def main(self, client): return client.ironic_client.node.create(**self.args) diff --git a/shade/openstackcloud.py b/shade/openstackcloud.py index d7563971c..277821764 100644 --- a/shade/openstackcloud.py +++ b/shade/openstackcloud.py @@ -31,7 +31,6 @@ import requestsexceptions from six.moves import urllib import keystoneauth1.exceptions -import novaclient.exceptions as nova_exceptions import shade from shade.exc import * # noqa @@ -1612,9 +1611,10 @@ class OpenStackCloud( :returns: A list of ``munch.Munch`` containing keypair info. """ - with _utils.shade_exceptions("Error fetching keypair list"): - return self._normalize_keypairs( - self.manager.submit_task(_tasks.KeypairList())) + return self._normalize_keypairs([ + k['keypair'] for k in self._compute_client.get( + '/os-keypairs', + error_message="Error fetching keypair list")]) def list_networks(self, filters=None): """List all available networks. @@ -2968,11 +2968,15 @@ class OpenStackCloud( :raises: OpenStackCloudException on operation error. """ - with _utils.shade_exceptions("Unable to create keypair {name}".format( - name=name)): - return self._normalize_keypair( - self.manager.submit_task(_tasks.KeypairCreate( - name=name, public_key=public_key))) + keypair = { + 'name': name, + } + if public_key: + keypair['public_key'] = public_key + return self._normalize_keypair(self._compute_client.post( + '/os-keypairs', + json={'keypair': keypair}, + error_message="Unable to create keypair {name}".format(name=name))) def delete_keypair(self, name): """Delete a keypair. @@ -2984,15 +2988,11 @@ class OpenStackCloud( :raises: OpenStackCloudException on operation error. """ try: - self.manager.submit_task(_tasks.KeypairDelete(key=name)) - except nova_exceptions.NotFound: + self._compute_client.delete('/os-keypairs/{name}'.format( + name=name)) + except OpenStackCloudURINotFound: self.log.debug("Keypair %s not found for deleting", name) return False - except OpenStackCloudException: - raise - except Exception as e: - raise OpenStackCloudException( - "Unable to delete keypair %s: %s" % (name, e)) return True def create_network(self, name, shared=False, admin_state_up=True, diff --git a/shade/tests/unit/test_keypair.py b/shade/tests/unit/test_keypair.py index 55c3f94f3..2fa3e3ae1 100644 --- a/shade/tests/unit/test_keypair.py +++ b/shade/tests/unit/test_keypair.py @@ -34,11 +34,6 @@ class TestKeypair(base.RequestsMockTestCase): 'keypair': { 'name': self.key['name'], 'public_key': self.key['public_key']}})), - dict(method='GET', - uri=self.get_mock_url( - 'compute', 'public', - append=['os-keypairs', self.keyname]), - json={'keypair': self.key}), ]) new_key = self.cloud.create_keypair(