Merge "Adds keypairs support for the Nova V3 API"
This commit is contained in:
commit
13e37ede5b
novaclient
@ -16,37 +16,45 @@ from novaclient.tests.v1_1 import fakes
|
||||
from novaclient.v1_1 import keypairs
|
||||
|
||||
|
||||
cs = fakes.FakeClient()
|
||||
|
||||
|
||||
class KeypairsTest(utils.TestCase):
|
||||
def setUp(self):
|
||||
super(KeypairsTest, self).setUp()
|
||||
self.cs = self._get_fake_client()
|
||||
self.keypair_type = self._get_keypair_type()
|
||||
self.keypair_prefix = keypairs.KeypairManager.keypair_prefix
|
||||
|
||||
def _get_fake_client(self):
|
||||
return fakes.FakeClient()
|
||||
|
||||
def _get_keypair_type(self):
|
||||
return keypairs.Keypair
|
||||
|
||||
def test_get_keypair(self):
|
||||
kp = cs.keypairs.get('test')
|
||||
cs.assert_called('GET', '/os-keypairs/test')
|
||||
kp = self.cs.keypairs.get('test')
|
||||
self.cs.assert_called('GET', '/%s/test' % self.keypair_prefix)
|
||||
self.assertTrue(isinstance(kp, keypairs.Keypair))
|
||||
self.assertEqual(kp.name, 'test')
|
||||
|
||||
def test_list_keypairs(self):
|
||||
kps = cs.keypairs.list()
|
||||
cs.assert_called('GET', '/os-keypairs')
|
||||
kps = self.cs.keypairs.list()
|
||||
self.cs.assert_called('GET', '/%s' % self.keypair_prefix)
|
||||
[self.assertTrue(isinstance(kp, keypairs.Keypair)) for kp in kps]
|
||||
|
||||
def test_delete_keypair(self):
|
||||
kp = cs.keypairs.list()[0]
|
||||
kp = self.cs.keypairs.list()[0]
|
||||
kp.delete()
|
||||
cs.assert_called('DELETE', '/os-keypairs/test')
|
||||
cs.keypairs.delete('test')
|
||||
cs.assert_called('DELETE', '/os-keypairs/test')
|
||||
cs.keypairs.delete(kp)
|
||||
cs.assert_called('DELETE', '/os-keypairs/test')
|
||||
self.cs.assert_called('DELETE', '/%s/test' % self.keypair_prefix)
|
||||
self.cs.keypairs.delete('test')
|
||||
self.cs.assert_called('DELETE', '/%s/test' % self.keypair_prefix)
|
||||
self.cs.keypairs.delete(kp)
|
||||
self.cs.assert_called('DELETE', '/%s/test' % self.keypair_prefix)
|
||||
|
||||
def test_create_keypair(self):
|
||||
kp = cs.keypairs.create("foo")
|
||||
cs.assert_called('POST', '/os-keypairs')
|
||||
kp = self.cs.keypairs.create("foo")
|
||||
self.cs.assert_called('POST', '/%s' % self.keypair_prefix)
|
||||
self.assertTrue(isinstance(kp, keypairs.Keypair))
|
||||
|
||||
def test_import_keypair(self):
|
||||
kp = cs.keypairs.create("foo", "fake-public-key")
|
||||
cs.assert_called('POST', '/os-keypairs')
|
||||
kp = self.cs.keypairs.create("foo", "fake-public-key")
|
||||
self.cs.assert_called('POST', '/%s' % self.keypair_prefix)
|
||||
self.assertTrue(isinstance(kp, keypairs.Keypair))
|
||||
|
@ -311,3 +311,11 @@ class FakeHTTPClient(fakes_v1_1.FakeHTTPClient):
|
||||
{'name': 'inst2', 'uuid': 'uuid2'}
|
||||
]},
|
||||
})
|
||||
|
||||
#
|
||||
# Keypairs
|
||||
#
|
||||
get_keypairs_test = fakes_v1_1.FakeHTTPClient.get_os_keypairs_test
|
||||
get_keypairs = fakes_v1_1.FakeHTTPClient.get_os_keypairs
|
||||
delete_keypairs_test = fakes_v1_1.FakeHTTPClient.delete_os_keypairs_test
|
||||
post_keypairs = fakes_v1_1.FakeHTTPClient.post_os_keypairs
|
||||
|
31
novaclient/tests/v3/test_keypairs.py
Normal file
31
novaclient/tests/v3/test_keypairs.py
Normal file
@ -0,0 +1,31 @@
|
||||
# Copyright 2013 IBM Corp.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from novaclient.tests.v1_1 import test_keypairs
|
||||
from novaclient.tests.v3 import fakes
|
||||
from novaclient.v3 import keypairs
|
||||
|
||||
|
||||
class KeypairsTest(test_keypairs.KeypairsTest):
|
||||
def setUp(self):
|
||||
super(KeypairsTest, self).setUp()
|
||||
self.cs = self._get_fake_client()
|
||||
self.keypair_type = self._get_keypair_type()
|
||||
self.keypair_prefix = keypairs.KeypairManager.keypair_prefix
|
||||
|
||||
def _get_fake_client(self):
|
||||
return fakes.FakeClient()
|
||||
|
||||
def _get_keypair_type(self):
|
||||
return keypairs.Keypair
|
@ -52,6 +52,7 @@ class Keypair(base.Resource):
|
||||
|
||||
class KeypairManager(base.ManagerWithFind):
|
||||
resource_class = Keypair
|
||||
keypair_prefix = "os-keypairs"
|
||||
|
||||
def get(self, keypair):
|
||||
"""
|
||||
@ -60,7 +61,8 @@ class KeypairManager(base.ManagerWithFind):
|
||||
:param keypair: The ID of the keypair to get.
|
||||
:rtype: :class:`Keypair`
|
||||
"""
|
||||
return self._get("/os-keypairs/%s" % base.getid(keypair), "keypair")
|
||||
return self._get("/%s/%s" % (self.keypair_prefix, base.getid(keypair)),
|
||||
"keypair")
|
||||
|
||||
def create(self, name, public_key=None):
|
||||
"""
|
||||
@ -72,7 +74,7 @@ class KeypairManager(base.ManagerWithFind):
|
||||
body = {'keypair': {'name': name}}
|
||||
if public_key:
|
||||
body['keypair']['public_key'] = public_key
|
||||
return self._create('/os-keypairs', body, 'keypair')
|
||||
return self._create('/%s' % self.keypair_prefix, body, 'keypair')
|
||||
|
||||
def delete(self, key):
|
||||
"""
|
||||
@ -80,10 +82,10 @@ class KeypairManager(base.ManagerWithFind):
|
||||
|
||||
:param key: The :class:`Keypair` (or its ID) to delete.
|
||||
"""
|
||||
self._delete('/os-keypairs/%s' % (base.getid(key)))
|
||||
self._delete('/%s/%s' % (self.keypair_prefix, base.getid(key)))
|
||||
|
||||
def list(self):
|
||||
"""
|
||||
Get a list of keypairs.
|
||||
"""
|
||||
return self._list('/os-keypairs', 'keypairs')
|
||||
return self._list('/%s' % self.keypair_prefix, 'keypairs')
|
||||
|
@ -24,6 +24,7 @@ from novaclient.v3 import flavors
|
||||
from novaclient.v3 import hosts
|
||||
from novaclient.v3 import hypervisors
|
||||
from novaclient.v3 import images
|
||||
from novaclient.v3 import keypairs
|
||||
from novaclient.v3 import quota_classes
|
||||
from novaclient.v3 import quotas
|
||||
from novaclient.v3 import servers
|
||||
@ -72,6 +73,7 @@ class Client(object):
|
||||
self.flavor_access = flavor_access.FlavorAccessManager(self)
|
||||
self.hypervisors = hypervisors.HypervisorManager(self)
|
||||
self.images = images.ImageManager(self)
|
||||
self.keypairs = keypairs.KeypairManager(self)
|
||||
self.quotas = quotas.QuotaSetManager(self)
|
||||
self.quota_classes = quota_classes.QuotaClassSetManager(self)
|
||||
self.servers = servers.ServerManager(self)
|
||||
|
28
novaclient/v3/keypairs.py
Normal file
28
novaclient/v3/keypairs.py
Normal file
@ -0,0 +1,28 @@
|
||||
# Copyright 2013 IBM Corp.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
"""
|
||||
Keypair interface
|
||||
"""
|
||||
|
||||
from novaclient.v1_1 import keypairs
|
||||
|
||||
|
||||
class Keypair(keypairs.Keypair):
|
||||
pass
|
||||
|
||||
|
||||
class KeypairManager(keypairs.KeypairManager):
|
||||
resource_class = Keypair
|
||||
keypair_prefix = "keypairs"
|
Loading…
x
Reference in New Issue
Block a user