--- /dev/null
+# Copyright (c) 2017 Cable Television Laboratories, Inc. ("CableLabs")
+# and others. All rights reserved.
+#
+# 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.
+
+
+class Keypair:
+ """
+ SNAPS domain object for Keypairs. Should contain attributes that
+ are shared amongst cloud providers
+ """
+ def __init__(self, name, id, public_key):
+ """
+ Constructor
+ :param name: the keypair's name
+ :param id: the keypair's id
+ """
+ self.name = name
+ self.id = id
+ self.public_key = public_key
+
+ def __eq__(self, other):
+ return (self.name == other.name and self.id == other.id and
+ self.public_key == other.public_key)
--- /dev/null
+# Copyright (c) 2017 Cable Television Laboratories, Inc. ("CableLabs")
+# and others. All rights reserved.
+#
+# 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 unittest
+from snaps.domain.keypair import Keypair
+
+
+class KeypairDomainObjectTests(unittest.TestCase):
+ """
+ Tests the construction of the snaps.domain.test.Keypair class
+ """
+
+ def test_construction_positional(self):
+ keypair = Keypair('foo', '123-456', 'foo-bar')
+ self.assertEqual('foo', keypair.name)
+ self.assertEqual('123-456', keypair.id)
+ self.assertEqual('foo-bar', keypair.public_key)
+
+ def test_construction_named(self):
+ keypair = Keypair(public_key='foo-bar', id='123-456', name='foo')
+ self.assertEqual('foo', keypair.name)
+ self.assertEqual('123-456', keypair.id)
+ self.assertEqual('foo-bar', keypair.public_key)
from novaclient.exceptions import NotFound
from snaps.domain.flavor import Flavor
+from snaps.domain.keypair import Keypair
from snaps.domain.vm_inst import VmInst
from snaps.openstack.utils import keystone_utils, glance_utils, neutron_utils
:return: the keypair object
"""
logger.info('Creating keypair with name - ' + name)
- return nova.keypairs.create(name=name, public_key=key.decode('utf-8'))
+ os_kp = nova.keypairs.create(name=name, public_key=key.decode('utf-8'))
+ return Keypair(name=os_kp.name, id=os_kp.id, public_key=os_kp.public_key)
def keypair_exists(nova, keypair_obj):
:return: the keypair object or None if not found
"""
try:
- return nova.keypairs.get(keypair_obj)
+ os_kp = nova.keypairs.get(keypair_obj)
+ return Keypair(name=os_kp.name, id=os_kp.id, public_key=os_kp.public_key)
except:
return None
for keypair in keypairs:
if keypair.name == name:
- return keypair
+ return Keypair(name=keypair.name, id=keypair.id,
+ public_key=keypair.public_key)
return None
"""
Deletes a keypair object from OpenStack
:param nova: the Nova client
- :param key: the keypair object to delete
+ :param key: the SNAPS-OO keypair domain object to delete
"""
logger.debug('Deleting keypair - ' + key.name)
- nova.keypairs.delete(key)
+ nova.keypairs.delete(key.id)
def get_nova_availability_zones(nova):
from snaps.domain.test.flavor_tests import FlavorDomainObjectTests
from snaps.domain.test.image_tests import ImageDomainObjectTests
+from snaps.domain.test.keypair_tests import KeypairDomainObjectTests
from snaps.domain.test.stack_tests import StackDomainObjectTests
from snaps.domain.test.vm_inst_tests import (VmInstDomainObjectTests,
FloatingIpDomainObjectTests)
FlavorDomainObjectTests))
suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
KeypairSettingsUnitTests))
+ suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
+ KeypairDomainObjectTests))
suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
UserSettingsUnitTests))
suite.addTest(unittest.TestLoader().loadTestsFromTestCase(