You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by to...@apache.org on 2015/08/08 21:15:13 UTC

[2/4] libcloud git commit: Minor style cleanup and Python 2.5 compatibility fixes.

Minor style cleanup and Python 2.5 compatibility fixes.


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

Branch: refs/heads/trunk
Commit: 483b713667874d68b753d1b7e87cfe54d99610af
Parents: f6038f6
Author: Tomaz Muraus <to...@tomaz.me>
Authored: Sat Aug 8 20:35:03 2015 +0200
Committer: Tomaz Muraus <to...@tomaz.me>
Committed: Sat Aug 8 20:35:03 2015 +0200

----------------------------------------------------------------------
 libcloud/common/runabove.py          | 55 ++++++++++++++++---------------
 libcloud/compute/drivers/runabove.py | 51 ++++++++++------------------
 2 files changed, 46 insertions(+), 60 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/483b7136/libcloud/common/runabove.py
----------------------------------------------------------------------
diff --git a/libcloud/common/runabove.py b/libcloud/common/runabove.py
index 6345980..af839f3 100644
--- a/libcloud/common/runabove.py
+++ b/libcloud/common/runabove.py
@@ -1,24 +1,27 @@
-# licensed to the apache software foundation (asf) under one or more
-# contributor license agreements.  see the notice file distributed with
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
 # this work for additional information regarding copyright ownership.
-# the asf licenses this file to you under the apache license, version 2.0
-# (the "license"); you may not use this file except in compliance with
-# the license.  you may obtain a copy of the license at
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
 #
-#     http://www.apache.org/licenses/license-2.0
+#     http://www.apache.org/licenses/LICENSE-2.0
 #
-# unless required by applicable law or agreed to in writing, software
-# distributed under the license is distributed on an "as is" basis,
-# without warranties or conditions of any kind, either express or implied.
-# see the license for the specific language governing permissions and
-# limitations under the license.
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
 
 import hashlib
 import time
+
 try:
     import simplejson as json
 except ImportError:
     import json
+
 from libcloud.common.base import ConnectionUserAndKey, JsonResponse
 from libcloud.httplib_ssl import LibcloudHTTPSConnection
 
@@ -29,10 +32,10 @@ LOCATIONS = {
     'BHS-1': {'id': 'BHS-1', 'name': 'Montreal 1', 'country': 'CA'}
 }
 DEFAULT_ACCESS_RULES = [
-    {"method": "GET", "path": "/*"},
-    {"method": "POST", "path": "/*"},
-    {"method": "PUT", "path": "/*"},
-    {"method": "DELETE", "path": "/*"},
+    {'method': 'GET', 'path': '/*'},
+    {'method': 'POST', 'path': '/*'},
+    {'method': 'PUT', 'path': '/*'},
+    {'method': 'DELETE', 'path': '/*'},
 ]
 
 
@@ -61,18 +64,18 @@ class RunAboveConnection(ConnectionUserAndKey):
         self.consumer_key = kwargs.pop('ex_consumer_key', None)
         if self.consumer_key is None:
             consumer_key_json = self.request_consumer_key(user_id)
-            msg = "Your consumer key isn't validated, " \
-                "go to '{validationUrl}' for valid it. After instantiate " \
-                "your driver with \"ex_consumer_key='{consumerKey}'\"."\
-                .format(**consumer_key_json)
+            msg = ("Your consumer key isn't validated, "
+                   "go to '%(validationUrl)s' for valid it. After instantiate "
+                   "your driver with \"ex_consumer_key='%(consumerKey)s'\"." %
+                   consumer_key_json)
             raise RunAboveException(msg)
         super(RunAboveConnection, self).__init__(user_id, *args, **kwargs)
 
     def request_consumer_key(self, user_id):
         action = self.request_path + '/auth/credential'
         data = json.dumps({
-            "accessRules": DEFAULT_ACCESS_RULES,
-            "redirection": "http://runabove.com",
+            'accessRules': DEFAULT_ACCESS_RULES,
+            'redirection': 'http://runabove.com',
         })
         headers = {
             'Content-Type': 'application/json',
@@ -113,9 +116,9 @@ class RunAboveConnection(ConnectionUserAndKey):
 
     def add_default_headers(self, headers):
         headers.update({
-            "X-Ra-Application": self.user_id,
-            "X-Ra-Consumer": self.consumer_key,
-            "Content-type": "application/json",
+            'X-Ra-Application': self.user_id,
+            'X-Ra-Consumer': self.consumer_key,
+            'Content-type': 'application/json',
         })
         return headers
 
@@ -126,8 +129,8 @@ class RunAboveConnection(ConnectionUserAndKey):
         signature = self.make_signature(method, action, data, timestamp)
         headers = headers or {}
         headers.update({
-            "X-Ra-Timestamp": timestamp,
-            "X-Ra-Signature": signature
+            'X-Ra-Timestamp': timestamp,
+            'X-Ra-Signature': signature
         })
         return super(RunAboveConnection, self)\
             .request(action, params=params, data=data, headers=headers,

http://git-wip-us.apache.org/repos/asf/libcloud/blob/483b7136/libcloud/compute/drivers/runabove.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/runabove.py b/libcloud/compute/drivers/runabove.py
index 5e5252b..a3ff95b 100644
--- a/libcloud/compute/drivers/runabove.py
+++ b/libcloud/compute/drivers/runabove.py
@@ -22,7 +22,8 @@ from libcloud.compute.drivers.openstack import OpenStackKeyPair
 
 
 class RunAboveNodeDriver(NodeDriver):
-    """libcloud driver for the RunAbove API
+    """
+    Libcloud driver for the RunAbove API
 
     Rough mapping of which is which:
 
@@ -53,7 +54,8 @@ class RunAboveNodeDriver(NodeDriver):
     NODE_STATE_MAP = OpenStackNodeDriver.NODE_STATE_MAP
 
     def __init__(self, key, secret, ex_consumer_key=None):
-        """Instantiate the driver with the given API key
+        """
+        Instantiate the driver with the given API key
 
         :param   key: the API key to use (required)
         :type    key: ``str``
@@ -64,24 +66,12 @@ class RunAboveNodeDriver(NodeDriver):
         self.consumer_key = ex_consumer_key
         NodeDriver.__init__(self, key, secret, ex_consumer_key=ex_consumer_key)
 
-    def _ex_connection_class_kwargs(self):
-        return {'ex_consumer_key': self.consumer_key}
-
-    def _add_required_headers(self, headers, method, action, data, timestamp):
-        timestamp = self.connection.get_timestamp()
-        signature = self.connection.make_signature(method, action, data,
-                                                   str(timestamp))
-        headers.update({
-            "X-Ra-Timestamp": timestamp,
-            "X-Ra-Signature": signature
-        })
-
     def list_nodes(self, location=None):
         """
         List all Linodes that the API key can access
 
         This call will return all Linodes that the API key in use has access
-         to.
+        to.
         If a node is in this list, rebooting will work; however, creation and
         destruction are a separate grant.
 
@@ -100,10 +90,6 @@ class RunAboveNodeDriver(NodeDriver):
         response = self.connection.request(action, method='GET')
         return self._to_node(response.object)
 
-    def reboot_node(self, node):
-        raise NotImplementedError(
-            "reboot_node not implemented for this driver")
-
     def create_node(self, **kwargs):
         action = API_ROOT + '/instance'
         data = {
@@ -224,21 +210,6 @@ class RunAboveNodeDriver(NodeDriver):
         self.connection.request(action, data=data, method='DELETE')
         return True
 
-    def create_volume(self, size, name):
-        raise NotImplementedError(
-            "create_volume not implemented for this driver")
-
-    def destroy_volume(self, volume):
-        raise NotImplementedError(
-            "destroy_volume not implemented for this driver")
-
-    def ex_list_volumes(self, node, disk_id=None):
-        raise NotImplementedError(
-            "list_volumes not implemented for this driver")
-
-    def _to_volume(self, obj):
-        pass
-
     def _to_volumes(self, objs):
         return [self._to_volume(obj) for obj in objs]
 
@@ -293,3 +264,15 @@ class RunAboveNodeDriver(NodeDriver):
 
     def _to_key_pairs(self, objs):
         return [self._to_key_pair(obj) for obj in objs]
+
+    def _ex_connection_class_kwargs(self):
+        return {'ex_consumer_key': self.consumer_key}
+
+    def _add_required_headers(self, headers, method, action, data, timestamp):
+        timestamp = self.connection.get_timestamp()
+        signature = self.connection.make_signature(method, action, data,
+                                                   str(timestamp))
+        headers.update({
+            'X-Ra-Timestamp': timestamp,
+            'X-Ra-Signature': signature
+        })