Created
January 26, 2016 07:44
-
-
Save jerm/e8539d29102b426a4299 to your computer and use it in GitHub Desktop.
function to return names and/or ips of instances connected to an aws ELB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_elb_member_info(load_balancers): | |
""" Takes an ELB (Elastic Load balancer) name or list of ELB namess and | |
returns a dict of: | |
ips: a list containing the private ip address of each instance | |
names: a list containing the tag_Name of each instancee | |
""" | |
import boto | |
elbs = boto.connect_elb().get_all_load_balancers(load_balancers) | |
instance_infos = [] | |
for elb in elbs: | |
instance_infos += elb.instances | |
reservations = boto.connect_ec2().get_all_instances( | |
instance_ids=[instance.id for instance in instance_infos]) | |
instance_names = [i.tags['Name'] for r in reservations | |
for i in r.instances] | |
instance_ips = [i.private_ip_address for r in reservations | |
for i in r.instances] | |
return {"names": instance_names, "ips": instance_ips} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment