Переглянути джерело

Use key_pair consistently (vs. keypair)

Enis Afgan 10 роки тому
батько
коміт
a003957a8f

+ 4 - 4
cloudbridge/cloud/base/services.py

@@ -80,19 +80,19 @@ class BaseKeyPairService(
     def __init__(self, provider):
         super(BaseKeyPairService, self).__init__(provider)
 
-    def delete(self, keypair_id):
+    def delete(self, key_pair_id):
         """
         Delete an existing key pair.
 
-        :type keypair_id: str
-        :param keypair_id: The id of the key pair to be deleted.
+        :type key_pair_id: str
+        :param key_pair_id: The id of the key pair to be deleted.
 
         :rtype: ``bool``
         :return:  ``True`` if the key does not exist. Note that this implies
                   that the key may not have been deleted by this method but
                   instead has not existed in the first place.
         """
-        kp = self.get(keypair_id)
+        kp = self.get(key_pair_id)
         if kp:
             kp.delete()
         return True

+ 1 - 1
cloudbridge/cloud/interfaces/provider.py

@@ -129,7 +129,7 @@ class CloudProvider(object):
     @abstractproperty
     def security(self):
         """
-        Provides access to keypair management and firewall control
+        Provides access to key pair management and firewall control
 
         Example:
 

+ 14 - 13
cloudbridge/cloud/interfaces/services.py

@@ -200,7 +200,7 @@ class InstanceService(PageableObjectMixin, CloudService):
 
     @abstractmethod
     def create(self, name, image, instance_type, zone=None,
-               keypair=None, security_groups=None, user_data=None,
+               key_pair=None, security_groups=None, user_data=None,
                launch_config=None,
                **kwargs):
         """
@@ -220,9 +220,9 @@ class InstanceService(PageableObjectMixin, CloudService):
         :type  zone: ``Zone`` or ``str``
         :param zone: The Zone or its name, where the instance should be placed.
 
-        :type  keypair: ``KeyPair`` or ``str``
-        :param keypair: The KeyPair object or its name, to set for the
-                        instance.
+        :type  key_pair: ``KeyPair`` or ``str``
+        :param key_pair: The KeyPair object or its name, to set for the
+                         instance.
 
         :type  security_groups: A ``list`` of ``SecurityGroup`` objects or a
                                 list of ``str`` names
@@ -730,18 +730,19 @@ class KeyPairService(PageableObjectMixin, CloudService):
     __metaclass__ = ABCMeta
 
     @abstractmethod
-    def get(self, keypair_id):
+    def get(self, key_pair_id):
         """
-        Returns a KeyPair given its ID. Returns ``None`` if the KeyPair
-        does not exist. On some providers, such as AWS and Openstack,
-        the KeyPair id is the same as its name.
+        Return a KeyPair given its ID or ``None`` if not found.
+
+        On some providers, such as AWS and Openstack, the KeyPair ID is
+        the same as its name.
 
         Example:
 
         .. code-block:: python
 
-            keypair = provider.security.keypairs.get('my_keypair_id')
-            print(keypair.id, keypair.name)
+            key_pair = provider.security.keypairs.get('my_key_pair_id')
+            print(key_pair.id, key_pair.name)
 
         :rtype: :class:`.KeyPair`
         :return:  a KeyPair instance
@@ -782,12 +783,12 @@ class KeyPairService(PageableObjectMixin, CloudService):
         pass
 
     @abstractmethod
-    def delete(self, keypair_id):
+    def delete(self, key_pair_id):
         """
         Delete an existing SecurityGroup.
 
-        :type keypair_id: str
-        :param keypair_id: The id of the key pair to be deleted.
+        :type key_pair_id: str
+        :param key_pair_id: The id of the key pair to be deleted.
 
         :rtype: ``bool``
         :return:  ``True`` if the key does not exist, ``False`` otherwise. Note

+ 10 - 10
cloudbridge/cloud/providers/aws/services.py

@@ -83,13 +83,13 @@ class AWSKeyPairService(BaseKeyPairService):
     def __init__(self, provider):
         super(AWSKeyPairService, self).__init__(provider)
 
-    def get(self, keypair_id):
+    def get(self, key_pair_id):
         """
-        Returns a KeyPair given its id.
+        Returns a KeyPair given its ID.
         """
         try:
             kps = self.provider.ec2_conn.get_all_key_pairs(
-                keynames=[keypair_id])
+                keynames=[key_pair_id])
             return AWSKeyPair(self.provider, kps[0])
         except EC2ResponseError:
             return None
@@ -121,13 +121,13 @@ class AWSKeyPairService(BaseKeyPairService):
 
     def create(self, name):
         """
-        Create a new keypair or return an existing one by the same name.
+        Create a new key pair or return an existing one by the same name.
 
         :type name: str
         :param name: The name of the key pair to be created.
 
         :rtype: ``object`` of :class:`.KeyPair`
-        :return:  A keypair instance or None if one was not be created.
+        :return:  A key pair instance or ``None`` if one was not be created.
         """
         kp = self.get(name)
         if kp:
@@ -446,7 +446,7 @@ class AWSInstanceService(BaseInstanceService):
         super(AWSInstanceService, self).__init__(provider)
 
     def create(self, name, image, instance_type, zone=None,
-               keypair=None, security_groups=None, user_data=None,
+               key_pair=None, security_groups=None, user_data=None,
                launch_config=None,
                **kwargs):
         """
@@ -456,9 +456,9 @@ class AWSInstanceService(BaseInstanceService):
         instance_size = instance_type.id if \
             isinstance(instance_type, InstanceType) else instance_type
         zone_id = zone.id if isinstance(zone, PlacementZone) else zone
-        keypair_name = keypair.name if isinstance(
-            keypair,
-            KeyPair) else keypair
+        key_pair_name = key_pair.name if isinstance(
+            key_pair,
+            KeyPair) else key_pair
         if security_groups:
             if isinstance(security_groups, list) and \
                     isinstance(security_groups[0], SecurityGroup):
@@ -476,7 +476,7 @@ class AWSInstanceService(BaseInstanceService):
         reservation = self.provider.ec2_conn.run_instances(
             image_id=image_id, instance_type=instance_size,
             min_count=1, max_count=1, placement=zone_id,
-            key_name=keypair_name, security_groups=security_groups_list,
+            key_name=key_pair_name, security_groups=security_groups_list,
             user_data=user_data, block_device_map=bdm, subnet_id=net_id)
         if reservation:
             instance = AWSInstance(self.provider, reservation.instances[0])

+ 8 - 8
cloudbridge/cloud/providers/openstack/services.py

@@ -79,13 +79,13 @@ class OpenStackKeyPairService(BaseKeyPairService):
     def __init__(self, provider):
         super(OpenStackKeyPairService, self).__init__(provider)
 
-    def get(self, keypair_id):
+    def get(self, key_pair_id):
         """
         Returns a KeyPair given its id.
         """
         try:
             return OpenStackKeyPair(
-                self.provider, self.provider.nova.keypairs.get(keypair_id))
+                self.provider, self.provider.nova.keypairs.get(key_pair_id))
         except NovaNotFound:
             return None
 
@@ -115,13 +115,13 @@ class OpenStackKeyPairService(BaseKeyPairService):
 
     def create(self, name):
         """
-        Create a new keypair or return an existing one by the same name.
+        Create a new key pair or return an existing one by the same name.
 
         :type name: str
         :param name: The name of the key pair to be created.
 
         :rtype: ``object`` of :class:`.KeyPair`
-        :return:  A keypair instance or ``None`` if one was not be created.
+        :return:  A key pair instance or ``None`` if one was not be created.
         """
         kp = self.get(name)
         if kp:
@@ -499,7 +499,7 @@ class OpenStackInstanceService(BaseInstanceService):
         super(OpenStackInstanceService, self).__init__(provider)
 
     def create(self, name, image, instance_type, zone=None,
-               keypair=None, security_groups=None, user_data=None,
+               key_pair=None, security_groups=None, user_data=None,
                launch_config=None,
                **kwargs):
         """
@@ -511,8 +511,8 @@ class OpenStackInstanceService(BaseInstanceService):
             self.provider.compute.instance_types.find(
                 name=instance_type)[0].id
         zone_id = zone.id if isinstance(zone, PlacementZone) else zone
-        keypair_name = keypair.name if \
-            isinstance(keypair, KeyPair) else keypair
+        key_pair_name = key_pair.name if \
+            isinstance(key_pair, KeyPair) else key_pair
         if security_groups:
             if isinstance(security_groups, list) and \
                     isinstance(security_groups[0], SecurityGroup):
@@ -534,7 +534,7 @@ class OpenStackInstanceService(BaseInstanceService):
             min_count=1,
             max_count=1,
             availability_zone=zone_id,
-            key_name=keypair_name,
+            key_name=key_pair_name,
             security_groups=security_groups_list,
             userdata=user_data,
             block_device_mapping_v2=bdm,

+ 1 - 1
docs/getting_started.rst

@@ -76,7 +76,7 @@ get a base Ubuntu image ``ami-d85e75b0`` and launch an instance.
     inst_type = provider.compute.instance_types.find(name='m1.small')
     inst = provider.compute.instances.create(
         name='Cloudbridge-intro', image=img, instance_type=inst_type,
-        keypair=kp, security_groups=[sg])
+        key_pair=kp, security_groups=[sg])
     # Refresh the state
     inst.refresh()
     inst.state

+ 3 - 3
docs/topics/launch.rst

@@ -38,7 +38,7 @@ only needing to specify the basic parameters:
 
     inst = provider.compute.instances.create(
         name='Cloudbridge-basic', image=img, instance_type=inst_type,
-        keypair=kp, security_groups=[sg])
+        key_pair=kp, security_groups=[sg])
 
 Launch with private networking
 ------------------------------
@@ -68,7 +68,7 @@ below). Finally, we can launch the instance:
     lc.add_network_interface(sn.id)
     inst = provider.compute.instances.create(
         name='Cloudbridge-VPC', image=img,  instance_type=inst_type,
-        launch_config=lc, keypair=kp, security_groups=[sg])
+        launch_config=lc, key_pair=kp, security_groups=[sg])
 
 
 Block device mapping
@@ -88,7 +88,7 @@ refer to :class:`.LaunchConfig`.
     lc.add_volume_device(source=img, size=11, is_root=True)
     inst = provider.compute.instances.create(
         name='Cloudbridge-BDM', image=img,  instance_type=inst_type,
-        launch_config=lc, keypair=kp, security_groups=[sg])
+        launch_config=lc, key_pair=kp, security_groups=[sg])
 
 where img is the :class:`.Image` object to use for the root volume.
 

+ 4 - 4
test/helpers.py

@@ -72,22 +72,22 @@ def get_provider_test_data(provider, key):
 
 def create_test_instance(
         provider, instance_name, zone=None, launch_config=None,
-        keypair=None, security_groups=None):
+        key_pair=None, security_groups=None):
     return provider.compute.instances.create(
         instance_name,
         get_provider_test_data(provider, 'image'),
         get_provider_test_data(provider, 'instance_type'),
         zone=zone,
-        keypair=keypair,
+        key_pair=key_pair,
         security_groups=security_groups,
         launch_config=launch_config)
 
 
-def get_test_instance(provider, name, keypair=None, security_groups=None):
+def get_test_instance(provider, name, key_pair=None, security_groups=None):
     instance = create_test_instance(
         provider,
         name,
-        keypair=keypair,
+        key_pair=key_pair,
         security_groups=security_groups)
     instance.wait_till_ready()
     return instance

+ 1 - 1
test/test_compute_service.py

@@ -103,7 +103,7 @@ class CloudComputeServiceTestCase(ProviderTestBase):
             name=name, description=name)
 
         test_instance = helpers.get_test_instance(self.provider,
-                                                  name, keypair=kp,
+                                                  name, key_pair=kp,
                                                   security_groups=[sg])
 
         def cleanup(inst, kp, sg):

+ 3 - 3
test/test_security_service.py

@@ -16,14 +16,14 @@ class CloudSecurityServiceTestCase(ProviderTestBase):
         kp = self.provider.security.key_pairs.create(name=name)
         with helpers.cleanup_action(
             lambda:
-                self.provider.security.key_pairs.delete(kp.id)
+                self.provider.security.key_pairs.delete(key_pair_id=kp.id)
         ):
             # test list method
             kpl = self.provider.security.key_pairs.list()
             list_kpl = [i for i in kpl if i.name == name]
             self.assertTrue(
                 len(list_kpl) == 1,
-                "List keypairs does not return the expected keypair %s" %
+                "List key pairs does not return the expected key pair %s" %
                 name)
 
             # check iteration
@@ -31,7 +31,7 @@ class CloudSecurityServiceTestCase(ProviderTestBase):
                         if i.name == name]
             self.assertTrue(
                 len(iter_kpl) == 1,
-                "Iter keypairs does not return the expected keypair %s" %
+                "Iter key pairs does not return the expected key pair %s" %
                 name)
 
             # check find