Changeset - b5c336276772
[Not reviewed]
feature-cli
0 1 0
Dennis Fink - 9 years ago 2015-10-25 22:13:47
dennis.fink@c3l.lu
Added hosts count
1 file changed with 23 insertions and 0 deletions:
0 comments (0 inline, 0 general)
ennstatus/cli/commands/stats.py
Show inline comments
 
@@ -18,6 +18,20 @@ def stats():
 
@click.pass_obj
 
def count(obj, by_type):
 

	
 

	
 
    def calculate_host_number(config, type='all'):
 

	
 
        if type == 'all':
 

	
 
            hosts = set()
 

	
 
            for values in config['ENNSTATUS_SERVERS'].values():
 
                ips = frozenset(values['IPS'])
 
                hosts.add(ips)
 

	
 
            return len(hosts)
 

	
 

	
 
    app = create_app()
 

	
 
    with app.app_context():
 
@@ -35,6 +49,15 @@ def count(obj, by_type):
 
            )
 
        )
 

	
 
        click.echo(
 
            'We have %s different hosts!' % (
 
                click.style(
 
                    str(calculate_host_number(app.config)),
 
                    fg='blue'
 
                )
 
            )
 
        )
 

	
 

	
 
@stats.command('countries')
 
@click.option('--by-type', 'by_type', is_flag=True, default=False)
0 comments (0 inline, 0 general)