compute/v2 keypairs resource

Change-Id: I9ffa9dc09891fd8a8ecdbb7a479a135031f780c2
This commit is contained in:
Terry Howe 2014-09-15 14:01:55 -06:00
parent c7262b0865
commit 56a9b13ba2
2 changed files with 77 additions and 0 deletions

View File

@ -0,0 +1,34 @@
# 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 openstack.compute import compute_service
from openstack import resource
class Keypairs(resource.Resource):
id_attribute = 'fingerprint'
resource_key = 'keypairs'
resources_key = 'keypairs'
base_path = '/os-keypairs'
service = compute_service.ComputeService()
# capabilities
allow_create = True
allow_retrieve = True
allow_update = True
allow_delete = True
allow_list = True
# Properties
fingerprint = resource.prop('fingerprint')
name = resource.prop('name')
public_key = resource.prop('public_key')

View File

@ -0,0 +1,43 @@
# 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.
import testtools
from openstack.compute.v2 import keypairs
IDENTIFIER = 'IDENTIFIER'
EXAMPLE = {
'fingerprint': '1',
'name': '2',
'public_key': '3',
}
class TestKeypairs(testtools.TestCase):
def test_basic(self):
sot = keypairs.Keypairs()
self.assertEqual('keypairs', sot.resource_key)
self.assertEqual('keypairs', sot.resources_key)
self.assertEqual('/os-keypairs', sot.base_path)
self.assertEqual('compute', sot.service.service_type)
self.assertTrue(sot.allow_create)
self.assertTrue(sot.allow_retrieve)
self.assertTrue(sot.allow_update)
self.assertTrue(sot.allow_delete)
self.assertTrue(sot.allow_list)
def test_make_it(self):
sot = keypairs.Keypairs(EXAMPLE)
self.assertEqual(EXAMPLE['fingerprint'], sot.fingerprint)
self.assertEqual(EXAMPLE['name'], sot.name)
self.assertEqual(EXAMPLE['public_key'], sot.public_key)