Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passes filter tag as a parameter #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions havoc/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def run_daemon(havoc, log, run_every='5min'):
@click.option('--logfile', default='/var/log/havoc.log', help="Logging file when the application is in daemon mode")
@click.option('--dry-run', is_flag=True, help="If use, HAvOC will display the result and not change haproxy.cfg")
@click.option('--debug', is_flag=True, help="Debug mode")
@click.option('--filter-tag', default="pool", help="Filter tag")
def cli(**options):
"""HAvOC (HAproxy clOud Configuration)

Expand Down
7 changes: 4 additions & 3 deletions havoc/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ def __init__(self, ec2, nova, options, log):
self.options = options


def get_ec2_instances_in_pool(self, pool, suffix):
def get_ec2_instances_in_pool(self, pool, suffix, filter_tag):
self.log.debug("AWS EC2 : Trying to find vm in %s", pool)
instances = []
if self.ec2 is None:
self.log.debug('EC2 provider is not setup. No instances will be returned for this pool : %s', pool)
return instances


filters = {'tag:pool': pool,'instance-state-name': 'running'}
filters = {'tag:{}'.format(filter_tag): pool, 'instance-state-name': 'running'}

if self.options['aws_vpc'] is not None:
filters['tag:vpc'] = self.options['aws_vpc']
Expand Down Expand Up @@ -156,13 +156,14 @@ def reload_haproxy(self):
return False

def run(self):
filter_tag = self.options['filter_tag']
instances = {}

# Retrieve instances
for pool in self.options['pools'].split(','):
self.log.debug("POOL : %s", pool)
#TODO: Create CLI parameters for suffixes
ec2_instances = self.get_ec2_instances_in_pool(pool, "_aws")
ec2_instances = self.get_ec2_instances_in_pool(pool, "_aws", filter_tag)
os_instances = self.get_os_instances_in_pool(pool, "_os")
instances[pool] = ec2_instances + os_instances

Expand Down