@@ -177,25 +177,33 @@ def fetch_instance_details_from_config(
177177
178178
179179def get_instance_details (instance_id , ec2 = None ):
180- filters = [{ "Name" : "instance-id" , "Values" : [ instance_id ]} ]
180+ return get_multiple_instance_details ( instance_ids = [ instance_id ], ec2 = ec2 )[ 0 ]
181181
182+
183+ def get_multiple_instance_details (instance_ids , ec2 = None ):
182184 try :
183- ec2_instance = list (ec2 .instances .filter (Filters = filters ))[ 0 ]
185+ ec2_instances = list (ec2 .instances .filter (InstanceIds = instance_ids ))
184186 except botocore .exceptions .ClientError :
185187 raise AWSConnectionError
186188
187189 instance_name = None
188- for tag in ec2_instance .tags :
189- if tag ["Key" ] == "Name" :
190- instance_name = tag ["Value" ]
191-
192- return {
193- "instance_id" : instance_id ,
194- "instance_name" : instance_name ,
195- "availability_zone" : ec2_instance .placement ["AvailabilityZone" ],
196- "vpc_id" : ec2_instance .vpc_id ,
197- "private_ip_address" : ec2_instance .private_ip_address or None ,
198- "public_ip_addess" : ec2_instance .public_ip_address or None ,
199- "private_dns_name" : ec2_instance .private_dns_name or None ,
200- "public_dns_name" : ec2_instance .public_dns_name or None ,
201- }
190+ instance_details = []
191+ for ec2_instance in ec2_instances :
192+ for tag in ec2_instance .tags :
193+ if tag ["Key" ] == "Name" :
194+ instance_name = tag ["Value" ]
195+
196+ instance_details .append (
197+ {
198+ "instance_id" : ec2_instance .id ,
199+ "instance_name" : instance_name ,
200+ "availability_zone" : ec2_instance .placement ["AvailabilityZone" ],
201+ "vpc_id" : ec2_instance .vpc_id ,
202+ "private_ip_address" : ec2_instance .private_ip_address or None ,
203+ "public_ip_addess" : ec2_instance .public_ip_address or None ,
204+ "private_dns_name" : ec2_instance .private_dns_name or None ,
205+ "public_dns_name" : ec2_instance .public_dns_name or None ,
206+ }
207+ )
208+
209+ return instance_details
0 commit comments