Skip to content

Conversation

rohanagrawal-amex
Copy link

Feature add for issue 17

Type of Change

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

def get_all_elbs(region=None):
if not region:
region = config.REGIONS
data = ""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please initialize the variable with the correct variable type. This should probably be data = []

data = ""
for region in config.REGIONS:
client = boto3.client("elb", region_name=region)
data = client.describe_load_balancers()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You overwrite data in every iteration of the loop. This way you will always only get the ELBs from the last region in the list. You need to append the ELBs from a region onto the list and return the final list in the end

flags.append(crayons.yellow(" Not used"))

for elb in not_used:
if len(flags) > 0:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You use one global flags array for all ELBs. How should this work when you have more than one ELB ?


response = get_all_elbs()
for ELB in response['LoadBalancerDescriptions']:
if len(ELB['Instances']) == 0:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stuff like this should already be done in the helper function. get_all_elbs should just return a list of all ELBs where you don't need to do any more checks or processing of the data

if id not in used_groups:
not_used.append(group)
if len(elb_sg) > 0:
if id not in elb_sg:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have a used_groups array with all SGs that are in use by anything. Just append the list of your SGs from the ELBs to this list and then you don't need to modify this part of the code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants