You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by or...@apache.org on 2010/03/16 04:59:44 UTC
svn commit: r923573 - /incubator/libcloud/trunk/libcloud/drivers/softlayer.py
Author: oremj
Date: Tue Mar 16 03:59:44 2010
New Revision: 923573
URL: http://svn.apache.org/viewvc?rev=923573&view=rev
Log:
Softlayer: list lcoations and create node.
Modified:
incubator/libcloud/trunk/libcloud/drivers/softlayer.py
Modified: incubator/libcloud/trunk/libcloud/drivers/softlayer.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/libcloud/drivers/softlayer.py?rev=923573&r1=923572&r2=923573&view=diff
==============================================================================
--- incubator/libcloud/trunk/libcloud/drivers/softlayer.py (original)
+++ incubator/libcloud/trunk/libcloud/drivers/softlayer.py Tue Mar 16 03:59:44 2010
@@ -20,10 +20,12 @@ import xmlrpclib
import libcloud
from libcloud.types import Provider
-from libcloud.base import NodeDriver, Node
+from libcloud.base import NodeDriver, Node, NodeLocation
API_PREFIX = "http://api.service.softlayer.com/xmlrpc/v3"
+DATACENTERS = ['sea01', 'wdc01', 'dal01']
+
class SoftLayerException(Exception):
pass
@@ -112,6 +114,64 @@ class SoftLayerNodeDriver(NodeDriver):
else:
return False
+ def create_node(self, **kwargs):
+ """
+ Right now the best way to create a new node in softlayer is by
+ cloning an already created node, so size and image do not apply.
+
+ @keyword node: A Node which will serve as the template for the new node
+ @type node: L{Node}
+
+ @keyword domain: e.g. libcloud.org
+ @type domain: str
+ """
+ name = kwargs['name']
+ location = kwargs['location']
+ node = kwargs['node']
+ domain = kwargs['domain']
+
+ res = self.connection.request(
+ "SoftLayer_Virtual_Guest",
+ "getOrderTemplate",
+ "HOURLY",
+ id=node.id
+ )
+
+ res['location'] = location.id
+ res['complexType'] = 'SoftLayer_Container_Product_Order_Virtual_Guest'
+ res['quantity'] = 1
+ res['virtualGuests'] = [
+ {
+ 'hostname': name,
+ 'domain': domain
+ }
+ ]
+
+ res = self.connection.request(
+ "SoftLayer_Product_Order",
+ "placeOrder",
+ res
+ )
+
+ return None # the instance won't be available for a while.
+
+ def _to_loc(self, loc):
+ return NodeLocation(
+ id=loc['id'],
+ name=loc['name'],
+ country="", # country data not available
+ driver=self
+ )
+
+ def list_locations(self):
+ res = self.connection.request(
+ "SoftLayer_Location_Datacenter",
+ "getDatacenters"
+ )
+
+ # checking "in DATACENTERS", because some of the locations returned by getDatacenters are not useable.
+ return [self._to_loc(l) for l in res if l['name'] in DATACENTERS]
+
def list_nodes(self):
nodes = self._to_nodes(
self.connection.request("SoftLayer_Account","getVirtualGuests")