Make compute_api use KeyPair objects
This makes compute_api's KeypairAPI use KeyPair objects to do its work. Most of the change here is to tests to account for the change. Related to blueprint compute-api-objects Change-Id: If516a88eac107670d9ae37fcfaf56f2add9dd0c5
This commit is contained in:
@@ -54,6 +54,16 @@ class KeypairController(object):
|
||||
def __init__(self):
|
||||
self.api = compute_api.KeypairAPI()
|
||||
|
||||
def _filter_keypair(self, keypair, **attrs):
|
||||
clean = {
|
||||
'name': keypair.name,
|
||||
'public_key': keypair.public_key,
|
||||
'fingerprint': keypair.fingerprint,
|
||||
}
|
||||
for attr in attrs:
|
||||
clean[attr] = keypair[attr]
|
||||
return clean
|
||||
|
||||
@wsgi.serializers(xml=KeypairTemplate)
|
||||
def create(self, req, body):
|
||||
"""
|
||||
@@ -84,9 +94,12 @@ class KeypairController(object):
|
||||
keypair = self.api.import_key_pair(context,
|
||||
context.user_id, name,
|
||||
params['public_key'])
|
||||
keypair = self._filter_keypair(keypair, user_id=True)
|
||||
else:
|
||||
keypair = self.api.create_key_pair(context, context.user_id,
|
||||
name)
|
||||
keypair, private_key = self.api.create_key_pair(
|
||||
context, context.user_id, name)
|
||||
keypair = self._filter_keypair(keypair, user_id=True)
|
||||
keypair['private_key'] = private_key
|
||||
|
||||
return {'keypair': keypair}
|
||||
|
||||
@@ -134,11 +147,7 @@ class KeypairController(object):
|
||||
key_pairs = self.api.get_key_pairs(context, context.user_id)
|
||||
rval = []
|
||||
for key_pair in key_pairs:
|
||||
rval.append({'keypair': {
|
||||
'name': key_pair['name'],
|
||||
'public_key': key_pair['public_key'],
|
||||
'fingerprint': key_pair['fingerprint'],
|
||||
}})
|
||||
rval.append({'keypair': self._filter_keypair(key_pair)})
|
||||
|
||||
return {'keypairs': rval}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user