libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rbogorods...@apache.org
Subject svn commit: r1029795 - in /incubator/libcloud/trunk: libcloud/drivers/rackspace.py test/fixtures/rackspace/v1_slug_limits.xml test/test_rackspace.py
Date Mon, 01 Nov 2010 19:17:03 GMT
Author: rbogorodskiy
Date: Mon Nov  1 19:17:03 2010
New Revision: 1029795

URL: http://svn.apache.org/viewvc?rev=1029795&view=rev
Log:
Add extra call ex_limits to Rackspace driver to
obtain information about account's limits (such
as allowed request rate or maximum RAM used by
servers).

Added:
    incubator/libcloud/trunk/test/fixtures/rackspace/v1_slug_limits.xml
Modified:
    incubator/libcloud/trunk/libcloud/drivers/rackspace.py
    incubator/libcloud/trunk/test/test_rackspace.py

Modified: incubator/libcloud/trunk/libcloud/drivers/rackspace.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/libcloud/drivers/rackspace.py?rev=1029795&r1=1029794&r2=1029795&view=diff
==============================================================================
--- incubator/libcloud/trunk/libcloud/drivers/rackspace.py (original)
+++ incubator/libcloud/trunk/libcloud/drivers/rackspace.py Mon Nov  1 19:17:03 2010
@@ -347,3 +347,30 @@ class RackspaceNodeDriver(NodeDriver):
                      driver=self.connection.driver,
                      extra={'serverId': el.get('serverId')})
         return i
+
+    def ex_limits(self):
+        """
+        Extra call to get account's limits, such as
+        rates (for example amount of POST requests per day)
+        and absolute limits like total amount of available
+        RAM to be used by servers.
+        
+        @return: C{dict} with keys 'rate' and 'absolute'
+        """
+        def _to_rate(el):
+            rate = {}
+            for item in el.items():
+                rate[item[0]] = item[1]
+
+            return rate
+
+        def _to_absolute(el):
+            return {el.get('name'): el.get('value')}
+
+        limits = self.connection.request("/limits").object
+        rate = [ _to_rate(el) for el in self._findall(limits, 'rate/limit') ]
+        absolute = {}
+        for item in self._findall(limits, 'absolute/limit'):
+            absolute.update(_to_absolute(item))
+
+        return {"rate": rate, "absolute": absolute}

Added: incubator/libcloud/trunk/test/fixtures/rackspace/v1_slug_limits.xml
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/test/fixtures/rackspace/v1_slug_limits.xml?rev=1029795&view=auto
==============================================================================
--- incubator/libcloud/trunk/test/fixtures/rackspace/v1_slug_limits.xml (added)
+++ incubator/libcloud/trunk/test/fixtures/rackspace/v1_slug_limits.xml Mon Nov  1 19:17:03
2010
@@ -0,0 +1,15 @@
+<?xml version="1.0" ?>
+<limits xmlns="http://docs.rackspacecloud.com/servers/api/v1.0">
+	<rate>
+		<limit URI="*changes-since*" regex="changes-since" remaining="3" resetTime="1288636970"
unit="MINUTE" value="3" verb="GET"/>
+		<limit URI="*" regex=".*" remaining="10" resetTime="1288636970" unit="MINUTE" value="10"
verb="PUT"/>
+		<limit URI="*" regex=".*" remaining="10" resetTime="1288636970" unit="MINUTE" value="10"
verb="POST"/>
+		<limit URI="*" regex=".*" remaining="600" resetTime="1288636970" unit="MINUTE" value="600"
verb="DELETE"/>
+		<limit URI="/servers*" regex="^/servers" remaining="500" resetTime="1288636970" unit="DAY"
value="500" verb="POST"/>
+	</rate>
+	<absolute>
+		<limit name="maxIPGroupMembers" value="25"/>
+		<limit name="maxIPGroups" value="25"/>
+		<limit name="maxTotalRAMSize" value="921600"/>
+	</absolute>
+</limits>

Modified: incubator/libcloud/trunk/test/test_rackspace.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/test/test_rackspace.py?rev=1029795&r1=1029794&r2=1029795&view=diff
==============================================================================
--- incubator/libcloud/trunk/test/test_rackspace.py (original)
+++ incubator/libcloud/trunk/test/test_rackspace.py Mon Nov  1 19:17:03 2010
@@ -103,6 +103,11 @@ class RackspaceTests(unittest.TestCase, 
         ret = node.destroy()
         self.assertTrue(ret is True)
 
+    def test_ex_limits(self):
+        limits = self.driver.ex_limits()
+        self.assertTrue("rate" in limits)
+        self.assertTrue("absolute" in limits)
+
 class RackspaceMockHttp(MockHttp):
 
     fixtures = FileFixtures('rackspace')
@@ -153,6 +158,10 @@ class RackspaceMockHttp(MockHttp):
         # only used by reboot() right now, but we will need to parse body someday !!!!
         return (httplib.ACCEPTED, "", {}, httplib.responses[httplib.ACCEPTED])
 
+    def _v1_0_slug_limits(self, method, url, body, headers):
+        body = self.fixtures.load('v1_slug_limits.xml')
+        return (httplib.ACCEPTED, body, {}, httplib.responses[httplib.ACCEPTED])
+
     def _v1_0_slug_servers_72258(self, method, url, body, headers):
         if method != "DELETE":
             raise NotImplemented



Mime
View raw message