From 0d513496620880517aa27d0b5ee1e306f7d06ad7 Mon Sep 17 00:00:00 2001 From: Steve Pulec Date: Tue, 5 Mar 2013 22:11:58 -0500 Subject: [PATCH] add get_console_output --- moto/ec2/responses/general.py | 30 ++++++++++++++++++++++++++++-- tests/test_ec2/test_general.py | 16 ++++++++++++++-- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/moto/ec2/responses/general.py b/moto/ec2/responses/general.py index 8c4eba053..ad133a30c 100644 --- a/moto/ec2/responses/general.py +++ b/moto/ec2/responses/general.py @@ -1,9 +1,35 @@ from jinja2 import Template from moto.ec2.models import ec2_backend -from moto.ec2.utils import resource_ids_from_querystring +from moto.ec2.utils import instance_ids_from_querystring class General(object): + def __init__(self, querystring): + self.querystring = querystring + self.instance_ids = instance_ids_from_querystring(querystring) + def get_console_output(self): - raise NotImplementedError('General.get_console_output is not yet implemented') + instance_id = self.instance_ids[0] + instance = ec2_backend.get_instance(instance_id) + if instance: + template = Template(GET_CONSOLE_OUTPUT_RESULT) + return template.render(instance=instance) + else: + return "", dict(status=404) + + +GET_CONSOLE_OUTPUT_RESULT = ''' + + 59dbff89-35bd-4eac-99ed-be587EXAMPLE + {{ instance.id }} + 2010-10-14T01:12:41.000Z + TGludXggdmVyc2lvbiAyLjYuMTYteGVuVSAoYnVpbGRlckBwYXRjaGJhdC5hbWF6b25zYSkgKGdj +YyB2ZXJzaW9uIDQuMC4xIDIwMDUwNzI3IChSZWQgSGF0IDQuMC4xLTUpKSAjMSBTTVAgVGh1IE9j +dCAyNiAwODo0MToyNiBTQVNUIDIwMDYKQklPUy1wcm92aWRlZCBwaHlzaWNhbCBSQU0gbWFwOgpY +ZW46IDAwMDAwMDAwMDAwMDAwMDAgLSAwMDAwMDAwMDZhNDAwMDAwICh1c2FibGUpCjk4ME1CIEhJ +R0hNRU0gYXZhaWxhYmxlLgo3MjdNQiBMT1dNRU0gYXZhaWxhYmxlLgpOWCAoRXhlY3V0ZSBEaXNh +YmxlKSBwcm90ZWN0aW9uOiBhY3RpdmUKSVJRIGxvY2t1cCBkZXRlY3Rpb24gZGlzYWJsZWQKQnVp +bHQgMSB6b25lbGlzdHMKS2VybmVsIGNvbW1hbmQgbGluZTogcm9vdD0vZGV2L3NkYTEgcm8gNApF +bmFibGluZyBmYXN0IEZQVSBzYXZlIGFuZCByZXN0b3JlLi4uIGRvbmUuCg== +''' diff --git a/tests/test_ec2/test_general.py b/tests/test_ec2/test_general.py index 031bd2c1c..f8314a848 100644 --- a/tests/test_ec2/test_general.py +++ b/tests/test_ec2/test_general.py @@ -1,9 +1,21 @@ import boto +from boto.exception import EC2ResponseError import sure # flake8: noqa from moto import mock_ec2 @mock_ec2 -def test_general(): - pass +def test_console_output(): + conn = boto.connect_ec2('the_key', 'the_secret') + reservation = conn.run_instances('ami-1234abcd') + instance_id = reservation.instances[0].id + + output = conn.get_console_output(instance_id) + output.output.should_not.equal(None) + + +@mock_ec2 +def test_console_output_without_instance(): + conn = boto.connect_ec2('the_key', 'the_secret') + conn.get_console_output.when.called_with('i-1234abcd').should.throw(Exception)