libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From or...@apache.org
Subject svn commit: r927236 - in /incubator/libcloud/trunk: libcloud/drivers/softlayer.py test/fixtures/softlayer/v3_SoftLayer_Account_getVirtualGuests.xml test/test_softlayer.py
Date Thu, 25 Mar 2010 00:10:24 GMT
Author: oremj
Date: Thu Mar 25 00:10:24 2010
New Revision: 927236

URL: http://svn.apache.org/viewvc?rev=927236&view=rev
Log:
SoftLayer:
    * Support for softlayer object masks.
    * Pulls in powerstate data.

Modified:
    incubator/libcloud/trunk/libcloud/drivers/softlayer.py
    incubator/libcloud/trunk/test/fixtures/softlayer/v3_SoftLayer_Account_getVirtualGuests.xml
    incubator/libcloud/trunk/test/test_softlayer.py

Modified: incubator/libcloud/trunk/libcloud/drivers/softlayer.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/libcloud/drivers/softlayer.py?rev=927236&r1=927235&r2=927236&view=diff
==============================================================================
--- incubator/libcloud/trunk/libcloud/drivers/softlayer.py (original)
+++ incubator/libcloud/trunk/libcloud/drivers/softlayer.py Thu Mar 25 00:10:24 2010
@@ -28,6 +28,11 @@ DATACENTERS = {
     'dal01': {'country': 'US'}
 }
 
+NODE_STATE_MAP = {
+    'RUNNING': NodeState.RUNNING,
+    'HALTED': NodeState.TERMINATED
+}
+
 class SoftLayerException(Exception):
     pass
 
@@ -63,9 +68,15 @@ class SoftLayerConnection(object):
         self.key = key 
         self.ua = []
 
-    def request(self, service, method, *args, **init_params):
+    def request(self, service, method, *args, **kwargs):
         sl = self.proxyCls(service, self._user_agent())
-        params = [self._get_auth_param(service, init_params)] + list(args)
+
+        headers = {}
+        headers.update(self._get_auth_headers())
+        headers.update(self._get_init_params(service, kwargs.get('id')))
+        headers.update(self._get_object_mask(service, kwargs.get('object_mask')))
+        params = [{'headers': headers}] + list(args)
+
         try:
             return getattr(sl, method)(*params)
         except xmlrpclib.Fault, e:
@@ -82,20 +93,30 @@ class SoftLayerConnection(object):
     def user_agent_append(self, s):
         self.ua.append(s)
 
-    def _get_auth_param(self, service, init_params=None):
-        if not init_params:
-            init_params = {}
-
+    def _get_auth_headers(self):
         return {
-            'headers': {
-                'authenticate': {
-                    'username': self.user,
-                    'apiKey': self.key
-                },
-                '%sInitParameters' % service: init_params
+            'authenticate': {
+                'username': self.user,
+                'apiKey': self.key
             }
         }
 
+    def _get_init_params(self, service, id):
+        if id is not None:
+            return {
+                '%sInitParameters' % service: {'id': id}
+            }
+        else:
+            return {}
+
+    def _get_object_mask(self, service, mask):
+        if mask is not None:
+            return {
+                '%sObjectMask' % service: {'mask': mask}
+            }
+        else:
+            return {}
+
 class SoftLayerNodeDriver(NodeDriver):
     connectionCls = SoftLayerConnection
     name = 'SoftLayer'
@@ -111,8 +132,10 @@ class SoftLayerNodeDriver(NodeDriver):
         return Node(
             id=host['id'],
             name=host['hostname'],
-            # TODO: figure out how to get the correct power state
-            state=NodeState.UNKNOWN,
+            state=NODE_STATE_MAP.get(
+                host['powerState']['keyName'],
+                NodeState.UNKNOWN
+            ),
             public_ip=host['primaryIpAddress'],
             private_ip=host['primaryBackendIpAddress'],
             driver=self
@@ -197,9 +220,15 @@ class SoftLayerNodeDriver(NodeDriver):
         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")
+        mask = {
+            'virtualGuests': {'powerState': ''}
+        }
+        res = self.connection.request(
+            "SoftLayer_Account",
+            "getVirtualGuests",
+            object_mask=mask
         )
+        nodes = self._to_nodes(res)
         return nodes
 
     def reboot_node(self, node):

Modified: incubator/libcloud/trunk/test/fixtures/softlayer/v3_SoftLayer_Account_getVirtualGuests.xml
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/test/fixtures/softlayer/v3_SoftLayer_Account_getVirtualGuests.xml?rev=927236&r1=927235&r2=927236&view=diff
==============================================================================
--- incubator/libcloud/trunk/test/fixtures/softlayer/v3_SoftLayer_Account_getVirtualGuests.xml
(original)
+++ incubator/libcloud/trunk/test/fixtures/softlayer/v3_SoftLayer_Account_getVirtualGuests.xml
Thu Mar 25 00:10:24 2010
@@ -15,13 +15,13 @@
       <member>
        <name>id</name>
        <value>
-        <int>0</int>
+        <int>1111</int>
        </value>
       </member>
       <member>
        <name>accountId</name>
        <value>
-        <int>0</int>
+        <int>11111</int>
        </value>
       </member>
       <member>
@@ -33,13 +33,13 @@
       <member>
        <name>uuid</name>
        <value>
-        <string>ea11b502-8e2d-d8d0-1111-611111111111</string>
+        <string>11111111-8121-d110-c111-6fh1e165hh9c</string>
        </value>
       </member>
       <member>
        <name>hostname</name>
        <value>
-        <string>test</string>
+        <string>test01</string>
        </value>
       </member>
       <member>
@@ -81,13 +81,13 @@
       <member>
        <name>modifyDate</name>
        <value>
-        <string>2010-03-17T19:23:59-05:00</string>
+        <string>2010-03-24T18:54:01-05:00</string>
        </value>
       </member>
       <member>
        <name>metricPollDate</name>
        <value>
-        <string>2010-03-17T19:23:00-05:00</string>
+        <string>2010-03-24T18:53:00-05:00</string>
        </value>
       </member>
       <member>
@@ -97,15 +97,159 @@
        </value>
       </member>
       <member>
+       <name>powerState</name>
+       <value>
+        <struct>
+         <member>
+          <name>name</name>
+          <value>
+           <string>Running</string>
+          </value>
+         </member>
+         <member>
+          <name>keyName</name>
+          <value>
+           <string>RUNNING</string>
+          </value>
+         </member>
+        </struct>
+       </value>
+      </member>
+      <member>
+       <name>primaryIpAddress</name>
+       <value>
+        <string>67.255.155.255</string>
+       </value>
+      </member>
+      <member>
+       <name>primaryBackendIpAddress</name>
+       <value>
+        <string>10.20.255.255</string>
+       </value>
+      </member>
+     </struct>
+    </value>
+    <value>
+     <struct>
+      <member>
+       <name>privateNetworkOnlyFlag</name>
+       <value>
+        <boolean>0</boolean>
+       </value>
+      </member>
+      <member>
+       <name>id</name>
+       <value>
+        <int>11111</int>
+       </value>
+      </member>
+      <member>
+       <name>accountId</name>
+       <value>
+        <int>11111</int>
+       </value>
+      </member>
+      <member>
+       <name>statusId</name>
+       <value>
+        <int>1001</int>
+       </value>
+      </member>
+      <member>
+       <name>uuid</name>
+       <value>
+        <string>21a11114-4111-4141-19f3-51111610dd86</string>
+       </value>
+      </member>
+      <member>
+       <name>hostname</name>
+       <value>
+        <string>test02</string>
+       </value>
+      </member>
+      <member>
+       <name>domain</name>
+       <value>
+        <string>libcloud.org</string>
+       </value>
+      </member>
+      <member>
+       <name>maxCpu</name>
+       <value>
+        <int>1</int>
+       </value>
+      </member>
+      <member>
+       <name>maxCpuUnits</name>
+       <value>
+        <string>CORE</string>
+       </value>
+      </member>
+      <member>
+       <name>maxMemory</name>
+       <value>
+        <int>1024</int>
+       </value>
+      </member>
+      <member>
+       <name>startCpus</name>
+       <value>
+        <int>1</int>
+       </value>
+      </member>
+      <member>
+       <name>createDate</name>
+       <value>
+        <string>2010-03-23T17:06:13-05:00</string>
+       </value>
+      </member>
+      <member>
+       <name>modifyDate</name>
+       <value>
+        <string>2010-03-24T18:58:48-05:00</string>
+       </value>
+      </member>
+      <member>
+       <name>metricPollDate</name>
+       <value>
+        <string>2010-03-24T18:58:00-05:00</string>
+       </value>
+      </member>
+      <member>
+       <name>dedicatedAccountHostOnlyFlag</name>
+       <value>
+        <boolean>0</boolean>
+       </value>
+      </member>
+      <member>
+       <name>powerState</name>
+       <value>
+        <struct>
+         <member>
+          <name>name</name>
+          <value>
+           <string>Running</string>
+          </value>
+         </member>
+         <member>
+          <name>keyName</name>
+          <value>
+           <string>RUNNING</string>
+          </value>
+         </member>
+        </struct>
+       </value>
+      </member>
+      <member>
        <name>primaryIpAddress</name>
        <value>
-        <string>62.233.333.333</string>
+        <string>174.255.255.244</string>
        </value>
       </member>
       <member>
        <name>primaryBackendIpAddress</name>
        <value>
-        <string>10.20.172.130</string>
+        <string>10.255.255.255</string>
        </value>
       </member>
      </struct>

Modified: incubator/libcloud/trunk/test/test_softlayer.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/test/test_softlayer.py?rev=927236&r1=927235&r2=927236&view=diff
==============================================================================
--- incubator/libcloud/trunk/test/test_softlayer.py (original)
+++ incubator/libcloud/trunk/test/test_softlayer.py Thu Mar 25 00:10:24 2010
@@ -21,6 +21,7 @@ import xmlrpclib
 
 from libcloud.drivers.softlayer import SoftLayerProxy, SoftLayerNodeDriver as SoftLayer
 from libcloud.base import Node, NodeImage, NodeSize
+from libcloud.types import NodeState
 
 from test import MockHttp, TestCaseMixin
 from test.file_fixtures import FileFixtures
@@ -46,7 +47,8 @@ class SoftLayerTests(unittest.TestCase):
 
     def test_list_nodes(self):
         node = self.driver.list_nodes()[0]
-        self.assertEqual(node.name, 'test')
+        self.assertEqual(node.name, 'test01')
+        self.assertEqual(node.state, NodeState.RUNNING)
 
     def test_list_locations(self):
         locations = self.driver.list_locations()



Mime
View raw message