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 2011/01/03 22:27:14 UTC

svn commit: r1054760 - /incubator/libcloud/trunk/libcloud/drivers/rackspace.py

Author: pquerna
Date: Mon Jan  3 21:27:14 2011
New Revision: 1054760

URL: http://svn.apache.org/viewvc?rev=1054760&view=rev
Log:
Add ex_set_password and ex_set_server_name to Rackspace driver.

Submitted by: Peter Herndon
Based on: https://github.com/tpherndon/libcloud/commit/c18efa96343148462f03095943b06d09142a907f

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

Modified: incubator/libcloud/trunk/libcloud/drivers/rackspace.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/libcloud/drivers/rackspace.py?rev=1054760&r1=1054759&r2=1054760&view=diff
==============================================================================
--- incubator/libcloud/trunk/libcloud/drivers/rackspace.py (original)
+++ incubator/libcloud/trunk/libcloud/drivers/rackspace.py Mon Jan  3 21:27:14 2011
@@ -231,6 +231,46 @@ class RackspaceNodeDriver(NodeDriver):
         """
         return [NodeLocation(0, "Rackspace DFW1/ORD1", 'US', self)]
 
+    def _change_password_or_name(self, node, name=None, password=None):
+        uri = '/servers/%s' % (node.id)
+
+        if not name:
+            name = node.name
+
+        body = { 'xmlns': NAMESPACE,
+                 'name': name}
+
+        if password != None:
+            body['adminPass'] = password
+
+        server_elm = ET.Element('server', body)
+
+        resp = self.connection.request(uri, method='PUT', data=ET.tostring(server_elm))
+
+        if resp.status == 204 and password != None:
+            node.extra['password'] = password
+
+        return resp.status == 204
+
+    def ex_set_password(self, node, password):
+        """
+        Sets the Node's root password.
+
+        This will reboot the instance to complete the operation.
+
+        L{node.extra['password']} will be set to the new value if the
+        operation was successful.
+        """
+        return self._change_password_or_name(node, password=password)
+
+    def ex_set_server_name(self, node, name):
+        """
+        Sets the Node's name.
+
+        This will reboot the instance to complete the operation.
+        """
+        return self._change_password_or_name(node, name=name)
+
     def create_node(self, **kwargs):
         """Create a new rackspace node