2
0
Эх сурвалжийг харах

Use key_pair consistently (vs. keypair)

Enis Afgan 10 жил өмнө
parent
commit
a003957a8f

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

@@ -80,19 +80,19 @@ class BaseKeyPairService(
     def __init__(self, provider):
     def __init__(self, provider):
         super(BaseKeyPairService, self).__init__(provider)
         super(BaseKeyPairService, self).__init__(provider)
 
 
-    def delete(self, keypair_id):
+    def delete(self, key_pair_id):
         """
         """
         Delete an existing key pair.
         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``
         :rtype: ``bool``
         :return:  ``True`` if the key does not exist. Note that this implies
         :return:  ``True`` if the key does not exist. Note that this implies
                   that the key may not have been deleted by this method but
                   that the key may not have been deleted by this method but
                   instead has not existed in the first place.
                   instead has not existed in the first place.
         """
         """
-        kp = self.get(keypair_id)
+        kp = self.get(key_pair_id)
         if kp:
         if kp:
             kp.delete()
             kp.delete()
         return True
         return True

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

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

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

@@ -200,7 +200,7 @@ class InstanceService(PageableObjectMixin, CloudService):
 
 
     @abstractmethod
     @abstractmethod
     def create(self, name, image, instance_type, zone=None,
     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,
                launch_config=None,
                **kwargs):
                **kwargs):
         """
         """
@@ -220,9 +220,9 @@ class InstanceService(PageableObjectMixin, CloudService):
         :type  zone: ``Zone`` or ``str``
         :type  zone: ``Zone`` or ``str``
         :param zone: The Zone or its name, where the instance should be placed.
         :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
         :type  security_groups: A ``list`` of ``SecurityGroup`` objects or a
                                 list of ``str`` names
                                 list of ``str`` names
@@ -730,18 +730,19 @@ class KeyPairService(PageableObjectMixin, CloudService):
     __metaclass__ = ABCMeta
     __metaclass__ = ABCMeta
 
 
     @abstractmethod
     @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:
         Example:
 
 
         .. code-block:: python
         .. 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`
         :rtype: :class:`.KeyPair`
         :return:  a KeyPair instance
         :return:  a KeyPair instance
@@ -782,12 +783,12 @@ class KeyPairService(PageableObjectMixin, CloudService):
         pass
         pass
 
 
     @abstractmethod
     @abstractmethod
-    def delete(self, keypair_id):
+    def delete(self, key_pair_id):
         """
         """
         Delete an existing SecurityGroup.
         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``
         :rtype: ``bool``
         :return:  ``True`` if the key does not exist, ``False`` otherwise. Note
         :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):
     def __init__(self, provider):
         super(AWSKeyPairService, self).__init__(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:
         try:
             kps = self.provider.ec2_conn.get_all_key_pairs(
             kps = self.provider.ec2_conn.get_all_key_pairs(
-                keynames=[keypair_id])
+                keynames=[key_pair_id])
             return AWSKeyPair(self.provider, kps[0])
             return AWSKeyPair(self.provider, kps[0])
         except EC2ResponseError:
         except EC2ResponseError:
             return None
             return None
@@ -121,13 +121,13 @@ class AWSKeyPairService(BaseKeyPairService):
 
 
     def create(self, name):
     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
         :type name: str
         :param name: The name of the key pair to be created.
         :param name: The name of the key pair to be created.
 
 
         :rtype: ``object`` of :class:`.KeyPair`
         :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)
         kp = self.get(name)
         if kp:
         if kp:
@@ -446,7 +446,7 @@ class AWSInstanceService(BaseInstanceService):
         super(AWSInstanceService, self).__init__(provider)
         super(AWSInstanceService, self).__init__(provider)
 
 
     def create(self, name, image, instance_type, zone=None,
     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,
                launch_config=None,
                **kwargs):
                **kwargs):
         """
         """
@@ -456,9 +456,9 @@ class AWSInstanceService(BaseInstanceService):
         instance_size = instance_type.id if \
         instance_size = instance_type.id if \
             isinstance(instance_type, InstanceType) else instance_type
             isinstance(instance_type, InstanceType) else instance_type
         zone_id = zone.id if isinstance(zone, PlacementZone) else zone
         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 security_groups:
             if isinstance(security_groups, list) and \
             if isinstance(security_groups, list) and \
                     isinstance(security_groups[0], SecurityGroup):
                     isinstance(security_groups[0], SecurityGroup):
@@ -476,7 +476,7 @@ class AWSInstanceService(BaseInstanceService):
         reservation = self.provider.ec2_conn.run_instances(
         reservation = self.provider.ec2_conn.run_instances(
             image_id=image_id, instance_type=instance_size,
             image_id=image_id, instance_type=instance_size,
             min_count=1, max_count=1, placement=zone_id,
             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)
             user_data=user_data, block_device_map=bdm, subnet_id=net_id)
         if reservation:
         if reservation:
             instance = AWSInstance(self.provider, reservation.instances[0])
             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):
     def __init__(self, provider):
         super(OpenStackKeyPairService, self).__init__(provider)
         super(OpenStackKeyPairService, 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:
         try:
             return OpenStackKeyPair(
             return OpenStackKeyPair(
-                self.provider, self.provider.nova.keypairs.get(keypair_id))
+                self.provider, self.provider.nova.keypairs.get(key_pair_id))
         except NovaNotFound:
         except NovaNotFound:
             return None
             return None
 
 
@@ -115,13 +115,13 @@ class OpenStackKeyPairService(BaseKeyPairService):
 
 
     def create(self, name):
     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
         :type name: str
         :param name: The name of the key pair to be created.
         :param name: The name of the key pair to be created.
 
 
         :rtype: ``object`` of :class:`.KeyPair`
         :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)
         kp = self.get(name)
         if kp:
         if kp:
@@ -499,7 +499,7 @@ class OpenStackInstanceService(BaseInstanceService):
         super(OpenStackInstanceService, self).__init__(provider)
         super(OpenStackInstanceService, self).__init__(provider)
 
 
     def create(self, name, image, instance_type, zone=None,
     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,
                launch_config=None,
                **kwargs):
                **kwargs):
         """
         """
@@ -511,8 +511,8 @@ class OpenStackInstanceService(BaseInstanceService):
             self.provider.compute.instance_types.find(
             self.provider.compute.instance_types.find(
                 name=instance_type)[0].id
                 name=instance_type)[0].id
         zone_id = zone.id if isinstance(zone, PlacementZone) else zone
         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 security_groups:
             if isinstance(security_groups, list) and \
             if isinstance(security_groups, list) and \
                     isinstance(security_groups[0], SecurityGroup):
                     isinstance(security_groups[0], SecurityGroup):
@@ -534,7 +534,7 @@ class OpenStackInstanceService(BaseInstanceService):
             min_count=1,
             min_count=1,
             max_count=1,
             max_count=1,
             availability_zone=zone_id,
             availability_zone=zone_id,
-            key_name=keypair_name,
+            key_name=key_pair_name,
             security_groups=security_groups_list,
             security_groups=security_groups_list,
             userdata=user_data,
             userdata=user_data,
             block_device_mapping_v2=bdm,
             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_type = provider.compute.instance_types.find(name='m1.small')
     inst = provider.compute.instances.create(
     inst = provider.compute.instances.create(
         name='Cloudbridge-intro', image=img, instance_type=inst_type,
         name='Cloudbridge-intro', image=img, instance_type=inst_type,
-        keypair=kp, security_groups=[sg])
+        key_pair=kp, security_groups=[sg])
     # Refresh the state
     # Refresh the state
     inst.refresh()
     inst.refresh()
     inst.state
     inst.state

+ 3 - 3
docs/topics/launch.rst

@@ -38,7 +38,7 @@ only needing to specify the basic parameters:
 
 
     inst = provider.compute.instances.create(
     inst = provider.compute.instances.create(
         name='Cloudbridge-basic', image=img, instance_type=inst_type,
         name='Cloudbridge-basic', image=img, instance_type=inst_type,
-        keypair=kp, security_groups=[sg])
+        key_pair=kp, security_groups=[sg])
 
 
 Launch with private networking
 Launch with private networking
 ------------------------------
 ------------------------------
@@ -68,7 +68,7 @@ below). Finally, we can launch the instance:
     lc.add_network_interface(sn.id)
     lc.add_network_interface(sn.id)
     inst = provider.compute.instances.create(
     inst = provider.compute.instances.create(
         name='Cloudbridge-VPC', image=img,  instance_type=inst_type,
         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
 Block device mapping
@@ -88,7 +88,7 @@ refer to :class:`.LaunchConfig`.
     lc.add_volume_device(source=img, size=11, is_root=True)
     lc.add_volume_device(source=img, size=11, is_root=True)
     inst = provider.compute.instances.create(
     inst = provider.compute.instances.create(
         name='Cloudbridge-BDM', image=img,  instance_type=inst_type,
         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.
 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(
 def create_test_instance(
         provider, instance_name, zone=None, launch_config=None,
         provider, instance_name, zone=None, launch_config=None,
-        keypair=None, security_groups=None):
+        key_pair=None, security_groups=None):
     return provider.compute.instances.create(
     return provider.compute.instances.create(
         instance_name,
         instance_name,
         get_provider_test_data(provider, 'image'),
         get_provider_test_data(provider, 'image'),
         get_provider_test_data(provider, 'instance_type'),
         get_provider_test_data(provider, 'instance_type'),
         zone=zone,
         zone=zone,
-        keypair=keypair,
+        key_pair=key_pair,
         security_groups=security_groups,
         security_groups=security_groups,
         launch_config=launch_config)
         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(
     instance = create_test_instance(
         provider,
         provider,
         name,
         name,
-        keypair=keypair,
+        key_pair=key_pair,
         security_groups=security_groups)
         security_groups=security_groups)
     instance.wait_till_ready()
     instance.wait_till_ready()
     return instance
     return instance

+ 1 - 1
test/test_compute_service.py

@@ -103,7 +103,7 @@ class CloudComputeServiceTestCase(ProviderTestBase):
             name=name, description=name)
             name=name, description=name)
 
 
         test_instance = helpers.get_test_instance(self.provider,
         test_instance = helpers.get_test_instance(self.provider,
-                                                  name, keypair=kp,
+                                                  name, key_pair=kp,
                                                   security_groups=[sg])
                                                   security_groups=[sg])
 
 
         def cleanup(inst, kp, 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)
         kp = self.provider.security.key_pairs.create(name=name)
         with helpers.cleanup_action(
         with helpers.cleanup_action(
             lambda:
             lambda:
-                self.provider.security.key_pairs.delete(kp.id)
+                self.provider.security.key_pairs.delete(key_pair_id=kp.id)
         ):
         ):
             # test list method
             # test list method
             kpl = self.provider.security.key_pairs.list()
             kpl = self.provider.security.key_pairs.list()
             list_kpl = [i for i in kpl if i.name == name]
             list_kpl = [i for i in kpl if i.name == name]
             self.assertTrue(
             self.assertTrue(
                 len(list_kpl) == 1,
                 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)
                 name)
 
 
             # check iteration
             # check iteration
@@ -31,7 +31,7 @@ class CloudSecurityServiceTestCase(ProviderTestBase):
                         if i.name == name]
                         if i.name == name]
             self.assertTrue(
             self.assertTrue(
                 len(iter_kpl) == 1,
                 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)
                 name)
 
 
             # check find
             # check find