libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject [1/2] libcloud git commit: Adding ex_terminate_on_shutdown to ec2 compute driver
Date Fri, 09 Oct 2015 17:22:56 GMT
Repository: libcloud
Updated Branches:
  refs/heads/trunk b3d6d9f38 -> 24adc1e89


Adding ex_terminate_on_shutdown to ec2 compute driver

To support termination of the instance if the OS shutdown
command is called

Closes #595

Signed-off-by: Tomaz Muraus <tomaz@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/317c4a34
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/317c4a34
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/317c4a34

Branch: refs/heads/trunk
Commit: 317c4a348adbf0c7aee38d425971378a22cdd1c7
Parents: b3d6d9f
Author: Kyle Long <uilwen@gmail.com>
Authored: Fri Oct 9 09:55:43 2015 -0500
Committer: Tomaz Muraus <tomaz@apache.org>
Committed: Fri Oct 9 18:01:18 2015 +0200

----------------------------------------------------------------------
 libcloud/compute/drivers/ec2.py   | 10 ++++++++++
 libcloud/test/compute/test_ec2.py | 20 ++++++++++++++++++++
 2 files changed, 30 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/317c4a34/libcloud/compute/drivers/ec2.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/ec2.py b/libcloud/compute/drivers/ec2.py
index dfeee7c..74c44b8 100644
--- a/libcloud/compute/drivers/ec2.py
+++ b/libcloud/compute/drivers/ec2.py
@@ -2321,6 +2321,13 @@ class BaseEC2NodeDriver(NodeDriver):
                                          node returned will NOT have
                                          the public ip assigned yet.
         :type       ex_assign_public_ip: ``bool``
+
+        :keyword    ex_terminate_on_shutdown: Indicates if the instance
+                                              should be terminated instead
+                                              of just shut down when using
+                                              the operating systems command
+                                              for system shutdown.
+        :type       ex_terminate_on_shutdown: ``bool``
         """
         image = kwargs["image"]
         size = kwargs["size"]
@@ -2332,6 +2339,9 @@ class BaseEC2NodeDriver(NodeDriver):
             'InstanceType': size.id
         }
 
+        if kwargs.get("ex_terminate_on_shutdown", False):
+            params["InstanceInitiatedShutdownBehavior"] = "terminate"
+
         if 'ex_security_groups' in kwargs and 'ex_securitygroup' in kwargs:
             raise ValueError('You can only supply ex_security_groups or'
                              ' ex_securitygroup')

http://git-wip-us.apache.org/repos/asf/libcloud/blob/317c4a34/libcloud/test/compute/test_ec2.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_ec2.py b/libcloud/test/compute/test_ec2.py
index a1ff899..3f74cec 100644
--- a/libcloud/test/compute/test_ec2.py
+++ b/libcloud/test/compute/test_ec2.py
@@ -136,6 +136,18 @@ class EC2Tests(LibcloudTestCase, TestCaseMixin):
             ex_assign_public_ip=True,
         )
 
+    def test_create_node_with_ex_terminate_on_shutdown(self):
+        EC2MockHttp.type = 'create_ex_terminate_on_shutdown'
+        image = NodeImage(id='ami-be3adfd7',
+                          name=self.image_name,
+                          driver=self.driver)
+        size = NodeSize('m1.small', 'Small Instance', None, None, None, None,
+                        driver=self.driver)
+
+        # The important part about the test is asserted inside
+        # EC2MockHttp._create_ex_terminate_on_shutdown
+        self.driver.create_node(name='foo', image=image, size=size, ex_terminate_on_shutdown=True)
+
     def test_create_node_with_metadata(self):
         image = NodeImage(id='ami-be3adfd7',
                           name=self.image_name,
@@ -1276,6 +1288,14 @@ class EC2MockHttp(MockHttpTestCase):
         body = self.fixtures.load('run_instances_with_subnet_and_security_group.xml')
         return (httplib.OK, body, {}, httplib.responses[httplib.OK])
 
+    def _create_ex_terminate_on_shutdown_RunInstances(self, method, url, body, headers):
+        self.assertUrlContainsQueryParams(url, {
+            'InstanceInitiatedShutdownBehavior': 'terminate'
+        })
+
+        body = self.fixtures.load('run_instances.xml')
+        return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
     def _ex_security_groups_RunInstances(self, method, url, body, headers):
         self.assertUrlContainsQueryParams(url, {'SecurityGroup.1': 'group1'})
         self.assertUrlContainsQueryParams(url, {'SecurityGroup.2': 'group2'})


Mime
View raw message