Convert keypairs calls to REST

Change-Id: Iea7c8267e87c5b5beb83e9315f41a61ae714005f
This commit is contained in:
Monty Taylor 2017-06-16 18:23:07 -05:00
parent caa69b4117
commit b9a2c296e6
No known key found for this signature in database
GPG Key ID: 7BAE94BC7141A594
3 changed files with 16 additions and 36 deletions

View File

@ -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)

View File

@ -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,

View File

@ -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(