libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject [1/4] git commit: Issue LIBCLOUD-471: Add ex_get_console_output method to the EC2 driver.
Date Thu, 26 Dec 2013 16:55:52 GMT
Updated Branches:
  refs/heads/trunk 5a68e0070 -> 166a11f6e


Issue LIBCLOUD-471: Add ex_get_console_output method to the EC2 driver.

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/f185e449
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/f185e449
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/f185e449

Branch: refs/heads/trunk
Commit: f185e4490d76768bc61c7ffc314aa434490c9a7f
Parents: 5a68e00
Author: Chris DeRamus <chris@divvycloud.com>
Authored: Thu Dec 26 08:34:05 2013 -0500
Committer: Tomaz Muraus <tomaz@apache.org>
Committed: Thu Dec 26 17:13:01 2013 +0100

----------------------------------------------------------------------
 libcloud/compute/drivers/ec2.py                 | 31 ++++++++++++++++++++
 .../compute/fixtures/ec2/get_console_output.xml |  6 ++++
 libcloud/test/compute/test_ec2.py               |  9 ++++++
 3 files changed, 46 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/f185e449/libcloud/compute/drivers/ec2.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/ec2.py b/libcloud/compute/drivers/ec2.py
index a13201e..4b389df 100644
--- a/libcloud/compute/drivers/ec2.py
+++ b/libcloud/compute/drivers/ec2.py
@@ -2689,6 +2689,37 @@ class BaseEC2NodeDriver(NodeDriver):
         res = self.connection.request(self.path, params=params).object
         return self._get_terminate_boolean(res)
 
+    def ex_get_console_output(self, node):
+        """
+        Get console output for the node. This returns a base64 decoded string
+
+        :param      node: Node which should be used
+        :type       node: :class:`Node`
+
+        :return:    Dictionary that contains the instance/node id, an
+                    ISO 8601 formatted datetime and base64 decoded
+                    console output for the node in question.
+        :rtype:     ``dict``
+        """
+        params = {
+            'Action': 'GetConsoleOutput',
+            'InstanceId': node.id
+        }
+
+        response = self.connection.request(self.path, params=params).object
+
+        timestamp = findattr(element=response,
+                             xpath='timestamp',
+                             namespace=NAMESPACE)
+
+        encoded_string = findattr(element=response,
+                                  xpath='output',
+                                  namespace=NAMESPACE)
+
+        return {'instance_id': node.id,
+                'timestamp': parse_date(timestamp),
+                'output': base64.b64decode(b(encoded_string))}
+
     def _get_common_security_group_params(self, group_id, protocol,
                                           from_port, to_port, cidr_ips,
                                           group_pairs):

http://git-wip-us.apache.org/repos/asf/libcloud/blob/f185e449/libcloud/test/compute/fixtures/ec2/get_console_output.xml
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/ec2/get_console_output.xml b/libcloud/test/compute/fixtures/ec2/get_console_output.xml
new file mode 100644
index 0000000..5d74cd6
--- /dev/null
+++ b/libcloud/test/compute/fixtures/ec2/get_console_output.xml
@@ -0,0 +1,6 @@
+<GetConsoleOutputResponse xmlns="http://ec2.amazonaws.com/doc/2013-10-15/">
+    <requestId>f0ffb5ce-8d62-4ab9-add7-67a0f99c9811</requestId>
+    <instanceId>i-40128925</instanceId>
+    <timestamp>2013-12-02T12:31:38.000Z</timestamp>
+    <output>VGVzdCBTdHJpbmc=</output>
+</GetConsoleOutputResponse>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/f185e449/libcloud/test/compute/test_ec2.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_ec2.py b/libcloud/test/compute/test_ec2.py
index 239b9ef..3a29793 100644
--- a/libcloud/test/compute/test_ec2.py
+++ b/libcloud/test/compute/test_ec2.py
@@ -839,6 +839,11 @@ class EC2Tests(LibcloudTestCase, TestCaseMixin):
         resp = self.driver.ex_delete_subnet(subnet=subnet)
         self.assertTrue(resp)
 
+    def test_ex_get_console_output(self):
+        node = self.driver.list_nodes()[0]
+        resp = self.driver.ex_get_console_output(node)
+        self.assertEqual('Test String', resp['output'])
+
 
 class EC2USWest1Tests(EC2Tests):
     region = 'us-west-1'
@@ -1146,6 +1151,10 @@ class EC2MockHttp(MockHttpTestCase):
         body = self.fixtures.load('delete_subnet.xml')
         return (httplib.OK, body, {}, httplib.responses[httplib.OK])
 
+    def _GetConsoleOutput(self, method, url, body, headers):
+        body = self.fixtures.load('get_console_output.xml')
+        return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
 
 class EucMockHttp(EC2MockHttp):
     fixtures = ComputeFileFixtures('ec2')


Mime
View raw message