From d651b4169133ed8ef17d63d0418f733061fc1a6d Mon Sep 17 00:00:00 2001 From: Robb Wagoner Date: Fri, 26 Jun 2015 15:39:08 -0700 Subject: [PATCH 1/2] return health of instances and counts --- cloud/amazon/ec2_elb_lb.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/cloud/amazon/ec2_elb_lb.py b/cloud/amazon/ec2_elb_lb.py index 566db2d329a..9d626a98194 100644 --- a/cloud/amazon/ec2_elb_lb.py +++ b/cloud/amazon/ec2_elb_lb.py @@ -384,9 +384,33 @@ class ElbManager(object): 'hosted_zone_name': check_elb.canonical_hosted_zone_name, 'hosted_zone_id': check_elb.canonical_hosted_zone_name_id, 'lb_cookie_policy': lb_cookie_policy, - 'app_cookie_policy': app_cookie_policy + 'app_cookie_policy': app_cookie_policy, + 'instances': [instance.id for instance in check_elb.instances], + 'out_of_service_count': 0, + 'in_service_count': 0, + 'unknown_instance_state_count': 0 } + # status of instances behind the ELB + if info['instances']: + info['instance_health'] = [ dict({ + "instance_id": instance_state.instance_id, + "reason_code": instance_state.reason_code, + "state": instance_state.state, + }) for instance_state in self.elb_conn.describe_instance_health(self.name)] + else: + info['instance_health'] = [] + + # instance state counts: InService or OutOfService + if info['instance_health']: + for instance_state in info['instance_health']: + if instance_state['state'] == "InService": + info['in_service_count'] += 1 + elif instance_state['state'] == "OutOfService": + info['out_of_service_count'] += 1 + else: + info['unknown_instance_state_count'] =+ 1 + if check_elb.health_check: info['health_check'] = { 'target': check_elb.health_check.target, From 8f0d462fd0e966fbb04e4fbcf4685a2fd600fee0 Mon Sep 17 00:00:00 2001 From: Robb Wagoner Date: Thu, 2 Jul 2015 06:16:43 -0700 Subject: [PATCH 2/2] remove double dict & fix increment bug --- cloud/amazon/ec2_elb_lb.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cloud/amazon/ec2_elb_lb.py b/cloud/amazon/ec2_elb_lb.py index 9d626a98194..04be9e2813c 100644 --- a/cloud/amazon/ec2_elb_lb.py +++ b/cloud/amazon/ec2_elb_lb.py @@ -393,11 +393,11 @@ class ElbManager(object): # status of instances behind the ELB if info['instances']: - info['instance_health'] = [ dict({ - "instance_id": instance_state.instance_id, - "reason_code": instance_state.reason_code, - "state": instance_state.state, - }) for instance_state in self.elb_conn.describe_instance_health(self.name)] + info['instance_health'] = [ dict( + instance_id = instance_state.instance_id, + reason_code = instance_state.reason_code, + state = instance_state.state + ) for instance_state in self.elb_conn.describe_instance_health(self.name)] else: info['instance_health'] = [] @@ -409,7 +409,7 @@ class ElbManager(object): elif instance_state['state'] == "OutOfService": info['out_of_service_count'] += 1 else: - info['unknown_instance_state_count'] =+ 1 + info['unknown_instance_state_count'] += 1 if check_elb.health_check: info['health_check'] = {