diff options
| author | John Tran <jtran@attinteractive.com> | 2011-03-18 11:49:11 -0700 |
|---|---|---|
| committer | John Tran <jtran@attinteractive.com> | 2011-03-18 11:49:11 -0700 |
| commit | 5a9d2eb44ced0affe143e6274c9c9326f1c2d7da (patch) | |
| tree | c653b5d6c5753d1f1e0e3fb2f38853c1178d6828 | |
| parent | 2002b0920fb4a5ad3403e2243eb19809b3cb631b (diff) | |
| download | nova-5a9d2eb44ced0affe143e6274c9c9326f1c2d7da.tar.gz nova-5a9d2eb44ced0affe143e6274c9c9326f1c2d7da.tar.xz nova-5a9d2eb44ced0affe143e6274c9c9326f1c2d7da.zip | |
created api endpoint to allow uploading of public key
| -rw-r--r-- | nova/api/ec2/cloud.py | 12 | ||||
| -rw-r--r-- | nova/tests/test_cloud.py | 16 |
2 files changed, 28 insertions, 0 deletions
diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py index cadda97db..6fe01b0e9 100644 --- a/nova/api/ec2/cloud.py +++ b/nova/api/ec2/cloud.py @@ -302,6 +302,18 @@ class CloudController(object): 'keyMaterial': data['private_key']} # TODO(vish): when context is no longer an object, pass it here + def import_public_key(self, context, key_name, public_key, + fingerprint=None): + LOG.audit(_("Import key %s"), key_name, context=context) + key = {} + key['user_id'] = context.user_id + key['name'] = key_name + key['public_key'] = public_key + if fingerprint: + key['fingerprint'] = fingerprint + db.key_pair_create(context, key) + return True + def delete_key_pair(self, context, key_name, **kwargs): LOG.audit(_("Delete key pair %s"), key_name, context=context) try: diff --git a/nova/tests/test_cloud.py b/nova/tests/test_cloud.py index cf8ee7eff..03b1ad2fc 100644 --- a/nova/tests/test_cloud.py +++ b/nova/tests/test_cloud.py @@ -279,6 +279,22 @@ class CloudTestCase(test.TestCase): self.assertTrue(filter(lambda k: k['keyName'] == 'test1', keys)) self.assertTrue(filter(lambda k: k['keyName'] == 'test2', keys)) + def test_import_public_key(self): + result = self.cloud.import_public_key(self.context, + 'testimportkey', 'mytestpubkey', 'mytestfprint') + self.assertTrue(result) + keydata = db.key_pair_get(self.context, + self.context.user.id, + 'testimportkey') + print "PUBLIC_KEY:" + file = open('/tmp/blah', 'w') + file.write(keydata['public_key']) + file.close() + print keydata['public_key'] + self.assertEqual('mytestpubkey', keydata['public_key']) + self.assertEqual('mytestfprint', keydata['fingerprint']) + self.assertTrue(1) + def test_delete_key_pair(self): self._create_key('test') self.cloud.delete_key_pair(self.context, 'test') |
