libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r1081404 - in /incubator/libcloud/trunk/libcloud: compute/drivers/cloudsigma.py drivers/cloudsigma.py pricing.py utils.py
Date Mon, 14 Mar 2011 14:43:46 GMT
Author: tomaz
Date: Mon Mar 14 14:43:45 2011
New Revision: 1081404

URL: http://svn.apache.org/viewvc?rev=1081404&view=rev
Log:
1. Add docstrings to the pricing module
2. Move utility methods from the cloudsigma driver to the utils module

Modified:
    incubator/libcloud/trunk/libcloud/compute/drivers/cloudsigma.py
    incubator/libcloud/trunk/libcloud/drivers/cloudsigma.py
    incubator/libcloud/trunk/libcloud/pricing.py
    incubator/libcloud/trunk/libcloud/utils.py

Modified: incubator/libcloud/trunk/libcloud/compute/drivers/cloudsigma.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/libcloud/compute/drivers/cloudsigma.py?rev=1081404&r1=1081403&r2=1081404&view=diff
==============================================================================
--- incubator/libcloud/trunk/libcloud/compute/drivers/cloudsigma.py (original)
+++ incubator/libcloud/trunk/libcloud/compute/drivers/cloudsigma.py Mon Mar 14 14:43:45 2011
@@ -20,6 +20,7 @@ import re
 import time
 import base64
 
+from libcloud.utils import str2dicts, str2list, dict2str
 from libcloud.common.base import ConnectionUserAndKey, Response
 from libcloud.common.types import InvalidCredsError
 from libcloud.compute.types import NodeState, Provider
@@ -556,99 +557,3 @@ class CloudSigmaZrhNodeDriver(CloudSigma
     CloudSigma node driver for the Zurich end-point
     """
     connectionCls = CloudSigmaZrhConnection
-
-# Utility methods (should we place them in libcloud/utils.py ?)
-def str2dicts(data):
-    """
-    Create a list of dictionaries from a whitespace and newline delimited text.
-
-    For example, this:
-    cpu 1100
-    ram 640
-
-    cpu 2200
-    ram 1024
-
-    becomes:
-    [{'cpu': '1100', 'ram': '640'}, {'cpu': '2200', 'ram': '1024'}]
-    """
-    list_data = []
-    list_data.append({})
-    d = list_data[-1]
-
-    lines = data.split('\n')
-    for line in lines:
-        line = line.strip()
-
-        if not line:
-            d = {}
-            list_data.append(d)
-            d = list_data[-1]
-            continue
-
-        whitespace = line.find(' ')
-
-        if not whitespace:
-            continue
-
-        key = line[0:whitespace]
-        value = line[whitespace + 1:]
-        d.update({key: value})
-
-    list_data = [value for value in list_data if value != {}]
-    return list_data
-
-def str2list(data):
-    """
-    Create a list of values from a whitespace and newline delimited text (keys are ignored).
-
-    For example, this:
-    ip 1.2.3.4
-    ip 1.2.3.5
-    ip 1.2.3.6
-
-    becomes:
-    ['1.2.3.4', '1.2.3.5', '1.2.3.6']
-    """
-    list_data = []
-
-    for line in data.split('\n'):
-        line = line.strip()
-
-        if not line:
-            continue
-
-        try:
-            splitted = line.split(' ')
-            # key = splitted[0]
-            value = splitted[1]
-        except Exception:
-            continue
-
-        list_data.append(value)
-
-    return list_data
-
-def dict2str(data):
-    """
-    Create a string with a whitespace and newline delimited text from a dictionary.
-
-    For example, this:
-    {'cpu': '1100', 'ram': '640', 'smp': 'auto'}
-
-    becomes:
-    cpu 1100
-    ram 640
-    smp auto
-
-    cpu 2200
-    ram 1024
-    """
-    result = ''
-    for k in data:
-        if data[k] != None:
-            result += '%s %s\n' % (str(k), str(data[k]))
-        else:
-            result += '%s\n' % str(k)
-
-    return result

Modified: incubator/libcloud/trunk/libcloud/drivers/cloudsigma.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/libcloud/drivers/cloudsigma.py?rev=1081404&r1=1081403&r2=1081404&view=diff
==============================================================================
--- incubator/libcloud/trunk/libcloud/drivers/cloudsigma.py (original)
+++ incubator/libcloud/trunk/libcloud/drivers/cloudsigma.py Mon Mar 14 14:43:45 2011
@@ -15,6 +15,8 @@
 # limitations under the License.
 
 from libcloud.utils import deprecated_warning
+
+from libcloud.utils import str2dicts, str2list, dict2str
 from libcloud.compute.drivers.cloudsigma import *
 
 deprecated_warning(__name__)

Modified: incubator/libcloud/trunk/libcloud/pricing.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/libcloud/pricing.py?rev=1081404&r1=1081403&r2=1081404&view=diff
==============================================================================
--- incubator/libcloud/trunk/libcloud/pricing.py (original)
+++ incubator/libcloud/trunk/libcloud/pricing.py Mon Mar 14 14:43:45 2011
@@ -61,9 +61,21 @@ def get_pricing(driver_type, driver_name
     return pricing
 
 def invalidate_pricing_cache():
+    """
+    Invalidate the cache for all the drivers.
+    """
     PRICING_DATA['compute'] = {}
     PRICING_DATA['storage'] = {}
 
 def invalidate_module_pricing_cache(driver_type, driver_name):
+    """
+    Invalidate the cache for the specified driver.
+
+    @type driver_type: C{str}
+    @param driver_type: Driver type ('compute' or 'storage')
+
+    @type driver_name: C{str}
+    @param driver_name: Driver name
+    """
     if driver_name in PRICING_DATA[driver_type]:
         del PRICING_DATA[driver_type][driver_name]

Modified: incubator/libcloud/trunk/libcloud/utils.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/libcloud/utils.py?rev=1081404&r1=1081403&r2=1081404&view=diff
==============================================================================
--- incubator/libcloud/trunk/libcloud/utils.py (original)
+++ incubator/libcloud/trunk/libcloud/utils.py Mon Mar 14 14:43:45 2011
@@ -61,6 +61,100 @@ def deprecated_warning(module):
                        (module, OLD_API_REMOVE_VERSION),
                   category=DeprecationWarning)
 
+def str2dicts(data):
+    """
+    Create a list of dictionaries from a whitespace and newline delimited text.
+
+    For example, this:
+    cpu 1100
+    ram 640
+
+    cpu 2200
+    ram 1024
+
+    becomes:
+    [{'cpu': '1100', 'ram': '640'}, {'cpu': '2200', 'ram': '1024'}]
+    """
+    list_data = []
+    list_data.append({})
+    d = list_data[-1]
+
+    lines = data.split('\n')
+    for line in lines:
+        line = line.strip()
+
+        if not line:
+            d = {}
+            list_data.append(d)
+            d = list_data[-1]
+            continue
+
+        whitespace = line.find(' ')
+
+        if not whitespace:
+            continue
+
+        key = line[0:whitespace]
+        value = line[whitespace + 1:]
+        d.update({key: value})
+
+    list_data = [value for value in list_data if value != {}]
+    return list_data
+
+def str2list(data):
+    """
+    Create a list of values from a whitespace and newline delimited text (keys are ignored).
+
+    For example, this:
+    ip 1.2.3.4
+    ip 1.2.3.5
+    ip 1.2.3.6
+
+    becomes:
+    ['1.2.3.4', '1.2.3.5', '1.2.3.6']
+    """
+    list_data = []
+
+    for line in data.split('\n'):
+        line = line.strip()
+
+        if not line:
+            continue
+
+        try:
+            splitted = line.split(' ')
+            # key = splitted[0]
+            value = splitted[1]
+        except Exception:
+            continue
+
+        list_data.append(value)
+
+    return list_data
+
+def dict2str(data):
+    """
+    Create a string with a whitespace and newline delimited text from a dictionary.
+
+    For example, this:
+    {'cpu': '1100', 'ram': '640', 'smp': 'auto'}
+
+    becomes:
+    cpu 1100
+    ram 640
+    smp auto
+
+    cpu 2200
+    ram 1024
+    """
+    result = ''
+    for k in data:
+        if data[k] != None:
+            result += '%s %s\n' % (str(k), str(data[k]))
+        else:
+            result += '%s\n' % str(k)
+
+    return result
 def get_driver(drivers, provider):
     """
     Get a driver.



Mime
View raw message