Fix lint, clarify licensing.

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

Branch: refs/heads/trunk
Commit: ab701a1054ab778129a1cfa36a4a2707ad33de74
Parents: 0161098
Author: Tomaz Muraus <[email protected]>
Authored: Sat Apr 4 23:59:25 2015 +0200
Committer: Tomaz Muraus <[email protected]>
Committed: Sun Apr 5 00:22:45 2015 +0200

----------------------------------------------------------------------
 libcloud/common/azure.py            |   9 ++-
 libcloud/common/base.py             |  11 +--
 libcloud/compute/drivers/azure.py   | 114 ++++++++++++++++---------------
 libcloud/test/compute/test_azure.py |  10 ++-
 4 files changed, 76 insertions(+), 68 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/ab701a10/libcloud/common/azure.py
----------------------------------------------------------------------
diff --git a/libcloud/common/azure.py b/libcloud/common/azure.py
index 727046e..bd3c504 100644
--- a/libcloud/common/azure.py
+++ b/libcloud/common/azure.py
@@ -31,7 +31,8 @@ except ImportError:
 
 from libcloud.common.types import InvalidCredsError
 from libcloud.common.types import LibcloudError, MalformedResponseError
-from libcloud.common.base import ConnectionUserAndKey, RawResponse, 
CertificateConnection
+from libcloud.common.base import ConnectionUserAndKey, RawResponse
+from libcloud.common.base import CertificateConnection
 from libcloud.common.base import XmlResponse
 
 # Azure API version
@@ -91,7 +92,9 @@ class AzureResponse(XmlResponse):
         )
 
     def parse_body(self):
-        if int(self.status) == httplib.TEMPORARY_REDIRECT and 
self.connection.driver.follow_redirects:
+        is_redirect = int(self.status) == httplib.TEMPORARY_REDIRECT
+
+        if is_redirect and self.connection.driver.follow_redirects:
             raise AzureRedirectException(self)
         else:
             return super(AzureResponse, self).parse_body()
@@ -287,5 +290,5 @@ class 
AzureServiceManagementConnection(CertificateConnection):
         """
         headers['x-ms-version'] = "2014-05-01"
         headers['x-ms-date'] = time.strftime(AZURE_TIME_FORMAT, time.gmtime())
-        #headers['host'] = self.host
+        #  headers['host'] = self.host
         return headers

http://git-wip-us.apache.org/repos/asf/libcloud/blob/ab701a10/libcloud/common/base.py
----------------------------------------------------------------------
diff --git a/libcloud/common/base.py b/libcloud/common/base.py
index 9bbb1a6..b5c9ec6 100644
--- a/libcloud/common/base.py
+++ b/libcloud/common/base.py
@@ -571,13 +571,13 @@ class Connection(object):
         if not hasattr(kwargs, 'port'):
             kwargs.update({'port': port})
 
-        if not hasattr(kwargs, 'key_file') and hasattr(self, 'key_file' ):
+        if not hasattr(kwargs, 'key_file') and hasattr(self, 'key_file'):
             kwargs.update({'key_file': self.key_file})
 
-        if not hasattr(kwargs, 'cert_file') and hasattr(self, 'cert_file' ):
+        if not hasattr(kwargs, 'cert_file') and hasattr(self, 'cert_file'):
             kwargs.update({'cert_file': self.cert_file})
 
-        #kwargs = {'host': host, 'port': int(port)}
+        #  kwargs = {'host': host, 'port': int(port)}
 
         # Timeout is only supported in Python 2.6 and later
         # http://docs.python.org/library/httplib.html#httplib.HTTPConnection
@@ -948,6 +948,7 @@ class ConnectionKey(Connection):
                                             proxy_url=proxy_url)
         self.key = key
 
+
 class CertificateConnection(Connection):
     """
     Base connection class which accepts a single ``cert_file`` argument.
@@ -959,10 +960,12 @@ class CertificateConnection(Connection):
         passed value.
         """
         super(CertificateConnection, self).__init__(secure=secure, host=host,
-                                            port=port, url=url, 
timeout=timeout)
+                                                    port=port, url=url,
+                                                    timeout=timeout)
 
         self.cert_file = cert_file
 
+
 class ConnectionUserAndKey(ConnectionKey):
     """
     Base connection class which accepts a ``user_id`` and ``key`` argument.

http://git-wip-us.apache.org/repos/asf/libcloud/blob/ab701a10/libcloud/compute/drivers/azure.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/azure.py 
b/libcloud/compute/drivers/azure.py
index 2b48c4f..06300ab 100644
--- a/libcloud/compute/drivers/azure.py
+++ b/libcloud/compute/drivers/azure.py
@@ -16,7 +16,6 @@
 
 """
 import httplib
-import itertools
 import re
 import time
 import collections
@@ -26,13 +25,11 @@ import copy
 import base64
 
 from libcloud.utils.py3 import urlquote as url_quote
-from libcloud.utils.py3 import urlunquote as url_unquote
 from libcloud.common.azure import (AzureServiceManagementConnection,
                                    AzureRedirectException)
 from libcloud.compute.providers import Provider
 from libcloud.compute.base import Node, NodeDriver, NodeLocation, NodeSize
 from libcloud.compute.base import NodeImage, StorageVolume
-from libcloud.compute.base import KeyPair
 from libcloud.compute.types import NodeState
 from libcloud.common.types import LibcloudError
 from datetime import datetime
@@ -148,7 +145,7 @@ AZURE_COMPUTE_INSTANCE_TYPES = {
         'price': '1.60',
         'max_data_disks': 16,
         'cores': 8
-    }    
+    }
 }
 
 _KNOWN_SERIALIZATION_XFORMS = {
@@ -241,7 +238,7 @@ class AzureNodeDriver(NodeDriver):
         Lists all images
 
         :rtype: ``list`` of :class:`NodeImage`
-        """        
+        """
         data = self._perform_get(self._get_image_path(), Images)
 
         custom_image_data = self._perform_get(
@@ -278,10 +275,10 @@ class AzureNodeDriver(NodeDriver):
         """
         List all nodes
 
-        ex_cloud_service_name parameter is used to scope the request 
+        ex_cloud_service_name parameter is used to scope the request
         to a specific Cloud Service. This is a required parameter as
         nodes cannot exist outside of a Cloud Service nor be shared
-        between a Cloud Service within Azure. 
+        between a Cloud Service within Azure.
 
         :param      ex_cloud_service_name: Cloud Service name
         :type       ex_cloud_service_name: ``str``
@@ -322,10 +319,10 @@ class AzureNodeDriver(NodeDriver):
         """
         Reboots a node.
 
-        ex_cloud_service_name parameter is used to scope the request 
+        ex_cloud_service_name parameter is used to scope the request
         to a specific Cloud Service. This is a required parameter as
         nodes cannot exist outside of a Cloud Service nor be shared
-        between a Cloud Service within Azure. 
+        between a Cloud Service within Azure.
 
         :param      ex_cloud_service_name: Cloud Service name
         :type       ex_cloud_service_name: ``str``
@@ -371,7 +368,7 @@ class AzureNodeDriver(NodeDriver):
                 return True
             else:
                 return False
-        except Exception, e:
+        except Exception:
             return False
 
     def list_volumes(self, node=None):
@@ -405,16 +402,16 @@ class AzureNodeDriver(NodeDriver):
            Reference: http://bit.ly/1fIsCb7
            [www.windowsazure.com/en-us/documentation/]
 
-           We default to: 
+           We default to:
 
            + 3389/TCP - RDP - 1st Microsoft instance.
-           + RANDOM/TCP - RDP - All succeeding Microsoft instances. 
+           + RANDOM/TCP - RDP - All succeeding Microsoft instances.
 
-           + 22/TCP - SSH - 1st Linux instance 
+           + 22/TCP - SSH - 1st Linux instance
            + RANDOM/TCP - SSH - All succeeding Linux instances.
 
-          The above replicates the standard behavior of the Azure UI. 
-          You can retrieve the assigned ports to each instance by 
+          The above replicates the standard behavior of the Azure UI.
+          You can retrieve the assigned ports to each instance by
           using the following private function:
 
           _get_endpoint_ports(service_name)
@@ -430,14 +427,15 @@ class AzureNodeDriver(NodeDriver):
                         Name of the Azure Storage Service.
            :type        ex_storage_service_name:  ``str``
 
-           :keyword     ex_deployment_name: Optional. The name of the 
deployment
+           :keyword     ex_deployment_name: Optional. The name of the
+                                            deployment.
                                             If this is not passed in we default
                                             to using the Cloud Service name.
             :type       ex_deployment_name: ``str``
 
-           :keyword     ex_new_deployment: Optional. Tells azure to create a 
new
-                                           deployment rather than add to an 
existing
-                                           one.
+           :keyword     ex_new_deployment: Optional. Tells azure to create a
+                                           new deployment rather than add to an
+                                           existing one.
             :type       ex_deployment_name: ``boolean``
 
            :keyword     ex_deployment_slot: Optional: Valid values: production|
@@ -500,10 +498,8 @@ class AzureNodeDriver(NodeDriver):
                 )
 
                 for instances in endpoints.role_instance_list:
-                    ports = [
-                        ep.public_port
-                        for ep in instances.instance_endpoints
-                    ]
+                    ports = [ep.public_port for ep in
+                             instances.instance_endpoints]
 
                     while port in ports:
                         port = random.randint(41952, 65535)
@@ -593,7 +589,7 @@ class AzureNodeDriver(NodeDriver):
 
             if image.extra.get('vm_image', False):
                 vm_image_id = image.id
-                #network_config = None
+                #  network_config = None
             else:
                 blob_url = "http://{0}.blob.core.windows.net".format(
                     ex_storage_service_name
@@ -641,7 +637,7 @@ class AzureNodeDriver(NodeDriver):
 
             if image.extra['vm_image']:
                 vm_image_id = image.id
-                #network_config = None
+                #  network_config = None
             else:
                 blob_url = "http://{0}.blob.core.windows.net".format(
                     ex_storage_service_name
@@ -694,18 +690,18 @@ class AzureNodeDriver(NodeDriver):
                      ex_deployment_slot="Production"):
         """Remove Azure Virtual Machine
 
-        This removes the instance, but does not 
+        This removes the instance, but does not
         remove the disk. You will need to use destroy_volume.
         Azure sometimes has an issue where it will hold onto
-        a blob lease for an extended amount of time. 
+        a blob lease for an extended amount of time.
 
         :keyword     ex_cloud_service_name: Required.
                      Name of the Azure Cloud Service.
         :type        ex_cloud_service_name:  ``str``
 
         :keyword     ex_deployment_slot: Optional: The name of the deployment
-                                         slot. If this is not passed in we 
-                                         default to production. 
+                                         slot. If this is not passed in we
+                                         default to production.
         :type        ex_deployment_slot:  ``str``
         """
 
@@ -795,7 +791,7 @@ class AzureNodeDriver(NodeDriver):
         :rtype: ``bool``
         """
 
-        #add check to ensure all nodes have been deleted
+        #  add check to ensure all nodes have been deleted
         response = self._perform_cloud_service_delete(
             self._get_hosted_service_path(ex_cloud_service_name)
         )
@@ -828,8 +824,9 @@ class AzureNodeDriver(NodeDriver):
         ]
 
         all_endpoints.extend(endpoints)
-
-        return self.ex_set_instance_endpoints(node, all_endpoints, 
ex_deployment_slot)
+        result = self.ex_set_instance_endpoints(node, all_endpoints,
+                                                ex_deployment_slot)
+        return result
 
     def ex_set_instance_endpoints(self,
                                   node,
@@ -1024,7 +1021,7 @@ class AzureNodeDriver(NodeDriver):
         """
         Convert the AZURE_COMPUTE_INSTANCE_TYPES into NodeSize
         """
-        
+
         return NodeSize(
             id=data["id"],
             name=data["name"],
@@ -1174,7 +1171,7 @@ class AzureNodeDriver(NodeDriver):
         )
 
         self.raise_for_response(_check_availability, 200)
-                
+
         return _check_availability.result
 
     def _create_storage_account(self, **kwargs):
@@ -1210,7 +1207,7 @@ class AzureNodeDriver(NodeDriver):
 
             self.raise_for_response(response, 202)
 
-        # We need to wait for this to be created before we can 
+        # We need to wait for this to be created before we can
         # create the storage container and the instance.
         self._ex_complete_async_azure_operation(
             response,
@@ -1231,7 +1228,7 @@ class AzureNodeDriver(NodeDriver):
         request.path, request.query = self._update_request_uri_query(request)
         request.headers = self._update_management_header(request)
         response = self._perform_request(request)
-#TODO
+
         if response_type is not None:
             return self._parse_response(response, response_type)
 
@@ -1334,10 +1331,10 @@ class AzureNodeDriver(NodeDriver):
             request.headers['Content-Length'] = str(len(request.body))
 
         # append additional headers base on the service
-        #request.headers.append(('x-ms-version', X_MS_VERSION))
+        #  request.headers.append(('x-ms-version', X_MS_VERSION))
 
         # if it is not GET or HEAD request, must set content-type.
-        if not request.method in ['GET', 'HEAD']:
+        if request.method not in ['GET', 'HEAD']:
             for key in request.headers:
                 if 'content-type' == key.lower():
                     break
@@ -1673,12 +1670,14 @@ class AzureNodeDriver(NodeDriver):
     def _get_deployment_path_using_name(self,
                                         service_name,
                                         deployment_name=None):
-        return self._get_path(
-            'services/hostedservices/'
-            + _str(service_name)
-            + '/deployments',
+        components = [
+            'services/hostedservices/',
+            _str(service_name),
+            '/deployments',
             deployment_name
-        )
+        ]
+        path = ''.join(components)
+        return self._get_path(path)
 
     def _get_path(self, resource, name):
         path = '/' + self.subscription_id + '/' + resource
@@ -1756,19 +1755,23 @@ class AzureNodeDriver(NodeDriver):
                 driver=self
             )
 
-    #def get_connection(self):
-    #    certificate_path = "/Users/baldwin/.azure/managementCertificate.pem"
-    #    port = HTTPS_PORT
-    #    connection = HTTPSConnection(
-    #        azure_service_management_host,
-    #        int(port),
-    #        cert_file=certificate_path)
-    #    return connection
+    """
+    def get_connection(self):
+        certificate_path = "/Users/baldwin/.azure/managementCertificate.pem"
+        port = HTTPS_PORT
+        connection = HTTPSConnection(
+            azure_service_management_host,
+            int(port),
+            cert_file=certificate_path)
+        return connection
+    """
 
 """
 XML Serializer
 
-Borrowed from the Azure SDK for Python. 
+Borrowed from the Azure SDK for Python which is licensed under Apache 2.0.
+
+https://github.com/Azure/azure-sdk-for-python
 """
 
 
@@ -2606,7 +2609,7 @@ class AzureXmlSerializer(object):
         xml = ET.Element(document_element_name)
         xml.attrib["xmlns:i"] = "http://www.w3.org/2001/XMLSchema-instance";
         xml.attrib["xmlns"] = "http://schemas.microsoft.com/windowsazure";
-        
+
         if inner_xml is not None:
             xml.append(inner_xml)
 
@@ -2646,7 +2649,7 @@ class AzureXmlSerializer(object):
 """
 Data Classes
 
-Borrowed from the Azure SDK for Python. 
+Borrowed from the Azure SDK for Python.
 """
 
 
@@ -2700,7 +2703,8 @@ class LinuxConfigurationSet(WindowsAzureData):
         self.host_name = host_name
         self.user_name = user_name
         self.user_password = user_password
-        self.disable_ssh_password_authentication = 
disable_ssh_password_authentication
+        self.disable_ssh_password_authentication = \
+            disable_ssh_password_authentication
         self.ssh = SSH()
 
 

http://git-wip-us.apache.org/repos/asf/libcloud/blob/ab701a10/libcloud/test/compute/test_azure.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_azure.py 
b/libcloud/test/compute/test_azure.py
index ae16757..6424b83 100644
--- a/libcloud/test/compute/test_azure.py
+++ b/libcloud/test/compute/test_azure.py
@@ -2,7 +2,6 @@ import libcloud
 from libcloud.common.types import LibcloudError
 from libcloud.compute.base import NodeAuthPassword, NodeImage, NodeSize
 from libcloud.compute.drivers.azure import azure_service_management_host
-from libcloud.common.azure import AzureServiceManagementConnection
 
 __author__ = 'david'
 
@@ -21,8 +20,7 @@ from libcloud.compute.providers import get_driver
 
 
 class AzureNodeDriverTests(unittest.TestCase):
-
-    #required otherwise we get client side SSL verification
+    #  required otherwise we get client side SSL verification
     libcloud.security.VERIFY_SSL_CERT = False
 
     SUBSCRIPTION_ID = '3761b98b-673d-526c-8d55-fee918758e6e'
@@ -138,7 +136,7 @@ class AzureNodeDriverTests(unittest.TestCase):
 
         self.assertTrue(result)
 
-    #simulating attempting to reboot a node that ifas already rebooting
+    #  simulating attempting to reboot a node that is already rebooting
     def test_restart_node_fail_no_deployment(self):
 
         node = Node(
@@ -438,7 +436,7 @@ class AzureMockHttp(MockHttp):
         return (httplib.OK, body, headers, httplib.responses[httplib.OK])
 
     def 
_3761b98b_673d_526c_8d55_fee918758e6e_services_hostedservices_dcoddkinztest01_deployments_dc03_roleinstances_dc03(self,
 method, url, body, headers):
-        headers["x-ms-request-id"]="acc33f6756cda6fd96826394fce4c9f3"
+        headers["x-ms-request-id"] = "acc33f6756cda6fd96826394fce4c9f3"
         return (httplib.ACCEPTED, body, headers, 
httplib.responses[httplib.ACCEPTED])
 
     def 
_3761b98b_673d_526c_8d55_fee918758e6e_services_hostedservices_dcoddkinztest02_deploymentslots_Production(self,
 method, url, body, headers):
@@ -545,7 +543,7 @@ class AzureMockHttp(MockHttp):
         return (httplib.OK, body, headers, httplib.responses[httplib.OK])
 
     def 
_3761b98b_673d_526c_8d55_fee918758e6e_services_hostedservices_testdcabc2_deployments_dcoddkinztest02_roles(self,
 method, url, body, headers):
-        headers["x-ms-request-id"]="acc33f6756cda6fd96826394fce4c9f3"
+        headers["x-ms-request-id"] = "acc33f6756cda6fd96826394fce4c9f3"
         return (httplib.ACCEPTED, body, headers, 
httplib.responses[httplib.ACCEPTED])
 
     def 
_3761b98b_673d_526c_8d55_fee918758e6e_services_hostedservices_testdcabc3(self, 
method, url, body, headers):

Reply via email to