Use auto scaling group managed ELBs if present.
This commit is contained in:
parent
b0c534842b
commit
4b9b047878
1 changed files with 30 additions and 0 deletions
|
@ -105,6 +105,7 @@ import os
|
||||||
try:
|
try:
|
||||||
import boto
|
import boto
|
||||||
import boto.ec2
|
import boto.ec2
|
||||||
|
import boto.ec2.autoscale
|
||||||
import boto.ec2.elb
|
import boto.ec2.elb
|
||||||
from boto.regioninfo import RegionInfo
|
from boto.regioninfo import RegionInfo
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@ -255,6 +256,9 @@ class ElbManager:
|
||||||
for elb lookup instead of returning what elbs
|
for elb lookup instead of returning what elbs
|
||||||
are attached to self.instance_id"""
|
are attached to self.instance_id"""
|
||||||
|
|
||||||
|
if not ec2_elbs:
|
||||||
|
ec2_elbs = self._get_auto_scaling_group_lbs()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
elb = connect_to_aws(boto.ec2.elb, self.region,
|
elb = connect_to_aws(boto.ec2.elb, self.region,
|
||||||
**self.aws_connect_params)
|
**self.aws_connect_params)
|
||||||
|
@ -273,6 +277,32 @@ class ElbManager:
|
||||||
lbs.append(lb)
|
lbs.append(lb)
|
||||||
return lbs
|
return lbs
|
||||||
|
|
||||||
|
def _get_auto_scaling_group_lbs(self):
|
||||||
|
"""Returns a list of ELBs associated with self.instance_id
|
||||||
|
indirectly through its auto scaling group membership"""
|
||||||
|
|
||||||
|
try:
|
||||||
|
asg = connect_to_aws(boto.ec2.autoscale, self.region, **self.aws_connect_params)
|
||||||
|
except (boto.exception.NoAuthHandlerFound, StandardError), e:
|
||||||
|
self.module.fail_json(msg=str(e))
|
||||||
|
|
||||||
|
asg_instances = asg.get_all_autoscaling_instances([self.instance_id])
|
||||||
|
if len(asg_instances) > 1:
|
||||||
|
self.module.fail_json(msg="Illegal state, expected one auto scaling group instance.")
|
||||||
|
|
||||||
|
if not asg_instances:
|
||||||
|
asg_elbs = []
|
||||||
|
else:
|
||||||
|
asg_name = asg_instances[0].group_name
|
||||||
|
|
||||||
|
asgs = asg.get_all_groups([asg_name])
|
||||||
|
if len(asg_instances) != 1:
|
||||||
|
self.module.fail_json(msg="Illegal state, expected one auto scaling group.")
|
||||||
|
|
||||||
|
asg_elbs = asgs[0].load_balancers
|
||||||
|
|
||||||
|
return asg_elbs
|
||||||
|
|
||||||
def _get_instance(self):
|
def _get_instance(self):
|
||||||
"""Returns a boto.ec2.InstanceObject for self.instance_id"""
|
"""Returns a boto.ec2.InstanceObject for self.instance_id"""
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Add table
Reference in a new issue