libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject [05/10] libcloud git commit: [LIBCLOUD-802] Refactor codes according to the project convention
Date Sat, 12 Mar 2016 21:52:39 GMT
http://git-wip-us.apache.org/repos/asf/libcloud/blob/ae4c482b/libcloud/compute/providers.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/providers.py b/libcloud/compute/providers.py
index 9ac944c..dfe7e5d 100644
--- a/libcloud/compute/providers.py
+++ b/libcloud/compute/providers.py
@@ -173,7 +173,7 @@ DRIVERS = {
     ('libcloud.compute.drivers.ciscoccs', 'CiscoCCSNodeDriver'),
     Provider.NTTA:
     ('libcloud.compute.drivers.ntta', 'NTTAmericaNodeDriver'),
-    Provider.ECS:
+    Provider.ALIYUN_ECS:
     ('libcloud.compute.drivers.ecs', 'ECSDriver'),
 
     # Deprecated

http://git-wip-us.apache.org/repos/asf/libcloud/blob/ae4c482b/libcloud/compute/types.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/types.py b/libcloud/compute/types.py
index 34884e0..226966f 100644
--- a/libcloud/compute/types.py
+++ b/libcloud/compute/types.py
@@ -100,7 +100,7 @@ class Provider(Type):
     :cvar VULTR: vultr driver.
     :cvar AZURE: Azure driver.
     :cvar AURORACOMPUTE: Aurora Compute driver.
-    :cvar ECS: Aliyun ECS driver.
+    :cvar ALIYUN_ECS: Aliyun ECS driver.
     """
     AZURE = 'azure'
     DUMMY = 'dummy'
@@ -160,7 +160,7 @@ class Provider(Type):
     NTTA = 'ntta'
     MEDONE = 'medone'
     CISCOCCS = 'ciscoccs'
-    ECS = 'ecs'
+    ALIYUN_ECS = 'ecs'
 
     # OpenStack based providers
     HPCLOUD = 'hpcloud'

http://git-wip-us.apache.org/repos/asf/libcloud/blob/ae4c482b/libcloud/loadbalancer/drivers/slb.py
----------------------------------------------------------------------
diff --git a/libcloud/loadbalancer/drivers/slb.py b/libcloud/loadbalancer/drivers/slb.py
index a7eab40..03ca6be 100644
--- a/libcloud/loadbalancer/drivers/slb.py
+++ b/libcloud/loadbalancer/drivers/slb.py
@@ -14,6 +14,7 @@
 # limitations under the License.
 
 __all__ = [
+    'SLB_API_VERSION',
     'SLBDriver'
 ]
 
@@ -313,19 +314,23 @@ class SLBDriver(Driver):
     def list_protocols(self):
         return list(PROTOCOL_TO_LISTENER_MAP.keys())
 
-    def list_balancers(self, ex_balancer_ids=[], ex_filters=None):
+    def list_balancers(self, ex_balancer_ids=None, ex_filters=None):
         """
         List all loadbalancers
+
         @inherits :class:`Driver.list_balancers`
+
         :keyword ex_balancer_ids: a list of balancer ids to filter results
                                   Only balancers which's id in this list
                                   will be returned
-        :type ex_balancer_ids: ``list``
+        :type ex_balancer_ids: ``list`` of ``str``
+
         :keyword ex_filters: attributes to filter results. Only balancers
                              which have all the desired attributes
                              and values will be returned
         :type ex_filters: ``dict``
         """
+
         params = {'Action': 'DescribeLoadBalancers',
                   'RegionId': self.region}
         if ex_balancer_ids and isinstance(ex_balancer_ids, list):
@@ -338,7 +343,41 @@ class SLBDriver(Driver):
         return self._to_balancers(resp_body)
 
     def create_balancer(self, name, port, protocol, algorithm, members,
+                        ex_bandwidth=None, ex_internet_charge_type=None,
+                        ex_address_type=None, ex_vswitch_id=None,
+                        ex_master_zone_id=None, ex_slave_zone_id=None,
+                        ex_client_token=None,
                         **kwargs):
+        """
+        Create a new load balancer instance
+
+        @inherits: :class:`Driver.create_balancer`
+
+        :keyword ex_bandwidth: The max bandwidth limit for `paybybandwidth`
+                               internet charge type, in Mbps unit
+        :type ex_bandwidth: ``int`` in range [1, 1000]
+
+        :keyword ex_internet_charge_type: The internet charge type
+        :type ex_internet_charge_type: a ``str`` of `paybybandwidth`
+                                       or `paybytraffic`
+
+        :keyword ex_address_type: The listening IP address type
+        :type ex_address_type: a ``str`` of `internet` or `intranet`
+
+        :keyword ex_vswitch_id: The vswitch id in a VPC network
+        :type ex_vswitch_id: ``str``
+
+        :keyword ex_master_zone_id: The id of the master availability zone
+        :type ex_master_zone_id: ``str``
+
+        :keyword ex_slave_zone_id: The id of the slave availability zone
+        :type ex_slave_zone_id: ``str``
+
+        :keyword ex_client_token: The token generated by client to
+                                  identify requests
+        :type ex_client_token: ``str``
+        """
+
         # 1.Create load balancer
         params = {'Action': 'CreateLoadBalancer',
                   'RegionId': self.region}
@@ -352,30 +391,39 @@ class SLBDriver(Driver):
         if protocol not in PROTOCOL_TO_LISTENER_MAP:
             raise AttributeError('unsupport protocol %s' % protocol)
 
-        extra_param_keys = [
-            'AddressType',
-            'VSwitchId',
-            'InternetChargeType',
-            'Bandwidth',
-            'ClientToken',
-            'MasterZoneId',
-            'SlaveZoneId'
-        ]
-        extra = self._get_extra_params(extra_param_keys, kwargs)
         # Bandwidth in range [1, 1000] Mbps
         bandwidth = -1
-        if 'Bandwidth' in extra and extra['Bandwidth']:
+        if ex_bandwidth:
             try:
-                bandwidth = int(extra['Bandwidth'])
+                bandwidth = int(ex_bandwidth)
             except ValueError:
-                raise AttributeError('Bandwidth should be a integer in '
+                raise AttributeError('ex_bandwidth should be a integer in '
                                      'range [1, 1000].')
+            params['Bandwidth'] = bandwidth
 
-        charge_type = extra.get('InternetChargeType', None)
-        if charge_type and charge_type.lower() == 'paybybandwidth':
-            if bandwidth == -1:
-                raise AttributeError('PayByBandwidth need Bandwidth be set')
-        params.update(extra)
+        if ex_internet_charge_type:
+            if ex_internet_charge_type.lower() == 'paybybandwidth':
+                if bandwidth == -1:
+                    raise AttributeError('PayByBandwidth internet charge type'
+                                         ' need ex_bandwidth be set')
+            params['InternetChargeType'] = ex_internet_charge_type
+
+        if ex_address_type:
+            if ex_address_type.lower() not in ('internet', 'intranet'):
+                raise AttributeError('ex_address_type should be "internet" '
+                                     'or "intranet"')
+            params['AddressType'] = ex_address_type
+
+        if ex_vswitch_id:
+            params['VSwitchId'] = ex_vswitch_id
+
+        if ex_master_zone_id:
+            params['MasterZoneId'] = ex_master_zone_id
+        if ex_slave_zone_id:
+            params['SlaveZoneId'] = ex_slave_zone_id
+
+        if ex_client_token:
+            params['ClientToken'] = ex_client_token
 
         if members and isinstance(members, list):
             backend_ports = [member.port for member in members]
@@ -461,11 +509,14 @@ class SLBDriver(Driver):
     def ex_get_balancer_attribute(self, balancer):
         """
         Get balancer attribute
+
         :param balancer: the balancer to get attribute
         :type balancer: ``LoadBalancer``
+
         :return: the balancer attribute
         :rtype: ``SLBLoadBalancerAttribute``
         """
+
         params = {'Action': 'DescribeLoadBalancerAttribute',
                   'LoadBalancerId': balancer.id}
         resp_body = self.connection.request(self.path, params).object
@@ -475,11 +526,14 @@ class SLBDriver(Driver):
     def ex_list_listeners(self, balancer):
         """
         Get all listener related to the given balancer
+
         :param balancer: the balancer to list listeners
         :type balancer: ``LoadBalancer``
+
         :return: a list of listeners
         :rtype: ``list`` of ``SLBLoadBalancerListener``
         """
+
         attribute = self.ex_get_balancer_attribute(balancer)
         listeners = [SLBLoadBalancerListener(each['ListenerPort'], None,
                                              None, None)
@@ -490,22 +544,29 @@ class SLBDriver(Driver):
                            bandwidth, **kwargs):
         """
         Create load balancer listening rule.
+
         :param balancer: the balancer which the rule belongs to.
                          The listener created will listen on the port of the
                          the balancer as default. 'ListenerPort' in kwargs
                          will *OVERRIDE* it.
         :type balancer: ``LoadBalancer``
+
         :param backend_port: the backend server port
         :type backend_port: ``int``
+
         :param protocol: the balancer protocol, default to http
         :type protocol: ``str``
+
         :param algorithm: the balancer routing algorithm
         :type algorithm: ``Algorithm``
+
         :param bandwidth: the listener bandwidth limits
         :type bandwidth: ``str``
+
         :return: the created listener
         :rtype: ``SLBLoadBalancerListener``
         """
+
         cls = PROTOCOL_TO_LISTENER_MAP.get(protocol,
                                            SLBLoadBalancerHttpListener)
         if 'ListenerPort' in kwargs:
@@ -523,13 +584,17 @@ class SLBDriver(Driver):
     def ex_start_listener(self, balancer, port):
         """
         Start balancer's listener listening the given port.
+
         :param balancer: a load balancer
         :type balancer: ``LoadBalancer``
+
         :param port: listening port
         :type port: ``int``
+
         :return: whether operation is success
         :rtype: ``bool``
         """
+
         params = {'Action': 'StartLoadBalancerListener',
                   'LoadBalancerId': balancer.id,
                   'ListenerPort': port}
@@ -539,13 +604,17 @@ class SLBDriver(Driver):
     def ex_stop_listener(self, balancer, port):
         """
         Stop balancer's listener listening the given port.
+
         :param balancer: a load balancer
         :type balancer: ``LoadBalancer``
+
         :param port: listening port
         :type port: ``int``
+
         :return: whether operation is success
         :rtype: ``bool``
         """
+
         params = {'Action': 'StopLoadBalancerListener',
                   'LoadBalancerId': balancer.id,
                   'ListenerPort': port}
@@ -556,17 +625,22 @@ class SLBDriver(Driver):
                               private_key):
         """
         Upload certificate and private key for https load balancer listener
+
         :param name: the certificate name
         :type name: ``str``
+
         :param server_certificate: the content of the certificate to upload
                                    in PEM format
         :type server_certificate: ``str``
+
         :param private_key: the content of the private key to upload
                             in PEM format
         :type private_key: ``str``
+
         :return: new created certificate info
         :rtype: ``SLBServerCertificate``
         """
+
         params = {'Action': 'UploadServerCertificate',
                   'RegionId': self.region,
                   'ServerCertificate': server_certificate,
@@ -579,11 +653,14 @@ class SLBDriver(Driver):
     def ex_list_certificates(self, certificate_ids=[]):
         """
         List all server certificates
+
         :param certificate_ids: certificate ids to filter results
         :type certificate_ids: ``str``
+
         :return: certificates
         :rtype: ``SLBServerCertificate``
         """
+
         params = {'Action': 'DescribeServerCertificates',
                   'RegionId': self.region}
         if certificate_ids and isinstance(certificate_ids, list):
@@ -600,11 +677,14 @@ class SLBDriver(Driver):
     def ex_delete_certificate(self, certificate_id):
         """
         Delete the given server certificate
+
         :param certificate_id: the id of the certificate to delete
         :type certificate_id: ``str``
+
         :return: whether process is success
         :rtype: ``bool``
         """
+
         params = {'Action': 'DeleteServerCertificate',
                   'RegionId': self.region,
                   'ServerCertificateId': certificate_id}
@@ -614,13 +694,17 @@ class SLBDriver(Driver):
     def ex_set_certificate_name(self, certificate_id, name):
         """
         Set server certificate name.
+
         :param certificate_id: the id of the server certificate to update
         :type certificate_id: ``str``
+
         :param name: the new name
         :type name: ``str``
+
         :return: whether updating is success
         :rtype: ``bool``
         """
+
         params = {'Action': 'SetServerCertificateName',
                   'RegionId': self.region,
                   'ServerCertificateId': certificate_id,
@@ -740,13 +824,6 @@ class SLBDriver(Driver):
         return SLBServerCertificate(id=_id, name=name,
                                     fingerprint=fingerprint)
 
-    def _get_extra_params(self, extra_param_keys, kwargs):
-        params = {}
-        for key in extra_param_keys:
-            if key in kwargs:
-                params[key] = kwargs[key]
-        return params
-
     def _list_to_json(self, value):
         try:
             return json.dumps(value)

http://git-wip-us.apache.org/repos/asf/libcloud/blob/ae4c482b/libcloud/loadbalancer/providers.py
----------------------------------------------------------------------
diff --git a/libcloud/loadbalancer/providers.py b/libcloud/loadbalancer/providers.py
index b619c9d..f60e6d3 100644
--- a/libcloud/loadbalancer/providers.py
+++ b/libcloud/loadbalancer/providers.py
@@ -42,7 +42,7 @@ DRIVERS = {
     ('libcloud.loadbalancer.drivers.softlayer', 'SoftlayerLBDriver'),
     Provider.DIMENSIONDATA:
     ('libcloud.loadbalancer.drivers.dimensiondata', 'DimensionDataLBDriver'),
-    Provider.SLB:
+    Provider.ALIYUN_SLB:
     ('libcloud.loadbalancer.drivers.slb', 'SLBDriver'),
 
     # Deprecated

http://git-wip-us.apache.org/repos/asf/libcloud/blob/ae4c482b/libcloud/loadbalancer/types.py
----------------------------------------------------------------------
diff --git a/libcloud/loadbalancer/types.py b/libcloud/loadbalancer/types.py
index 0d5deec..45d6c6a 100644
--- a/libcloud/loadbalancer/types.py
+++ b/libcloud/loadbalancer/types.py
@@ -33,7 +33,7 @@ class LibcloudLBImmutableError(LibcloudLBError):
 
 class Provider(object):
     """
-    :cvar SLB: Aliyun SLB loadbalancer driver
+    :cvar ALIYUN_SLB: Aliyun SLB loadbalancer driver
     """
     RACKSPACE = 'rackspace'
     GOGRID = 'gogrid'
@@ -44,7 +44,7 @@ class Provider(object):
     GCE = 'gce'
     SOFTLAYER = 'softlayer'
     DIMENSIONDATA = 'dimensiondata'
-    SLB = 'slb'
+    ALIYUN_SLB = 'slb'
 
     # Deprecated
     RACKSPACE_US = 'rackspace_us'

http://git-wip-us.apache.org/repos/asf/libcloud/blob/ae4c482b/libcloud/storage/providers.py
----------------------------------------------------------------------
diff --git a/libcloud/storage/providers.py b/libcloud/storage/providers.py
index 0bf1e41..1cb31e4 100644
--- a/libcloud/storage/providers.py
+++ b/libcloud/storage/providers.py
@@ -58,7 +58,7 @@ DRIVERS = {
     ('libcloud.storage.drivers.auroraobjects', 'AuroraObjectsStorageDriver'),
     Provider.BACKBLAZE_B2:
     ('libcloud.storage.drivers.backblaze_b2', 'BackblazeB2StorageDriver'),
-    Provider.OSS:
+    Provider.ALIYUN_OSS:
     ('libcloud.storage.drivers.oss', 'OSSStorageDriver'),
 
     # Deprecated

http://git-wip-us.apache.org/repos/asf/libcloud/blob/ae4c482b/libcloud/storage/types.py
----------------------------------------------------------------------
diff --git a/libcloud/storage/types.py b/libcloud/storage/types.py
index 9c536e3..247e59f 100644
--- a/libcloud/storage/types.py
+++ b/libcloud/storage/types.py
@@ -43,7 +43,7 @@ class Provider(object):
     :cvar NIMBUS: Nimbus.io driver
     :cvar LOCAL: Local storage driver
     :cvar AURORAOBJECTS: AuroraObjects storage driver
-    :cvar OSS: Aliyun OSS storage driver
+    :cvar ALIYUN_OSS: Aliyun OSS storage driver
     """
     DUMMY = 'dummy'
     S3 = 's3'
@@ -65,7 +65,7 @@ class Provider(object):
     KTUCLOUD = 'ktucloud'
     AURORAOBJECTS = 'auroraobjects'
     BACKBLAZE_B2 = 'backblaze_b2'
-    OSS = 'oss'
+    ALIYUN_OSS = 'oss'
 
     # Deperecated
     CLOUDFILES_US = 'cloudfiles_us'

http://git-wip-us.apache.org/repos/asf/libcloud/blob/ae4c482b/libcloud/test/compute/test_ecs.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_ecs.py b/libcloud/test/compute/test_ecs.py
index 96e482e..495f7b2 100644
--- a/libcloud/test/compute/test_ecs.py
+++ b/libcloud/test/compute/test_ecs.py
@@ -160,7 +160,7 @@ class ECSDriverTestCase(LibcloudTestCase):
         node = self.driver.create_node(name=self.name, image=self.fake_image,
                                        size=self.fake_size,
                                        ex_security_group_id='sg-28ou0f3xa',
-                                       ex_data_disk=self.data_disk)
+                                       ex_data_disks=self.data_disk)
         self.assertIsNotNone(node)
 
     def test_list_sizes(self):

http://git-wip-us.apache.org/repos/asf/libcloud/blob/ae4c482b/libcloud/test/loadbalancer/test_slb.py
----------------------------------------------------------------------
diff --git a/libcloud/test/loadbalancer/test_slb.py b/libcloud/test/loadbalancer/test_slb.py
index 926aed0..0325cb2 100644
--- a/libcloud/test/loadbalancer/test_slb.py
+++ b/libcloud/test/loadbalancer/test_slb.py
@@ -114,11 +114,11 @@ class SLBDriverTestCases(unittest.TestCase):
         self.protocol = 'http'
         self.algorithm = Algorithm.WEIGHTED_ROUND_ROBIN
         self.extra = {
-            'AddressType': 'internet',
-            'InternetChargeType': 'paybytraffic',
-            'Bandwidth': 1,
-            'MasterZoneId': 'cn-hangzhou-d',
-            'SlaveZoneId': 'cn-hangzhou-b',
+            'ex_address_type': 'internet',
+            'ex_internet_charge_type': 'paybytraffic',
+            'ex_bandwidth': 1,
+            'ex_master_zone_id': 'cn-hangzhou-d',
+            'ex_slave_zone_id': 'cn-hangzhou-b',
             'StickySession': 'on',
             'HealthCheck': 'on'}
         self.members = [Member('node1', None, None)]
@@ -153,12 +153,12 @@ class SLBDriverTestCases(unittest.TestCase):
     def test_create_balancer_bandwidth_value_error(self):
         self.assertRaises(AttributeError, self.driver.create_balancer,
                           None, 80, 'http', Algorithm.WEIGHTED_ROUND_ROBIN,
-                          None, Bandwidth='NAN')
+                          None, ex_bandwidth='NAN')
 
     def test_create_balancer_paybybandwidth_without_bandwidth_exception(self):
         self.assertRaises(AttributeError, self.driver.create_balancer,
                           None, 80, 'http', Algorithm.WEIGHTED_ROUND_ROBIN,
-                          None, InternetChargeType='paybybandwidth')
+                          None, ex_internet_charge_type='paybybandwidth')
 
     def test_balancer_list_members(self):
         balancer = self.driver.get_balancer(balancer_id='tests')
@@ -312,15 +312,15 @@ class SLBMockHttp(MockHttpTestCase):
     def _CreateLoadBalancer(self, method, url, body, headers):
         params = {'RegionId': self.test.region,
                   'LoadBalancerName': self.test.name}
-        balancer_keys = [
-            'AddressType',
-            'InternetChargeType',
-            'Bandwidth',
-            'MasterZoneId',
-            'SlaveZoneId'
-        ]
+        balancer_keys = {
+            'AddressType': 'ex_address_type',
+            'InternetChargeType': 'ex_internet_charge_type',
+            'Bandwidth': 'ex_bandwidth',
+            'MasterZoneId': 'ex_master_zone_id',
+            'SlaveZoneId': 'ex_slave_zone_id'
+        }
         for key in balancer_keys:
-            params[key] = str(self.test.extra[key])
+            params[key] = str(self.test.extra[balancer_keys[key]])
 
         self.assertUrlContainsQueryParams(url, params)
         body = self.fixtures.load('create_load_balancer.xml')


Mime
View raw message