libcloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From or...@apache.org
Subject svn commit: r915436 - in /incubator/libcloud/trunk/libcloud: drivers/softlayer.py providers.py types.py
Date Tue, 23 Feb 2010 17:04:56 GMT
Author: oremj
Date: Tue Feb 23 17:04:55 2010
New Revision: 915436

URL: http://svn.apache.org/viewvc?rev=915436&view=rev
Log:
SoftLayer: list nodes

Modified:
    incubator/libcloud/trunk/libcloud/drivers/softlayer.py
    incubator/libcloud/trunk/libcloud/providers.py
    incubator/libcloud/trunk/libcloud/types.py

Modified: incubator/libcloud/trunk/libcloud/drivers/softlayer.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/libcloud/drivers/softlayer.py?rev=915436&r1=915435&r2=915436&view=diff
==============================================================================
--- incubator/libcloud/trunk/libcloud/drivers/softlayer.py (original)
+++ incubator/libcloud/trunk/libcloud/drivers/softlayer.py Tue Feb 23 17:04:55 2010
@@ -25,29 +25,38 @@
 
 API_PREFIX = "http://api.service.softlayer.com/xmlrpc/v3"
 
+class SoftLayerException(Exception):
+    pass
+
 class SoftLayerTransport(xmlrpclib.Transport):
     user_agent = "libcloud/%s (SoftLayer)" % libcloud.__version__
 
 class SoftLayerProxy(xmlrpclib.ServerProxy):
+    transportCls = SoftLayerTransport
+
     def __init__(self, service, verbose=0):
         xmlrpclib.ServerProxy.__init__(
             self,
             uri="%s/%s" % (API_PREFIX, service),
-            transport=SoftLayerTransport(use_datetime=0),
+            transport=self.transportCls(use_datetime=0),
             verbose=verbose
         )
 
 class SoftLayerConnection(object):
+    proxyCls = SoftLayerProxy
     driver = None
 
     def __init__(self, user, key):
         self.user = user
         self.key = key 
 
-    def request(self, service, method, *args):
-        sl = SoftLayerProxy(service)
-        params = [self._get_auth_param(service)] + list(args)
-        return getattr(sl, method)(*params)
+    def request(self, service, method, *args, **init_params):
+        sl = self.proxyCls(service)
+        params = [self._get_auth_param(service, init_params)] + list(args)
+        try:
+            return getattr(sl, method)(*params)
+        except xmlrpclib.Fault, e:
+            raise SoftLayerException(e)
 
     def _get_auth_param(self, service, init_params=None):
         if not init_params:
@@ -65,9 +74,38 @@
 
 class SoftLayerNodeDriver(NodeDriver):
     connectionCls = SoftLayerConnection
+    name = 'SoftLayer'
+    type = Provider.SOFTLAYER
 
-    def __init__(self, user, key=None, secure=False):
+    def __init__(self, key, secret=None, secure=False):
         self.key = key
         self.secret = secret
-        self.connection = connectionCls(user, key)
+        self.connection = self.connectionCls(key, secret)
         self.connection.driver = self
+
+    def _to_node(self, host):
+        return Node(
+            id=host['id'],
+            name=host['hostname'],
+            state=host['statusId'],
+            public_ip=host['primaryIpAddress'],
+            private_ip=host['primaryBackendIpAddress'],
+            driver=self
+        )
+    
+    def _to_nodes(self, hosts):
+        return [self._to_node(h) for h in hosts]
+
+    def list_nodes(self):
+        nodes = self._to_nodes(
+            self.connection.request("SoftLayer_Account","getVirtualGuests")
+        )
+        return nodes
+
+    def reboot_node(self, node):
+        res = self.connection.request(
+            "SoftLayer_Virtual_Guest", 
+            "rebootHard", 
+            id=node.id
+        )
+        return res

Modified: incubator/libcloud/trunk/libcloud/providers.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/libcloud/providers.py?rev=915436&r1=915435&r2=915436&view=diff
==============================================================================
--- incubator/libcloud/trunk/libcloud/providers.py (original)
+++ incubator/libcloud/trunk/libcloud/providers.py Tue Feb 23 17:04:55 2010
@@ -40,7 +40,9 @@
     Provider.RIMUHOSTING:
         ('libcloud.drivers.rimuhosting', 'RimuHostingNodeDriver'),
     Provider.VOXEL:
-        ('libcloud.drivers.voxel', 'VoxelNodeDriver'),	
+        ('libcloud.drivers.voxel', 'VoxelNodeDriver'),
+    Provider.SOFTLAYER:
+        ('libcloud.drivers.softlayer', 'SoftLayerNodeDriver'),
 }
 
 def get_driver(provider):

Modified: incubator/libcloud/trunk/libcloud/types.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/libcloud/types.py?rev=915436&r1=915435&r2=915436&view=diff
==============================================================================
--- incubator/libcloud/trunk/libcloud/types.py (original)
+++ incubator/libcloud/trunk/libcloud/types.py Tue Feb 23 17:04:55 2010
@@ -46,6 +46,7 @@
     RIMUHOSTING = 9
     EC2_US_WEST = 10
     VOXEL = 11
+    SOFTLAYER = 12
 
 class NodeState(object):
     """



Mime
View raw message