You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by pq...@apache.org on 2009/12/31 03:31:22 UTC

svn commit: r894765 - /incubator/libcloud/trunk/libcloud/drivers/linode.py

Author: pquerna
Date: Thu Dec 31 02:31:22 2009
New Revision: 894765

URL: http://svn.apache.org/viewvc?rev=894765&view=rev
Log:
Add List locations to linode driver

Modified:
    incubator/libcloud/trunk/libcloud/drivers/linode.py

Modified: incubator/libcloud/trunk/libcloud/drivers/linode.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/libcloud/drivers/linode.py?rev=894765&r1=894764&r2=894765&view=diff
==============================================================================
--- incubator/libcloud/trunk/libcloud/drivers/linode.py (original)
+++ incubator/libcloud/trunk/libcloud/drivers/linode.py Thu Dec 31 02:31:22 2009
@@ -22,7 +22,7 @@
 #
 
 from libcloud.types import Provider, NodeState
-from libcloud.base import ConnectionKey, Response, NodeDriver, NodeSize, Node
+from libcloud.base import ConnectionKey, Response, NodeDriver, NodeSize, Node, NodeLocation
 from libcloud.base import NodeImage
 from copy import copy
 
@@ -375,6 +375,22 @@
             distros.append(i)
         return distros
 
+    def list_locations(self):
+        params = { "api_action": "avail.datacenters" }
+        data = self.connection.request(LINODE_ROOT, params=params).object
+        nl = []
+        for dc in data:
+            country = None
+            #TODO: this is a hack!
+            if dc["LOCATION"][-3:] == "USA":
+                country = "US"
+            elif dc["LOCATION"][-2:] == "UK":
+                country = "GB"
+            else:
+                raise LinodeException(0xFD, "Unable to convert data center location to country: '%s'" % dc["LOCATION"])
+            nl.append(NodeLocation(dc["DATACENTERID"], dc["LOCATION"], country, self))
+        return nl
+
     def linode_set_datacenter(self, did):
         # Set the datacenter for create requests.
         #