diff --git a/moto/ec2/models.py b/moto/ec2/models.py index 91b98cca6..63f0a3123 100644 --- a/moto/ec2/models.py +++ b/moto/ec2/models.py @@ -542,6 +542,14 @@ class InstanceBackend(object): instances.append(instance) return instances + def all_running_instances(self): + instances = [] + for reservation in self.all_reservations(): + for instance in reservation.instances: + if instance.state_code == 16: + instances.append(instance) + return instances + def get_multi_instances_by_id(self, instance_ids): """ :param instance_ids: A string list with instance ids diff --git a/moto/ec2/responses/instances.py b/moto/ec2/responses/instances.py index 49050f9d6..b1ccc7e12 100644 --- a/moto/ec2/responses/instances.py +++ b/moto/ec2/responses/instances.py @@ -4,7 +4,7 @@ from jinja2 import Template from moto.core.responses import BaseResponse from moto.core.utils import camelcase_to_underscores from moto.ec2.utils import instance_ids_from_querystring, filters_from_querystring, filter_reservations, \ - dict_from_querystring + dict_from_querystring, optional_from_querystring class InstanceResponse(BaseResponse): @@ -69,11 +69,15 @@ class InstanceResponse(BaseResponse): def describe_instance_status(self): instance_ids = instance_ids_from_querystring(self.querystring) + include_all_instances = optional_from_querystring('IncludeAllInstances', + self.querystring) == 'true' if instance_ids: instances = self.ec2_backend.get_multi_instances_by_id(instance_ids) - else: + elif include_all_instances: instances = self.ec2_backend.all_instances() + else: + instances = self.ec2_backend.all_running_instances() template = Template(EC2_INSTANCE_STATUS) return template.render(instances=instances) @@ -512,27 +516,36 @@ EC2_INSTANCE_STATUS = """ {{ instance.id }} us-east-1d - 16 - running + {{ instance.state_code }} + {{ instance.state }} - - ok -
- - reachability - passed - -
-
- - ok -
- - reachability - passed - -
-
+ {% if instance.state_code == 16 %} + + ok +
+ + reachability + passed + +
+
+ + ok +
+ + reachability + passed + +
+
+ {% else %} + + not-applicable + + + not-applicable + + {% endif %} {% endfor %}