libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject [08/10] libcloud git commit: Update with some style and consistency changes
Date Thu, 08 Oct 2015 12:19:26 GMT
Update with some style and consistency changes

Closes #593


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/0fa19efe
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/0fa19efe
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/0fa19efe

Branch: refs/heads/trunk
Commit: 0fa19efe03a161d08c5d2d6b6225bdb43325aa9b
Parents: 1e6b54a
Author: Anthony Shaw <anthony.p.shaw@gmail.com>
Authored: Thu Oct 8 09:06:16 2015 +1100
Committer: Tomaz Muraus <tomaz@apache.org>
Committed: Thu Oct 8 14:12:26 2015 +0200

----------------------------------------------------------------------
 libcloud/common/dimensiondata.py               | 38 ++++++++++--
 libcloud/compute/drivers/dimensiondata.py      | 64 ++++++++++-----------
 libcloud/loadbalancer/drivers/dimensiondata.py | 59 ++++++++++++++-----
 libcloud/test/compute/test_dimensiondata.py    |  6 +-
 4 files changed, 112 insertions(+), 55 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/0fa19efe/libcloud/common/dimensiondata.py
----------------------------------------------------------------------
diff --git a/libcloud/common/dimensiondata.py b/libcloud/common/dimensiondata.py
index 424582b..d6792d9 100644
--- a/libcloud/common/dimensiondata.py
+++ b/libcloud/common/dimensiondata.py
@@ -307,19 +307,19 @@ class DimensionDataPublicIpBlock(object):
     DimensionData Public IP Block with location.
     """
 
-    def __init__(self, id, baseIp, size, location, network_domain,
+    def __init__(self, id, base_ip, size, location, network_domain,
                  status):
         self.id = str(id)
-        self.baseIp = baseIp
+        self.base_ip = base_ip
         self.size = size
         self.location = location
         self.network_domain = network_domain
         self.status = status
 
     def __repr__(self):
-        return (('<DimensionDataNetworkDomain: id=%s, baseIp=%s,'
+        return (('<DimensionDataNetworkDomain: id=%s, base_ip=%s,'
                  'size=%s, location=%s, status=%s>')
-                % (self.id, self.baseIp, self.size, self.location,
+                % (self.id, self.base_ip, self.size, self.location,
                    self.status))
 
 
@@ -329,7 +329,7 @@ class DimensionDataFirewallRule(object):
     """
 
     def __init__(self, id, name, action, location, network_domain,
-                 status, ipVersion, protocol, source, destination,
+                 status, ip_version, protocol, source, destination,
                  enabled):
         self.id = str(id)
         self.name = name
@@ -337,7 +337,7 @@ class DimensionDataFirewallRule(object):
         self.location = location
         self.network_domain = network_domain
         self.status = status
-        self.ipVersion = ipVersion
+        self.ip_version = ip_version
         self.protocol = protocol
         self.source = source
         self.destination = destination
@@ -386,6 +386,32 @@ class DimensionDataVlan(object):
 
     def __init__(self, id, name, description, location, status,
                  private_ipv4_range_address, private_ipv4_range_size):
+        """
+        Initialize an instance of ``DimensionDataVlan``
+
+        :param id: The ID of the VLAN
+        :type  id: ``string``
+
+        :param name: The name of the VLAN
+        :type  name: ``string``
+
+        :param description: Plan text description of the VLAN
+        :type  description: ``string``
+
+        :param location: The location (data center) of the VLAN
+        :type  location: ``NodeLocation``
+
+        :param status: The status of the VLAN
+        :type  status: ``DimensionDataStatus``
+
+        :param private_ipv4_range_address: The host address of the VLAN
+                                            IP space
+        :type  private_ipv4_range_address: ``string``
+
+        :param private_ipv4_range_address: The size (e.g. '24') of the VLAN
+                                            as a CIDR range size
+        :type  private_ipv4_range_address: ``string``
+        """
         self.id = str(id)
         self.name = name
         self.location = location

http://git-wip-us.apache.org/repos/asf/libcloud/blob/0fa19efe/libcloud/compute/drivers/dimensiondata.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/dimensiondata.py b/libcloud/compute/drivers/dimensiondata.py
index 4d911d2..95087af 100644
--- a/libcloud/compute/drivers/dimensiondata.py
+++ b/libcloud/compute/drivers/dimensiondata.py
@@ -171,8 +171,8 @@ class DimensionDataNodeDriver(NodeDriver):
             'server/deleteServer',
             method='POST',
             data=ET.tostring(request_elm)).object
-        responseCode = findtext(body, 'responseCode', TYPES_URN)
-        return responseCode == 'IN_PROGRESS' or responseCode == 'OK'
+        response_code = findtext(body, 'response_code', TYPES_URN)
+        return response_code in ['IN_PROGRESS', 'OK']
 
     def reboot_node(self, node):
         request_elm = ET.Element('rebootServer',
@@ -181,8 +181,8 @@ class DimensionDataNodeDriver(NodeDriver):
             'server/rebootServer',
             method='POST',
             data=ET.tostring(request_elm)).object
-        responseCode = findtext(body, 'responseCode', TYPES_URN)
-        return responseCode == 'IN_PROGRESS' or responseCode == 'OK'
+        response_code = findtext(body, 'response_code', TYPES_URN)
+        return response_code in ['IN_PROGRESS', 'OK']
 
     def list_nodes(self):
         nodes = self._to_nodes(
@@ -310,8 +310,8 @@ class DimensionDataNodeDriver(NodeDriver):
             'server/startServer',
             method='POST',
             data=ET.tostring(request_elm)).object
-        responseCode = findtext(body, 'responseCode', TYPES_URN)
-        return responseCode == 'IN_PROGRESS' or responseCode == 'OK'
+        response_code = findtext(body, 'response_code', TYPES_URN)
+        return response_code in ['IN_PROGRESS', 'OK']
 
     def ex_shutdown_graceful(self, node):
         """
@@ -331,8 +331,8 @@ class DimensionDataNodeDriver(NodeDriver):
             'server/shutdownServer',
             method='POST',
             data=ET.tostring(request_elm)).object
-        responseCode = findtext(body, 'responseCode', TYPES_URN)
-        return responseCode == 'IN_PROGRESS' or responseCode == 'OK'
+        response_code = findtext(body, 'response_code', TYPES_URN)
+        return response_code in ['IN_PROGRESS', 'OK']
 
     def ex_power_off(self, node):
         """
@@ -352,8 +352,8 @@ class DimensionDataNodeDriver(NodeDriver):
             'server/powerOffServer',
             method='POST',
             data=ET.tostring(request_elm)).object
-        responseCode = findtext(body, 'responseCode', TYPES_URN)
-        return responseCode == 'IN_PROGRESS' or responseCode == 'OK'
+        response_code = findtext(body, 'response_code', TYPES_URN)
+        return response_code in ['IN_PROGRESS', 'OK']
 
     def ex_reset(self, node):
         """
@@ -373,8 +373,8 @@ class DimensionDataNodeDriver(NodeDriver):
             'server/resetServer',
             method='POST',
             data=ET.tostring(request_elm)).object
-        responseCode = findtext(body, 'responseCode', TYPES_URN)
-        return responseCode == 'IN_PROGRESS' or responseCode == 'OK'
+        response_code = findtext(body, 'response_code', TYPES_URN)
+        return response_code in ['IN_PROGRESS', 'OK']
 
     def ex_attach_node_to_vlan(self, node, vlan):
         request = ET.Element('addNic',
@@ -387,8 +387,8 @@ class DimensionDataNodeDriver(NodeDriver):
             'server/addNic',
             method='POST',
             data=ET.tostring(request)).object
-        responseCode = findtext(response, 'responseCode', TYPES_URN)
-        return responseCode == 'IN_PROGRESS' or responseCode == 'OK'
+        response_code = findtext(response, 'response_code', TYPES_URN)
+        return response_code in ['IN_PROGRESS', 'OK']
 
     def ex_destroy_nic(self, nic_id):
         request = ET.Element('removeNic',
@@ -399,8 +399,8 @@ class DimensionDataNodeDriver(NodeDriver):
             'server/removeNic',
             method='POST',
             data=ET.tostring(request)).object
-        responseCode = findtext(response, 'responseCode', TYPES_URN)
-        return responseCode == 'IN_PROGRESS' or responseCode == 'OK'
+        response_code = findtext(response, 'response_code', TYPES_URN)
+        return response_code in ['IN_PROGRESS', 'OK']
 
     def ex_list_networks(self, location=None):
         """
@@ -462,7 +462,7 @@ class DimensionDataNodeDriver(NodeDriver):
         network_domain_id = None
 
         for info in findall(response, 'info', TYPES_URN):
-            if info.get('name') == 'networkDomainId"':
+            if info.get('name') == 'networkDomainId':
                 network_domain_id = info.get('value')
 
         return DimensionDataNetworkDomain(
@@ -501,8 +501,8 @@ class DimensionDataNodeDriver(NodeDriver):
             method='POST',
             data=ET.tostring(delete_node)).object
 
-        responseCode = findtext(result, 'responseCode', TYPES_URN)
-        return responseCode == 'IN_PROGRESS' or responseCode == 'OK'
+        response_code = findtext(result, 'response_code', TYPES_URN)
+        return response_code in ['IN_PROGRESS', 'OK']
 
     def ex_create_vlan(self,
                        network_domain,
@@ -596,8 +596,8 @@ class DimensionDataNodeDriver(NodeDriver):
             method='POST',
             data=ET.tostring(delete_node)).object
 
-        responseCode = findtext(result, 'responseCode', TYPES_URN)
-        return responseCode == 'IN_PROGRESS' or responseCode == 'OK'
+        response_code = findtext(result, 'response_code', TYPES_URN)
+        return response_code in ['IN_PROGRESS', 'OK']
 
     def ex_list_vlans(self, location=None, network_domain=None):
         """
@@ -656,8 +656,8 @@ class DimensionDataNodeDriver(NodeDriver):
             method='POST',
             data=ET.tostring(delete_node)).object
 
-        responseCode = findtext(result, 'responseCode', TYPES_URN)
-        return responseCode == 'IN_PROGRESS' or responseCode == 'OK'
+        response_code = findtext(result, 'response_code', TYPES_URN)
+        return response_code in ['IN_PROGRESS', 'OK']
 
     def ex_get_node_by_id(self, id):
         node = self.connection.request_with_orgId_api_2(
@@ -678,7 +678,7 @@ class DimensionDataNodeDriver(NodeDriver):
         ET.SubElement(create_node, "networkDomainId").text = network_domain.id
         ET.SubElement(create_node, "name").text = rule.name
         ET.SubElement(create_node, "action").text = rule.action
-        ET.SubElement(create_node, "ipVersion").text = rule.ipVersion
+        ET.SubElement(create_node, "ipVersion").text = rule.ip_version
         ET.SubElement(create_node, "protocol").text = rule.protocol
         # Setup source port rule
         source = ET.SubElement(create_node, "source")
@@ -738,8 +738,8 @@ class DimensionDataNodeDriver(NodeDriver):
             method='POST',
             data=ET.tostring(update_node)).object
 
-        responseCode = findtext(result, 'responseCode', TYPES_URN)
-        return responseCode == 'IN_PROGRESS' or responseCode == 'OK'
+        response_code = findtext(result, 'response_code', TYPES_URN)
+        return response_code in ['IN_PROGRESS', 'OK']
 
     def ex_delete_firewall_rule(self, rule):
         update_node = ET.Element('deleteFirewallrule', {'xmlns': TYPES_URN})
@@ -749,8 +749,8 @@ class DimensionDataNodeDriver(NodeDriver):
             method='POST',
             data=ET.tostring(update_node)).object
 
-        responseCode = findtext(result, 'responseCode', TYPES_URN)
-        return responseCode == 'IN_PROGRESS' or responseCode == 'OK'
+        response_code = findtext(result, 'response_code', TYPES_URN)
+        return response_code in ['IN_PROGRESS', 'OK']
 
     def ex_create_nat_rule(self, network_domain, internal_ip, external_ip):
         create_node = ET.Element('createNatRule', {'xmlns': TYPES_URN})
@@ -797,8 +797,8 @@ class DimensionDataNodeDriver(NodeDriver):
             method='POST',
             data=ET.tostring(update_node)).object
 
-        responseCode = findtext(result, 'responseCode', TYPES_URN)
-        return responseCode == 'IN_PROGRESS' or responseCode == 'OK'
+        response_code = findtext(result, 'response_code', TYPES_URN)
+        return response_code in ['IN_PROGRESS', 'OK']
 
     def ex_get_location_by_id(self, id):
         """
@@ -854,7 +854,7 @@ class DimensionDataNodeDriver(NodeDriver):
             network_domain=network_domain,
             name=findtext(element, 'name', TYPES_URN),
             action=findtext(element, 'action', TYPES_URN),
-            ipVersion=findtext(element, 'ipVersion', TYPES_URN),
+            ip_version=findtext(element, 'ipVersion', TYPES_URN),
             protocol=findtext(element, 'protocol', TYPES_URN),
             enabled=findtext(element, 'enabled', TYPES_URN),
             source=self._to_firewall_address(
@@ -895,7 +895,7 @@ class DimensionDataNodeDriver(NodeDriver):
             network_domain=self.ex_get_network_domain(
                 findtext(element, 'networkDomainId', TYPES_URN)
             ),
-            baseIp=findtext(element, 'baseIp', TYPES_URN),
+            base_ip=findtext(element, 'baseIp', TYPES_URN),
             size=findtext(element, 'size', TYPES_URN),
             location=location,
             status=status)

http://git-wip-us.apache.org/repos/asf/libcloud/blob/0fa19efe/libcloud/loadbalancer/drivers/dimensiondata.py
----------------------------------------------------------------------
diff --git a/libcloud/loadbalancer/drivers/dimensiondata.py b/libcloud/loadbalancer/drivers/dimensiondata.py
index 3325d4b..41fe29d 100644
--- a/libcloud/loadbalancer/drivers/dimensiondata.py
+++ b/libcloud/loadbalancer/drivers/dimensiondata.py
@@ -274,8 +274,8 @@ class DimensionDataLBDriver(Driver):
             'networkDomainVip/removePoolMember',
             method='POST',
             data=ET.tostring(create_pool_m)).object
-        responseCode = findtext(result, 'responseCode', TYPES_URN)
-        return responseCode == 'OK' or responseCode == 'IN_PROGRESS'
+        response_code = findtext(result, 'response_code', TYPES_URN)
+        return response_code in ['IN_PROGRESS', 'OK']
 
     def destroy_balancer(self, balancer):
         """
@@ -295,8 +295,8 @@ class DimensionDataLBDriver(Driver):
             'networkDomainVip/deleteVirtualListener',
             method='POST',
             data=ET.tostring(delete_listener)).object
-        responseCode = findtext(result, 'responseCode', TYPES_URN)
-        return responseCode == 'OK' or responseCode == 'IN_PROGRESS'
+        response_code = findtext(result, 'response_code', TYPES_URN)
+        return response_code in ['IN_PROGRESS', 'OK']
 
     def ex_set_current_network_domain(self, network_domain_id):
         """
@@ -424,6 +424,15 @@ class DimensionDataLBDriver(Driver):
         )
 
     def ex_update_node(self, node):
+        """
+        Update the properties of a node
+
+        :param pool: The instance of ``DimensionDataNode`` to update
+        :type  pool: ``DimensionDataNode``
+
+        :return: The instance of ``DimensionDataNode``
+        :rtype: ``DimensionDataNode``
+        """
         create_node_elm = ET.Element('editNode', {'xmlns': TYPES_URN})
         ET.SubElement(create_node_elm, "connectionLimit") \
             .text = str(node.connection_limit)
@@ -437,6 +446,18 @@ class DimensionDataLBDriver(Driver):
         return node
 
     def ex_set_node_state(self, node, enabled):
+        """
+        Change the state of a node (enable/disable)
+
+        :param pool: The instance of ``DimensionDataNode`` to update
+        :type  pool: ``DimensionDataNode``
+
+        :param enabled: The target state of the node
+        :type  enabled: ``bool``
+
+        :return: The instance of ``DimensionDataNode``
+        :rtype: ``DimensionDataNode``
+        """
         create_node_elm = ET.Element('editNode', {'xmlns': TYPES_URN})
         ET.SubElement(create_node_elm, "status") \
             .text = "ENABLED" if enabled is True else "DISABLED"
@@ -636,6 +657,16 @@ class DimensionDataLBDriver(Driver):
         return self._to_pool(pool)
 
     def ex_update_pool(self, pool):
+        """
+        Update the properties of an existing pool
+        only method, serviceDownAction and slowRampTime are updated
+
+        :param pool: The instance of ``DimensionDataPool`` to update
+        :type  pool: ``DimensionDataPool``
+
+        :return: ``True`` for success, ``False`` for failure
+        :rtype: ``bool``
+        """
         create_node_elm = ET.Element('editPool', {'xmlns': TYPES_URN})
 
         ET.SubElement(create_node_elm, "loadBalanceMethod") \
@@ -649,8 +680,8 @@ class DimensionDataLBDriver(Driver):
             action='networkDomainVip/editPool',
             method='POST',
             data=ET.tostring(create_node_elm)).object
-        responseCode = findtext(response, 'responseCode', TYPES_URN)
-        return responseCode == 'OK' or responseCode == 'IN_PROGRESS'
+        response_code = findtext(response, 'response_code', TYPES_URN)
+        return response_code in ['IN_PROGRESS', 'OK']
 
     def ex_destroy_pool(self, pool):
         """
@@ -670,8 +701,8 @@ class DimensionDataLBDriver(Driver):
             action='networkDomainVip/deletePool',
             method='POST',
             data=ET.tostring(destroy_request)).object
-        responseCode = findtext(result, 'responseCode', TYPES_URN)
-        return responseCode == 'OK' or responseCode == 'IN_PROGRESS'
+        response_code = findtext(result, 'response_code', TYPES_URN)
+        return response_code in ['IN_PROGRESS', 'OK']
 
     def ex_get_pool_members(self, pool_id):
         """
@@ -715,8 +746,8 @@ class DimensionDataLBDriver(Driver):
             method='POST',
             data=ET.tostring(request)).object
 
-        responseCode = findtext(result, 'responseCode', TYPES_URN)
-        return responseCode == 'OK' or responseCode == 'IN_PROGRESS'
+        response_code = findtext(result, 'response_code', TYPES_URN)
+        return response_code in ['IN_PROGRESS', 'OK']
 
     def ex_destroy_pool_member(self, member, destroy_node=False):
         """
@@ -744,8 +775,8 @@ class DimensionDataLBDriver(Driver):
         if member.node_id is not None and destroy_node is True:
             return self.ex_destroy_node(member.node_id)
         else:
-            responseCode = findtext(result, 'responseCode', TYPES_URN)
-            return responseCode == 'OK'
+            response_code = findtext(result, 'response_code', TYPES_URN)
+            return response_code in ['IN_PROGRESS', 'OK']
 
     def ex_get_nodes(self):
         """
@@ -789,8 +820,8 @@ class DimensionDataLBDriver(Driver):
             action='networkDomainVip/deleteNode',
             method='POST',
             data=ET.tostring(destroy_request)).object
-        responseCode = findtext(result, 'responseCode', TYPES_URN)
-        return responseCode == 'OK' or responseCode == 'IN_PROGRESS'
+        response_code = findtext(result, 'response_code', TYPES_URN)
+        return response_code in ['IN_PROGRESS', 'OK']
 
     def _to_nodes(self, object):
         nodes = []

http://git-wip-us.apache.org/repos/asf/libcloud/blob/0fa19efe/libcloud/test/compute/test_dimensiondata.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_dimensiondata.py b/libcloud/test/compute/test_dimensiondata.py
index 4013943..af436de 100644
--- a/libcloud/test/compute/test_dimensiondata.py
+++ b/libcloud/test/compute/test_dimensiondata.py
@@ -293,7 +293,7 @@ class DimensionDataTests(unittest.TestCase, TestCaseMixin):
     def test_ex_list_public_ip_blocks(self):
         net = self.driver.ex_get_network_domain('8cdfd607-f429-4df6-9352-162cfc0891be')
         blocks = self.driver.ex_list_public_ip_blocks(net)
-        self.assertEqual(blocks[0].baseIp, '168.128.4.18')
+        self.assertEqual(blocks[0].base_ip, '168.128.4.18')
         self.assertEqual(blocks[0].size, '2')
         self.assertEqual(blocks[0].id, '9945dc4a-bdce-11e4-8c14-b8ca3a5d9ef8')
         self.assertEqual(blocks[0].location.id, 'NA9')
@@ -302,7 +302,7 @@ class DimensionDataTests(unittest.TestCase, TestCaseMixin):
     def test_ex_get_public_ip_block(self):
         net = self.driver.ex_get_network_domain('8cdfd607-f429-4df6-9352-162cfc0891be')
         block = self.driver.ex_get_public_ip_block('9945dc4a-bdce-11e4-8c14-b8ca3a5d9ef8')
-        self.assertEqual(block.baseIp, '168.128.4.18')
+        self.assertEqual(block.base_ip, '168.128.4.18')
         self.assertEqual(block.size, '2')
         self.assertEqual(block.id, '9945dc4a-bdce-11e4-8c14-b8ca3a5d9ef8')
         self.assertEqual(block.location.id, 'NA9')
@@ -320,7 +320,7 @@ class DimensionDataTests(unittest.TestCase, TestCaseMixin):
         self.assertEqual(rules[0].network_domain.id, '8cdfd607-f429-4df6-9352-162cfc0891be')
         self.assertEqual(rules[0].name, 'CCDEFAULT.BlockOutboundMailIPv4')
         self.assertEqual(rules[0].action, 'DROP')
-        self.assertEqual(rules[0].ipVersion, 'IPV4')
+        self.assertEqual(rules[0].ip_version, 'IPV4')
         self.assertEqual(rules[0].protocol, 'TCP')
         self.assertEqual(rules[0].source.ip_address, 'ANY')
         self.assertTrue(rules[0].source.any_ip)


Mime
View raw message