You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by to...@apache.org on 2011/03/22 14:51:41 UTC
svn commit: r1084180 - in /incubator/libcloud/trunk:
libcloud/compute/drivers/ec2.py
test/compute/fixtures/ec2/modify_instance_attribute.xml
test/compute/test_ec2.py
Author: tomaz
Date: Tue Mar 22 13:51:41 2011
New Revision: 1084180
URL: http://svn.apache.org/viewvc?rev=1084180&view=rev
Log:
Add extension method for modifying instance attributes and change the node size.
Added:
incubator/libcloud/trunk/test/compute/fixtures/ec2/modify_instance_attribute.xml
Modified:
incubator/libcloud/trunk/libcloud/compute/drivers/ec2.py
incubator/libcloud/trunk/test/compute/test_ec2.py
Modified: incubator/libcloud/trunk/libcloud/compute/drivers/ec2.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/libcloud/compute/drivers/ec2.py?rev=1084180&r1=1084179&r2=1084180&view=diff
==============================================================================
--- incubator/libcloud/trunk/libcloud/compute/drivers/ec2.py (original)
+++ incubator/libcloud/trunk/libcloud/compute/drivers/ec2.py Tue Mar 22 13:51:41 2011
@@ -699,6 +699,28 @@ class EC2NodeDriver(NodeDriver):
node_elastic_ips = self.ex_describe_addresses([node])
return node_elastic_ips[node.id]
+ def ex_modify_instance_attribute(self, node, attributes):
+ attributes = attributes or {}
+ attributes.update({'InstanceId': node.id})
+
+ params = { 'Action': 'ModifyInstanceAttribute' }
+ params.update(attributes)
+
+ result = self.connection.request(self.path,
+ params=params.copy()).object
+ element = self._findtext(result, 'return')
+ return element == 'true'
+
+ def ex_change_node_size(self, node, new_size):
+ if 'instancetype' in node.extra:
+ current_instance_type = node.extra['instancetype']
+
+ if current_instance_type == new_size.id:
+ raise ValueError('New instance size is the same as the current one')
+
+ attributes = { 'InstanceType.Value': new_size.id }
+ return self.ex_modify_instance_attribute(node, attributes)
+
def create_node(self, **kwargs):
"""Create a new EC2 node
Added: incubator/libcloud/trunk/test/compute/fixtures/ec2/modify_instance_attribute.xml
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/test/compute/fixtures/ec2/modify_instance_attribute.xml?rev=1084180&view=auto
==============================================================================
--- incubator/libcloud/trunk/test/compute/fixtures/ec2/modify_instance_attribute.xml (added)
+++ incubator/libcloud/trunk/test/compute/fixtures/ec2/modify_instance_attribute.xml Tue Mar 22 13:51:41 2011
@@ -0,0 +1,4 @@
+<ModifyInstanceAttributeResponse xmlns="http://ec2.amazonaws.com/doc/2010-08-31/">
+ <requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
+ <return>true</return>
+</ModifyInstanceAttributeResponse>
Modified: incubator/libcloud/trunk/test/compute/test_ec2.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/test/compute/test_ec2.py?rev=1084180&r1=1084179&r2=1084180&view=diff
==============================================================================
--- incubator/libcloud/trunk/test/compute/test_ec2.py (original)
+++ incubator/libcloud/trunk/test/compute/test_ec2.py Tue Mar 22 13:51:41 2011
@@ -208,6 +208,25 @@ class EC2Tests(unittest.TestCase, TestCa
self.assertTrue(node2.id in nodes_elastic_ips2)
self.assertEqual(nodes_elastic_ips2[node2.id], [])
+ def test_ex_change_node_size_same_size(self):
+ size = NodeSize('m1.small', 'Small Instance', None, None, None, None, driver=self.driver)
+ node = Node('i-4382922a', None, None, None, None, self.driver,
+ extra={'instancetype': 'm1.small'})
+
+ try:
+ self.driver.ex_change_node_size(node=node, new_size=size)
+ except ValueError:
+ pass
+ else:
+ self.fail('Same size was passed, but an exception was not thrown')
+
+ def test_ex_change_node_size(self):
+ size = NodeSize('m1.large', 'Small Instance', None, None, None, None, driver=self.driver)
+ node = Node('i-4382922a', None, None, None, None, self.driver,
+ extra={'instancetype': 'm1.small'})
+
+ result = self.driver.ex_change_node_size(node=node, new_size=size)
+ self.assertTrue(result)
class EC2MockHttp(MockHttp):
@@ -261,6 +280,9 @@ class EC2MockHttp(MockHttp):
body = self.fixtures.load('describe_addresses_multi.xml')
return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+ def _ModifyInstanceAttribute(self, method, url, body, headers):
+ body = self.fixtures.load('modify_instance_attribute.xml')
+ return (httplib.OK, body, {}, httplib.responses[httplib.OK])
class EC2APSETests(EC2Tests):
def setUp(self):